-
Notifications
You must be signed in to change notification settings - Fork 324
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 all 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 |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
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 @@ | |
readCache *ReadCache | ||
messageBatcher *batch.Manager | ||
apiStats *nodestats.APILocalStats | ||
sgdIndexer blockindex.SGDRegistry | ||
} | ||
|
||
// jobDesc provides a struct to get and store logs in core.LogsInRange | ||
|
@@ -212,12 +214,19 @@ | |
} | ||
|
||
// WithAPIStats is the option to return RPC stats through API. | ||
func WithAPIStats(stats *nodestats.APILocalStats) Option { | ||
return func(svr *coreService) { | ||
svr.apiStats = stats | ||
} | ||
} | ||
|
||
// 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) | ||
} | ||
|
@@ -270,8 +279,8 @@ | |
|
||
if core.broadcastHandler != nil { | ||
core.messageBatcher = batch.NewManager(func(msg *batch.Message) error { | ||
return core.broadcastHandler(context.Background(), core.bc.ChainID(), msg.Data) | ||
}) | ||
} | ||
|
||
return &core, nil | ||
|
@@ -488,7 +497,7 @@ | |
return status.Errorf(codes.InvalidArgument, "ChainID does not match, expecting %d, got %d", core.bc.ChainID(), chainID) | ||
} | ||
if ge.IsMidway(core.bc.TipHeight()) && chainID != core.bc.ChainID() && chainID != 0 { | ||
return status.Errorf(codes.InvalidArgument, "ChainID does not match, expecting %d, got %d", core.bc.ChainID(), chainID) | ||
} | ||
return nil | ||
} | ||
|
@@ -1690,7 +1699,7 @@ | |
return nil, nil, nil, err | ||
} | ||
if gasLimit == 0 { | ||
gasLimit = core.bc.Genesis().BlockGasLimit | ||
} | ||
traces := logger.NewStructLogger(config) | ||
ctx = protocol.WithVMConfigCtx(ctx, vm.Config{ | ||
|
@@ -1721,7 +1730,7 @@ | |
return nil, nil, nil, err | ||
} | ||
getblockHash := func(height uint64) (hash.Hash256, error) { | ||
return blkHash, nil | ||
} | ||
retval, receipt, err := core.simulateExecution(ctx, callerAddr, exec, getblockHash) | ||
return retval, receipt, traces, err | ||
|
@@ -1732,18 +1741,19 @@ | |
if core.apiStats == nil { | ||
return | ||
} | ||
elapsed := time.Since(start) | ||
core.apiStats.ReportCall(nodestats.APIReport{ | ||
Method: method, | ||
HandlingTime: elapsed, | ||
Success: success, | ||
}, size) | ||
} | ||
|
||
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: add default depositGasFunc when ps.helperCtx.DepositGasFunc not set