From 583c8fdad097b4ef2abc076d4c804a7489ffda14 Mon Sep 17 00:00:00 2001 From: Ryan Staudt Date: Wed, 24 Nov 2021 13:12:19 -0600 Subject: [PATCH] chaincfg: Add AssumeValid param. This introduces an AssumeValid parameter that is the hash of a block that has been externally verified to be valid. In a subsequent commit, it will be used to allow several validation checks to be skipped for blocks that are both an ancestor of the assumed valid block and an ancestor of the best header. Note that the AssumeValid block hash that is specified for mainnet and testnet is for the same block that was used for MinKnownChainWork. Using the same block for both of these slightly simplifies the process for external verification of the values when they are updated periodically with new releases. --- chaincfg/mainnetparams.go | 10 ++++++++++ chaincfg/params.go | 7 +++++++ chaincfg/regnetparams.go | 6 ++++++ chaincfg/simnetparams.go | 6 ++++++ chaincfg/testnetparams.go | 10 ++++++++++ 5 files changed, 39 insertions(+) diff --git a/chaincfg/mainnetparams.go b/chaincfg/mainnetparams.go index bfd30239..4a365d53 100644 --- a/chaincfg/mainnetparams.go +++ b/chaincfg/mainnetparams.go @@ -116,6 +116,16 @@ func MainNetParams() *Params { {601900, newHashFromStr("00000000000000001c1865a45a038bb680fc076d70cd88c1843e3e669cb54942")}, }, + // AssumeValid is the hash of a block that has been externally verified + // to be valid. It allows several validation checks to be skipped for + // blocks that are both an ancestor of the assumed valid block and an + // ancestor of the best header. This is intended to be updated + // periodically with new releases. + // + // Block 00000000000000001251efb83ad1a5c71351b50fe9195f009cf0bf5a7cd99d52 + // Height: 606000 + AssumeValid: *newHashFromStr("00000000000000001251efb83ad1a5c71351b50fe9195f009cf0bf5a7cd99d52"), + // MinKnownChainWork is the minimum amount of known total work for the // chain at a given point in time. This is intended to be updated // periodically with new releases. diff --git a/chaincfg/params.go b/chaincfg/params.go index c19f050f..1ce05356 100644 --- a/chaincfg/params.go +++ b/chaincfg/params.go @@ -335,6 +335,13 @@ type Params struct { // will likely be changed to only allow a single checkpoint in the future. Checkpoints []Checkpoint + // AssumeValid is the hash of a block that has been externally verified to + // be valid. It allows several validation checks to be skipped for blocks + // that are both an ancestor of the assumed valid block and an ancestor of + // the best header. This is intended to be updated periodically with new + // releases. It may not be set for networks that do not require it. + AssumeValid chainhash.Hash + // MinKnownChainWork is the minimum amount of known total work for the chain // at a given point in time. This is intended to be updated periodically // with new releases. It may be nil for networks that do not require it. diff --git a/chaincfg/regnetparams.go b/chaincfg/regnetparams.go index e4aa30ff..8f2cf9fe 100644 --- a/chaincfg/regnetparams.go +++ b/chaincfg/regnetparams.go @@ -112,6 +112,12 @@ func RegNetParams() *Params { // Checkpoints ordered from oldest to newest. Checkpoints: nil, + // AssumeValid is the hash of a block that has been externally verified + // to be valid. + // + // Not set for regression test network since its chain is dynamic. + AssumeValid: chainhash.Hash{}, + // MinKnownChainWork is the minimum amount of known total work for the // chain at a given point in time. // diff --git a/chaincfg/simnetparams.go b/chaincfg/simnetparams.go index 43763ad6..a18e5a79 100644 --- a/chaincfg/simnetparams.go +++ b/chaincfg/simnetparams.go @@ -111,6 +111,12 @@ func SimNetParams() *Params { // Checkpoints ordered from oldest to newest. Checkpoints: nil, + // AssumeValid is the hash of a block that has been externally verified + // to be valid. + // + // Not set for simnet test network since its chain is dynamic. + AssumeValid: chainhash.Hash{}, + // MinKnownChainWork is the minimum amount of known total work for the // chain at a given point in time. // diff --git a/chaincfg/testnetparams.go b/chaincfg/testnetparams.go index 5cdb15ba..5416c35b 100644 --- a/chaincfg/testnetparams.go +++ b/chaincfg/testnetparams.go @@ -111,6 +111,16 @@ func TestNet3Params() *Params { {803810, newHashFromStr("000000016e841f4d94c3b253bc7bdf3a13217c7f28a5935bbaec37c7752678e9")}, }, + // AssumeValid is the hash of a block that has been externally verified + // to be valid. It allows several validation checks to be skipped for + // blocks that are both an ancestor of the assumed valid block and an + // ancestor of the best header. This is intended to be updated + // periodically with new releases. + // + // Block 00000000d64ceb1a686315ed56235e9a6838e3a22e9ec9bd92c2e04c09e0778b + // Height: 807905 + AssumeValid: *newHashFromStr("00000000d64ceb1a686315ed56235e9a6838e3a22e9ec9bd92c2e04c09e0778b"), + // MinKnownChainWork is the minimum amount of known total work for the // chain at a given point in time. This is intended to be updated // periodically with new releases.