diff --git a/action/protocol/execution/evm/evm.go b/action/protocol/execution/evm/evm.go index b907f75752..223f37ea9a 100644 --- a/action/protocol/execution/evm/evm.go +++ b/action/protocol/execution/evm/evm.go @@ -292,13 +292,10 @@ func ExecuteContract( sharedGasFee.Mul(sharedGasFee, ps.txCtx.GasPrice) } totalGasFee = new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), ps.txCtx.GasPrice) - if ps.helperCtx.DepositGasFunc != nil { - depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee) - if err != nil { - return nil, nil, err - } + depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee) + if err != nil { + return nil, nil, err } - } if err := stateDB.CommitContracts(); err != nil { diff --git a/action/protocol/execution/protocol_test.go b/action/protocol/execution/protocol_test.go index 45e95afdef..03230aaf7a 100644 --- a/action/protocol/execution/protocol_test.go +++ b/action/protocol/execution/protocol_test.go @@ -294,8 +294,9 @@ func readExecution( return nil, nil, err } ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: dao.GetBlockHash, - GetBlockTime: getBlockTimeForTest, + GetBlockHash: dao.GetBlockHash, + GetBlockTime: getBlockTimeForTest, + DepositGasFunc: rewarding.DepositGasWithSGD, }) return sf.SimulateExecution(ctx, addr, exec) } diff --git a/api/coreservice.go b/api/coreservice.go index ee93191af8..c25604fa64 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -200,7 +200,6 @@ type ( readCache *ReadCache messageBatcher *batch.Manager apiStats *nodestats.APILocalStats - sgdIndexer blockindex.SGDRegistry getBlockTime evm.GetBlockTime } @@ -238,13 +237,6 @@ func WithAPIStats(stats *nodestats.APILocalStats) Option { } } -// WithSGDIndexer is the option to return SGD Indexer through API. -func WithSGDIndexer(sgdIndexer blockindex.SGDRegistry) Option { - return func(svr *coreService) { - svr.sgdIndexer = sgdIndexer - } -} - type intrinsicGasCalculator interface { IntrinsicGas() (uint64, error) } @@ -1913,7 +1905,6 @@ func (core *coreService) simulateExecution(ctx context.Context, addr address.Add GetBlockHash: getBlockHash, GetBlockTime: getBlockTime, DepositGasFunc: rewarding.DepositGasWithSGD, - Sgd: core.sgdIndexer, }) return core.sf.SimulateExecution(ctx, addr, exec) } diff --git a/chainservice/builder.go b/chainservice/builder.go index 6661fde001..167934821e 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -654,13 +654,12 @@ func (builder *Builder) registerRollDPoSProtocol() error { return nil, err } - // TODO: add depositGas ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: dao.GetBlockHash, - GetBlockTime: getBlockTime, + GetBlockHash: dao.GetBlockHash, + GetBlockTime: getBlockTime, + DepositGasFunc: rewarding.DepositGasWithSGD, }) data, _, err := factory.SimulateExecution(ctx, addr, ex) - return data, err }, candidatesutil.CandidatesFromDB, diff --git a/chainservice/chainservice.go b/chainservice/chainservice.go index c01e4df557..b1864f7626 100644 --- a/chainservice/chainservice.go +++ b/chainservice/chainservice.go @@ -195,7 +195,6 @@ func (cs *ChainService) NewAPIServer(cfg api.Config, plugins map[int]interface{} }), api.WithNativeElection(cs.electionCommittee), api.WithAPIStats(cs.apiStats), - api.WithSGDIndexer(cs.sgdIndexer), } svr, err := api.NewServerV2( diff --git a/e2etest/staking_test.go b/e2etest/staking_test.go index d0bf610caa..fe9d8e05fd 100644 --- a/e2etest/staking_test.go +++ b/e2etest/staking_test.go @@ -24,6 +24,7 @@ import ( "github.com/iotexproject/iotex-core/action/protocol" "github.com/iotexproject/iotex-core/action/protocol/execution/evm" "github.com/iotexproject/iotex-core/action/protocol/poll" + "github.com/iotexproject/iotex-core/action/protocol/rewarding" "github.com/iotexproject/iotex-core/blockchain/genesis" "github.com/iotexproject/iotex-core/config" "github.com/iotexproject/iotex-core/pkg/unit" @@ -123,8 +124,9 @@ func TestStakingContract(t *testing.T) { } ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: dao.GetBlockHash, - GetBlockTime: fakeGetBlockTime, + GetBlockHash: dao.GetBlockHash, + GetBlockTime: fakeGetBlockTime, + DepositGasFunc: rewarding.DepositGasWithSGD, }) data, _, err := sf.SimulateExecution(ctx, addr, ex) diff --git a/state/factory/factory_test.go b/state/factory/factory_test.go index 424df5edd7..264f0f25d3 100644 --- a/state/factory/factory_test.go +++ b/state/factory/factory_test.go @@ -1229,6 +1229,7 @@ func testSimulateExecution(ctx context.Context, sf Factory, t *testing.T) { GetBlockTime: func(u uint64) (time.Time, error) { return time.Time{}, nil }, + DepositGasFunc: rewarding.DepositGasWithSGD, }) _, _, err = sf.SimulateExecution(ctx, addr, ex) require.NoError(err)