Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Jun 21, 2024
2 parents a25028d + e6287e2 commit cd0626a
Show file tree
Hide file tree
Showing 128 changed files with 2,145 additions and 1,789 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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,13 @@ start-upgrade-test-light: zetanode-upgrade
@echo "--> Starting light upgrade test (no ZetaChain state populating before upgrade)"
cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-upgrade.yml -f docker-compose-upgrade-light.yml up -d

start-localnet: zetanode
start-localnet: zetanode start-localnet-skip-build

start-localnet-skip-build:
@echo "--> Starting localnet"
cd contrib/localnet/ && $(DOCKER) compose -f docker-compose.yml -f docker-compose-setup-only.yml up -d

stop-localnet:
start-e2e-import-mainnet-test: zetanode
@echo "--> Starting e2e import-data test"
cd contrib/localnet/ && ./scripts/import-data.sh mainnet && $(DOCKER) compose -f docker-compose.yml -f docker-compose-import-data.yml up -d
Expand Down
9 changes: 0 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ import (

"github.com/zeta-chain/zetacore/app/ante"
"github.com/zeta-chain/zetacore/docs/openapi"
"github.com/zeta-chain/zetacore/pkg/chains"
zetamempool "github.com/zeta-chain/zetacore/pkg/mempool"
srvflags "github.com/zeta-chain/zetacore/server/flags"
authoritymodule "github.com/zeta-chain/zetacore/x/authority"
Expand Down Expand Up @@ -598,14 +597,6 @@ func New(
app.LightclientKeeper,
)

// initializing map of cctx gateways so crosschain module can decide which one to use
// based on chain info of destination chain
cctxGateways := map[chains.CCTXGateway]crosschainkeeper.CCTXGateway{
chains.CCTXGateway_observers: crosschainkeeper.NewCCTXGatewayObservers(app.CrosschainKeeper),
chains.CCTXGateway_zevm: crosschainkeeper.NewCCTXGatewayZEVM(app.CrosschainKeeper),
}
app.CrosschainKeeper.SetCCTXGateways(cctxGateways)

// initialize ibccrosschain keeper and set it to the crosschain keeper
// there is a circular dependency between the two keepers, crosschain keeper must be initialized first

Expand Down
119 changes: 61 additions & 58 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
12 changes: 4 additions & 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 @@ -289,6 +282,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestMessagePassingEVMtoZEVMRevertFailName,
}
bitcoinTests := []string{
e2etests.TestBitcoinDepositName,
e2etests.TestBitcoinDepositRefundName,
e2etests.TestBitcoinWithdrawSegWitName,
e2etests.TestBitcoinWithdrawInvalidAddressName,
e2etests.TestZetaWithdrawBTCRevertName,
Expand All @@ -297,6 +292,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
bitcoinAdvancedTests := []string{
e2etests.TestBitcoinWithdrawTaprootName,
e2etests.TestBitcoinWithdrawLegacyName,
e2etests.TestBitcoinWithdrawMultipleName,
e2etests.TestBitcoinWithdrawP2SHName,
e2etests.TestBitcoinWithdrawP2WSHName,
e2etests.TestBitcoinWithdrawRestrictedName,
Expand Down Expand Up @@ -396,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
23 changes: 19 additions & 4 deletions cmd/zetae2e/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"os"
"sort"
"sync"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -223,11 +224,25 @@ func StressTest(cmd *cobra.Command, _ []string) {
fmt.Println(" 1. Periodically Withdraw ETH from ZEVM to EVM")
fmt.Println(" 2. Display Network metrics to monitor performance [Num Pending outbound tx], [Num Trackers]")

e2eTest.WG.Add(2)
go WithdrawCCtx(e2eTest) // Withdraw from ZEVM to EVM
go EchoNetworkMetrics(e2eTest) // Display Network metrics periodically to monitor performance
var wg sync.WaitGroup

e2eTest.WG.Wait()
wg.Add(2)

go func() {
defer wg.Done()

// Withdraw from ZEVM to EVM
WithdrawCCtx(e2eTest)
}()

go func() {
defer wg.Done()

// Display Network metrics periodically to monitor performance
EchoNetworkMetrics(e2eTest)
}()

wg.Wait()
}

// WithdrawCCtx withdraw ETHZRC20 from ZEVM to EVM
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 @@ -51,7 +58,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 @@ -68,9 +75,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 @@ -192,7 +192,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 docs/development/LOCAL_TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $ docker logs -f orchestrator

To stop the tests,
```bash
make stop-test
make stop-localnet
```

### Run monitoring setup
Expand Down
20 changes: 20 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,23 @@ zeta_chain_id: "zetachain-1"
```
NOTE: config is in progress, contracts on the zEVM must be added
## Debugging
It's possible to debug a single test using Delve debugger.
1. Make sure delve is installed. `go install github.com/go-delve/delve/cmd/dlv@latest`
2. Configure your IDE to use Delve as the debugger. For Goland, you can do the following:
- Go to "Run" > "Edit Run Configurations"
- Hit "+" > "Go Remote". Keep port as default (`2345`). Toggle "On Disconnect" > "Stop Delve process"
3. Make sure that localnet is running. For a quick start, you can use `make start-localnet-skip-build`.
Networks need some time to generate blocks.
4. Run test as following: `./e2e/scripts/debug.sh my_test_name arg1 arg2 arg_n`.
Example: `./e2e/scripts/debug.sh bitcoin_withdraw_restricted 0.001`
5. Place a breakpoint in the code.
6. Go to the editor's debug panel and hit "Debug" button.

You can also run an alias of `zetae2e run` like so:
```shell
`./e2e/scripts/run.sh bitcoin_withdraw_restricted 0.001`
```
Loading

0 comments on commit cd0626a

Please sign in to comment.