Skip to content

Commit

Permalink
refactor: derive tx factory on each iteration (#156)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Apr 22, 2024
1 parent c1e33eb commit b7813c9
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions go/node/client/v1beta2/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b7813c9

Please sign in to comment.