-
Notifications
You must be signed in to change notification settings - Fork 328
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
Changes from 2 commits
ef90d46
76fcc47
0e9860f
4c3aa58
87d436b
81b38f9
9d0a29c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
||
|
@@ -279,6 +280,10 @@ func ExecuteContract( | |
sharedGas uint64 | ||
sharedGasFee, totalGasFee *big.Int | ||
) | ||
// if gas price is zero, set it to smallest unit | ||
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) | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will panic without WithSGDIndexer() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No panic, evm will check sgd != nil internally. |
||
}) | ||
return core.sf.SimulateExecution(ctx, addr, exec) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no hard fork?
There was a problem hiding this comment.
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.