-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(config): support custom signet block time #10864
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1316,6 +1316,12 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, | |
| numNets++ | ||
| cfg.ActiveNetParams = chainreg.BitcoinSigNetParams | ||
|
|
||
| err := validateSigNetBackendOptions(cfg.Bitcoin) | ||
| if err != nil { | ||
| return nil, mkErr("error validating bitcoin "+ | ||
| "params: %v", err) | ||
| } | ||
|
|
||
| // Let the user overwrite the default signet parameters. | ||
| // The challenge defines the actual signet network to | ||
| // join and the seed nodes are needed for network | ||
|
|
@@ -1349,6 +1355,20 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, | |
| chainParams := chaincfg.CustomSignetParams( | ||
| sigNetChallenge, sigNetSeeds, | ||
| ) | ||
| if cfg.Bitcoin.SigNetBlockTime != 0 { | ||
| if cfg.Bitcoin.SigNetChallenge == "" { | ||
| return nil, mkErr("signet block time " + | ||
| "requires custom signet challenge") | ||
| } | ||
|
|
||
| err := applySigNetBlockTime( | ||
| &chainParams, cfg.Bitcoin.SigNetBlockTime, | ||
| ) | ||
| if err != nil { | ||
| return nil, mkErr("invalid signet block "+ | ||
| "time: %v", err) | ||
| } | ||
| } | ||
| cfg.ActiveNetParams.Params = &chainParams | ||
| } | ||
| if numNets > 1 { | ||
|
|
@@ -2501,6 +2521,69 @@ func configToFlatMap(cfg Config) (map[string]string, | |
| return result, deprecated, nil | ||
| } | ||
|
|
||
| // validateSigNetBackendOptions validates custom signet options against the | ||
| // selected chain backend. | ||
| func validateSigNetBackendOptions(cfg *lncfg.Chain) error { | ||
| if cfg == nil { | ||
| return fmt.Errorf("bitcoin config cannot be nil") | ||
| } | ||
|
|
||
| if !cfg.SigNet { | ||
| return nil | ||
| } | ||
|
|
||
| switch cfg.Node { | ||
| case bitcoindBackendName: | ||
| switch { | ||
| case cfg.SigNetChallenge != "": | ||
| return fmt.Errorf("bitcoin.signetchallenge must not " + | ||
| "be set with bitcoin.node=bitcoind; " + | ||
| "configure custom signet consensus options " + | ||
| "on bitcoind instead") | ||
|
|
||
| case cfg.SigNetBlockTime != 0: | ||
| return fmt.Errorf("bitcoin.signetblocktime must not " + | ||
| "be set with bitcoin.node=bitcoind; " + | ||
| "configure custom signet consensus options " + | ||
| "on bitcoind instead") | ||
| } | ||
|
|
||
| case btcdBackendName: | ||
| if cfg.SigNetBlockTime != 0 { | ||
| return fmt.Errorf("bitcoin.signetblocktime is not " + | ||
| "supported with bitcoin.node=btcd; btcd does " + | ||
| "not currently support custom signet block " + | ||
| "intervals") | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // applySigNetBlockTime updates the expected block interval used by custom | ||
| // signet header validation. This is needed for custom signets whose backing | ||
| // bitcoind nodes were started with -signetblocktime. | ||
| func applySigNetBlockTime(params *chaincfg.Params, | ||
| blockTime time.Duration) error { | ||
|
|
||
| if params == nil { | ||
| return fmt.Errorf("params cannot be nil") | ||
| } | ||
|
|
||
| if blockTime < time.Second { | ||
| return fmt.Errorf("must be at least one second") | ||
| } | ||
|
|
||
| if blockTime > params.TargetTimespan { | ||
| return fmt.Errorf("must not exceed target timespan %v", | ||
| params.TargetTimespan) | ||
| } | ||
|
|
||
| params.TargetTimePerBlock = blockTime | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are other fields of type time.Duration in chaincfg.Params // TargetTimespan is the desired amount of time that should elapse
// before the block difficulty requirement is examined to determine how
// it should be changed in order to maintain the desired block
// generation rate.
TargetTimespan time.DurationTargetTimespan should be changed so that difficulty is re-targeted every 2016 blocks. Also I see MinDiffReductionTime, but it seems to be disabled in signet.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, Supporting custom |
||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // logWarningsForDeprecation logs a warning if a deprecated config option is | ||
| // set. | ||
| func logWarningsForDeprecation(cfg Config) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.