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

[BREAKING CHANGE] Hardcoding a Default assume_valid_target to Reduce the Timecost of Block Synchronization in IBD mode #4254

Merged
merged 19 commits into from
Mar 28, 2024

Conversation

eval-exec
Copy link
Collaborator

@eval-exec eval-exec commented Dec 4, 2023

What problem does this PR solve?

Issue Number: close #4253

What's Changed:

Related changes

  • Set a block in 60 days ago as default assume_valid_target if user doesn't explictly specify --assume-valid-target argument.
  • User specified --assume-valid-target will overwrite the default hardcoded assume_valid_target
  • If user specify --assume-valid-target 0x0000000000000000000000000000000000000000000000000000000000000000, ckb will do full verification.

full block synchronization result

image
block synchronize from 0 to 12,500,000,
v0.115.0-rc2: need 30h40m
this PR: need 12h40m

This PR's performance test results show a 59% reduction in block synchronization time compared to v0.115.0-rc2.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code ci-runs-only: [ quick_checks,linters ]

Side effects

  • None

Release note

Title Only: Include only the PR title in the release note.

@eval-exec eval-exec added t:enhancement Type: Feature, refactoring. m:sync module: ckb-sync labels Dec 5, 2023
@eval-exec
Copy link
Collaborator Author

eval-exec commented Dec 5, 2023

In the early phase of "finding block header of assume_valid_target" CKB will print many logs like:

32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:20.256 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10890000, hash: Byte32(0x662ba941ac8dd506832704a35fc13534e1ac402aa708670936af03d27114c643), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:22.676 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10900000, hash: Byte32(0xc793a8184a272be18a0736b4a3713f19f75ba9f8913c88ca8d65b05a03304306), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:25.162 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10910000, hash: Byte32(0xa7d0e834174d4c0677648c66b8d74868ce4dcf8514d8f7c40c909cf6f68578ff), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:27.096 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10920000, hash: Byte32(0xe4162e3db5b73eedffa5267595f4b6596cf765b5b6afeae7b1e1649eff057eed), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:29.217 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10930000, hash: Byte32(0x43ce8a7e8c1d65f313d8d1b217145477d5cbc24e12a5ffc9104da2e7ab0d0a04), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:31.193 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10940000, hash: Byte32(0x418fe666fa6c47b98f79c2f6d579b590e4c3449dc555614063f4d3450df32852), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait
2023-12-04 07:51:33.148 +00:00 BlockDownload INFO ckb_sync::synchronizer  best known header number: 10950000, hash: Byte32(0xa17857353561c5488bb0d82f4ad60114c96a3032eb9cbca771fc40e43ecb51c0), can't find assume valid target temporarily, hash: Byte32(0xe9b97767424dd04aa65a1f7ad562b0faf8dd0fbf2a213d1586ea7969160f5996) please wait

These logs will appear about 1 hour, need to reword these into more friendly message, like:
INFO current best known header: {number}-{hash}, assume_valid_target: {number}-{hash}, CKB need {duration} to reach the target, progress {27%}

@eval-exec eval-exec self-assigned this Dec 12, 2023
@eval-exec eval-exec changed the title Hardcoding a Default assume_valid_target to Reduce the Timecost of Block Synchronization [BREAKING CHANGE] Hardcoding a Default assume_valid_target to Reduce the Timecost of Block Synchronization in IBD mode Dec 12, 2023
@eval-exec eval-exec marked this pull request as ready for review December 20, 2023 07:13
@eval-exec eval-exec requested a review from a team as a code owner December 20, 2023 07:13
@eval-exec eval-exec requested review from doitian and removed request for a team December 20, 2023 07:13
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
Copy link
Member

@doitian doitian Feb 29, 2024

Choose a reason for hiding this comment

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

Could you let this script update the file util/constant/src/sync.rs directly? You can add start and end mark around the assume valie target config options to simplify the modification.

@eval-exec eval-exec force-pushed the exec/develop-assume branch from 17b3960 to 69a47a1 Compare March 21, 2024 12:05
@eval-exec
Copy link
Collaborator Author

@doitian How about creating a template file named default_assume_valid_target.rs.template and then using envsubst to generate default_assume_valid_target.rs from this template file?

Ref: https://www.baeldung.com/linux/envsubst-command

@doitian
Copy link
Member

doitian commented Mar 22, 2024

@doitian How about creating a template file named default_assume_valid_target.rs.template and then using envsubst to generate default_assume_valid_target.rs from this template file?

Ref: https://www.baeldung.com/linux/envsubst-command

I think you can just use shell HEREDOC string

cat <<EOF
/// The \`mod mainnet\` and \`mod testnet\`'s codes are generated
/// by script: ./devtools/release/update_default_valid_target.sh

/// sync config related to mainnet
pub mod mainnet {
    // Default assume valid target for mainnet, expect to be a block 60 days ago.
    // Need to update when CKB's new release
    // in mainnet: the 60 days ago block is:
    // height: $MAINNET_HEIGHT
    // hash: $MAINNET_HASH
    // date: $GENERATED_AT
    // you can view this block in https://explorer.nervos.org/block/$MAINNET_HASH
    pub const DEFAULT_ASSUME_VALID_TARGET: &str =
        "$MAINNET_HASH";
}

/// sync config related to testnet
pub mod testnet {
    // Default assume valid target for testnet, expect to be a block 60 days ago.
    // Need to update when CKB's new release
    // in testnet: the 60 days ago block is:
    // height: $TESTNET_HEIGHT
    // hash: $TESTNET_HASH
    // date: $GENERATED_AT
    // you can view this block in https://pudge.explorer.nervos.org/block/$TESTNET_HASH
    pub const DEFAULT_ASSUME_VALID_TARGET: &str =
        "$TESTNET_HASH";
}
EOF

doitian
doitian previously approved these changes Mar 27, 2024
@doitian
Copy link
Member

doitian commented Mar 27, 2024

missing documentation for a module

@eval-exec
Copy link
Collaborator Author

@eval-exec eval-exec force-pushed the exec/develop-assume branch 2 times, most recently from be79e85 to 457f87b Compare March 27, 2024 09:11
@eval-exec
Copy link
Collaborator Author

eval-exec commented Mar 27, 2024

I will upload the comparison chart of the full block synchronization results between this PR and v0.115.0-rc2 in a few hours.

@eval-exec eval-exec force-pushed the exec/develop-assume branch from 457f87b to c742a03 Compare March 28, 2024 02:04
@eval-exec
Copy link
Collaborator Author

I will upload the comparison chart of the full block synchronization results between this PR and v0.115.0-rc2 in a few hours.

The comparison chart has been uploaded to the PR's description.

I think this PR is ready to be reviewed.

@eval-exec eval-exec requested review from quake and chenyukang March 28, 2024 02:50
@doitian doitian added this pull request to the merge queue Mar 28, 2024
Merged via the queue into nervosnetwork:develop with commit 892e06c Mar 28, 2024
32 checks passed
@doitian doitian mentioned this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
m:sync module: ckb-sync t:enhancement Type: Feature, refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hardcoding a Default assume_valid_target to Reduce the Timecost of Block Synchronization
2 participants