-
Notifications
You must be signed in to change notification settings - Fork 562
fix(rpc): cache back access list within same block #1585
Changes from all commits
92ba99f
83fdbe4
78869d4
5b427f9
3172072
b8f6834
32705aa
8c6664c
d2252b8
cfcde2a
2f54334
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 |
---|---|---|
|
@@ -255,6 +255,9 @@ message QueryTraceTxRequest { | |
bytes proposer_address = 8 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress"]; | ||
// chain_id is the the eip155 chain id parsed from the requested block header | ||
int64 chain_id = 9; | ||
// fix_clear_access_list_height defines the upgrade height for fix clear access list before processing each | ||
// transaction | ||
int64 fix_clear_access_list_height = 10; | ||
} | ||
|
||
// QueryTraceTxResponse defines TraceTx response | ||
|
@@ -279,6 +282,9 @@ message QueryTraceBlockRequest { | |
bytes proposer_address = 8 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress"]; | ||
// chain_id is the eip155 chain id parsed from the requested block header | ||
int64 chain_id = 9; | ||
// fix_clear_access_list_height defines the upgrade height for fix clear access list before processing each | ||
// transaction | ||
int64 fix_clear_access_list_height = 10; | ||
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. Same question as above. |
||
} | ||
|
||
// QueryTraceBlockResponse defines TraceBlock response | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -390,6 +390,38 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type | |||||||
return &types.EstimateGasResponse{Gas: hi}, nil | ||||||||
} | ||||||||
|
||||||||
// GetTxTraceResultForTx returns statedb with cached address list when need patch | ||||||||
func (k Keeper) GetTxTraceResultForTx( | ||||||||
ctx sdk.Context, | ||||||||
tx *types.MsgEthereumTx, | ||||||||
signer ethtypes.Signer, | ||||||||
cfg *statedb.EVMConfig, | ||||||||
txConfig statedb.TxConfig, | ||||||||
patch bool, | ||||||||
lastDB *statedb.StateDB, | ||||||||
) (*statedb.StateDB, error) { | ||||||||
ethTx := tx.AsTransaction() | ||||||||
msg, err := ethTx.AsMessage(signer, cfg.BaseFee) | ||||||||
if err != nil { | ||||||||
return lastDB, err | ||||||||
} | ||||||||
txConfig.TxHash = ethTx.Hash() | ||||||||
var stateDB *statedb.StateDB | ||||||||
if patch { | ||||||||
stateDB = statedb.New(ctx, &k, txConfig) | ||||||||
if lastDB != nil { | ||||||||
stateDB.SetAddressToAccessList(lastDB.GetAddressToAccessList()) | ||||||||
} | ||||||||
lastDB = stateDB | ||||||||
} | ||||||||
rsp, err := k.ApplyMessageWithStateDB(ctx, msg, types.NewNoOpTracer(), true, cfg, txConfig, stateDB) | ||||||||
if err != nil { | ||||||||
return lastDB, err | ||||||||
} | ||||||||
txConfig.LogIndex += uint(len(rsp.Logs)) | ||||||||
return lastDB, nil | ||||||||
} | ||||||||
|
||||||||
// TraceTx configures a new tracer according to the provided configuration, and | ||||||||
// executes the given message in the provided environment. The return value will | ||||||||
// be tracer dependent. | ||||||||
|
@@ -421,22 +453,14 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ | |||||||
if err != nil { | ||||||||
return nil, status.Errorf(codes.Internal, "failed to load evm config: %s", err.Error()) | ||||||||
} | ||||||||
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight())) | ||||||||
|
||||||||
height := ctx.BlockHeight() | ||||||||
patch := height < req.FixClearAccessListHeight | ||||||||
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. Here, I see that you are accessing the 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. Cut off height config might be different based on chain, and not sure if env variable is better way than JSONRPCConfig for keeper to access? |
||||||||
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(height)) | ||||||||
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())) | ||||||||
var lastDB *statedb.StateDB | ||||||||
for i, tx := range req.Predecessors { | ||||||||
ethTx := tx.AsTransaction() | ||||||||
msg, err := ethTx.AsMessage(signer, cfg.BaseFee) | ||||||||
if err != nil { | ||||||||
continue | ||||||||
} | ||||||||
txConfig.TxHash = ethTx.Hash() | ||||||||
txConfig.TxIndex = uint(i) | ||||||||
rsp, err := k.ApplyMessageWithConfig(ctx, msg, types.NewNoOpTracer(), true, cfg, txConfig) | ||||||||
if err != nil { | ||||||||
continue | ||||||||
} | ||||||||
txConfig.LogIndex += uint(len(rsp.Logs)) | ||||||||
lastDB, _ = k.GetTxTraceResultForTx(ctx, tx, signer, cfg, txConfig, patch, lastDB) | ||||||||
4rgon4ut marked this conversation as resolved.
Show resolved
Hide resolved
Check warning Code scanning / gosec Returned error is not propagated up the stack.
Returned error is not propagated up the stack.
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.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
tx := req.Msg.AsTransaction() | ||||||||
|
@@ -450,8 +474,11 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ | |||||||
// ignore error. default to no traceConfig | ||||||||
_ = json.Unmarshal([]byte(req.TraceConfig.TracerJsonConfig), &tracerConfig) | ||||||||
} | ||||||||
|
||||||||
result, _, err := k.traceTx(ctx, cfg, txConfig, signer, tx, req.TraceConfig, false, tracerConfig) | ||||||||
stateDB := statedb.New(ctx, &k, txConfig) | ||||||||
if lastDB != nil { | ||||||||
stateDB.SetAddressToAccessList(lastDB.GetAddressToAccessList()) | ||||||||
} | ||||||||
result, _, err := k.traceTx(ctx, cfg, txConfig, stateDB, signer, tx, req.TraceConfig, false, tracerConfig) | ||||||||
if err != nil { | ||||||||
// error will be returned with detail status from traceTx | ||||||||
return nil, err | ||||||||
|
@@ -467,6 +494,39 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ | |||||||
}, nil | ||||||||
} | ||||||||
|
||||||||
// GetTxTraceResultForBlock returns TxTraceResult and | ||||||||
// statedb with cached address list when need patch and | ||||||||
Comment on lines
+497
to
+498
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. Can you complete the sentence you have started here? |
||||||||
func (k Keeper) GetTxTraceResultForBlock( | ||||||||
ctx sdk.Context, | ||||||||
tx *types.MsgEthereumTx, | ||||||||
signer ethtypes.Signer, | ||||||||
cfg *statedb.EVMConfig, | ||||||||
txConfig statedb.TxConfig, | ||||||||
traceConfig *types.TraceConfig, | ||||||||
patch bool, | ||||||||
lastDB *statedb.StateDB, | ||||||||
) (*statedb.StateDB, *types.TxTraceResult) { | ||||||||
result := new(types.TxTraceResult) | ||||||||
ethTx := tx.AsTransaction() | ||||||||
txConfig.TxHash = ethTx.Hash() | ||||||||
var stateDB *statedb.StateDB | ||||||||
if patch { | ||||||||
stateDB = statedb.New(ctx, &k, txConfig) | ||||||||
if lastDB != nil { | ||||||||
stateDB.SetAddressToAccessList(lastDB.GetAddressToAccessList()) | ||||||||
} | ||||||||
lastDB = stateDB | ||||||||
} | ||||||||
traceResult, logIndex, err := k.traceTx(ctx, cfg, txConfig, stateDB, signer, ethTx, traceConfig, true, nil) | ||||||||
if err != nil { | ||||||||
result.Error = err.Error() | ||||||||
} else { | ||||||||
txConfig.LogIndex = logIndex | ||||||||
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. Why assign |
||||||||
result.Result = traceResult | ||||||||
} | ||||||||
return lastDB, result | ||||||||
} | ||||||||
|
||||||||
// TraceBlock configures a new tracer according to the provided configuration, and | ||||||||
// executes the given message in the provided environment for all the transactions in the queried block. | ||||||||
// The return value will be tracer dependent. | ||||||||
|
@@ -499,24 +559,18 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest) | |||||||
if err != nil { | ||||||||
return nil, status.Error(codes.Internal, "failed to load evm config") | ||||||||
} | ||||||||
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight())) | ||||||||
height := ctx.BlockHeight() | ||||||||
patch := height < req.FixClearAccessListHeight | ||||||||
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(height)) | ||||||||
txsLength := len(req.Txs) | ||||||||
results := make([]*types.TxTraceResult, 0, txsLength) | ||||||||
|
||||||||
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())) | ||||||||
var lastDB *statedb.StateDB | ||||||||
for i, tx := range req.Txs { | ||||||||
result := types.TxTraceResult{} | ||||||||
ethTx := tx.AsTransaction() | ||||||||
txConfig.TxHash = ethTx.Hash() | ||||||||
txConfig.TxIndex = uint(i) | ||||||||
traceResult, logIndex, err := k.traceTx(ctx, cfg, txConfig, signer, ethTx, req.TraceConfig, true, nil) | ||||||||
if err != nil { | ||||||||
result.Error = err.Error() | ||||||||
} else { | ||||||||
txConfig.LogIndex = logIndex | ||||||||
result.Result = traceResult | ||||||||
} | ||||||||
results = append(results, &result) | ||||||||
var result *types.TxTraceResult | ||||||||
lastDB, result = k.GetTxTraceResultForBlock(ctx, tx, signer, cfg, txConfig, req.TraceConfig, patch, lastDB) | ||||||||
results = append(results, result) | ||||||||
} | ||||||||
|
||||||||
resultData, err := json.Marshal(results) | ||||||||
|
@@ -534,6 +588,7 @@ func (k *Keeper) traceTx( | |||||||
ctx sdk.Context, | ||||||||
cfg *statedb.EVMConfig, | ||||||||
txConfig statedb.TxConfig, | ||||||||
stateDB *statedb.StateDB, | ||||||||
signer ethtypes.Signer, | ||||||||
tx *ethtypes.Transaction, | ||||||||
traceConfig *types.TraceConfig, | ||||||||
|
@@ -602,7 +657,7 @@ func (k *Keeper) traceTx( | |||||||
} | ||||||||
}() | ||||||||
|
||||||||
res, err := k.ApplyMessageWithConfig(ctx, msg, tracer, commitMessage, cfg, txConfig) | ||||||||
res, err := k.ApplyMessageWithStateDB(ctx, msg, tracer, commitMessage, cfg, txConfig, stateDB) | ||||||||
if err != nil { | ||||||||
return nil, 0, status.Error(codes.Internal, err.Error()) | ||||||||
} | ||||||||
|
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.
Why does this constant have to be included in the
.proto
file for this request? Why can't it be included in the code elsewhere?