Skip to content

Commit

Permalink
Merge branch 'develop' into cctx-validate-inbound
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito authored Jun 20, 2024
2 parents 7f3bf86 + ca9b90f commit e835137
Show file tree
Hide file tree
Showing 92 changed files with 1,432 additions and 1,235 deletions.
5 changes: 3 additions & 2 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ RUN mkdir -p /root/.zetacored/cosmovisor/genesis/bin && \
ENV PATH /root/.zetacored/cosmovisor/current/bin/:/root/.zetaclientd/upgrades/current/:${PATH}

COPY contrib/localnet/scripts /root
COPY contrib/localnet/ssh_config /root/.ssh/config
COPY contrib/localnet/ssh_config /etc/ssh/ssh_config.d/localnet.conf
COPY contrib/localnet/zetacored /root/zetacored

RUN chmod 755 /root/*.sh
RUN chmod 755 /root/*.sh && \
chmod 644 /etc/ssh/ssh_config.d/localnet.conf

WORKDIR /usr/local/bin
EXPOSE 22
Expand Down
115 changes: 58 additions & 57 deletions changelog.md

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions cmd/zetaclientd/gen_pre_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/binance-chain/tss-lib/ecdsa/keygen"
"github.com/spf13/cobra"
)

func init() {
RootCmd.AddCommand(GenPrePramsCmd)
}

var GenPrePramsCmd = &cobra.Command{
Use: "gen-pre-params <path>",
Short: "Generate pre parameters for TSS",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
startTime := time.Now()
preParams, err := keygen.GeneratePreParams(time.Second * 300)
if err != nil {
return err
}

file, err := os.OpenFile(args[0], os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
}
defer file.Close()
err = json.NewEncoder(file).Encode(preParams)
if err != nil {
return err
}
fmt.Printf("Generated new pre-parameters in %v\n", time.Since(startTime))
return nil
},
}
32 changes: 19 additions & 13 deletions cmd/zetacored/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"os"
"testing"

"github.com/cometbft/cometbft/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/testutil/sample"
)

func TestParsefileToObserverMapper(t *testing.T) {
Expand All @@ -20,31 +19,38 @@ func TestParsefileToObserverMapper(t *testing.T) {
require.NoError(t, err)
}(t, file)
app.SetConfig()
createObserverList(file)

observerAddress := sample.AccAddress()
commonGrantAddress := sample.AccAddress()
validatorAddress := sample.AccAddress()

createObserverList(file, observerAddress, commonGrantAddress, validatorAddress)
obsListReadFromFile, err := ParsefileToObserverDetails(file)
require.NoError(t, err)
for _, obs := range obsListReadFromFile {
require.Equal(
t,
obs.ObserverAddress,
observerAddress,
)
require.Equal(
t,
obs.ZetaClientGranteeAddress,
sdk.AccAddress(crypto.AddressHash([]byte("ObserverGranteeAddress"))).String(),
commonGrantAddress,
)
}
}

func createObserverList(fp string) {
func createObserverList(fp string, observerAddress, commonGrantAddress, validatorAddress string) {
var listReader []ObserverInfoReader
commonGrantAddress := sdk.AccAddress(crypto.AddressHash([]byte("ObserverGranteeAddress")))
observerAddress := sdk.AccAddress(crypto.AddressHash([]byte("ObserverAddress")))
validatorAddress := sdk.ValAddress(crypto.AddressHash([]byte("ValidatorAddress")))
info := ObserverInfoReader{
ObserverAddress: observerAddress.String(),
ZetaClientGranteeAddress: commonGrantAddress.String(),
StakingGranteeAddress: commonGrantAddress.String(),
ObserverAddress: observerAddress,
ZetaClientGranteeAddress: commonGrantAddress,
StakingGranteeAddress: commonGrantAddress,
StakingMaxTokens: "100000000",
StakingValidatorAllowList: []string{validatorAddress.String()},
StakingValidatorAllowList: []string{validatorAddress},
SpendMaxTokens: "100000000",
GovGranteeAddress: commonGrantAddress.String(),
GovGranteeAddress: commonGrantAddress,
ZetaClientGranteePubKey: "zetapub1addwnpepqggtjvkmj6apcqr6ynyc5edxf2mpf5fxp2d3kwupemxtfwvg6gm7qv79fw0",
}
listReader = append(listReader, info)
Expand Down
9 changes: 1 addition & 8 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
// set account prefix to zeta
setCosmosConfig()

// wait for Genesis
// if setup is skip, we assume that the genesis is already created
if !skipSetup {
logger.Print("⏳ wait 70s for genesis")
time.Sleep(70 * time.Second)
}

zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{utils.FungibleAdminName},
Expand Down Expand Up @@ -399,7 +392,7 @@ func waitKeygenHeight(
logger *runner.Logger,
) {
// wait for keygen to be completed
keygenHeight := int64(60)
keygenHeight := int64(35)
logger.Print("⏳ wait height %v for keygen to be completed", keygenHeight)
for {
time.Sleep(2 * time.Second)
Expand Down
19 changes: 16 additions & 3 deletions contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ services:
- "26657:26657"
- "6060:6060"
- "9090:9090"
healthcheck:
# use the zevm endpoint for the healthcheck as it is the slowest to come up
test: ["CMD", "curl", "-f", "-X", "POST", "--data", '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}', "-H", "Content-Type: application/json", "http://localhost:8545"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
start_interval: 1s
networks:
mynetwork:
ipv4_address: 172.20.0.11
Expand Down Expand Up @@ -78,6 +86,7 @@ services:
- HOTKEY_PASSWORD=password # test purposes only
volumes:
- ssh:/root/.ssh
- preparams:/root/preparams

zetaclient1:
image: zetanode:latest
Expand All @@ -93,6 +102,7 @@ services:
- HOTKEY_PASSWORD=password # test purposes only
volumes:
- ssh:/root/.ssh
- preparams:/root/preparams

eth:
image: ethereum/client-go:v1.10.26
Expand Down Expand Up @@ -127,8 +137,10 @@ services:
tty: true
container_name: orchestrator
depends_on:
- zetacore0
- eth
zetacore0:
condition: service_healthy
eth:
condition: service_started
hostname: orchestrator
networks:
mynetwork:
Expand All @@ -137,4 +149,5 @@ services:
volumes:
- ssh:/root/.ssh
volumes:
ssh:
ssh:
preparams:
13 changes: 10 additions & 3 deletions contrib/localnet/scripts/start-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ set_sepolia_endpoint() {
jq '.EVMChainConfigs."11155111".Endpoint = "http://eth2:8545"' /root/.zetacored/config/zetaclient_config.json > tmp.json && mv tmp.json /root/.zetacored/config/zetaclient_config.json
}

# generate pre-params as early as possible
# to reach keygen height on schedule
PREPARAMS_PATH="/root/preparams/${HOSTNAME}.json"
if [ ! -f "$PREPARAMS_PATH" ]; then
zetaclientd gen-pre-params "$PREPARAMS_PATH"
fi

# Wait for authorized_keys file to exist (generated by zetacore0)
while [ ! -f ~/.ssh/authorized_keys ]; do
echo "Waiting for authorized_keys file to exist..."
Expand Down Expand Up @@ -42,7 +49,7 @@ echo "Start zetaclientd"
if [[ $HOSTNAME == "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]]
then
MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --keyring-backend "$BACKEND"
zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --keyring-backend "$BACKEND" --pre-params "$PREPARAMS_PATH"

# check if the option is additional-evm
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
Expand All @@ -59,9 +66,9 @@ then
SEED=""
while [ -z "$SEED" ]
do
SEED=$(curl --retry 10 --retry-delay 5 --retry-connrefused -s zetaclient0:8123/p2p)
SEED=$(curl --retry 30 --retry-delay 1 --max-time 1 --retry-connrefused -s zetaclient0:8123/p2p)
done
zetaclientd init --peer "/ip4/172.20.0.21/tcp/6668/p2p/${SEED}" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 1 --keyring-backend "$BACKEND"
zetaclientd init --peer "/ip4/172.20.0.21/tcp/6668/p2p/${SEED}" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 1 --keyring-backend "$BACKEND" --pre-params "$PREPARAMS_PATH"

# check if the option is additional-evm
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
Expand Down
2 changes: 1 addition & 1 deletion contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ then

# 2. Add the observers, authorizations, required params and accounts to the genesis.json
zetacored collect-observer-info
zetacored add-observer-list --keygen-block 55
zetacored add-observer-list --keygen-block 25

# Check for the existence of "AddToOutTxTracker" string in the genesis file
# If this message is found in the genesis, it means add-observer-list has been run with the v16 binary for upgrade tests
Expand Down
4 changes: 1 addition & 3 deletions contrib/localnet/ssh_config
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

Host *
StrictHostKeyChecking no
IdentityFile ~/.ssh/localtest.pem
StrictHostKeyChecking no
2 changes: 1 addition & 1 deletion rpc/backend/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions testutil/keeper/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func AuthorityKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
return &k, ctx
}

// MockIsAuthorized mocks the IsAuthorized method of an authority keeper mock
func MockIsAuthorized(m *mock.Mock, address string, policyType types.PolicyType, isAuthorized bool) {
m.On("IsAuthorized", mock.Anything, address, policyType).Return(isAuthorized).Once()
// MockCheckAuthorization mocks the CheckAuthorization method of the authority keeper.
func MockCheckAuthorization(m *mock.Mock, msg sdk.Msg, authorizationResult error) {
m.On("CheckAuthorization", mock.Anything, msg).Return(authorizationResult).Once()
}

func SetAdminPolicies(ctx sdk.Context, ak *keeper.Keeper) string {
Expand Down
17 changes: 8 additions & 9 deletions testutil/keeper/mocks/crosschain/authority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions testutil/keeper/mocks/fungible/authority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions testutil/keeper/mocks/lightclient/authority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e835137

Please sign in to comment.