Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix(rpc): cache back access list within same block #1585

Closed
wants to merge 11 commits into from

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Jan 4, 2023

Closes: #1583

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@VictorTrustyDev
Copy link
Contributor

Hi @mmsqe, so what is the root cause?

@mmsqe
Copy link
Contributor Author

mmsqe commented Jan 4, 2023

Hi @mmsqe, so what is the root cause?

some old tnx make use of cached warmAccess within same block before this fix which use less gas, might need a config for patch height here.

@VictorTrustyDev
Copy link
Contributor

@mmsqe I see, totally understood, ty for your detailed explanation

@codecov
Copy link

codecov bot commented Jan 5, 2023

Codecov Report

Merging #1585 (2f54334) into main (c5fdad7) will increase coverage by 0.04%.
The diff coverage is 86.74%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1585      +/-   ##
==========================================
+ Coverage   68.35%   68.40%   +0.04%     
==========================================
  Files         110      110              
  Lines       10181    10225      +44     
==========================================
+ Hits         6959     6994      +35     
- Misses       2819     2827       +8     
- Partials      403      404       +1     
Impacted Files Coverage Δ
server/config/config.go 22.72% <0.00%> (-0.13%) ⬇️
x/evm/statedb/statedb.go 97.66% <0.00%> (-1.55%) ⬇️
x/evm/keeper/grpc_query.go 86.03% <89.47%> (+0.13%) ⬆️
rpc/backend/tracing.go 64.22% <100.00%> (+0.59%) ⬆️
x/evm/keeper/state_transition.go 78.62% <100.00%> (+0.33%) ⬆️

@mmsqe mmsqe marked this pull request as ready for review January 6, 2023 01:58
@mmsqe mmsqe requested a review from a team as a code owner January 6, 2023 01:58
@mmsqe mmsqe requested review from MalteHerrmann and adisaran64 and removed request for a team January 6, 2023 01:58
Copy link
Contributor

@adisaran64 adisaran64 left a comment

Choose a reason for hiding this comment

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

Hey @mmsqe ! Left some comments, was curious about your approach to solving the problem described in the ticket. There are also several CI issues, most importantly that many of the integration tests are failing (most likely because of your changes in state_transition.go and grpc_query.go?) It also might be a good idea to add your own tests for this functionality. This PR probably belongs in draft mode for now.

@@ -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;
Copy link
Contributor

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?

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above.

signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))

height := ctx.BlockHeight()
patch := height < req.FixClearAccessListHeight
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, I see that you are accessing the FixClearAccessListHeight from the request itself. Similar to the question above: why does the constant have to come from the request? Why can't it be stored elsewhere, ex. in the code for the evm keeper itself, to avoid changing the proto files and json-rpc configuration overall?

Copy link
Contributor Author

@mmsqe mmsqe Jan 6, 2023

Choose a reason for hiding this comment

The 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?

x/evm/keeper/grpc_query.go Outdated Show resolved Hide resolved
@mmsqe
Copy link
Contributor Author

mmsqe commented Jan 6, 2023

Hey @mmsqe ! Left some comments, was curious about your approach to solving the problem described in the ticket. There are also several CI issues, most importantly that many of the integration tests are failing (most likely because of your changes in state_transition.go and grpc_query.go?) It also might be a good idea to add your own tests for this functionality. This PR probably belongs in draft mode for now.

Most test fail due to duplicate register proto type when fixing, but I find the upgrade also have issue.

continue
}
txConfig.LogIndex += uint(len(rsp.Logs))
lastDB, _ = k.GetTxTraceResultForTx(ctx, tx, signer, cfg, txConfig, patch, lastDB)

Check warning

Code scanning / gosec

Returned error is not propagated up the stack.

Returned error is not propagated up the stack.
Copy link
Contributor

@MalteHerrmann MalteHerrmann left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this! Left some more comments

Comment on lines +497 to +498
// GetTxTraceResultForBlock returns TxTraceResult and
// statedb with cached address list when need patch and
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you complete the sentence you have started here?

return k.ApplyMessageWithStateDB(ctx, msg, tracer, commit, cfg, txConfig, nil)
}

func (k *Keeper) ApplyMessageWithStateDB(ctx sdk.Context,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a docstring here

}

// SetAddressToAccessList overwrite with new access list
func (s *StateDB) SetAddressToAccessList(accessList *accessList) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO including "address" here can be confusing

Suggested change
func (s *StateDB) SetAddressToAccessList(accessList *accessList) {
func (s *StateDB) SetAccessList(accessList *accessList) {

Comment on lines +399 to +400
// GetAddressToAccessList return full access list
func (s *StateDB) GetAddressToAccessList() *accessList {
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently not sure on the implication of the unexported-return warning - this seems like bad practice. Is there maybe a better way to handle this?

Suggested change
// GetAddressToAccessList return full access list
func (s *StateDB) GetAddressToAccessList() *accessList {
// GetAccessList return full access list
func (s *StateDB) GetAccessList() *accessList {

@@ -396,6 +396,16 @@ func (s *StateDB) AddAddressToAccessList(addr common.Address) {
}
}

// GetAddressToAccessList return full access list
func (s *StateDB) GetAddressToAccessList() *accessList {
return s.accessList
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be tested, especially with the golangci-lint warning

continue
}
txConfig.LogIndex += uint(len(rsp.Logs))
lastDB, _ = k.GetTxTraceResultForTx(ctx, tx, signer, cfg, txConfig, patch, lastDB)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
lastDB, _ = k.GetTxTraceResultForTx(ctx, tx, signer, cfg, txConfig, patch, lastDB)
//#nosec G703 -- if an error is returned, just continue with the next iteration
lastDB, _ = k.GetTxTraceResultForTx(ctx, tx, signer, cfg, txConfig, patch, lastDB)

if err != nil {
result.Error = err.Error()
} else {
txConfig.LogIndex = logIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

Why assign txConfig.LogIndex here when it doesn't get returned or used in the rest of the function?

@mmsqe
Copy link
Contributor Author

mmsqe commented Jan 17, 2023

Thanks for your work on this! Left some more comments

Sorry I forgot to close this PR, since #1603 might be more generic to handle these kind of bug or migrate, thanks for the review.

@mmsqe mmsqe closed this Jan 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong status and gas in debug_traceTransaction
5 participants