Skip to content
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, internal/web3ext: add optional first and last arguments to the admin_exportChain RPC. #20107

Merged
merged 1 commit into from
Dec 17, 2019

Conversation

ryanschneider
Copy link
Contributor

I was playing w/ the block importing/exporting logic today to get a better understanding of how it worked, and realized that the only way currently to export blocks is to use admin_exportChain (which exports the entire chain) or geth export (which requires the node to be stopped since only one process can have access to the leveldb).

So, this simply adds a new admin_exportBlocks RPC that takes the same arguments as geth export but can be done while the node is running.

@karalabe
Copy link
Member

karalabe commented Sep 26, 2019

I don't see a reason for adding a new method for this. You can add 2 more optional parameters to the existing admin_exportChain (*uint64 types). If they are nil, you default to the current behavior, if not, use the specified range.

@ryanschneider
Copy link
Contributor Author

ryanschneider commented Sep 28, 2019 via email

@ryanschneider ryanschneider changed the title eth, internal/web3ext: add an admin_exportBlocks RPC to export a range of blocks. eth, internal/web3ext: add optional first and last arguments to the admin_exportChain RPC. Oct 1, 2019
@ryanschneider
Copy link
Contributor Author

Ok @karalabe I've force pushed 353347c which adds the first and last as arguments to the admin_exportChain RPC. As far as I can tell I don't need to do anything special to support them as optional arguments, all cases worked as expected for me with the console:

$ ~/go/src/github.com/ethereum/go-ethereum/build/bin/geth attach /Users/ryans/Library/Ethereum/goerli/geth.ipc
Welcome to the Geth JavaScript console!

instance: Geth/v1.9.6-unstable-93ea2c70-20190920/darwin-amd64/go1.13
at block: 1396301 (Tue, 01 Oct 2019 13:51:27 PDT)
 datadir: /Users/ryans/Library/Ethereum/goerli
 modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> admin.exportChain("/tmp/all.gz", 1)
Error: first and last must be included or omitted as a pair
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

> admin.exportChain("/tmp/all.gz", 5,2)
Error: export failed: first (5) is greater than last (2)
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

> admin.exportChain("/tmp/1332997.gz", 1332997, 1333000)
true

eth/api.go Outdated
// ExportChain exports the current blockchain into a local file,
// or a range of blocks if first and last are non-nil
func (api *PrivateAdminAPI) ExportChain(file string, first *uint64, last *uint64) (bool, error) {
if first != nil && last == nil || first == nil && last != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why not let only the first be specified and from that point onward export the entire chain till head? Seems more robust to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean when first is set and last is nil? Ya, I can see that being useful. I'll update the PR to support that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, force pushed 947c62b which supports this behavior:

> admin.exportChain("/tmp/1332997.gz", 1332997, 1333000)
true
> admin.exportChain("/tmp/latest.gz", 1724972)
true
> admin.exportChain("/tmp/bad.gz", null, 1333000)
Error: last cannot be specified without first
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

@gballet gballet merged commit c4b7fdd into ethereum:master Dec 17, 2019
@karalabe karalabe added this to the 1.9.10 milestone Jan 20, 2020
enriquefynn pushed a commit to enriquefynn/go-ethereum that referenced this pull request Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants