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: dot/state: implement import-state subcommand #1455

Merged
merged 12 commits into from
Mar 12, 2021
Merged

Conversation

noot
Copy link
Contributor

@noot noot commented Mar 12, 2021

Changes

  • implement import-state subcommand which imports state at a given block and starts the chain at that block when the node is started

Tests

go test ./dot/state/ -run TestService_Import
go test ./dot/

I also wrote some docs on how to use the import-state subcommand with a substrate archive node: https://hackmd.io/@nZ-twauPRISEa6G9zg3XRw/SJ8BgXOXO please try it and let me know how it goes

Checklist

  • I have read CODE_OF_CONDUCT and CONTRIBUTING
  • I have provided as much information as possible and necessary
  • I have reviewed my own pull request before requesting a review
  • All integration tests and required coverage checks are passing

Issues

@@ -180,6 +180,18 @@ func (v *VerificationManager) VerifyBlock(header *types.Header) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

We should Unlock above when we return early. (line:168 and line:173)

}

hasHeader, _ := s.blockState.HasHeader(bd.Hash)
hasBody, _ := s.blockState.HasBlockBody(bd.Hash)
if hasHeader && hasBody && bd.Number().Int64() <= bestNum.Int64() {
if hasHeader && hasBody || bd.Number() != nil && bd.Number().Int64() <= bestNum.Int64() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is harder to read. Group logical statements in brackets.

DataDir: s.dbPath,
}

var err error
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this variable declaration inside the else statement.

// SkipVerify returns whether verification for the given header should be skipped or not.
// Only used in the case of imported state.
func (s *EpochState) SkipVerify(header *types.Header) (bool, error) {
skipToEpoch := s.skipToEpoch
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the variable copy avoided?

entries := make(map[string]string)
for _, pair := range pairs {
pairArr := pair.([]interface{})
entries[pairArr[0].(string)] = pairArr[1].(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assert as a safety check that the length of pairArr is always equal to two?

@noot noot requested a review from arijitAD March 12, 2021 15:15
@noot
Copy link
Contributor Author

noot commented Mar 12, 2021

@arijitAD comments addressed!

@noot noot merged commit c51be1c into development Mar 12, 2021
@noot noot deleted the noot/state-import branch March 12, 2021 17:25
github-actions bot pushed a commit that referenced this pull request Mar 12, 2021
noot: feat: dot/state: implement import-state subcommand (#1455)
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.

3 participants