Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix SimulateExecution, add sgd contract check #3983

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/pkg/log"
"github.com/iotexproject/iotex-core/pkg/tracer"
"github.com/iotexproject/iotex-core/pkg/unit"
"github.com/iotexproject/iotex-core/pkg/util/byteutil"
)

Expand Down Expand Up @@ -279,6 +280,10 @@ func ExecuteContract(
sharedGas uint64
sharedGasFee, totalGasFee *big.Int
)
// if gas price is zero, set it to smallest unit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no hard fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted it will fix gasprice in another pr.

if ps.txCtx.GasPrice.Sign() == 0 {
ps.txCtx.GasPrice = big.NewInt(unit.Qev)
}
if ps.featureCtx.SharedGasWithDapp && sgd != nil {
// TODO: sgd is whether nil should be checked in processSGD
receiver, sharedGas, err = processSGD(ctx, sm, execution, consumedGas, sgd)
Expand Down Expand Up @@ -639,15 +644,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,
})
Comment on lines -642 to -650
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After moving this logic out, need to update on all the calling places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: add default depositGasFunc when ps.helperCtx.DepositGasFunc not set

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will panic without WithSGDIndexer()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
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
Loading