arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Fix l2db reorg of forging l2txs
Eduard S eduard@iden3.io
Tue, 09 Feb 2021 17:11:21 +0100
commit

2bf3b843ed2f396d7c42b626b9e90dba598ded35

parent

277a1bc32116145033c7fee15e58c7b2215ce111

2 files changed, 6 insertions(+), 5 deletions(-)

jump to
M coordinator/coordinator.go → coordinator/coordinator.go

@@ -348,12 +348,12 @@ return nil

} func (c *Coordinator) handleStopPipeline(ctx context.Context, reason string) error { - if err := c.l2DB.Reorg(common.BatchNum(c.stats.Sync.LastBatch)); err != nil { - return tracerr.Wrap(err) - } if c.pipeline != nil { c.pipeline.Stop(c.ctx) c.pipeline = nil + } + if err := c.l2DB.Reorg(common.BatchNum(c.stats.Sync.LastBatch)); err != nil { + return tracerr.Wrap(err) } if strings.Contains(reason, common.AuctionErrMsgCannotForge) { //nolint:staticcheck // TODO: Check that we are in a slot in which we can't forge
M db/l2db/l2db.go → db/l2db/l2db.go

@@ -346,9 +346,10 @@ // Reorg updates the state of txs that were updated in a batch that has been discarted due to a blockchain reorg.

// The state of the affected txs can change form Forged -> Pending or from Invalid -> Pending func (l2db *L2DB) Reorg(lastValidBatch common.BatchNum) error { _, err := l2db.db.Exec( - `UPDATE tx_pool SET batch_num = NULL, state = $1 - WHERE (state = $2 OR state = $3) AND batch_num > $4`, + `UPDATE tx_pool SET batch_num = NULL, state = $1 + WHERE (state = $2 OR state = $3 OR state = $4) AND batch_num > $5`, common.PoolL2TxStatePending, + common.PoolL2TxStateForging, common.PoolL2TxStateForged, common.PoolL2TxStateInvalid, lastValidBatch,