Skip to content

Commit

Permalink
add sgdindexer to SimulateExecution
Browse files Browse the repository at this point in the history
  • Loading branch information
millken committed Nov 17, 2023
1 parent 7bce2b8 commit ef90d46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 0 additions & 9 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,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,
Expand Down
14 changes: 12 additions & 2 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions chainservice/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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(
Expand Down

0 comments on commit ef90d46

Please sign in to comment.