-
Notifications
You must be signed in to change notification settings - Fork 20.8k
eth: add debug_accountRange #17438
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
eth: add debug_accountRange #17438
Conversation
eth/api.go
Outdated
} | ||
|
||
//block hash or number, tx index, start address hash, max results | ||
func (api *PrivateDebugAPI) AccountRangeAt(ctx context.Context, blockNr uint64, txIndex int, startAddr *common.Hash, maxResults int) (AccountRangeAtResult, 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.
Is there a way to overload this so that I can have the rpc method accept a string for block number (e.g. "latest")?
I have not looked at the code, but we should think about the naming of the method. Existing |
Hm, since it has a starting address, would something like |
For cpp-eth the method is called |
core/state/statedb.go
Outdated
@@ -131,6 +131,10 @@ func (self *StateDB) Reset(root common.Hash) error { | |||
return nil | |||
} | |||
|
|||
func (self *StateDB) GetTrie() Trie { |
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.
I added this because I couldn't see any existing way to get access to the trie from the statedb
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.
You can do statedb.Database().OpenTrie()
This also needs unit tests. |
eth/api.go
Outdated
} | ||
|
||
//block hash or number, tx index, start address hash, max results | ||
func (api *PrivateDebugAPI) AccountRangeAt(ctx context.Context, blockNr uint64, txIndex int, startAddr *common.Hash, maxResults int) (AccountRangeAtResult, 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.
Are you sure startAddr
should not be of common.Address
type?
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.
I think you're right.
If to remove At. |
Looks like it wouldn't have be renamed. |
39c72f4
to
4d090fc
Compare
eth/api.go
Outdated
} | ||
|
||
blockHash := api.eth.blockchain.GetBlockByNumber(blockNr).Hash() | ||
_, _, statedb, err := api.computeTxEnv(blockHash, txIndex, 0) |
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.
I'm getting an error from this line:
> curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"debug_accountRange","params":[0, 0, "0x0000000000000000000000000000000000000000", 20],"id":1}' localhost:8545
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"parent 0000000000000000000000000000000000000000000000000000000000000000 not found"}}
Not sure what I'm doing wrong here.
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.
I had a very quick look, and it seems that the message comes from here:
block := api.eth.blockchain.GetBlockByHash(blockHash)
if block == nil {
return nil, vm.Context{}, nil, fmt.Errorf("block %x not found", blockHash)
}
parent := api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if parent == nil {
return nil, vm.Context{}, nil, fmt.Errorf("parent %x not found", block.ParentHash())
}
it seems normal that block 0's parent will not be found. The GetBlock
function uses both the hash and the block number to find the parent, and the block number will be invalid.
On mobile here, so apologies for brevity... We usually use a blocknumOrHash type for specifying blocks, which also accept e.g the string 'latest'. Also, any use of this on mainchain will go OOM pretty quickly, unless a subscription is used instead of a full json dump. Perhaps a default limit should be used; so one doesn't accidentally OOM a node just by checking out "oh I wonder how this method works..." |
Sounds good. Also the |
I thought the |
@holiman I looked through the codebase but couldn't find this type. Tried variations of capitalization as well. |
acd69b8
to
6bfaed3
Compare
See Line 133 in 5d30be4
go-ethereum/eth/api_backend.go Line 60 in 21c059b
blockNr rpc.BlockNumber
|
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
1 similar comment
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
2f76eb2
to
d23b14e
Compare
e4446a1
to
b7040ae
Compare
Updated this to be compatible with aleth/testeth. |
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.
I have made the requested changes, added some unit tests and made sure that the call could be invoked with a nil
pointer made sure that it worked with empty results.
@gballet not sure why you renamed this to "rpc: ...". The main change is in package "eth", the commit message prefix "eth" is appropriate. |
the feature was an RPC call, seems logical enough to me. |
WIP Adds a debug API method
AccountRangeAt
which returns all accounts in the state for a given block and transaction index.