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

feat(zetaclient): propagate context across codebase & refactor zetacore client #2428

Merged
merged 38 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3e09525
Implement `retry` package
swift1337 Jul 2, 2024
d59b701
Refactor zetacore query methods
swift1337 Jul 2, 2024
71efb8b
Refactor zetacore broadcast.go
swift1337 Jul 2, 2024
95a44e0
Refactor zetacore client construction
swift1337 Jul 2, 2024
fb865c5
Refactor zetacore client [WIP]
swift1337 Jul 3, 2024
0d3699f
Fix debug cli command
swift1337 Jul 3, 2024
d4e7db3
Add ctx to evm observer
swift1337 Jul 4, 2024
9b46ff7
Add ctx to evm observer & signer
swift1337 Jul 4, 2024
92869d0
Add `bg` package
swift1337 Jul 4, 2024
d3e1112
Add ctx to btc observer
swift1337 Jul 4, 2024
49b7e90
Add ctx to supply checker
swift1337 Jul 4, 2024
2cfd9cf
Add ctx to orchestrator & signers
swift1337 Jul 4, 2024
544f3ea
Fix lint errors
swift1337 Jul 4, 2024
73d6a79
Improve zetacore client configuration. Fix zetacore tests [WIP]
swift1337 Jul 4, 2024
8e23aff
Fix zetacore client test cases
swift1337 Jul 5, 2024
da8bf83
Fix other test cases
swift1337 Jul 5, 2024
67c50da
Merge branch 'develop' into feat/zetaclient-ctx
swift1337 Jul 5, 2024
b59444e
Resolve merge conflicts
swift1337 Jul 5, 2024
1d74153
Update changelog
swift1337 Jul 5, 2024
358d971
Address PR comments [1]
swift1337 Jul 8, 2024
380d93c
Address PR comments [2]
swift1337 Jul 8, 2024
55626c9
Remove logger pointer from bg package
swift1337 Jul 10, 2024
c94e1c8
Minor fix
swift1337 Jul 10, 2024
f94d0a1
Minor code improvement
swift1337 Jul 10, 2024
cace765
Converge config.New and config.NewConfig
swift1337 Jul 10, 2024
0c29b29
Improve NewSigner logging
swift1337 Jul 10, 2024
50c541d
Add zctx.Copy()
swift1337 Jul 11, 2024
b920238
Refactor Orchestrator shutdown logic
swift1337 Jul 11, 2024
23ef837
Fix retrier logic for monitors
swift1337 Jul 11, 2024
c94d844
Minor fix
swift1337 Jul 11, 2024
454a56b
Fix gosec
swift1337 Jul 11, 2024
2fae181
Update e2e readme
swift1337 Jul 11, 2024
b935800
Fix BTC outbound typo
swift1337 Jul 11, 2024
bcb19ae
Merge branch 'develop' into feat/zetaclient-ctx
swift1337 Jul 11, 2024
d36876d
Fix typo
swift1337 Jul 11, 2024
4bdf50f
Address PR comments
swift1337 Jul 12, 2024
5ff1728
Add test cases for `bg`
swift1337 Jul 12, 2024
7e96f9d
Handle ctx errors in `retry`
swift1337 Jul 12, 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 @@ -58,6 +58,7 @@
* [2375](https://github.com/zeta-chain/node/pull/2375) - improve & speedup code formatting
* [2380](https://github.com/zeta-chain/node/pull/2380) - use `ChainInfo` in `authority` to allow dynamically support new chains
* [2395](https://github.com/zeta-chain/node/pull/2395) - converge AppContext with ZetaCoreContext in zetaclient
* [2428](https://github.com/zeta-chain/node/pull/2428) - propagate context across codebase & refactor zetacore client

### Tests

Expand Down
22 changes: 12 additions & 10 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
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"
clientcontext "github.com/zeta-chain/zetacore/zetaclient/context"
zctx "github.com/zeta-chain/zetacore/zetaclient/context"
"github.com/zeta-chain/zetacore/zetaclient/keys"
"github.com/zeta-chain/zetacore/zetaclient/zetacore"
)
Expand Down Expand Up @@ -57,7 +57,8 @@ func debugCmd(_ *cobra.Command, args []string) error {
return err
}

appContext := clientcontext.New(cfg, zerolog.Nop())
appContext := zctx.New(cfg, zerolog.Nop())
ctx := zctx.WithAppContext(context.Background(), appContext)

chainID, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
Expand All @@ -74,15 +75,16 @@ func debugCmd(_ *cobra.Command, args []string) error {
"",
debugArgs.zetaChainID,
false,
nil)
zerolog.Nop(),
)
if err != nil {
return err
}
chainParams, err := client.GetChainParams()
chainParams, err := client.GetChainParams(ctx)
if err != nil {
return err
}
tssEthAddress, err := client.GetEthTssAddress()
tssEthAddress, err := client.GetEVMTSSAddress(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -148,19 +150,19 @@ func debugCmd(_ *cobra.Command, args []string) error {

switch coinType {
case coin.CoinType_Zeta:
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenZeta(tx, receipt, false)
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenZeta(ctx, tx, receipt, false)
if err != nil {
return err
}

case coin.CoinType_ERC20:
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenERC20(tx, receipt, false)
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenERC20(ctx, tx, receipt, false)
if err != nil {
return err
}

case coin.CoinType_Gas:
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenGas(tx, receipt, false)
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenGas(ctx, tx, receipt, false)
if err != nil {
return err
}
Expand All @@ -186,15 +188,15 @@ func debugCmd(_ *cobra.Command, args []string) error {
return err
}
btcObserver.WithBtcClient(btcClient)
ballotIdentifier, err = btcObserver.CheckReceiptForBtcTxHash(inboundHash, false)
ballotIdentifier, err = btcObserver.CheckReceiptForBtcTxHash(ctx, inboundHash, false)
if err != nil {
return err
}
}
fmt.Println("BallotIdentifier : ", ballotIdentifier)

// query ballot
ballot, err := client.GetBallot(ballotIdentifier)
ballot, err := client.GetBallot(ctx, ballotIdentifier)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Initialize(_ *cobra.Command, _ []string) error {
}

//Create new config struct
configData := config.New()
configData := config.New(true)

//Validate Peer eg. /ip4/172.0.2.1/tcp/6668/p2p/16Uiu2HAmACG5DtqmQsHtXg4G2sLS65ttv84e7MrL4kapkjfmhxAp
if len(initArgs.peer) != 0 {
Expand Down
45 changes: 32 additions & 13 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
Expand All @@ -16,35 +17,42 @@ import (

"github.com/zeta-chain/zetacore/pkg/chains"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/context"
zctx "github.com/zeta-chain/zetacore/zetaclient/context"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
mc "github.com/zeta-chain/zetacore/zetaclient/tss"
"github.com/zeta-chain/zetacore/zetaclient/zetacore"
)

func GenerateTss(
appContext *context.AppContext,
ctx context.Context,
logger zerolog.Logger,
client *zetacore.Client,
peers p2p.AddrList,
priKey secp256k1.PrivKey,
ts *metrics.TelemetryServer,
tssHistoricalList []observertypes.TSS,
tssPassword string,
hotkeyPassword string) (*mc.TSS, error) {
hotkeyPassword string,
) (*mc.TSS, error) {
app, err := zctx.FromContext(ctx)
if err != nil {
return nil, err
}

keygenLogger := logger.With().Str("module", "keygen").Logger()

// Bitcoin chain ID is currently used for using the correct signature format
// TODO: remove this once we have a better way to determine the signature format
// https://github.com/zeta-chain/node/issues/1397
bitcoinChainID := chains.BitcoinRegtest.ChainId
btcChain, _, btcEnabled := appContext.GetBTCChainAndConfig()
btcChain, _, btcEnabled := app.GetBTCChainAndConfig()
if btcEnabled {
bitcoinChainID = btcChain.ChainId
}

tss, err := mc.NewTSS(
appContext,
ctx,
app,
peers,
priKey,
preParams,
Expand Down Expand Up @@ -74,7 +82,7 @@ func GenerateTss(
// This loop will try keygen at the keygen block and then wait for keygen to be successfully reported by all nodes before breaking out of the loop.
// If keygen is unsuccessful, it will reset the triedKeygenAtBlock flag and try again at a new keygen block.

keyGen := appContext.GetKeygen()
keyGen := app.GetKeygen()
if keyGen.Status == observertypes.KeygenStatus_KeyGenSuccess {
return tss, nil
}
Expand All @@ -86,7 +94,7 @@ func GenerateTss(
// Try generating TSS at keygen block , only when status is pending keygen and generation has not been tried at the block
if keyGen.Status == observertypes.KeygenStatus_PendingKeygen {
// Return error if RPC is not working
currentBlock, err := client.GetBlockHeight()
currentBlock, err := client.GetBlockHeight(ctx)
if err != nil {
keygenLogger.Error().Err(err).Msg("GetBlockHeight RPC error")
continue
Expand All @@ -101,16 +109,21 @@ func GenerateTss(
if currentBlock > lastBlock {
lastBlock = currentBlock
keygenLogger.Info().
Msgf("Waiting For Keygen Block to arrive or new keygen block to be set. Keygen Block : %d Current Block : %d ChainID %s ", keyGen.BlockNumber, currentBlock, appContext.Config().ChainID)
Msgf("Waiting For Keygen Block to arrive or new keygen block to be set. Keygen Block : %d Current Block : %d ChainID %s ", keyGen.BlockNumber, currentBlock, app.Config().ChainID)
}
continue
}
// Try keygen only once at a particular block, irrespective of whether it is successful or failure
triedKeygenAtBlock = true
err = keygenTss(keyGen, tss, keygenLogger)
err = keygenTss(ctx, keyGen, tss, keygenLogger)
if err != nil {
keygenLogger.Error().Err(err).Msg("keygenTss error")
tssFailedVoteHash, err := client.SetTSS("", keyGen.BlockNumber, chains.ReceiveStatus_failed)
tssFailedVoteHash, err := client.PostVoteTSS(
ctx,
"",
keyGen.BlockNumber,
chains.ReceiveStatus_failed,
)
if err != nil {
keygenLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
return nil, err
Expand All @@ -128,7 +141,8 @@ func GenerateTss(
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
tssSuccessVoteHash, err := client.SetTSS(
tssSuccessVoteHash, err := client.PostVoteTSS(
ctx,
newTss.CurrentPubkey,
keyGen.BlockNumber,
chains.ReceiveStatus_success,
Expand All @@ -155,7 +169,7 @@ func GenerateTss(
return nil, errors.New("unexpected state for TSS generation")
}

func keygenTss(keyGen observertypes.Keygen, tss *mc.TSS, keygenLogger zerolog.Logger) error {
func keygenTss(ctx context.Context, keyGen observertypes.Keygen, tss *mc.TSS, keygenLogger zerolog.Logger) error {
keygenLogger.Info().Msgf("Keygen at blocknum %d , TSS signers %s ", keyGen.BlockNumber, keyGen.GranteePubkeys)
var req keygen.Request
req = keygen.NewRequest(keyGen.GranteePubkeys, keyGen.BlockNumber, "0.14.0")
Expand All @@ -168,7 +182,12 @@ func keygenTss(keyGen observertypes.Keygen, tss *mc.TSS, keygenLogger zerolog.Lo
return err
}
index := fmt.Sprintf("keygen-%s-%d", digest, keyGen.BlockNumber)
zetaHash, err := tss.ZetacoreClient.PostBlameData(&res.Blame, tss.ZetacoreClient.Chain().ChainId, index)
zetaHash, err := tss.ZetacoreClient.PostVoteBlameData(
ctx,
&res.Blame,
tss.ZetacoreClient.Chain().ChainId,
index,
)
if err != nil {
keygenLogger.Error().Err(err).Msg("error sending blame data to core")
return err
Expand Down
Loading
Loading