Skip to content

Commit

Permalink
statedb revert to snapshot for ignored batches (#1742)
Browse files Browse the repository at this point in the history
* statedb revert to snapshot for ignored batches

* address pr review
  • Loading branch information
tudor-malene authored Jan 16, 2024
1 parent 16173af commit bdce4a8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail
if err != nil {
return nil, fmt.Errorf("could not create stateDB. Cause: %w", err)
}
// snap := stateDB.Snapshot()
snap := stateDB.Snapshot()

var messages common.CrossChainMessages
var transfers common.ValueTransferEvents
Expand Down Expand Up @@ -203,6 +203,20 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail
return nil, fmt.Errorf("batch computation failed due to cross chain messages. Cause: %w", err)
}

if failForEmptyBatch &&
len(txReceipts) == 0 &&
len(ccReceipts) == 0 &&
len(transactionsToProcess)-len(excludedTxs) == 0 &&
len(crossChainTransactions) == 0 &&
len(messages) == 0 &&
len(transfers) == 0 {
if snap > 0 {
//// revert any unexpected mutation to the statedb
stateDB.RevertToSnapshot(snap)
}
return nil, ErrNoTransactionsToProcess
}

// we need to copy the batch to reset the internal hash cache
copyBatch := *batch
copyBatch.Header.Root = stateDB.IntermediateRoot(false)
Expand All @@ -215,18 +229,6 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail

allReceipts := append(txReceipts, ccReceipts...)
executor.populateHeader(&copyBatch, allReceipts)
if failForEmptyBatch &&
len(txReceipts) == 0 &&
len(ccReceipts) == 0 &&
len(transactionsToProcess)-len(excludedTxs) == 0 &&
len(crossChainTransactions) == 0 &&
len(messages) == 0 &&
len(transfers) == 0 {
// todo review why this is failing deployment with "panic: revision id 0 cannot be reverted" - https://github.com/ten-protocol/ten-internal/issues/2654
//// revert any unexpected mutation to the statedb
//stateDB.RevertToSnapshot(snap)
return nil, ErrNoTransactionsToProcess
}

// the logs and receipts produced by the EVM have the wrong hash which must be adjusted
for _, receipt := range allReceipts {
Expand Down

0 comments on commit bdce4a8

Please sign in to comment.