Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(zetaclient)!: improve AppContext #2568

Merged
merged 28 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
daf4b6c
Implement chain registry
swift1337 Jul 25, 2024
f24d05a
Rewrite test-cases for AppContext
swift1337 Jul 26, 2024
0474abd
Drop `supplychecker`
swift1337 Jul 26, 2024
3d6e05f
Refactor app ctx Update worker
swift1337 Jul 29, 2024
fc39f4e
Refactor orchestrator
swift1337 Jul 29, 2024
782cef3
Refactor observer&signer; DROP postBlockHeaders
swift1337 Jul 29, 2024
031e7e0
Fix test cases [1]
swift1337 Jul 29, 2024
09478d6
Update changelog
swift1337 Jul 29, 2024
2d6e312
Allow Zeta Chain in appContext; address PR comments [1]
swift1337 Jul 30, 2024
487d7e1
Fix app context update
swift1337 Jul 30, 2024
5c63646
Check for `chain.IsZeta()`
swift1337 Jul 30, 2024
f2e3fac
Add AppContext.FilterChains
swift1337 Jul 30, 2024
e6fe5d7
Fix test cases [2]
swift1337 Jul 30, 2024
ca9826e
Fix test cases [3]
swift1337 Jul 30, 2024
ef8a500
Merge branch 'develop' into refactor/chain-params
swift1337 Jul 30, 2024
c642109
Address PR comments [1]
swift1337 Jul 30, 2024
38cb3cb
Address PR comments [2]
swift1337 Jul 30, 2024
65a3830
Add tests for `slices`
swift1337 Jul 30, 2024
ce22258
Merge branch 'develop' into refactor/chain-params
swift1337 Jul 30, 2024
e383125
Fix e2e tests [1]
swift1337 Jul 31, 2024
ac0ea1e
Fix e2e tests [2]
swift1337 Jul 31, 2024
c157e0d
Merge branch 'refactor/chain-params' of github.com:zeta-chain/node in…
swift1337 Jul 31, 2024
975c78e
Merge branch 'develop' into refactor/chain-params
swift1337 Aug 2, 2024
05b3d97
Resolve conflicts, converge codebase between PRs
swift1337 Aug 2, 2024
ac9fcf2
Add lodash; remove slices pkg
swift1337 Aug 2, 2024
aa57ba6
Address PR comments
swift1337 Aug 2, 2024
18b445d
Minor logging fix
swift1337 Aug 2, 2024
0f48ce3
Address PR comments
swift1337 Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* [2542](https://github.com/zeta-chain/node/pull/2542) - adjust permissions to be more restrictive
* [2572](https://github.com/zeta-chain/node/pull/2572) - turn off IBC modules
* [2556](https://github.com/zeta-chain/node/pull/2556) - refactor migrator length check to use consensus type
* [2568](https://github.com/zeta-chain/node/pull/2568) - improve AppContext
swift1337 marked this conversation as resolved.
Show resolved Hide resolved

### Tests

Expand Down
94 changes: 47 additions & 47 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"context"
"fmt"
"os"
"strconv"
"strings"

"cosmossdk.io/errors"
"github.com/btcsuite/btcd/rpcclient"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -14,10 +16,8 @@ import (
"github.com/rs/zerolog"
"github.com/spf13/cobra"

"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
"github.com/zeta-chain/zetacore/testutil/sample"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer"
evmobserver "github.com/zeta-chain/zetacore/zetaclient/chains/evm/observer"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand All @@ -34,12 +34,16 @@ type debugArguments struct {
zetaChainID string
}

var homeDir = os.ExpandEnv("$HOME/.zetacored")
swift1337 marked this conversation as resolved.
Show resolved Hide resolved

func init() {
RootCmd.AddCommand(DebugCmd())
DebugCmd().Flags().
StringVar(&debugArgs.zetaCoreHome, "core-home", "/Users/tanmay/.zetacored", "peer address, e.g. /dns/tss1/tcp/6668/ipfs/16Uiu2HAmACG5DtqmQsHtXg4G2sLS65ttv84e7MrL4kapkjfmhxAp")
DebugCmd().Flags().StringVar(&debugArgs.zetaNode, "node", "46.4.15.110", "public ip address")
DebugCmd().Flags().StringVar(&debugArgs.zetaChainID, "chain-id", "athens_7001-1", "pre-params file path")
cmd := DebugCmd()

cmd.Flags().StringVar(&debugArgs.zetaCoreHome, "core-home", homeDir, "zetecore home directory")
cmd.Flags().StringVar(&debugArgs.zetaNode, "node", "46.4.15.110", "public ip address")
cmd.Flags().StringVar(&debugArgs.zetaChainID, "chain-id", "athens_7001-1", "pre-params file path")

RootCmd.AddCommand(cmd)
}

func DebugCmd() *cobra.Command {
Expand All @@ -54,20 +58,16 @@ func debugCmd(_ *cobra.Command, args []string) error {
cobra.ExactArgs(2)
cfg, err := config.Load(debugArgs.zetaCoreHome)
if err != nil {
return err
return errors.Wrap(err, "failed to load config")
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
}

appContext := zctx.New(cfg, zerolog.Nop())
ctx := zctx.WithAppContext(context.Background(), appContext)
inboundHash := args[0]

chainID, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
return err
return errors.Wrap(err, "failed to parse chain id")
}

inboundHash := args[0]
var ballotIdentifier string

// create a new zetacore client
client, err := zetacore.NewClient(
&keys.Keys{OperatorAddress: sdk.MustAccAddressFromBech32(sample.AccAddress())},
Expand All @@ -80,21 +80,30 @@ func debugCmd(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
chainParams, err := client.GetChainParams(ctx)
if err != nil {
return err

appContext := zctx.New(cfg, zerolog.Nop())
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
ctx := zctx.WithAppContext(context.Background(), appContext)

if err := client.UpdateAppContext(ctx, appContext, zerolog.Nop()); err != nil {
return errors.Wrap(err, "failed to update app context")
}

var ballotIdentifier string

tssEthAddress, err := client.GetEVMTSSAddress(ctx)
if err != nil {
return err
}
chain, found := chains.GetChainFromChainID(chainID, appContext.GetAdditionalChains())
if !found {
return fmt.Errorf("invalid chain id")

chain, err := appContext.GetChain(chainID)
if err != nil {
return err
}

chainProto := chain.RawChain()

// get ballot identifier according to the chain type
if chains.IsEVMChain(chain.ChainId, appContext.GetAdditionalChains()) {
if chain.IsEVM() {
evmObserver := evmobserver.Observer{}
evmObserver.WithZetacoreClient(client)
var ethRPC *ethrpc.EthRPC
Expand All @@ -109,43 +118,34 @@ func debugCmd(_ *cobra.Command, args []string) error {
}
evmObserver.WithEvmClient(client)
evmObserver.WithEvmJSONRPC(ethRPC)
evmObserver.WithChain(chain)
evmObserver.WithChain(*chainProto)
}
}
hash := ethcommon.HexToHash(inboundHash)
tx, isPending, err := evmObserver.TransactionByHash(inboundHash)
if err != nil {
return fmt.Errorf("tx not found on chain %s , %d", err.Error(), chain.ChainId)
return fmt.Errorf("tx not found on chain %s, %d", err.Error(), chain.ID())
}

if isPending {
return fmt.Errorf("tx is still pending")
}

receipt, err := client.TransactionReceipt(context.Background(), hash)
if err != nil {
return fmt.Errorf("tx receipt not found on chain %s, %d", err.Error(), chain.ChainId)
return fmt.Errorf("tx receipt not found on chain %s, %d", err.Error(), chain.ID())
}

for _, chainParams := range chainParams {
if chainParams.ChainId == chainID {
evmObserver.SetChainParams(observertypes.ChainParams{
ChainId: chainID,
ConnectorContractAddress: chainParams.ConnectorContractAddress,
ZetaTokenContractAddress: chainParams.ZetaTokenContractAddress,
Erc20CustodyContractAddress: chainParams.Erc20CustodyContractAddress,
})
evmChainParams, found := appContext.GetEVMChainParams(chainID)
if !found {
return fmt.Errorf("missing chain params for chain %d", chainID)
}
evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress
if strings.EqualFold(tx.To, chainParams.ConnectorContractAddress) {
coinType = coin.CoinType_Zeta
} else if strings.EqualFold(tx.To, chainParams.Erc20CustodyContractAddress) {
coinType = coin.CoinType_ERC20
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = coin.CoinType_Gas
}
}
params := chain.Params()

evmObserver.SetChainParams(*params)

if strings.EqualFold(tx.To, params.ConnectorContractAddress) {
coinType = coin.CoinType_Zeta
} else if strings.EqualFold(tx.To, params.Erc20CustodyContractAddress) {
coinType = coin.CoinType_ERC20
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = coin.CoinType_Gas
}

switch coinType {
Expand All @@ -170,10 +170,10 @@ func debugCmd(_ *cobra.Command, args []string) error {
fmt.Println("CoinType not detected")
}
fmt.Println("CoinType : ", coinType)
} else if chains.IsBitcoinChain(chain.ChainId, appContext.GetAdditionalChains()) {
} else if chain.IsUTXO() {
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
btcObserver := btcobserver.Observer{}
btcObserver.WithZetacoreClient(client)
btcObserver.WithChain(chain)
btcObserver.WithChain(*chainProto)
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Expand Down
17 changes: 8 additions & 9 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/spf13/cobra"

"github.com/zeta-chain/zetacore/pkg/authz"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/constant"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/chains/base"
Expand Down Expand Up @@ -143,11 +142,11 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Debug().Msgf("CreateAuthzSigner is ready")

// Initialize core parameters from zetacore
err = zetacoreClient.UpdateAppContext(ctx, appContext, true, startLogger)
if err != nil {
if err = zetacoreClient.UpdateAppContext(ctx, appContext, startLogger); err != nil {
startLogger.Error().Err(err).Msg("Error getting core parameters")
return err
}

startLogger.Info().Msgf("Config is updated from zetacore %s", maskCfg(cfg))

go zetacoreClient.UpdateAppContextWorker(ctx, appContext)
Expand Down Expand Up @@ -214,16 +213,16 @@ func start(_ *cobra.Command, _ []string) error {
return err
}

bitcoinChainID := chains.BitcoinRegtest.ChainId
btcChain, _, btcEnabled := appContext.GetBTCChainAndConfig()
if btcEnabled {
bitcoinChainID = btcChain.ChainId
btcChains := appContext.FilterChains(zctx.Chain.IsUTXO)
if len(btcChains) == 0 {
return errors.New("no BTC chains found")
}

tss, err := mc.NewTSS(
ctx,
zetacoreClient,
tssHistoricalList,
bitcoinChainID,
btcChains[0].ID(),
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
hotkeyPass,
server,
)
Expand Down Expand Up @@ -266,7 +265,7 @@ func start(_ *cobra.Command, _ []string) error {
}
startLogger.Info().
Msgf("Current TSS address \n ETH : %s \n BTC : %s \n PubKey : %s ", tss.EVMAddress(), tss.BTCAddress(), tss.CurrentPubkey)
if len(appContext.GetEnabledChains()) == 0 {
if len(appContext.ListChainIDs()) == 0 {
startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String())
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func adminTestRoutine(

// depositing the necessary tokens on ZetaChain
txZetaDeposit := adminRunner.DepositZeta()
txEtherDeposit := adminRunner.DepositEther(false)
txEtherDeposit := adminRunner.DepositEther()
txERC20Deposit := adminRunner.DepositERC20()
adminRunner.WaitForMinedCCTX(txZetaDeposit)
adminRunner.WaitForMinedCCTX(txEtherDeposit)
Expand Down
5 changes: 2 additions & 3 deletions cmd/zetae2e/local/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func bitcoinTestRoutine(
deployerRunner *runner.E2ERunner,
verbose bool,
initBitcoinNetwork bool,
testHeader bool,
testNames ...string,
) func() error {
return func() (err error) {
Expand All @@ -42,14 +41,14 @@ func bitcoinTestRoutine(
bitcoinRunner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
txEtherDeposit := bitcoinRunner.DepositEther(false)
txEtherDeposit := bitcoinRunner.DepositEther()
txERC20Deposit := bitcoinRunner.DepositERC20()

bitcoinRunner.WaitForMinedCCTX(txEtherDeposit)
bitcoinRunner.WaitForMinedCCTX(txERC20Deposit)

bitcoinRunner.SetupBitcoinAccount(initBitcoinNetwork)
bitcoinRunner.DepositBTC(testHeader)
bitcoinRunner.DepositBTC()

// run bitcoin test
// Note: due to the extensive block generation in Bitcoin localnet, block header test is run first
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func erc20TestRoutine(
erc20Runner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
txEtherDeposit := erc20Runner.DepositEther(false)
txEtherDeposit := erc20Runner.DepositEther()
txERC20Deposit := erc20Runner.DepositERC20()
erc20Runner.WaitForMinedCCTX(txEtherDeposit)
erc20Runner.WaitForMinedCCTX(txERC20Deposit)
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/local/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func ethereumTestRoutine(
conf config.Config,
deployerRunner *runner.E2ERunner,
verbose bool,
testHeader bool,
testNames ...string,
) func() error {
return func() (err error) {
Expand All @@ -36,7 +35,7 @@ func ethereumTestRoutine(
startTime := time.Now()

// depositing the necessary tokens on ZetaChain
txEtherDeposit := ethereumRunner.DepositEther(testHeader)
txEtherDeposit := ethereumRunner.DepositEther()
ethereumRunner.WaitForMinedCCTX(txEtherDeposit)

// run ethereum test
Expand Down
7 changes: 2 additions & 5 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
ethereumTests = append(ethereumTests, ethereumAdvancedTests...)
}

// skip the header proof test if we run light test or skipHeaderProof is enabled
testHeader := !light && !skipHeaderProof

eg.Go(erc20TestRoutine(conf, deployerRunner, verbose, erc20Tests...))
eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...))
eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...))
eg.Go(bitcoinTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, testHeader, bitcoinTests...))
eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, testHeader, ethereumTests...))
eg.Go(bitcoinTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, bitcoinTests...))
eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...))
}

if testAdmin {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ethereumWithdrawPerformanceRoutine(
startTime := time.Now()

// depositing the necessary tokens on ZetaChain
txEtherDeposit := r.DepositEther(false)
txEtherDeposit := r.DepositEther()
r.WaitForMinedCCTX(txEtherDeposit)

tests, err := r.GetE2ETestsToRunByName(
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func zetaTestRoutine(

// depositing the necessary tokens on ZetaChain
txZetaDeposit := zetaRunner.DepositZeta()
txEtherDeposit := zetaRunner.DepositEther(false)
txEtherDeposit := zetaRunner.DepositEther()
zetaRunner.WaitForMinedCCTX(txZetaDeposit)
zetaRunner.WaitForMinedCCTX(txEtherDeposit)

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/zevm_mp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func zevmMPTestRoutine(

// depositing the necessary tokens on ZetaChain
txZetaDeposit := zevmMPRunner.DepositZeta()
txEtherDeposit := zevmMPRunner.DepositEther(false)
txEtherDeposit := zevmMPRunner.DepositEther()
zevmMPRunner.WaitForMinedCCTX(txZetaDeposit)
zevmMPRunner.WaitForMinedCCTX(txEtherDeposit)

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func StressTest(cmd *cobra.Command, _ []string) {
e2eTest.SetZEVMContracts()

// deposit on ZetaChain
e2eTest.DepositEther(false)
e2eTest.DepositEther()
e2eTest.DepositZeta()
case "TESTNET":
ethZRC20Addr := must(e2eTest.SystemContract.GasCoinZRC20ByChainId(&bind.CallOpts{}, big.NewInt(5)))
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_eth_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestEtherDeposit(r *runner.E2ERunner, args []string) {
amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestEtherDeposit.")

hash := r.DepositEtherWithAmount(false, amount) // in wei
hash := r.DepositEtherWithAmount(amount) // in wei
// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, hash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "deposit")
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_migrate_chain_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) {
// deposit Ethers and ERC20 on ZetaChain
etherAmount := big.NewInt(1e18)
etherAmount = etherAmount.Mul(etherAmount, big.NewInt(10))
txEtherDeposit := newRunner.DepositEtherWithAmount(false, etherAmount)
txEtherDeposit := newRunner.DepositEtherWithAmount(etherAmount)
newRunner.WaitForMinedCCTX(txEtherDeposit)

// perform withdrawals on the new chain
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_stress_eth_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestStressEtherDeposit(r *runner.E2ERunner, args []string) {
// send the deposits
for i := 0; i < numDeposits; i++ {
i := i
hash := r.DepositEtherWithAmount(false, depositAmount)
hash := r.DepositEtherWithAmount(depositAmount)
r.Logger.Print("index %d: starting deposit, tx hash: %s", i, hash.Hex())

eg.Go(func() error { return monitorEtherDeposit(r, hash, i, time.Now()) })
Expand Down
Loading
Loading