From 6481a0b74c59b963bc04c8e1e4e643ea0ab5db47 Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 3 Oct 2024 13:20:20 +0900 Subject: [PATCH] feat: update nonce error handling --- inspector/scripts/json-rpc-sync-check.sh | 2 +- node/pkg/chain/helper/helper.go | 8 ++++++++ node/pkg/chain/noncemanager/noncemanager.go | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/inspector/scripts/json-rpc-sync-check.sh b/inspector/scripts/json-rpc-sync-check.sh index 01f665d97..b05fca2b6 100755 --- a/inspector/scripts/json-rpc-sync-check.sh +++ b/inspector/scripts/json-rpc-sync-check.sh @@ -6,7 +6,7 @@ readonly OUR_KAIROS_JSON_RPC="http://100.93.31.29:8551" readonly OUR_KAIA_JSON_RPC="http://100.75.43.49:8551" readonly PUBLIC_KAIROS_JSON_RPC="https://public-en-kairos.node.kaia.io" -readonly PUBLIC_KAIA_JSON_RPC="https://public-en-cypress.klaytn.net" +readonly PUBLIC_KAIA_JSON_RPC="https://public-en.node.kaia.io" check_klay_sync_baobab() { our_block_hex=$(get_our_klay_block $OUR_KAIROS_JSON_RPC) diff --git a/node/pkg/chain/helper/helper.go b/node/pkg/chain/helper/helper.go index a88fdbed4..6cc74a172 100644 --- a/node/pkg/chain/helper/helper.go +++ b/node/pkg/chain/helper/helper.go @@ -275,6 +275,10 @@ func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contrac } else if errors.Is(err, errorSentinel.ErrChainTransactionFail) { return err // if transaction fails, the data will probably be too old to retry } else if utils.IsNonceError(err) || err == context.DeadlineExceeded { + err = noncemanager.ResetNonce(ctx, t.wallet, t.clients[clientIndex]) + if err != nil { + return err + } nonce, err = noncemanager.GetAndIncrementNonce(t.wallet) if err != nil { return err @@ -302,6 +306,10 @@ func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contrac } else if errors.Is(err, errorSentinel.ErrChainTransactionFail) { return err // if transaction fails, the data will probably be too old to retry } else if utils.IsNonceError(err) || err == context.DeadlineExceeded { + err = noncemanager.ResetNonce(ctx, t.wallet, t.clients[clientIndex]) + if err != nil { + return err + } nonce, err = noncemanager.GetAndIncrementNonce(t.wallet) if err != nil { return err diff --git a/node/pkg/chain/noncemanager/noncemanager.go b/node/pkg/chain/noncemanager/noncemanager.go index 7ef2ffd6c..489814da6 100644 --- a/node/pkg/chain/noncemanager/noncemanager.go +++ b/node/pkg/chain/noncemanager/noncemanager.go @@ -1,8 +1,11 @@ package noncemanager import ( + "context" "fmt" "sync" + + "bisonai.com/miko/node/pkg/chain/utils" ) type NonceManager struct { @@ -25,6 +28,10 @@ func Get() *NonceManager { return Manager } +func ResetNonce(ctx context.Context, address string, client utils.ClientInterface) error { + return Get().ResetNonce(ctx, address, client) +} + func Set(address string, nonce uint64) { Get().SetNonce(address, nonce) } @@ -33,6 +40,17 @@ func GetAndIncrementNonce(address string) (uint64, error) { return Get().GetAndIncrementNonce(address) } +func (m *NonceManager) ResetNonce(ctx context.Context, address string, client utils.ClientInterface) error { + m.mu.Lock() + defer m.mu.Unlock() + nonce, err := utils.GetNonceFromPk(ctx, address, client) + if err != nil { + return err + } + m.nonces[address] = nonce + return nil +} + func (m *NonceManager) SetNonce(address string, nonce uint64) { m.mu.Lock() defer m.mu.Unlock()