Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Adds cli interface to allow reseting chain to a particular block #9782

Merged
merged 13 commits into from
Jan 16, 2019

Conversation

seunlanlege
Copy link
Member

added BlockChainReset trait, client impl, and cli interface(?)

closes #8259

@parity-cla-bot
Copy link

It looks like @seunlanlege signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@seunlanlege seunlanlege changed the title Adds cli interface to allow reseting chain to a particular block (WIP) Adds cli interface to allow reseting chain to a particular block Oct 19, 2018
@seunlanlege seunlanlege added A0-pleasereview 🤓 Pull request needs code review. A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M4-core ⛓ Core client code / Rust. labels Oct 19, 2018
@5chdn 5chdn added this to the 2.2 milestone Oct 24, 2018
@5chdn 5chdn removed the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Oct 26, 2018
@5chdn 5chdn modified the milestones: 2.2, 2.3 Oct 29, 2018
@sorpaas sorpaas added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 25, 2018
@5chdn 5chdn added the A3-stale 🍃 Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Dec 14, 2018
@5chdn
Copy link
Contributor

5chdn commented Dec 14, 2018

Are you still working on that?

@seunlanlege
Copy link
Member Author

currently blocked on #9910

@tomusdrw
Copy link
Collaborator

@seunlanlege can we add a TODO and get this one merged so that it's not blocked?

@seunlanlege
Copy link
Member Author

yeah sure

@seunlanlege seunlanlege changed the title (WIP) Adds cli interface to allow reseting chain to a particular block Adds cli interface to allow reseting chain to a particular block Dec 21, 2018
@seunlanlege seunlanlege added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. A3-stale 🍃 Pull request did not receive any updates in a long time. No review needed at this stage. Close it. labels Dec 21, 2018
@5chdn
Copy link
Contributor

5chdn commented Dec 28, 2018

@dvdplm @tomusdrw could you review this?

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

few more grumbles

ethcore/src/blockchain/blockchain.rs Outdated Show resolved Hide resolved
ethcore/src/client/client.rs Outdated Show resolved Hide resolved
ethcore/src/client/client.rs Outdated Show resolved Hide resolved
parity/cli/mod.rs Outdated Show resolved Hide resolved
parity/cli/mod.rs Outdated Show resolved Hide resolved
parity/cli/mod.rs Outdated Show resolved Hide resolved
parity/configuration.rs Outdated Show resolved Hide resolved
.bold()
.paint(format!("{:#?}", hashes))
);

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be either debug or trace instead of info. Can you explain why it is info?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using info because i need to communicate to the user which blocks are being deleted.

Copy link
Member Author

Choose a reason for hiding this comment

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

the user shouldn't need to run parity with -l trace or debug to see it

Copy link
Collaborator

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

LGTM, just a question on the logging level

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

lgtm, tiny grumble on making the argument required instead of panicking when not provided.

parity/cli/mod.rs Outdated Show resolved Hide resolved
@5chdn
Copy link
Contributor

5chdn commented Jan 16, 2019

Can we get docs for this?

@5chdn 5chdn merged commit cdba22a into master Jan 16, 2019
@5chdn 5chdn deleted the reset-blockchain branch January 16, 2019 15:37
@5chdn 5chdn added the B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. label Jan 16, 2019
@@ -37,7 +37,8 @@ pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType};
pub use self::traits::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, CallContract, TransactionInfo, RegistryInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, BadBlocks,
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not introduced by this PR, but those three lines should all use tab for indentation.

@HCastano HCastano mentioned this pull request Feb 12, 2019
18 tasks
HCastano pushed a commit to HCastano/parity-ethereum that referenced this pull request Feb 12, 2019
…nethereum#9782)

* added BlockChainReset trait, client impl, and cli interface

* show block hashes to be deleted and new best block, update best block in db, better cli interface

* delete BlockNumber from COL_EXTRA

* add TODO comment

* add BlockReciepts to imports

* refactor block_headers_from_best_block, better cli documentation

* exit gracefully if reset arg isn't supplied

* fix cli usage macro

* removed stray int literals

* use Vec::with_capacity

Co-Authored-By: seunlanlege <seunlanlege@gmail.com>

* cast n to usize

* correct imports

* make db reset arg required
@ordian ordian mentioned this pull request Feb 12, 2019
This was referenced Jun 1, 2019
@ghost ghost mentioned this pull request Jun 11, 2019
@stone212
Copy link

