Skip to content

Commit

Permalink
[evm] gate the generation of suicide transaction log (#4198)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Mar 25, 2024
1 parent e85611f commit 6af54b6
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions action/protocol/execution/evm/evmstatedbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,23 @@ func (stateDB *StateDBAdapter) Suicide(evmAddr common.Address) bool {
stateDB.logError(err)
return false
}
// before calling Suicide, EVM will transfer the contract's balance to beneficiary
// need to create a transaction log on successful suicide
if stateDB.lastAddBalanceAmount.Cmp(actBalance) == 0 {
if stateDB.lastAddBalanceAmount.Cmp(big.NewInt(0)) > 0 {
from, _ := address.FromBytes(evmAddr[:])
stateDB.addTransactionLogs(&action.TransactionLog{
Type: iotextypes.TransactionLogType_IN_CONTRACT_TRANSFER,
Sender: from.String(),
Recipient: stateDB.lastAddBalanceAddr,
Amount: stateDB.lastAddBalanceAmount,
})
}
} else {
if stateDB.suicideTxLogMismatchPanic {
// To ensure data consistency, generate this log after the hard-fork
// a separate patch file will be created later to provide missing logs before the hard-fork
// TODO: remove this gating once the hard-fork has passed
if stateDB.suicideTxLogMismatchPanic {
// before calling Suicide, EVM will transfer the contract's balance to beneficiary
// need to create a transaction log on successful suicide
if stateDB.lastAddBalanceAmount.Cmp(actBalance) == 0 {
if stateDB.lastAddBalanceAmount.Cmp(big.NewInt(0)) > 0 {
from, _ := address.FromBytes(evmAddr[:])
stateDB.addTransactionLogs(&action.TransactionLog{
Type: iotextypes.TransactionLogType_IN_CONTRACT_TRANSFER,
Sender: from.String(),
Recipient: stateDB.lastAddBalanceAddr,
Amount: stateDB.lastAddBalanceAmount,
})
}
} else {
log.L().Panic("suicide contract's balance does not match",
zap.String("suicide", actBalance.String()),
zap.String("beneficiary", stateDB.lastAddBalanceAmount.String()))
Expand Down

0 comments on commit 6af54b6

Please sign in to comment.