Skip to content

Commit 4be8aba

Browse files
yihuangaljo242
andauthored
feat: AddPrecompileFn on stateObject not needed (cosmos#511)
* Problem: AddPrecompileFn on stateObject not needed what is does is only add a journal entry, not related to the state object at all. Solution: - remove the method, move the logic to statedb directly. * remove unused parameter * changelog --------- Co-authored-by: Alex | Interchain Labs <[email protected]>
1 parent 2a0eb3a commit 4be8aba

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [\#467](https://github.com/cosmos/evm/pull/467) Replace GlobalEVMMempool by passing to JSONRPC on initiate.
2020
- [\#352](https://github.com/cosmos/evm/pull/352) Remove the creation of a Geth EVM instance, stateDB during the AnteHandler balance check.
2121
- [\#496](https://github.com/cosmos/evm/pull/496) Simplify mempool instantiation by using configs instead of objects.
22+
- [\#511](https://github.com/cosmos/evm/pull/511) Minor code cleanup for `AddPrecompileFn`.
2223

2324
### FEATURES
2425

precompiles/common/precompile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (p Precompile) RunSetup(
7373

7474
// add precompileCall entry on the stateDB journal
7575
// this allows to revert the changes within an evm tx
76-
err = stateDB.AddPrecompileFn(p.Address(), snapshot, events)
76+
err = stateDB.AddPrecompileFn(snapshot, events)
7777
if err != nil {
7878
return sdk.Context{}, nil, nil, uint64(0), nil, err
7979
}

x/vm/statedb/state_object.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/holiman/uint256"
99

1010
"github.com/cosmos/evm/x/vm/types"
11-
12-
sdk "github.com/cosmos/cosmos-sdk/types"
1311
)
1412

1513
// Account is the Ethereum consensus representation of accounts.
@@ -136,16 +134,6 @@ func (s *stateObject) SetBalance(amount *uint256.Int) uint256.Int {
136134
return prev
137135
}
138136

139-
// AddPrecompileFn appends to the journal an entry
140-
// with a snapshot of the multi-store and events
141-
// previous to the precompile call
142-
func (s *stateObject) AddPrecompileFn(snapshot int, events sdk.Events) {
143-
s.db.journal.append(precompileCallChange{
144-
snapshot: snapshot,
145-
events: events,
146-
})
147-
}
148-
149137
func (s *stateObject) setBalance(amount *uint256.Int) {
150138
s.account.Balance = amount
151139
}

x/vm/statedb/statedb.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,11 @@ func (s *StateDB) setStateObject(object *stateObject) {
434434
// AddPrecompileFn adds a precompileCall journal entry
435435
// with a snapshot of the multi-store and events previous
436436
// to the precompile call.
437-
func (s *StateDB) AddPrecompileFn(addr common.Address, snapshot int, events sdk.Events) error {
438-
stateObject := s.getOrNewStateObject(addr)
439-
if stateObject == nil {
440-
return fmt.Errorf("could not add precompile call to address %s. State object not found", addr)
441-
}
442-
stateObject.AddPrecompileFn(snapshot, events)
437+
func (s *StateDB) AddPrecompileFn(snapshot int, events sdk.Events) error {
438+
s.journal.append(precompileCallChange{
439+
snapshot: snapshot,
440+
events: events,
441+
})
443442
s.precompileCallsCounter++
444443
if s.precompileCallsCounter > types.MaxPrecompileCalls {
445444
return fmt.Errorf("max calls to precompiles (%d) reached", types.MaxPrecompileCalls)

0 commit comments

Comments
 (0)