Skip to content

Commit

Permalink
Removing of dead code related to pre-Byzantium (Fantom-foundation#116)
Browse files Browse the repository at this point in the history
* Simplify StateDB interaction - Byzantium was always enabled

* Remove unused state prefetcher
  • Loading branch information
thaarok authored Apr 11, 2024
1 parent 07dc2fe commit f4c1aad
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 138 deletions.
5 changes: 2 additions & 3 deletions ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,6 @@ func (api *PublicDebugAPI) traceBlock(ctx context.Context, block *evmcore.EvmBlo
var (
txs = block.Transactions
blockHash = block.Hash
is158orBz = api.b.ChainConfig().IsByzantium(block.Number) || api.b.ChainConfig().IsEIP158(block.Number)
signer = gsignercache.Wrap(types.MakeSigner(api.b.ChainConfig(), block.Number))
results = make([]*txTraceResult, len(txs))
)
Expand All @@ -2274,7 +2273,7 @@ func (api *PublicDebugAPI) traceBlock(ctx context.Context, block *evmcore.EvmBlo
results[i] = &txTraceResult{TxHash: tx.Hash(), Result: res}
// Finalize the state so any modifications are written to the trie
// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
statedb.Finalise(is158orBz)
statedb.Finalise()
}
return results, nil
}
Expand Down Expand Up @@ -2312,7 +2311,7 @@ func (api *PublicDebugAPI) stateAtTransaction(ctx context.Context, block *evmcor
return nil, statedb, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
}
// Ensure any modifications are committed to the state
statedb.Finalise(vmenv.ChainConfig().IsByzantium(block.Number) || vmenv.ChainConfig().IsEIP158(block.Number))
statedb.Finalise()
}
return nil, statedb, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, block.Hash)
}
Expand Down
4 changes: 2 additions & 2 deletions ethapi/tx_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *PublicTxTraceAPI) replayBlock(ctx context.Context, block *evmcore.EvmBl
log.Debug("Error replaying transaction", "txHash", tx.Hash().String(), "err", res.Err.Error())
}

state.Finalise(true)
state.Finalise()

// Check correct replay status according to receipt data
if (failed && receipts[i].Status == 1) || (!failed && receipts[i].Status == 0) {
Expand Down Expand Up @@ -245,7 +245,7 @@ func (s *PublicTxTraceAPI) traceTx(
result, err := evmcore.ApplyMessage(vmenv, msg, gp)

traceActions := txTracer.GetResult()
state.Finalise(true)
state.Finalise()

// err is error occured before EVM execution
if err != nil {
Expand Down
24 changes: 0 additions & 24 deletions evmcore/blocks.go

This file was deleted.

93 changes: 0 additions & 93 deletions evmcore/state_prefetcher.go

This file was deleted.

9 changes: 2 additions & 7 deletions evmcore/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,12 @@ func applyTransaction(
}

// Update the state with pending changes.
var root []byte
if config.IsByzantium(blockNumber) {
statedb.Finalise(true)
} else {
root = statedb.IntermediateRoot(config.IsEIP158(blockNumber)).Bytes()
}
statedb.Finalise()
*usedGas += result.UsedGas

// Create a new receipt for the transaction, storing the intermediate root and gas used
// by the tx.
receipt := &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: *usedGas}
receipt := &types.Receipt{Type: tx.Type(), CumulativeGasUsed: *usedGas}
if result.Failed() {
receipt.Status = types.ReceiptStatusFailed
} else {
Expand Down
7 changes: 1 addition & 6 deletions gossip/evmstore/carmen.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,10 @@ func (c *CarmenStateDB) GetRefund() uint64 {
return c.db.GetRefund()
}

func (c *CarmenStateDB) Finalise(deleteEmptyObjects bool) {
func (c *CarmenStateDB) Finalise() {
c.db.EndTransaction()
}

func (c *CarmenStateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
c.db.EndTransaction()
return common.Hash(c.db.GetHash())
}

// Prepare sets the current transaction hash and index which are
// used when the EVM emits new state logs.
func (c *CarmenStateDB) Prepare(txHash common.Hash, txIndex int) {
Expand Down
5 changes: 2 additions & 3 deletions inter/state/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ type StateDB interface {
SetCode(addr common.Address, code []byte)
SetStorage(addr common.Address, storage map[common.Hash]common.Hash)
Copy() StateDB
Finalise(deleteEmptyObjects bool)
IntermediateRoot(deleteEmptyObjects bool) common.Hash
Prepare(thash common.Hash, ti int)
Finalise()
Prepare(txHash common.Hash, txIndex int)
Commit(deleteEmptyObjects bool) (common.Hash, error)

BeginBlock(number uint64)
Expand Down

0 comments on commit f4c1aad

Please sign in to comment.