From 83766edd89506cf0f54c88a00235858c17e3b465 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Sun, 3 Sep 2023 11:44:39 +0530 Subject: [PATCH] Snapshot fix: save snapshot at blockNumber - 1 --- plugin/evm/limit_order.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugin/evm/limit_order.go b/plugin/evm/limit_order.go index eb7f366c4d..4dbc944695 100644 --- a/plugin/evm/limit_order.go +++ b/plugin/evm/limit_order.go @@ -232,12 +232,15 @@ func (lop *limitOrderProcesser) listenAndStoreLimitOrderTransactions() { // If n is the block at which snapshot should be saved(n is multiple of [snapshotInterval]), save the snapshot // when logs of block number >= n + 1 are received before applying them in memory db - blockNumberFloor := ((blockNumber - 1) / snapshotInterval) * snapshotInterval + // snapshot should be saved at block number = blockNumber - 1 because Accepted logs + // have been applied in memory DB at this point + snapshotBlockNumber := blockNumber - 1 + blockNumberFloor := ((snapshotBlockNumber) / snapshotInterval) * snapshotInterval if blockNumberFloor > lop.snapshotSavedBlockNumber { - log.Info("Saving memory DB snapshot", "blockNumber", blockNumber, "blockNumberFloor", blockNumberFloor) - floorBlock := lop.blockChain.GetBlockByNumber(blockNumberFloor) - lop.memoryDb.Accept(blockNumberFloor, floorBlock.Timestamp()) - err := lop.saveMemoryDBSnapshot(big.NewInt(int64(blockNumberFloor))) + log.Info("Saving memory DB snapshot", "snapshotBlockNumber", snapshotBlockNumber, "current blockNumber", blockNumber, "blockNumberFloor", blockNumberFloor) + snapshotBlock := lop.blockChain.GetBlockByNumber(snapshotBlockNumber) + lop.memoryDb.Accept(snapshotBlockNumber, snapshotBlock.Timestamp()) + err := lop.saveMemoryDBSnapshot(big.NewInt(int64(snapshotBlockNumber))) if err != nil { log.Error("Error in saving memory DB snapshot", "err", err) }