diff --git a/action/protocol/execution/evm/evm.go b/action/protocol/execution/evm/evm.go index a36a2f0434..49e33594f5 100644 --- a/action/protocol/execution/evm/evm.go +++ b/action/protocol/execution/evm/evm.go @@ -291,10 +291,13 @@ func ExecuteContract( sharedGasFee.Mul(sharedGasFee, ps.txCtx.GasPrice) } totalGasFee = new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), ps.txCtx.GasPrice) - depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee) - if err != nil { - return nil, nil, err + if ps.helperCtx.DepositGasFunc != nil { + depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee) + if err != nil { + return nil, nil, err + } } + } if err := stateDB.CommitContracts(); err != nil { @@ -639,15 +642,6 @@ func SimulateExecution( ) ctx = protocol.WithFeatureCtx(ctx) - // TODO: move the logic out of SimulateExecution - helperCtx := mustGetHelperCtx(ctx) - ctx = WithHelperCtx(ctx, HelperContext{ - GetBlockHash: helperCtx.GetBlockHash, - DepositGasFunc: func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) { - return nil, nil - }, - Sgd: nil, - }) return ExecuteContract( ctx, sm, diff --git a/api/coreservice.go b/api/coreservice.go index 2a5cb68ea1..3ec74fad9e 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -39,6 +39,7 @@ import ( accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util" "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/action/protocol/rolldpos" "github.com/iotexproject/iotex-core/actpool" logfilter "github.com/iotexproject/iotex-core/api/logfilter" @@ -182,6 +183,7 @@ type ( readCache *ReadCache messageBatcher *batch.Manager apiStats *nodestats.APILocalStats + sgdIndexer blockindex.SGDRegistry } // jobDesc provides a struct to get and store logs in core.LogsInRange @@ -218,6 +220,13 @@ 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) } @@ -1741,9 +1750,10 @@ func (core *coreService) Track(ctx context.Context, start time.Time, method stri } func (core *coreService) simulateExecution(ctx context.Context, addr address.Address, exec *action.Execution, getBlockHash evm.GetBlockHash) ([]byte, *action.Receipt, error) { - // TODO: add depositGas ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: getBlockHash, + GetBlockHash: getBlockHash, + DepositGasFunc: rewarding.DepositGasWithSGD, + Sgd: core.sgdIndexer, }) return core.sf.SimulateExecution(ctx, addr, exec) } diff --git a/chainservice/chainservice.go b/chainservice/chainservice.go index dd6157ed82..73ad4b669f 100644 --- a/chainservice/chainservice.go +++ b/chainservice/chainservice.go @@ -191,6 +191,7 @@ 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(