-
Notifications
You must be signed in to change notification settings - Fork 228
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
feat: add RPC truncate #2064
feat: add RPC truncate #2064
Conversation
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.
- The code is a bit too complex. The chain service should provide a interface to allow setting any stored block as tip.
- Also it is better to leave the stored blocks untouched. Once a node receives a stored block, and it has better cumulative difficulty, the chain service should set tip to this new block instead.
I think the Thanks for @zhangsoledad doing some refactoring, it may be more simple. PTAL.
RPC "truncate" is to reproduce a specified environment when test. The "environment" includes tx-pool, chain, and database. So I think removing the truncated blocks from database is better. As for "sync" a stored block and the stored block has a better cumulative difficulty, It is out of this PR. |
@@ -501,6 +501,14 @@ impl TxPoolService { | |||
} | |||
}); | |||
} | |||
|
|||
pub(crate) async fn clear_pool(&self) { |
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.
This method also deserves an RPC method.
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.
Please resolve the conflicts
bors r=quake,doitian |
Build succeeded:
|
For convenient to reproduce a specified environment when test, this PR adds RPC
truncate(target_tip_hash)
to roll-back the blockchain downto the target block. It trigger the below behaviours:target_tip_hash
. In short, reset the tip to the target block.