Skip to content

Commit 94be7c8

Browse files
committed
stateDB interface
1 parent 2b28583 commit 94be7c8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

action/protocol/execution/evm/evm.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,22 @@ type (
9595
actionCtx protocol.ActionCtx
9696
helperCtx HelperContext
9797
}
98+
99+
stateDB interface {
100+
vm.StateDB
101+
102+
CommitContracts() error
103+
Logs() []*action.Log
104+
TransactionLogs() []*action.TransactionLog
105+
clear()
106+
Error() error
107+
}
98108
)
99109

100110
// newParams creates a new context for use in the EVM.
101111
func newParams(
102112
ctx context.Context,
103113
execution action.TxData,
104-
stateDB *StateDBAdapter,
105114
) (*Params, error) {
106115
var (
107116
actionCtx = protocol.MustGetActionCtx(ctx)
@@ -134,15 +143,15 @@ func newParams(
134143
}
135144
case featureCtx.FixGetHashFnHeight:
136145
getHashFn = func(n uint64) common.Hash {
137-
hash, err := getBlockHash(stateDB.blockHeight - (n + 1))
146+
hash, err := getBlockHash(blkCtx.BlockHeight - (n + 1))
138147
if err == nil {
139148
return common.BytesToHash(hash[:])
140149
}
141150
return common.Hash{}
142151
}
143152
default:
144153
getHashFn = func(n uint64) common.Hash {
145-
hash, err := getBlockHash(stateDB.blockHeight - n)
154+
hash, err := getBlockHash(blkCtx.BlockHeight - n)
146155
if err != nil {
147156
// initial implementation did wrong, should return common.Hash{} in case of error
148157
return common.BytesToHash(hash[:])
@@ -241,7 +250,7 @@ func ExecuteContract(
241250
if err != nil {
242251
return nil, nil, err
243252
}
244-
ps, err := newParams(ctx, execution, stateDB)
253+
ps, err := newParams(ctx, execution)
245254
if err != nil {
246255
return nil, nil, err
247256
}
@@ -428,7 +437,7 @@ func getChainConfig(g genesis.Blockchain, height uint64, id uint32, getBlockTime
428437
}
429438

430439
// Error in executeInEVM is a consensus issue
431-
func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapter) ([]byte, uint64, uint64, string, iotextypes.ReceiptStatus, error) {
440+
func executeInEVM(ctx context.Context, evmParams *Params, stateDB stateDB) ([]byte, uint64, uint64, string, iotextypes.ReceiptStatus, error) {
432441
var (
433442
gasLimit = evmParams.blkCtx.GasLimit
434443
blockHeight = evmParams.blkCtx.BlockHeight

action/protocol/execution/evm/evm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func TestConstantinople(t *testing.T) {
297297
})
298298
stateDB, err := prepareStateDB(fCtx, sm)
299299
require.NoError(err)
300-
ps, err := newParams(fCtx, elp, stateDB)
300+
ps, err := newParams(fCtx, elp)
301301
require.NoError(err)
302302

303303
evm := vm.NewEVM(ps.context, ps.txCtx, stateDB, ps.chainConfig, ps.evmConfig)

0 commit comments

Comments
 (0)