From abb47dd806a890c843770deb83dcef80aed0dec0 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 12 Mar 2024 14:22:13 +0100 Subject: [PATCH 1/4] feat: add `pox_stx_threshold` amount to `/new_block` event data --- stacks-signer/src/client/stacks_client.rs | 1 + stackslib/src/chainstate/coordinator/tests.rs | 1 + stackslib/src/chainstate/stacks/boot/mod.rs | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/stacks-signer/src/client/stacks_client.rs b/stacks-signer/src/client/stacks_client.rs index 80481d598..9d300c09b 100644 --- a/stacks-signer/src/client/stacks_client.rs +++ b/stacks-signer/src/client/stacks_client.rs @@ -1143,6 +1143,7 @@ mod tests { stacked_amt: rand::thread_rng().next_u64() as u128, weight: 1, }]), + pox_stx_threshold: None, }; let stackers_response = GetStackersResponse { stacker_set: stacker_set.clone(), diff --git a/stackslib/src/chainstate/coordinator/tests.rs b/stackslib/src/chainstate/coordinator/tests.rs index e3fc8f21c..3367bf554 100644 --- a/stackslib/src/chainstate/coordinator/tests.rs +++ b/stackslib/src/chainstate/coordinator/tests.rs @@ -511,6 +511,7 @@ impl RewardSetProvider for StubbedRewardSetProvider { missed_reward_slots: vec![], }, signers: None, + pox_stx_threshold: None, }) } diff --git a/stackslib/src/chainstate/stacks/boot/mod.rs b/stackslib/src/chainstate/stacks/boot/mod.rs index 67f485429..f9f128c3e 100644 --- a/stackslib/src/chainstate/stacks/boot/mod.rs +++ b/stackslib/src/chainstate/stacks/boot/mod.rs @@ -213,6 +213,34 @@ fn hex_deserialize<'de, D: serde::Deserializer<'de>>( Ok(bytes) } +fn serialize_optional_u128_as_string( + value: &Option, + serializer: S, +) -> Result +where + S: serde::Serializer, +{ + match value { + Some(v) => serializer.serialize_str(&v.to_string()), + None => serializer.serialize_none(), + } +} + +fn deserialize_optional_u128_from_string<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + use std::str::FromStr; + let opt_str = Option::::deserialize(deserializer)?; + match opt_str { + Some(s) => { + let parsed = u128::from_str(&s).map_err(serde::de::Error::custom)?; + Ok(Some(parsed)) + } + None => Ok(None), + } +} + #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct NakamotoSignerEntry { #[serde(serialize_with = "hex_serialize", deserialize_with = "hex_deserialize")] @@ -228,6 +256,12 @@ pub struct RewardSet { #[serde(skip_serializing_if = "Option::is_none", default)] // only generated for nakamoto reward sets pub signers: Option>, + #[serde( + serialize_with = "serialize_optional_u128_as_string", + deserialize_with = "deserialize_optional_u128_from_string", + skip_serializing_if = "Option::is_none" + )] + pub pox_stx_threshold: Option, } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] @@ -260,6 +294,7 @@ impl RewardSet { missed_reward_slots: vec![], }, signers: None, + pox_stx_threshold: None, } } @@ -843,6 +878,7 @@ impl StacksChainState { missed_reward_slots: missed_slots, }, signers: signer_set, + pox_stx_threshold: Some(threshold), } } From a97117cd2e08683f8b79b06f9ec8803abf6a8e0d Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 12 Mar 2024 17:59:46 +0100 Subject: [PATCH 2/4] chore: fix tests --- stackslib/src/chainstate/stacks/boot/mod.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/stackslib/src/chainstate/stacks/boot/mod.rs b/stackslib/src/chainstate/stacks/boot/mod.rs index f9f128c3e..42c6ef8fb 100644 --- a/stackslib/src/chainstate/stacks/boot/mod.rs +++ b/stackslib/src/chainstate/stacks/boot/mod.rs @@ -230,13 +230,10 @@ fn deserialize_optional_u128_from_string<'de, D>(deserializer: D) -> Result, { - use std::str::FromStr; - let opt_str = Option::::deserialize(deserializer)?; - match opt_str { - Some(s) => { - let parsed = u128::from_str(&s).map_err(serde::de::Error::custom)?; - Ok(Some(parsed)) - } + use serde::de::Error; + let s: Option = Option::deserialize(deserializer)?; + match s { + Some(str_val) => str_val.parse::().map(Some).map_err(D::Error::custom), None => Ok(None), } } @@ -258,8 +255,7 @@ pub struct RewardSet { pub signers: Option>, #[serde( serialize_with = "serialize_optional_u128_as_string", - deserialize_with = "deserialize_optional_u128_from_string", - skip_serializing_if = "Option::is_none" + deserialize_with = "deserialize_optional_u128_from_string" )] pub pox_stx_threshold: Option, } From 27df25951faf6b899cf6d3879bf4fb5c6cd03d33 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 12 Mar 2024 18:24:26 +0100 Subject: [PATCH 3/4] chore: simplify syntax --- stackslib/src/chainstate/stacks/boot/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stackslib/src/chainstate/stacks/boot/mod.rs b/stackslib/src/chainstate/stacks/boot/mod.rs index 42c6ef8fb..f93ab59cb 100644 --- a/stackslib/src/chainstate/stacks/boot/mod.rs +++ b/stackslib/src/chainstate/stacks/boot/mod.rs @@ -230,10 +230,9 @@ fn deserialize_optional_u128_from_string<'de, D>(deserializer: D) -> Result, { - use serde::de::Error; let s: Option = Option::deserialize(deserializer)?; match s { - Some(str_val) => str_val.parse::().map(Some).map_err(D::Error::custom), + Some(str_val) => str_val.parse::().map(Some).map_err(serde::de::Error::custom), None => Ok(None), } } From ebbfe1e87e59041d5d300a69b5323b16b8b3db00 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 12 Mar 2024 18:34:05 +0100 Subject: [PATCH 4/4] chore: pr feedback pox_stx_threshold to pox_ustx_threshold --- stacks-signer/src/client/stacks_client.rs | 2 +- stackslib/src/chainstate/coordinator/tests.rs | 2 +- stackslib/src/chainstate/stacks/boot/mod.rs | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/stacks-signer/src/client/stacks_client.rs b/stacks-signer/src/client/stacks_client.rs index 9d300c09b..1cf142e13 100644 --- a/stacks-signer/src/client/stacks_client.rs +++ b/stacks-signer/src/client/stacks_client.rs @@ -1143,7 +1143,7 @@ mod tests { stacked_amt: rand::thread_rng().next_u64() as u128, weight: 1, }]), - pox_stx_threshold: None, + pox_ustx_threshold: None, }; let stackers_response = GetStackersResponse { stacker_set: stacker_set.clone(), diff --git a/stackslib/src/chainstate/coordinator/tests.rs b/stackslib/src/chainstate/coordinator/tests.rs index 3367bf554..8bf7383d0 100644 --- a/stackslib/src/chainstate/coordinator/tests.rs +++ b/stackslib/src/chainstate/coordinator/tests.rs @@ -511,7 +511,7 @@ impl RewardSetProvider for StubbedRewardSetProvider { missed_reward_slots: vec![], }, signers: None, - pox_stx_threshold: None, + pox_ustx_threshold: None, }) } diff --git a/stackslib/src/chainstate/stacks/boot/mod.rs b/stackslib/src/chainstate/stacks/boot/mod.rs index f93ab59cb..687e04af2 100644 --- a/stackslib/src/chainstate/stacks/boot/mod.rs +++ b/stackslib/src/chainstate/stacks/boot/mod.rs @@ -232,7 +232,10 @@ where { let s: Option = Option::deserialize(deserializer)?; match s { - Some(str_val) => str_val.parse::().map(Some).map_err(serde::de::Error::custom), + Some(str_val) => str_val + .parse::() + .map(Some) + .map_err(serde::de::Error::custom), None => Ok(None), } } @@ -256,7 +259,7 @@ pub struct RewardSet { serialize_with = "serialize_optional_u128_as_string", deserialize_with = "deserialize_optional_u128_from_string" )] - pub pox_stx_threshold: Option, + pub pox_ustx_threshold: Option, } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] @@ -289,7 +292,7 @@ impl RewardSet { missed_reward_slots: vec![], }, signers: None, - pox_stx_threshold: None, + pox_ustx_threshold: None, } } @@ -873,7 +876,7 @@ impl StacksChainState { missed_reward_slots: missed_slots, }, signers: signer_set, - pox_stx_threshold: Some(threshold), + pox_ustx_threshold: Some(threshold), } }