Skip to content

Commit

Permalink
feat: update nonce error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Oct 3, 2024
1 parent 4ee6f2d commit 6481a0b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inspector/scripts/json-rpc-sync-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions node/pkg/chain/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions node/pkg/chain/noncemanager/noncemanager.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package noncemanager

import (
"context"
"fmt"
"sync"

"bisonai.com/miko/node/pkg/chain/utils"
)

type NonceManager struct {
Expand All @@ -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)
}
Expand All @@ -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()
Expand Down

0 comments on commit 6481a0b

Please sign in to comment.