From b7813c92ed83c34973fb2dc453eeed23bcda294b Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Sun, 21 Apr 2024 23:31:38 -0400 Subject: [PATCH] refactor: derive tx factory on each iteration (#156) Signed-off-by: Artur Troian --- go/node/client/v1beta2/tx.go | 49 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/go/node/client/v1beta2/tx.go b/go/node/client/v1beta2/tx.go index a4923cf7..a0301d94 100644 --- a/go/node/client/v1beta2/tx.go +++ b/go/node/client/v1beta2/tx.go @@ -379,7 +379,7 @@ func (c *serialBroadcaster) broadcaster(ptxf tx.Factory) { if sdkerrors.ErrWrongSequence.Is(rErr) { // attempt to sync account sequence if rSeq, err := c.syncAccountSequence(f.Sequence()); err == nil { - return rSeq + 1, true + return rSeq, true } return f.Sequence(), true @@ -397,27 +397,28 @@ func (c *serialBroadcaster) broadcaster(ptxf tx.Factory) { var err error var resp interface{} - txf := deriveTxfFromOptions(ptxf, req.opts) - - if c.cctx.GenerateOnly { - resp, err = c.generateTxs(txf, req.msgs...) - } else { - done: - for i := 0; i < 2; i++ { - var rseq uint64 - txs := broadcastTxs{ - msgs: req.msgs, - opts: req.opts, - } - resp, rseq, err = c.broadcastTxs(txf, txs) - ptxf = ptxf.WithSequence(rseq) - - rSeq, synced := syncSequence(ptxf, err) - ptxf = ptxf.WithSequence(rSeq) - - if !synced { - break done - } + done: + for i := 0; i < 2; i++ { + txf := deriveTxfFromOptions(ptxf, req.opts) + if c.cctx.GenerateOnly { + resp, err = c.generateTxs(txf, req.msgs...) + break done + } + + var rseq uint64 + txs := broadcastTxs{ + msgs: req.msgs, + opts: req.opts, + } + + resp, rseq, err = c.broadcastTxs(txf, txs) + ptxf = ptxf.WithSequence(rseq) + + rSeq, synced := syncSequence(ptxf, err) + ptxf = ptxf.WithSequence(rSeq) + + if !synced { + break done } } @@ -574,12 +575,12 @@ func (c *serialBroadcaster) broadcastTxs(txf tx.Factory, txs broadcastTxs) (inte return response, txf.Sequence(), err } + txf = txf.WithSequence(txf.Sequence() + 1) + if response.Code != 0 { return response, txf.Sequence(), sdkerrors.ABCIError(response.Codespace, response.Code, response.RawLog) } - txf = txf.WithSequence(txf.Sequence() + 1) - return response, txf.Sequence(), nil }