Skip to content

Commit

Permalink
multi: Add assumevalid config option.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rstaudt2 committed Dec 3, 2021
1 parent 2e7f235 commit 705fb08
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.go
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions doc.go
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions server.go
Expand Up @@ -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.
Expand Down

0 comments on commit 705fb08

Please sign in to comment.