From 705fb08fd9cc86c198268d80eafb411639cc1b02 Mon Sep 17 00:00:00 2001 From: Ryan Staudt Date: Tue, 30 Nov 2021 15:17:19 -0600 Subject: [PATCH] multi: Add assumevalid config option. This adds an assumevalid config option which allows for specifying a hash of an assume valid block or disabling assume valid. The usage is as follows: * (flag not specified): defaults to the hard-coded value in source * --assumevalid=0: disable AssumeValid * --assumevalid=[blockhash]: set AssumeValid to the specified block hash --- config.go | 1 + doc.go | 5 +++++ server.go | 20 ++++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.go b/config.go index 5bebf0c2a1..14d5a83474 100644 --- a/config.go +++ b/config.go @@ -195,6 +195,7 @@ type config struct { // Chain related options. DisableCheckpoints bool `long:"nocheckpoints" description:"Disable built-in checkpoints. Don't do this unless you know what you're doing"` DumpBlockchain string `long:"dumpblockchain" description:"Write blockchain as a flat file of blocks for use with addblock, to the specified filename"` + AssumeValid string `long:"assumevalid" description:"Hash of an assume valid block. Defaults to the hard-coded assume valid block that is updated periodically with new releases. Set to 0 to disable. Don't do this unless you know what you're doing"` // Relay and mempool policy. MinRelayTxFee float64 `long:"minrelaytxfee" description:"The minimum transaction fee in DCR/kB to be considered a non-zero fee"` diff --git a/doc.go b/doc.go index 114f59fc2d..3c7c9c65cd 100644 --- a/doc.go +++ b/doc.go @@ -121,6 +121,11 @@ Application Options: unless you know what you're doing --dumpblockchain= Write blockchain as a flat file of blocks for use with addblock, to the specified filename + --assumevalid= Hash of an assume valid block. Defaults to the + hard-coded assume valid block that is updated + periodically with new releases. Set to 0 to + disable. Don't do this unless you know what + you're doing --minrelaytxfee= The minimum transaction fee in DCR/kB to be considered a non-zero fee (default: 0.0001) --limitfreerelay= Limit relay of transactions with no transaction diff --git a/server.go b/server.go index 52a0ecfe7a..2a116d0c40 100644 --- a/server.go +++ b/server.go @@ -3470,12 +3470,24 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB, } s.feeEstimator = fe - // Only set assume valid block when checkpoints are enabled. A new config - // option to disable assume valid will be introduced in a future commit and - // will be used instead of the disable checkpoints option. + // Set assume valid when enabled. var assumeValid chainhash.Hash - if !cfg.DisableCheckpoints { + if cfg.AssumeValid != "0" { + // Default assume valid to the value specified by chain params. assumeValid = s.chainParams.AssumeValid + + // Override assume valid if specified by the config option. + if cfg.AssumeValid != "" { + hash, err := chainhash.NewHashFromStr(cfg.AssumeValid) + if err != nil { + err = fmt.Errorf("invalid hex for --assumevalid: %w", err) + return nil, err + } + assumeValid = *hash + srvrLog.Infof("Assume valid set to %v", assumeValid) + } + } else { + srvrLog.Info("Assume valid is disabled") } // Only configure checkpoints when enabled.