@@ -168,41 +168,23 @@ func (k *ParallelEVM) prepareTxnList(block *types.Block) ([]*txnCtx, map[common.
168168
169169func (k * ParallelEVM ) executeTxnCtxListInOrder (sdb * state.StateDB , list []* txnCtx , isRedo bool ) []* txnCtx {
170170 for index , tctx := range list {
171- nonExecuteSDB := sdb .Copy ()
172171 if tctx .err != nil {
173172 list [index ] = tctx
174173 continue
175174 }
175+ hasErr := false
176176 tctx .ctx .ExtraInterface = pending_state .NewPendingStateWrapper (pending_state .NewStateDBWrapper (sdb ), pending_state .NewStateContext (false ), int64 (index ))
177177 err := tctx .writing (tctx .ctx )
178178 if err != nil {
179+ hasErr = true
179180 tctx .err = err
180181 tctx .receipt = k .handleTxnError (err , tctx .ctx , tctx .ctx .Block , tctx .txn )
181- list [index ] = tctx
182- sdb = nonExecuteSDB
183- continue
184182 } else {
185183 tctx .receipt = k .handleTxnEvent (tctx .ctx , tctx .ctx .Block , tctx .txn , isRedo )
186- tctx .ps = tctx .ctx .ExtraInterface .(* pending_state.PendingStateWrapper )
187- sdb = tctx .ps .GetStateDB ()
188184 }
185+ tctx .ps = tctx .ctx .ExtraInterface .(* pending_state.PendingStateWrapper )
189186 list [index ] = tctx
190- // only for check message nonce
191- if tctx .req .Address != nil && * tctx .req .Address == testBridgeContractAddress {
192- messageNonceSlot := sdb .GetState (testBridgeContractAddress , testStorageSlotHash )
193- // logrus.Infof("testStorageSlotHash %s", testStorageSlotHash.String())
194- // logrus.Infof("executeTxnCtxListInOrder index %d, messageNonceSlot %s", index, messageNonceSlot.String())
195- currentMessageNonceSlot := new (big.Int ).SetBytes (messageNonceSlot .Bytes ())
196- //logrus.Infof("lastMessageNonceSlot %s", lastMessageNonceSlot.String())
197- if lastMessageNonceSlot .Cmp (big .NewInt (0 )) != 0 {
198- diff := new (big.Int ).Sub (currentMessageNonceSlot , lastMessageNonceSlot )
199- if diff .Cmp (big .NewInt (1 )) > 0 {
200- logrus .Warnf ("Message nonce slot increased by more than 1: txhash %s, before %s, after %s, index %d ,diff %s,tctx.ctx.Block.Height %d" , tctx .txn .TxnHash .String (), lastMessageNonceSlot .String (), currentMessageNonceSlot .String (), index , diff .String (), tctx .ctx .Block .Height )
201- metrics .WithdrawMessageNonceGap .WithLabelValues ("bridge" ).Inc ()
202- }
203- }
204- lastMessageNonceSlot .Set (currentMessageNonceSlot )
205- }
187+ k .checkNonce (sdb , tctx , hasErr )
206188 }
207189 k .gcCopiedStateDB (nil , list )
208190 return list
@@ -215,3 +197,33 @@ func (k *ParallelEVM) gcCopiedStateDB(copiedStateDBList []*pending_state.Pending
215197 ctx .ps = nil
216198 }
217199}
200+
201+ func (k * ParallelEVM ) checkNonce (sdb * state.StateDB , tctx * txnCtx , hasErr bool ) {
202+ if tctx .req .Address != nil && * tctx .req .Address == testBridgeContractAddress {
203+ messageNonceSlot := sdb .GetState (testBridgeContractAddress , testStorageSlotHash )
204+ currentMessageNonceSlot := new (big.Int ).SetBytes (messageNonceSlot .Bytes ())
205+ if lastMessageNonceSlot .Cmp (big .NewInt (0 )) != 0 {
206+ diff := new (big.Int ).Sub (currentMessageNonceSlot , lastMessageNonceSlot )
207+ if hasErr {
208+ if diff .Cmp (big .NewInt (0 )) != 0 {
209+ logrus .Warnf ("message nonce changed when error: txhash %s, before %s, after %s,diff %s,tctx.ctx.Block.Height %d" , tctx .txn .TxnHash .String (), lastMessageNonceSlot .String (), currentMessageNonceSlot .String (), diff .String (), tctx .ctx .Block .Height )
210+ metrics .WithdrawMessageNonceGap .WithLabelValues ("bridge" , "err_increased" ).Inc ()
211+ }
212+ } else {
213+ if diff .Cmp (big .NewInt (1 )) > 0 {
214+ logrus .Warnf ("message nonce slot increased by more than 1: txhash %s, before %s, after %s, diff %s,tctx.ctx.Block.Height %d" , tctx .txn .TxnHash .String (), lastMessageNonceSlot .String (), currentMessageNonceSlot .String (), diff .String (), tctx .ctx .Block .Height )
215+ metrics .WithdrawMessageNonceGap .WithLabelValues ("bridge" , "more_increase" ).Inc ()
216+ for _ , eachTctx := range k .blockTxnCtxList {
217+ slot := sdb .GetState (testBridgeContractAddress , testStorageSlotHash )
218+ nonce := new (big.Int ).SetBytes (slot .Bytes ())
219+ logrus .Infof ("txhash %s, message nonce %s, hasErr:%v" , eachTctx .txn .TxnHash .String (), nonce .String (), eachTctx .err != nil )
220+ if eachTctx .txn .TxnHash == tctx .txn .TxnHash {
221+ break
222+ }
223+ }
224+ }
225+ }
226+ }
227+ lastMessageNonceSlot .Set (currentMessageNonceSlot )
228+ }
229+ }
0 commit comments