Skip to content

Commit

Permalink
evm: fix InternalTransactions order (#450)
Browse files Browse the repository at this point in the history
* 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 <minh.bui@skymavis.com>
  • Loading branch information
Francesco4203 and minh-bq committed May 17, 2024
1 parent c4d229b commit 9e55df7
Show file tree
Hide file tree
Showing 3 changed files with 688 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er

// Process block using the parent state as reference point
substart := time.Now()
receipts, logs, internalTxs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig, bc.OpEvents()...)
publishEvents := []*vm.PublishEvent{}
if bc.enableAdditionalChainEvent {
publishEvents = bc.OpEvents()
}
receipts, logs, internalTxs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig, publishEvents...)
if err != nil {
bc.reportBlock(block, receipts, err)
atomic.StoreUint32(&followupInterrupt, 1)
Expand Down
9 changes: 9 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,15 @@ func (evm *EVM) PublishEvent(
err,
),
)
iTrans := *context.InternalTransactions
for i := len(iTrans) - 1; i > 0; {
if iTrans[i-1].InternalTransactionBody.Order > counter {
iTrans[i], iTrans[i-1] = iTrans[i-1], iTrans[i]
i--
} else {
break
}
}
}
}

Expand Down

0 comments on commit 9e55df7

Please sign in to comment.