Excellent tool! Is there a doc/example of actual usage?

@zemse
Copy link

zemse commented May 1, 2020

You have to run this command:

parity --config <path-to-config-file> db reset <number-of-blocks-to-delete>

This command needs a config file of your network. In case you don't have, you might have to use a --chain ethereum or --chain kovan instead of --config.

And example of the output is here:

$ parity --config config.toml db reset 10
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
     Running `/home/ubuntu/openethereum/target/debug/parity --config config.toml db reset 10`
Loading config file from config.toml
2020-05-01 14:21:56 UTC Running AuRa with an even number of validators (4) is not recommended (risk of network split).
2020-05-01 14:21:56 UTC Not preparing block; cannot sign.
2020-05-01 14:21:56 UTC Configured for Era_Swap_Network using AuthorityRound engine
2020-05-01 14:21:57 UTC Deleting block hashes [
    0x7305578867f56a3fdb1ac2b289741f62adefd900abb54e892830c1668bbb702d,
    0xe2228b860e846e121041b2d3968cf49dcd487f7d25ce71b8c7c677a2c0d5e025,
    0xc9b46799cfe9c37d2ac77a9771a8b0ea5a62e19f94afb39802323a73c4982a76,
    0xf1ae9013b82639c4b26af72b7f727336c968df2bd6ac4d23e764e59ce7c9c3f6,
    0x7942ceca1dbf8b85c197101baaaae1d8e72a1b1aa6554dd0fb362fa5e8b449d9,
    0xd79457d65a1ab7a705ba70d1d6f66e5ad3840a7e9c414ece7388448db5a690df,
    0x98d7188cc3ab7ea6b966f26f0cd0a8426969596e0df4643bd3ffbc9e3f3ba85a,
    0x5835e92e18a2448a15e344e76b61db462abc8943c90d9d634ba3fc531d9bb543,
    0x767d30605c8f31dcf450c9eee6819dc761dc9853c7064ff8dd522834d4931e28,
    0xd69093df9b6ed319ef89877bafbe44c08088e9db1dad26e7180c96e5f26c5c19,
]
2020-05-01 14:21:57 UTC New best block hash 0x1eb6a246f3fdbfcd965d74547dc5a7b20eb59332d5ba21ca1d5f58df60fb4923
2020-05-01 14:21:57 UTC Successfully reset db!

I had to go through the commits to guess how it works.

@dvdplm
Copy link
Collaborator

dvdplm commented May 1, 2020

You don't technically need a config file and openethereum db reset 123 works fine and will use the defaults (i.e. mainnet). You can use a config file if you want, or command line switches. This is consistent with all commands and not special for db reset.
Running openethereum --help will print the inline help for the command.

@astudnev
Copy link

astudnev commented Jun 1, 2020

After deleting twice 128 blocks i get error

2020-06-01 09:34:42 UTC State root not found for block #10500800 (d5c14706ef0a294b561e5037cb846047993da7c42af676986ea0c9ba9665d636)


====================

   0: panic_hook::gen_panic_msg
   1: panic_hook::set_with::{{closure}}
   2: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
   3: rust_begin_unwind
             at src/libstd/panicking.rs:378
   4: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   5: core::option::expect_none_failed
             at src/libcore/option.rs:1211
   6: ethcore::client::client::Client::latest_state_and_header
   7: ethcore::client::client::Client::state_at
   8: <ethcore::client::client::Client as ethcore_call_contract::call_contract::CallContract>::call_contract
   9: registrar::registrar::RegistrarClient::get_address
  10: <ethcore_private_tx::key_server_keys::SecretStoreKeys<C> as ethcore_private_tx::key_server_keys::KeyProvider>::update_acl_contract
  11: ethcore_private_tx::Provider::new
  12: ethcore_service::service::ClientService::start
  13: openethereum::run::execute_impl
  14: openethereum::main_direct
  15: openethereum::main
  16: std::rt::lang_start::{{closure}}
  17: main
  18: __libc_start_main
  19: _start


Thread 'main' panicked at 'State root of best block header always valid.: InvalidStateRoot(0xc7e3ff48be7b6ce8734c52353b13bedc095ec6235c27e3235f6e71421aa05326)', ethcore/src/client/client.rs:1043

This is a bug. Please report it at:

    https://github.com/openethereum/openethereum/issues/new


Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to reset the chain to a particular block
10 participants