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

feat: add RPC truncate #2064

Merged
merged 6 commits into from
Jun 22, 2020
Merged

feat: add RPC truncate #2064

merged 6 commits into from
Jun 22, 2020

Conversation

keroro520
Copy link
Contributor

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:

  • Roll-back the blockchain status, like cellset and transactions, downto the height corresponding to target_tip_hash. In short, reset the tip to the target block.
  • Delete the truncated blocks from database.
  • Clear the tx-pool, which may hold dirty transactions/proposals.

quake
quake previously approved these changes Jun 5, 2020
quake
quake previously approved these changes Jun 12, 2020
@zhangsoledad
Copy link
Member

#2120

Copy link
Member

@doitian doitian left a 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.

@keroro520
Copy link
Contributor Author

  • The code is a bit too complex. The chain service should provide a interface to allow setting any stored block as tip.

I think the ChainController::truncate is that interface.

Thanks for @zhangsoledad doing some refactoring, it may be more simple. PTAL.

  • 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.

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.

quake
quake previously approved these changes Jun 17, 2020
@@ -501,6 +501,14 @@ impl TxPoolService {
}
});
}

pub(crate) async fn clear_pool(&self) {
Copy link
Member

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.

Copy link
Member

@doitian doitian left a 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

@keroro520 keroro520 requested a review from doitian June 19, 2020 16:51
@doitian
Copy link
Member

doitian commented Jun 22, 2020

bors r=quake,doitian

@bors
Copy link
Contributor

bors bot commented Jun 22, 2020

Build succeeded:

  • continuous-integration/travis-ci/push

@bors bors bot merged commit 1d82366 into nervosnetwork:develop Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants