From d1873d0b4e189f11ac1e7040fd5a2cadd2c3223e Mon Sep 17 00:00:00 2001 From: Intizar Date: Wed, 28 Aug 2024 11:53:22 +0900 Subject: [PATCH] fix getting new nonce in delegated and direct funcs --- node/pkg/chain/helper/helper.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/node/pkg/chain/helper/helper.go b/node/pkg/chain/helper/helper.go index 3c0e769ac..d6f11a67c 100644 --- a/node/pkg/chain/helper/helper.go +++ b/node/pkg/chain/helper/helper.go @@ -243,26 +243,26 @@ func (t *ChainHelper) PublicAddressString() (string, error) { } func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) error { - nonce, err := noncemanager.GetAndIncrementNonce(t.wallet) - if err != nil { - return err - } - if t.delegatorUrl != "" { - err, tryDirect := t.submitDelegated(ctx, contractAddress, functionString, maxRetrial, nonce, args...) + err, tryDirect := t.submitDelegated(ctx, contractAddress, functionString, maxRetrial, args...) if !tryDirect { return err } } - return t.submitDirect(ctx, contractAddress, functionString, maxRetrial, nonce, args...) + return t.submitDirect(ctx, contractAddress, functionString, maxRetrial, args...) } -func (t *ChainHelper) submitDelegated(ctx context.Context, contractAddress string, functionString string, maxRetrial int, nonce uint64, args ...interface{}) (error, bool) { +func (t *ChainHelper) submitDelegated(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) (error, bool) { var err error var tx *types.Transaction clientIndex := 0 + nonce, err := noncemanager.GetAndIncrementNonce(t.wallet) + if err != nil { + return err, false + } + for i := 0; i < maxRetrial; i++ { tx, err = utils.MakeFeeDelegatedTx(ctx, t.clients[clientIndex], contractAddress, t.wallet, functionString, t.chainID, nonce, args...) if err != nil { @@ -296,11 +296,16 @@ func (t *ChainHelper) submitDelegated(ctx context.Context, contractAddress strin return err, true } -func (t *ChainHelper) submitDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, nonce uint64, args ...interface{}) error { +func (t *ChainHelper) submitDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) error { var err error var tx *types.Transaction clientIndex := 0 + nonce, err := noncemanager.GetAndIncrementNonce(t.wallet) + if err != nil { + return err + } + for i := 0; i < maxRetrial; i++ { tx, err = utils.MakeDirectTx(ctx, t.clients[clientIndex], contractAddress, t.wallet, functionString, t.chainID, nonce, args...) if err != nil {