-
Notifications
You must be signed in to change notification settings - Fork 660
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
pox-4: remove pox-reject #4163
pox-4: remove pox-reject #4163
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## next #4163 +/- ##
==========================================
- Coverage 82.91% 82.91% -0.01%
==========================================
Files 429 429
Lines 302249 302304 +55
==========================================
+ Hits 250613 250647 +34
- Misses 51636 51657 +21 ☔ View full report in Codecov by Sentry. |
This seems uncontroversial, let's get it merged. |
@@ -933,8 +856,6 @@ | |||
prepare-cycle-length: (var-get pox-prepare-cycle-length), | |||
first-burnchain-block-height: (var-get first-burnchain-block-height), | |||
reward-cycle-length: (var-get pox-reward-cycle-length), | |||
rejection-fraction: (var-get pox-rejection-fraction), | |||
current-rejection-votes: (next-cycle-rejection-votes), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of these fields will break /v2/pox
and lead to a runtime panic. Please fix stackslib/src/net/api/getpoxinfo.rs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done thanks to @kantai
@@ -1360,7 +1360,6 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> { | |||
Value::UInt(u128::from(first_block_height)), | |||
Value::UInt(u128::from(pox_prepare_length)), | |||
Value::UInt(u128::from(pox_reward_cycle_length)), | |||
Value::UInt(u128::from(pox_rejection_fraction)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also remove the declaration of pox_rejection_fraction
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
(begin | ||
(asserts! (not (var-get configured)) (err ERR_NOT_ALLOWED)) | ||
(var-set first-burnchain-block-height first-burn-height) | ||
(var-set pox-prepare-cycle-length prepare-cycle-length) | ||
(var-set pox-reward-cycle-length reward-cycle-length) | ||
(var-set pox-rejection-fraction rejection-fraction) | ||
(var-set first-2-1-reward-cycle begin-2-1-reward-cycle) | ||
(var-set first-pox-4-reward-cycle begin-pox-4-reward-cycle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @friedger, thanks for sending this! Please address my comments and I'll rereview. As-is, this would introduce a runtime panic in the /v2/pox
handler, because it expects PoX rejection state to be present in pox-4
.
622bceb
to
4eed0bd
Compare
In the interest of speeding this along, here's a suggested patch for dealing with the issue @jcnelson mentioned: It also adds a test which panics without the changes in diff --git a/stackslib/src/net/api/getpoxinfo.rs b/stackslib/src/net/api/getpoxinfo.rs
index 0987b9ede..32c9ed6db 100644
--- a/stackslib/src/net/api/getpoxinfo.rs
+++ b/stackslib/src/net/api/getpoxinfo.rs
@@ -70,7 +70,7 @@ pub struct RPCPoxNextCycleInfo {
pub blocks_until_prepare_phase: i64,
pub reward_phase_start_block_height: u64,
pub blocks_until_reward_phase: u64,
- pub ustx_until_pox_rejection: u64,
+ pub ustx_until_pox_rejection: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -90,7 +90,7 @@ pub struct RPCPoxInfoData {
pub prepare_phase_block_length: u64,
pub reward_phase_block_length: u64,
pub reward_slots: u64,
- pub rejection_fraction: u64,
+ pub rejection_fraction: Option<u64>,
pub total_liquid_supply_ustx: u64,
pub current_cycle: RPCPoxCurrentCycleInfo,
pub next_cycle: RPCPoxNextCycleInfo,
@@ -100,7 +100,7 @@ pub struct RPCPoxInfoData {
pub prepare_cycle_length: u64,
pub reward_cycle_id: u64,
pub reward_cycle_length: u64,
- pub rejection_votes_left_required: u64,
+ pub rejection_votes_left_required: Option<u64>,
pub next_reward_cycle_in: u64,
// Information specific to each PoX contract version
@@ -202,12 +202,6 @@ impl RPCPoxInfoData {
.to_owned()
.expect_u128() as u64;
- let rejection_fraction = res
- .get("rejection-fraction")
- .expect(&format!("FATAL: no 'rejection-fraction'"))
- .to_owned()
- .expect_u128() as u64;
-
let reward_cycle_id = res
.get("reward-cycle-id")
.expect(&format!("FATAL: no 'reward-cycle-id'"))
@@ -220,24 +214,39 @@ impl RPCPoxInfoData {
.to_owned()
.expect_u128() as u64;
- let current_rejection_votes = res
- .get("current-rejection-votes")
- .expect(&format!("FATAL: no 'current-rejection-votes'"))
- .to_owned()
- .expect_u128() as u64;
-
let total_liquid_supply_ustx = res
.get("total-liquid-supply-ustx")
.expect(&format!("FATAL: no 'total-liquid-supply-ustx'"))
.to_owned()
.expect_u128() as u64;
- let total_required = (total_liquid_supply_ustx as u128 / 100)
- .checked_mul(rejection_fraction as u128)
- .ok_or_else(|| NetError::DBError(DBError::Overflow))?
- as u64;
-
- let rejection_votes_left_required = total_required.saturating_sub(current_rejection_votes);
+ let has_rejection_data = pox_contract_name == POX_1_NAME
+ || pox_contract_name == POX_2_NAME
+ || pox_contract_name == POX_3_NAME;
+
+ let (rejection_fraction, rejection_votes_left_required) = if has_rejection_data {
+ let rejection_fraction = res
+ .get("rejection-fraction")
+ .expect(&format!("FATAL: no 'rejection-fraction'"))
+ .to_owned()
+ .expect_u128() as u64;
+
+ let current_rejection_votes = res
+ .get("current-rejection-votes")
+ .expect(&format!("FATAL: no 'current-rejection-votes'"))
+ .to_owned()
+ .expect_u128() as u64;
+
+ let total_required = (total_liquid_supply_ustx as u128 / 100)
+ .checked_mul(rejection_fraction as u128)
+ .ok_or_else(|| NetError::DBError(DBError::Overflow))?
+ as u64;
+
+ let votes_left = total_required.saturating_sub(current_rejection_votes);
+ (Some(rejection_fraction), Some(votes_left))
+ } else {
+ (None, None)
+ };
let burnchain_tip = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn())?;
diff --git a/testnet/stacks-node/src/mockamoto/tests.rs b/testnet/stacks-node/src/mockamoto/tests.rs
index 2c7df7000..a2d43f4f7 100644
--- a/testnet/stacks-node/src/mockamoto/tests.rs
+++ b/testnet/stacks-node/src/mockamoto/tests.rs
@@ -19,7 +19,7 @@ use wsts::curve::scalar::Scalar;
use super::MockamotoNode;
use crate::config::{EventKeyType, EventObserverConfig};
use crate::neon_node::PeerThread;
-use crate::tests::neon_integrations::{submit_tx, test_observer};
+use crate::tests::neon_integrations::{get_pox_info, submit_tx, test_observer};
use crate::tests::{make_contract_call, make_stacks_transfer, to_addr};
use crate::{Config, ConfigFile};
@@ -354,3 +354,63 @@ fn observe_set_aggregate_key() {
assert_eq!(orig_aggregate_key.unwrap(), orig_key);
assert_eq!(new_aggregate_key.unwrap(), orig_key);
}
+
+#[test]
+fn rpc_pox_info() {
+ let mut conf = Config::from_config_file(ConfigFile::mockamoto()).unwrap();
+ conf.node.mockamoto_time_ms = 10;
+ conf.node.rpc_bind = "127.0.0.1:19543".into();
+ conf.node.p2p_bind = "127.0.0.1:19544".into();
+
+ let observer_port = 19500;
+ test_observer::spawn_at(observer_port);
+ conf.events_observers.insert(EventObserverConfig {
+ endpoint: format!("localhost:{observer_port}"),
+ events_keys: vec![EventKeyType::AnyEvent],
+ });
+
+ let mut mockamoto = MockamotoNode::new(&conf).unwrap();
+ let globals = mockamoto.globals.clone();
+
+ let http_origin = format!("http://{}", &conf.node.rpc_bind);
+
+ let start = Instant::now();
+
+ let node_thread = thread::Builder::new()
+ .name("mockamoto-main".into())
+ .spawn(move || mockamoto.run())
+ .expect("FATAL: failed to start mockamoto main thread");
+
+ // mine 5 blocks
+ let completed = loop {
+ // complete within 2 minutes or abort
+ if Instant::now().duration_since(start) > Duration::from_secs(120) {
+ break false;
+ }
+ let latest_block = test_observer::get_blocks().pop();
+ thread::sleep(Duration::from_secs(1));
+ let Some(ref latest_block) = latest_block else {
+ info!("No block observed yet!");
+ continue;
+ };
+ let stacks_block_height = latest_block.get("block_height").unwrap().as_u64().unwrap();
+ info!("Block height observed: {stacks_block_height}");
+
+ if stacks_block_height >= 5 {
+ break true;
+ }
+ };
+
+ // fetch rpc poxinfo
+ let _pox_info = get_pox_info(&http_origin);
+
+ globals.signal_stop();
+
+ assert!(
+ completed,
+ "Mockamoto node failed to produce and announce 100 blocks before timeout"
+ );
+ node_thread
+ .join()
+ .expect("Failed to join node thread to exit");
+}
diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs
index 5676d1bb1..db507e48c 100644
--- a/testnet/stacks-node/src/tests/neon_integrations.rs
+++ b/testnet/stacks-node/src/tests/neon_integrations.rs
@@ -5992,7 +5992,7 @@ fn pox_integration_test() {
);
assert_eq!(
pox_info.rejection_fraction,
- pox_constants.pox_rejection_fraction
+ Some(pox_constants.pox_rejection_fraction)
);
assert_eq!(pox_info.reward_cycle_id, 0);
assert_eq!(pox_info.current_cycle.id, 0);
@@ -6060,7 +6060,7 @@ fn pox_integration_test() {
);
assert_eq!(
pox_info.rejection_fraction,
- pox_constants.pox_rejection_fraction
+ Some(pox_constants.pox_rejection_fraction)
);
assert_eq!(pox_info.reward_cycle_id, 14);
assert_eq!(pox_info.current_cycle.id, 14);
@@ -6191,7 +6191,7 @@ fn pox_integration_test() {
);
assert_eq!(
pox_info.rejection_fraction,
- pox_constants.pox_rejection_fraction
+ Some(pox_constants.pox_rejection_fraction)
);
assert_eq!(pox_info.reward_cycle_id, 14);
assert_eq!(pox_info.current_cycle.id, 14); |
…stacks-blockchain into feat/pox-4-vote-disabled
…x-4" This reverts commit aabce29.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @friedger!
Tagging @jcnelson for a re-review here |
Description
This PR removes
pox-reject
from pox-4 and relevant code in boot/mod.rsApplicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml