Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 9e55df7

Browse files
evm: fix InternalTransactions order (#450)
* evm: add order of internal transactions test * evm: reorder InternalTransactions * evm_test: add additional order or internal transactions tests Add more tests: - Multiple calls: one contract calls multiple contracts - Complex calls: one contract calls multiple contracts with various depths - Delegate calls: one contract delegate-calls multiple contracts * blockchain: add condition to check when to pass bc.OpEvents() to bc.processor.Process() Only some blocks need to be tracked with bc.OpEvents(), then just pass bc.OpEvents() to bc.processor.Process() when the flag bc.enableAdditionalChainEvent is on. --------- Co-authored-by: Bui Quang Minh <[email protected]>
1 parent c4d229b commit 9e55df7

File tree

3 files changed

+688
-1
lines changed

3 files changed

+688
-1
lines changed

core/blockchain.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
18421842

18431843
// Process block using the parent state as reference point
18441844
substart := time.Now()
1845-
receipts, logs, internalTxs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig, bc.OpEvents()...)
1845+
publishEvents := []*vm.PublishEvent{}
1846+
if bc.enableAdditionalChainEvent {
1847+
publishEvents = bc.OpEvents()
1848+
}
1849+
receipts, logs, internalTxs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig, publishEvents...)
18461850
if err != nil {
18471851
bc.reportBlock(block, receipts, err)
18481852
atomic.StoreUint32(&followupInterrupt, 1)

core/vm/evm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,15 @@ func (evm *EVM) PublishEvent(
693693
err,
694694
),
695695
)
696+
iTrans := *context.InternalTransactions
697+
for i := len(iTrans) - 1; i > 0; {
698+
if iTrans[i-1].InternalTransactionBody.Order > counter {
699+
iTrans[i], iTrans[i-1] = iTrans[i-1], iTrans[i]
700+
i--
701+
} else {
702+
break
703+
}
704+
}
696705
}
697706
}
698707

0 commit comments

Comments
 (0)