Skip to content

Commit 909049c

Browse files
committed
use the witness in statedb, revert applyTx signature (#36)
* use the witness in statedb, revert applyTx signature * fix miner tests * fix catalyst build
1 parent 7360d16 commit 909049c

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

core/chain_makers.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,10 @@ func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
104104
b.SetCoinbase(common.Address{})
105105
}
106106
b.statedb.Prepare(tx.Hash(), len(b.txs))
107-
receipt, accesses, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
107+
receipt, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
108108
if err != nil {
109109
panic(err)
110110
}
111-
if accesses != nil {
112-
if b.statedb.Witness() != nil {
113-
b.statedb.Witness().Merge(accesses)
114-
} else {
115-
b.statedb.SetWitness(accesses)
116-
}
117-
}
118111
b.txs = append(b.txs, tx)
119112
b.receipts = append(b.receipts, receipt)
120113
}

core/state_processor.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,28 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8080
return nil, nil, accesses, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
8181
}
8282
statedb.Prepare(tx.Hash(), i)
83-
receipt, acc, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv)
83+
receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv)
8484
if err != nil {
8585
return nil, nil, accesses, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
8686
}
8787
receipts = append(receipts, receipt)
8888
allLogs = append(allLogs, receipt.Logs...)
89-
accesses.Merge(acc)
9089
}
9190
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
9291
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
9392

9493
return receipts, allLogs, accesses, *usedGas, nil
9594
}
9695

97-
func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *types.AccessWitness, error) {
96+
func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) {
9897
// Create a new context to be used in the EVM environment.
9998
txContext := NewEVMTxContext(msg)
10099
evm.Reset(txContext, statedb)
101100

102101
// Apply the transaction to the current state (included in the env).
103102
result, err := ApplyMessage(evm, msg, gp)
104103
if err != nil {
105-
return nil, txContext.Accesses, err
104+
return nil, err
106105
}
107106

108107
// Update the state with pending changes.
@@ -130,23 +129,25 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
130129
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
131130
}
132131

132+
statedb.Witness().Merge(txContext.Accesses)
133+
133134
// Set the receipt logs and create the bloom filter.
134135
receipt.Logs = statedb.GetLogs(tx.Hash(), blockHash)
135136
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
136137
receipt.BlockHash = blockHash
137138
receipt.BlockNumber = blockNumber
138139
receipt.TransactionIndex = uint(statedb.TxIndex())
139-
return receipt, txContext.Accesses, err
140+
return receipt, err
140141
}
141142

142143
// ApplyTransaction attempts to apply a transaction to the given state database
143144
// and uses the input parameters for its environment. It returns the receipt
144145
// for the transaction, gas used and an error if the transaction failed,
145146
// indicating the block was invalid.
146-
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, *types.AccessWitness, error) {
147+
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
147148
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number), header.BaseFee)
148149
if err != nil {
149-
return nil, nil, err
150+
return nil, err
150151
}
151152
// Create a new context to be used in the EVM environment
152153
blockContext := NewEVMBlockContext(header, bc, author)

eth/catalyst/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ type blockExecutionEnv struct {
131131
func (env *blockExecutionEnv) commitTransaction(tx *types.Transaction, coinbase common.Address) error {
132132
vmconfig := *env.chain.GetVMConfig()
133133
snap := env.state.Snapshot()
134-
receipt, _, err := core.ApplyTransaction(env.chain.Config(), env.chain, &coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, vmconfig)
134+
receipt, err := core.ApplyTransaction(env.chain.Config(), env.chain, &coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, vmconfig)
135135
if err != nil {
136136
env.state.RevertToSnapshot(snap)
137137
return err

miner/worker.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -770,18 +770,18 @@ func (w *worker) updateSnapshot() {
770770
w.snapshotState = w.current.state.Copy()
771771
}
772772

773-
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, *types.AccessWitness, error) {
773+
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
774774
snap := w.current.state.Snapshot()
775775

776-
receipt, accesses, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
776+
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
777777
if err != nil {
778778
w.current.state.RevertToSnapshot(snap)
779-
return nil, accesses, err
779+
return nil, err
780780
}
781781
w.current.txs = append(w.current.txs, tx)
782782
w.current.receipts = append(w.current.receipts, receipt)
783783

784-
return receipt.Logs, accesses, nil
784+
return receipt.Logs, nil
785785
}
786786

787787
func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coinbase common.Address, interrupt *int32) bool {
@@ -844,12 +844,7 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
844844
// Start executing the transaction
845845
w.current.state.Prepare(tx.Hash(), w.current.tcount)
846846

847-
logs, accs, err := w.commitTransaction(tx, coinbase)
848-
if w.current.state.Witness() == nil {
849-
w.current.state.SetWitness(accs)
850-
} else {
851-
w.current.state.Witness().Merge(accs)
852-
}
847+
logs, err := w.commitTransaction(tx, coinbase)
853848
switch {
854849
case errors.Is(err, core.ErrGasLimitReached):
855850
// Pop the current out-of-gas transaction without shifting in the next from the account

0 commit comments

Comments
 (0)