From 37e8fb9953ed77c0232e2f51bb3f926afb0cc5dd Mon Sep 17 00:00:00 2001 From: cylewitruk Date: Fri, 10 Jan 2025 10:57:09 +0100 Subject: [PATCH 1/5] add config var --- .../mainnet/sbtc-signer/signer-config.toml.in | 8 +++++++ docker/sbtc/signer/signer-config.toml | 8 +++++++ signer/src/config/default.toml | 8 +++++++ signer/src/config/mod.rs | 22 +++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/docker/mainnet/sbtc-signer/signer-config.toml.in b/docker/mainnet/sbtc-signer/signer-config.toml.in index 3de4c8e5c..da0c8db44 100644 --- a/docker/mainnet/sbtc-signer/signer-config.toml.in +++ b/docker/mainnet/sbtc-signer/signer-config.toml.in @@ -149,6 +149,14 @@ bitcoin_block_horizon = 3000 # Environment: SIGNER_SIGNER__PROMETHEUS_EXPORTER_ENDPOINT prometheus_exporter_endpoint = "0.0.0.0:9184" +# When defined, the signer will attempt to re-run DKG after the specified +# Bitcoin block height. Please only use this parameter when instructed to by +# the sBTC team. +# +# Required: false +# Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT +dkg_rerun_bitcoin_height = 880088 + # !! ============================================================================== # !! Stacks Event Observer Configuration # !! diff --git a/docker/sbtc/signer/signer-config.toml b/docker/sbtc/signer/signer-config.toml index 630034e60..a3fd32af7 100644 --- a/docker/sbtc/signer/signer-config.toml +++ b/docker/sbtc/signer/signer-config.toml @@ -197,6 +197,14 @@ bootstrap_signing_set = [ # Required: true bootstrap_signatures_required = 2 +# When defined, the signer will attempt to re-run DKG after the specified +# Bitcoin block height. Please only use this parameter when instructed to by +# the sBTC team. +# +# Required: false +# Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT +# dkg_rerun_bitcoin_height = 1234 + # !! ============================================================================== # !! Stacks Event Observer Configuration # !! diff --git a/signer/src/config/default.toml b/signer/src/config/default.toml index bf71802a9..57cfc2001 100644 --- a/signer/src/config/default.toml +++ b/signer/src/config/default.toml @@ -205,6 +205,14 @@ sbtc_bitcoin_start_height = 101 # Environment: SIGNER_SIGNER__PROMETHEUS_EXPORTER_ENDPOINT # prometheus_exporter_endpoint = "[::]:9184" +# When defined, the signer will attempt to re-run DKG after the specified +# Bitcoin block height. Please only use this parameter when instructed to by +# the sBTC team. +# +# Required: false +# Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT +# dkg_rerun_bitcoin_height = 1234 + # !! ============================================================================== # !! Stacks Event Observer Configuration # !! diff --git a/signer/src/config/mod.rs b/signer/src/config/mod.rs index 9a90285e2..1048021a1 100644 --- a/signer/src/config/mod.rs +++ b/signer/src/config/mod.rs @@ -8,6 +8,7 @@ use serde::Deserialize; use stacks_common::types::chainstate::StacksAddress; use std::collections::BTreeSet; use std::num::NonZeroU16; +use std::num::NonZeroU64; use std::path::Path; use url::Url; @@ -253,6 +254,12 @@ pub struct SignerConfig { /// arrives. The default here is controlled by the /// [`MAX_DEPOSITS_PER_BITCOIN_TX`] constant pub max_deposits_per_bitcoin_tx: NonZeroU16, + + /// Configures a DKG re-run Bitcoin block height. If this is set and DKG + /// has already been run, the coordinator will attempt to re-run DKG after + /// this block height at most once. If DKG has never been run, this + /// configuration has no effect. + pub dkg_rerun_bitcoin_height: Option, } impl Validatable for SignerConfig { @@ -646,6 +653,21 @@ mod tests { assert!(Settings::new_from_default_config().is_err()); } + #[test] + fn default_config_toml_loads_dkg_rerun_bitcoin_height() { + clear_env(); + + let settings = Settings::new_from_default_config().unwrap(); + assert_eq!(settings.signer.dkg_rerun_bitcoin_height, None); + + std::env::set_var("SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT", "42"); + let settings = Settings::new_from_default_config().unwrap(); + assert_eq!( + settings.signer.dkg_rerun_bitcoin_height, + Some(NonZeroU64::new(42).unwrap()) + ); + } + #[test] fn default_config_toml_loads_signer_network_with_environment() { clear_env(); From 38512be86c9ff910797fffdce52484e419487c8a Mon Sep 17 00:00:00 2001 From: cylewitruk Date: Mon, 13 Jan 2025 13:44:06 +0100 Subject: [PATCH 2/5] add 'dkg_rounds_target' config param --- .../mainnet/sbtc-signer/signer-config.toml.in | 8 +++++ signer/src/config/default.toml | 8 +++++ signer/src/config/mod.rs | 29 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/docker/mainnet/sbtc-signer/signer-config.toml.in b/docker/mainnet/sbtc-signer/signer-config.toml.in index da0c8db44..bbd710d49 100644 --- a/docker/mainnet/sbtc-signer/signer-config.toml.in +++ b/docker/mainnet/sbtc-signer/signer-config.toml.in @@ -157,6 +157,14 @@ prometheus_exporter_endpoint = "0.0.0.0:9184" # Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT dkg_rerun_bitcoin_height = 880088 +# When defined, the signer will attempt/allow multiple rounds of DKG until the +# specified number of rounds have been completed. Please only use this parameter +# when instructed to by the sBTC team. +# +# Required: false +# Environment: SIGNER_SIGNER__DKG_ROUNDS_TARGET +dkg_rounds_target = 2 + # !! ============================================================================== # !! Stacks Event Observer Configuration # !! diff --git a/signer/src/config/default.toml b/signer/src/config/default.toml index 57cfc2001..178c8e56d 100644 --- a/signer/src/config/default.toml +++ b/signer/src/config/default.toml @@ -213,6 +213,14 @@ sbtc_bitcoin_start_height = 101 # Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT # dkg_rerun_bitcoin_height = 1234 +# When defined, the signer will attempt/allow multiple rounds of DKG until the +# specified number of rounds have been completed. Please only use this parameter +# when instructed to by the sBTC team. +# +# Required: false +# Environment: SIGNER_SIGNER__DKG_ROUNDS_TARGET +# dkg_rounds_target = 1 + # !! ============================================================================== # !! Stacks Event Observer Configuration # !! diff --git a/signer/src/config/mod.rs b/signer/src/config/mod.rs index 1048021a1..55c06d3a0 100644 --- a/signer/src/config/mod.rs +++ b/signer/src/config/mod.rs @@ -260,6 +260,12 @@ pub struct SignerConfig { /// this block height at most once. If DKG has never been run, this /// configuration has no effect. pub dkg_rerun_bitcoin_height: Option, + + /// Configures a target number of DKG rounds to run/accept. If this is set + /// and the number of DKG shares is less than this number, the coordinator + /// will continue to run DKG rounds until this number of rounds is reached, + /// assuming the conditions for `dkg_rerun_bitcoin_height` are also met. + pub dkg_rounds_target: Option, } impl Validatable for SignerConfig { @@ -398,6 +404,7 @@ impl Settings { "signer.max_deposits_per_bitcoin_tx", DEFAULT_MAX_DEPOSITS_PER_BITCOIN_TX, )?; + cfg_builder = cfg_builder.set_default("signer.dkg_rounds_target", 1)?; if let Some(path) = config_path { cfg_builder = cfg_builder.add_source(File::from(path.as_ref())); @@ -528,6 +535,10 @@ mod tests { Duration::from_secs(30) ); assert_eq!(settings.signer.dkg_max_duration, Duration::from_secs(120)); + assert_eq!( + settings.signer.dkg_rounds_target, + Some(NonZeroU16::new(1).unwrap()) + ); } #[test] @@ -668,6 +679,24 @@ mod tests { ); } + #[test] + fn default_config_toml_loads_dkg_rounds_target() { + clear_env(); + + let settings = Settings::new_from_default_config().unwrap(); + assert_eq!( + settings.signer.dkg_rounds_target, + Some(NonZeroU16::new(1).unwrap()) + ); + + std::env::set_var("SIGNER_SIGNER__DKG_ROUNDS_TARGET", "42"); + let settings = Settings::new_from_default_config().unwrap(); + assert_eq!( + settings.signer.dkg_rounds_target, + Some(NonZeroU16::new(42).unwrap()) + ); + } + #[test] fn default_config_toml_loads_signer_network_with_environment() { clear_env(); From dc7f3471e8bbf24cf8eec72310462cef2d970446 Mon Sep 17 00:00:00 2001 From: cylewitruk Date: Mon, 13 Jan 2025 14:09:34 +0100 Subject: [PATCH 3/5] use u32 instead of u16 for simplicity --- signer/src/config/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/signer/src/config/mod.rs b/signer/src/config/mod.rs index 55c06d3a0..8bcdbab0c 100644 --- a/signer/src/config/mod.rs +++ b/signer/src/config/mod.rs @@ -8,6 +8,7 @@ use serde::Deserialize; use stacks_common::types::chainstate::StacksAddress; use std::collections::BTreeSet; use std::num::NonZeroU16; +use std::num::NonZeroU32; use std::num::NonZeroU64; use std::path::Path; use url::Url; @@ -265,7 +266,7 @@ pub struct SignerConfig { /// and the number of DKG shares is less than this number, the coordinator /// will continue to run DKG rounds until this number of rounds is reached, /// assuming the conditions for `dkg_rerun_bitcoin_height` are also met. - pub dkg_rounds_target: Option, + pub dkg_rounds_target: Option, } impl Validatable for SignerConfig { @@ -537,7 +538,7 @@ mod tests { assert_eq!(settings.signer.dkg_max_duration, Duration::from_secs(120)); assert_eq!( settings.signer.dkg_rounds_target, - Some(NonZeroU16::new(1).unwrap()) + Some(NonZeroU32::new(1).unwrap()) ); } @@ -686,14 +687,14 @@ mod tests { let settings = Settings::new_from_default_config().unwrap(); assert_eq!( settings.signer.dkg_rounds_target, - Some(NonZeroU16::new(1).unwrap()) + Some(NonZeroU32::new(1).unwrap()) ); std::env::set_var("SIGNER_SIGNER__DKG_ROUNDS_TARGET", "42"); let settings = Settings::new_from_default_config().unwrap(); assert_eq!( settings.signer.dkg_rounds_target, - Some(NonZeroU16::new(42).unwrap()) + Some(NonZeroU32::new(42).unwrap()) ); } From 200ca30ba7e6f808dbaf987571e3fdec5b46c1e7 Mon Sep 17 00:00:00 2001 From: cylewitruk Date: Tue, 14 Jan 2025 09:44:46 +0100 Subject: [PATCH 4/5] pr comments --- .../mainnet/sbtc-signer/signer-config.toml.in | 8 ++-- docker/sbtc/signer/signer-config.toml | 12 +++++- signer/src/config/default.toml | 8 ++-- signer/src/config/mod.rs | 40 +++++++++---------- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/docker/mainnet/sbtc-signer/signer-config.toml.in b/docker/mainnet/sbtc-signer/signer-config.toml.in index bbd710d49..6bf347fdc 100644 --- a/docker/mainnet/sbtc-signer/signer-config.toml.in +++ b/docker/mainnet/sbtc-signer/signer-config.toml.in @@ -154,16 +154,16 @@ prometheus_exporter_endpoint = "0.0.0.0:9184" # the sBTC team. # # Required: false -# Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT -dkg_rerun_bitcoin_height = 880088 +# Environment: SIGNER_SIGNER__DKG_MIN_BITCOIN_BLOCK_HEIGHT +dkg_min_bitcoin_block_height = 880088 # When defined, the signer will attempt/allow multiple rounds of DKG until the # specified number of rounds have been completed. Please only use this parameter # when instructed to by the sBTC team. # # Required: false -# Environment: SIGNER_SIGNER__DKG_ROUNDS_TARGET -dkg_rounds_target = 2 +# Environment: SIGNER_SIGNER__DKG_TARGET_ROUNDS +dkg_target_rounds = 2 # !! ============================================================================== # !! Stacks Event Observer Configuration diff --git a/docker/sbtc/signer/signer-config.toml b/docker/sbtc/signer/signer-config.toml index a3fd32af7..a8aa6bc69 100644 --- a/docker/sbtc/signer/signer-config.toml +++ b/docker/sbtc/signer/signer-config.toml @@ -202,8 +202,16 @@ bootstrap_signatures_required = 2 # the sBTC team. # # Required: false -# Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT -# dkg_rerun_bitcoin_height = 1234 +# Environment: SIGNER_SIGNER__DKG_MIN_BITCOIN_BLOCK_HEIGHT +# dkg_min_bitcoin_block_height = 1234 + +# When defined, the signer will attempt/allow multiple rounds of DKG until the +# specified number of rounds have been completed. Please only use this parameter +# when instructed to by the sBTC team. +# +# Required: false +# Environment: SIGNER_SIGNER__DKG_TARGET_ROUNDS +# dkg_target_rounds = 1 # !! ============================================================================== # !! Stacks Event Observer Configuration diff --git a/signer/src/config/default.toml b/signer/src/config/default.toml index 178c8e56d..1807925f1 100644 --- a/signer/src/config/default.toml +++ b/signer/src/config/default.toml @@ -210,16 +210,16 @@ sbtc_bitcoin_start_height = 101 # the sBTC team. # # Required: false -# Environment: SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT -# dkg_rerun_bitcoin_height = 1234 +# Environment: SIGNER_SIGNER__DKG_MIN_BITCOIN_BLOCK_HEIGHT +# dkg_min_bitcoin_block_height = 1234 # When defined, the signer will attempt/allow multiple rounds of DKG until the # specified number of rounds have been completed. Please only use this parameter # when instructed to by the sBTC team. # # Required: false -# Environment: SIGNER_SIGNER__DKG_ROUNDS_TARGET -# dkg_rounds_target = 1 +# Environment: SIGNER_SIGNER__DKG_TARGET_ROUNDS +# dkg_target_rounds = 1 # !! ============================================================================== # !! Stacks Event Observer Configuration diff --git a/signer/src/config/mod.rs b/signer/src/config/mod.rs index 8bcdbab0c..017a8b1f7 100644 --- a/signer/src/config/mod.rs +++ b/signer/src/config/mod.rs @@ -255,18 +255,17 @@ pub struct SignerConfig { /// arrives. The default here is controlled by the /// [`MAX_DEPOSITS_PER_BITCOIN_TX`] constant pub max_deposits_per_bitcoin_tx: NonZeroU16, - - /// Configures a DKG re-run Bitcoin block height. If this is set and DKG - /// has already been run, the coordinator will attempt to re-run DKG after - /// this block height at most once. If DKG has never been run, this - /// configuration has no effect. - pub dkg_rerun_bitcoin_height: Option, - + /// Configures a DKG re-run Bitcoin block height. If this is set and DKG has + /// already been run, the coordinator will attempt to re-run DKG after this + /// block height is met if `dkg_target_rounds` has not been reached. If DKG + /// has never been run, this configuration has no effect. + pub dkg_min_bitcoin_block_height: Option, /// Configures a target number of DKG rounds to run/accept. If this is set /// and the number of DKG shares is less than this number, the coordinator /// will continue to run DKG rounds until this number of rounds is reached, - /// assuming the conditions for `dkg_rerun_bitcoin_height` are also met. - pub dkg_rounds_target: Option, + /// assuming the conditions for `dkg_rerun_bitcoin_height` are also met. If + /// DKG has never been run, this configuration has no effect. + pub dkg_target_rounds: NonZeroU32, } impl Validatable for SignerConfig { @@ -405,7 +404,7 @@ impl Settings { "signer.max_deposits_per_bitcoin_tx", DEFAULT_MAX_DEPOSITS_PER_BITCOIN_TX, )?; - cfg_builder = cfg_builder.set_default("signer.dkg_rounds_target", 1)?; + cfg_builder = cfg_builder.set_default("signer.dkg_target_rounds", 1)?; if let Some(path) = config_path { cfg_builder = cfg_builder.add_source(File::from(path.as_ref())); @@ -537,9 +536,10 @@ mod tests { ); assert_eq!(settings.signer.dkg_max_duration, Duration::from_secs(120)); assert_eq!( - settings.signer.dkg_rounds_target, - Some(NonZeroU32::new(1).unwrap()) + settings.signer.dkg_target_rounds, + NonZeroU32::new(1).unwrap() ); + assert_eq!(settings.signer.dkg_min_bitcoin_block_height, None); } #[test] @@ -670,12 +670,12 @@ mod tests { clear_env(); let settings = Settings::new_from_default_config().unwrap(); - assert_eq!(settings.signer.dkg_rerun_bitcoin_height, None); + assert_eq!(settings.signer.dkg_min_bitcoin_block_height, None); - std::env::set_var("SIGNER_SIGNER__DKG_RERUN_BITCOIN_HEIGHT", "42"); + std::env::set_var("SIGNER_SIGNER__DKG_MIN_BITCOIN_BLOCK_HEIGHT", "42"); let settings = Settings::new_from_default_config().unwrap(); assert_eq!( - settings.signer.dkg_rerun_bitcoin_height, + settings.signer.dkg_min_bitcoin_block_height, Some(NonZeroU64::new(42).unwrap()) ); } @@ -686,15 +686,15 @@ mod tests { let settings = Settings::new_from_default_config().unwrap(); assert_eq!( - settings.signer.dkg_rounds_target, - Some(NonZeroU32::new(1).unwrap()) + settings.signer.dkg_target_rounds, + NonZeroU32::new(1).unwrap() ); - std::env::set_var("SIGNER_SIGNER__DKG_ROUNDS_TARGET", "42"); + std::env::set_var("SIGNER_SIGNER__DKG_TARGET_ROUNDS", "42"); let settings = Settings::new_from_default_config().unwrap(); assert_eq!( - settings.signer.dkg_rounds_target, - Some(NonZeroU32::new(42).unwrap()) + settings.signer.dkg_target_rounds, + NonZeroU32::new(42).unwrap() ); } From 7fbbbea5f1fd4b41e96bac0391c68b66b7003248 Mon Sep 17 00:00:00 2001 From: cylewitruk Date: Tue, 14 Jan 2025 11:05:13 +0100 Subject: [PATCH 5/5] fix comments/test names --- signer/src/config/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/signer/src/config/mod.rs b/signer/src/config/mod.rs index 017a8b1f7..f2527fcc3 100644 --- a/signer/src/config/mod.rs +++ b/signer/src/config/mod.rs @@ -263,8 +263,8 @@ pub struct SignerConfig { /// Configures a target number of DKG rounds to run/accept. If this is set /// and the number of DKG shares is less than this number, the coordinator /// will continue to run DKG rounds until this number of rounds is reached, - /// assuming the conditions for `dkg_rerun_bitcoin_height` are also met. If - /// DKG has never been run, this configuration has no effect. + /// assuming the conditions for `dkg_min_bitcoin_block_height` are also met. + /// If DKG has never been run, this configuration has no effect. pub dkg_target_rounds: NonZeroU32, } @@ -666,7 +666,7 @@ mod tests { } #[test] - fn default_config_toml_loads_dkg_rerun_bitcoin_height() { + fn default_config_toml_loads_dkg_min_bitcoin_block_height() { clear_env(); let settings = Settings::new_from_default_config().unwrap(); @@ -681,7 +681,7 @@ mod tests { } #[test] - fn default_config_toml_loads_dkg_rounds_target() { + fn default_config_toml_loads_dkg_target_rounds() { clear_env(); let settings = Settings::new_from_default_config().unwrap();