Skip to content

Commit e7f3c55

Browse files
authored
Merge branch 'next' into chore/merge-2.05.0.2.0-to-next
2 parents dd4929b + 4e84127 commit e7f3c55

File tree

22 files changed

+97
-1070
lines changed

22 files changed

+97
-1070
lines changed

src/burnchains/burnchain.rs

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl BurnchainStateTransition {
115115
parent_snapshot: &BlockSnapshot,
116116
block_ops: &Vec<BlockstackOperationType>,
117117
missed_commits: &Vec<MissedBlockCommit>,
118-
sunset_end: u64,
119118
) -> Result<BurnchainStateTransition, burnchain_error> {
120119
// block commits and support burns discovered in this block.
121120
let mut block_commits: Vec<LeaderBlockCommitOp> = vec![];
@@ -167,9 +166,7 @@ impl BurnchainStateTransition {
167166
let mut windowed_block_commits = vec![block_commits];
168167
let mut windowed_missed_commits = vec![];
169168

170-
if !burnchain.is_in_prepare_phase(parent_snapshot.block_height + 1)
171-
&& parent_snapshot.block_height + 1 <= burnchain.pox_constants.sunset_end
172-
{
169+
if !burnchain.is_in_prepare_phase(parent_snapshot.block_height + 1) {
173170
// PoX reward-phase is active!
174171
// build a map of intended sortition -> missed commit for the missed commits
175172
// discovered in this block.
@@ -212,7 +209,7 @@ impl BurnchainStateTransition {
212209
} else {
213210
// PoX reward-phase is not active
214211
debug!(
215-
"Block {} is in a prepare phase or post-PoX sunset, so no windowing will take place",
212+
"Block {} is in a prepare phase, so no windowing will take place",
216213
parent_snapshot.block_height + 1
217214
);
218215

@@ -224,18 +221,14 @@ impl BurnchainStateTransition {
224221
windowed_block_commits.reverse();
225222
windowed_missed_commits.reverse();
226223

227-
// figure out if the PoX sunset finished during the window,
228-
// and/or which sortitions must be PoB due to them falling in a prepare phase.
224+
// figure out which sortitions must be PoB due to them falling in a prepare phase.
229225
let window_end_height = parent_snapshot.block_height + 1;
230226
let window_start_height = window_end_height + 1 - (windowed_block_commits.len() as u64);
231227
let mut burn_blocks = vec![false; windowed_block_commits.len()];
232228

233-
// set burn_blocks flags to accomodate prepare phases and PoX sunset
229+
// set burn_blocks flags to accomodate prepare phases
234230
for (i, b) in burn_blocks.iter_mut().enumerate() {
235-
if sunset_end <= window_start_height + (i as u64) {
236-
// past PoX sunset, so must burn
237-
*b = true;
238-
} else if burnchain.is_in_prepare_phase(window_start_height + (i as u64)) {
231+
if burnchain.is_in_prepare_phase(window_start_height + (i as u64)) {
239232
// must burn
240233
*b = true;
241234
} else {
@@ -462,40 +455,6 @@ impl Burnchain {
462455
self.network_id == NETWORK_ID_MAINNET
463456
}
464457

465-
/// the expected sunset burn is:
466-
/// total_commit * (progress through sunset phase) / (sunset phase duration)
467-
pub fn expected_sunset_burn(&self, burn_height: u64, total_commit: u64) -> u64 {
468-
if burn_height < self.pox_constants.sunset_start
469-
|| burn_height >= self.pox_constants.sunset_end
470-
{
471-
return 0;
472-
}
473-
474-
// no sunset burn needed in prepare phase -- it's already getting burnt
475-
if self.is_in_prepare_phase(burn_height) {
476-
return 0;
477-
}
478-
479-
let reward_cycle_height = self.reward_cycle_to_block_height(
480-
self.block_height_to_reward_cycle(burn_height)
481-
.expect("BUG: Sunset start is less than first_block_height"),
482-
);
483-
484-
if reward_cycle_height <= self.pox_constants.sunset_start {
485-
return 0;
486-
}
487-
488-
let sunset_duration =
489-
(self.pox_constants.sunset_end - self.pox_constants.sunset_start) as u128;
490-
let sunset_progress = (reward_cycle_height - self.pox_constants.sunset_start) as u128;
491-
492-
// use u128 to avoid any possibilities of overflowing in the calculation here.
493-
let expected_u128 = (total_commit as u128) * (sunset_progress) / sunset_duration;
494-
u64::try_from(expected_u128)
495-
// should never be possible, because sunset_burn is <= total_commit, which is a u64
496-
.expect("Overflowed u64 in calculating expected sunset_burn")
497-
}
498-
499458
pub fn is_reward_cycle_start(&self, burn_height: u64) -> bool {
500459
let effective_height = burn_height - self.first_block_height;
501460
// first block of the new reward cycle
@@ -743,20 +702,18 @@ impl Burnchain {
743702
}
744703
}
745704
}
746-
x if x == Opcodes::PreStx as u8 => {
747-
match PreStxOp::from_tx(block_header, burn_tx, burnchain.pox_constants.sunset_end) {
748-
Ok(op) => Some(BlockstackOperationType::PreStx(op)),
749-
Err(e) => {
750-
warn!(
751-
"Failed to parse pre stack stx tx";
752-
"txid" => %burn_tx.txid(),
753-
"data" => %to_hex(&burn_tx.data()),
754-
"error" => ?e,
755-
);
756-
None
757-
}
705+
x if x == Opcodes::PreStx as u8 => match PreStxOp::from_tx(block_header, burn_tx) {
706+
Ok(op) => Some(BlockstackOperationType::PreStx(op)),
707+
Err(e) => {
708+
warn!(
709+
"Failed to parse pre stack stx tx";
710+
"txid" => %burn_tx.txid(),
711+
"data" => %to_hex(&burn_tx.data()),
712+
"error" => ?e,
713+
);
714+
None
758715
}
759-
}
716+
},
760717
x if x == Opcodes::TransferStx as u8 => {
761718
let pre_stx_txid = TransferStxOp::get_sender_txid(burn_tx).ok()?;
762719
let pre_stx_tx = match pre_stx_op_map.get(&pre_stx_txid) {
@@ -794,12 +751,7 @@ impl Burnchain {
794751
};
795752
if let Some(BlockstackOperationType::PreStx(pre_stack_stx)) = pre_stx_tx {
796753
let sender = &pre_stack_stx.output;
797-
match StackStxOp::from_tx(
798-
block_header,
799-
burn_tx,
800-
sender,
801-
burnchain.pox_constants.sunset_end,
802-
) {
754+
match StackStxOp::from_tx(block_header, burn_tx, sender) {
803755
Ok(op) => Some(BlockstackOperationType::StackStx(op)),
804756
Err(e) => {
805757
warn!(
@@ -1864,7 +1816,6 @@ pub mod tests {
18641816
};
18651817

18661818
let block_commit_1 = LeaderBlockCommitOp {
1867-
sunset_burn: 0,
18681819
commit_outs: vec![],
18691820
block_header_hash: BlockHeaderHash::from_bytes(
18701821
&hex_bytes("2222222222222222222222222222222222222222222222222222222222222222")
@@ -1905,7 +1856,6 @@ pub mod tests {
19051856
};
19061857

19071858
let block_commit_2 = LeaderBlockCommitOp {
1908-
sunset_burn: 0,
19091859
commit_outs: vec![],
19101860
block_header_hash: BlockHeaderHash::from_bytes(
19111861
&hex_bytes("2222222222222222222222222222222222222222222222222222222222222223")
@@ -1946,7 +1896,6 @@ pub mod tests {
19461896
};
19471897

19481898
let block_commit_3 = LeaderBlockCommitOp {
1949-
sunset_burn: 0,
19501899
commit_outs: vec![],
19511900
block_header_hash: BlockHeaderHash::from_bytes(
19521901
&hex_bytes("2222222222222222222222222222222222222222222222222222222222222224")
@@ -2509,7 +2458,6 @@ pub mod tests {
25092458
// insert block commit paired to previous round's leader key, as well as a user burn
25102459
if i > 0 {
25112460
let next_block_commit = LeaderBlockCommitOp {
2512-
sunset_burn: 0,
25132461
commit_outs: vec![],
25142462
block_header_hash: BlockHeaderHash::from_bytes(&vec![
25152463
i, i, i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

src/burnchains/db.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@ mod tests {
430430

431431
let mut burnchain = Burnchain::regtest(":memory:");
432432
burnchain.pox_constants = PoxConstants::test_default();
433-
burnchain.pox_constants.sunset_start = 999;
434-
burnchain.pox_constants.sunset_end = 1000;
435433

436434
let first_block_header = burnchain_db.get_canonical_chain_tip().unwrap();
437435
assert_eq!(&first_block_header.block_hash, &first_bhh);
@@ -542,8 +540,6 @@ mod tests {
542540

543541
let mut burnchain = Burnchain::regtest(":memory:");
544542
burnchain.pox_constants = PoxConstants::test_default();
545-
burnchain.pox_constants.sunset_start = 999;
546-
burnchain.pox_constants.sunset_end = 1000;
547543

548544
let first_block_header = burnchain_db.get_canonical_chain_tip().unwrap();
549545
assert_eq!(&first_block_header.block_hash, &first_bhh);

src/burnchains/mod.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,6 @@ pub struct PoxConstants {
301301
/// percentage of liquid STX that must participate for PoX
302302
/// to occur
303303
pub pox_participation_threshold_pct: u64,
304-
/// last+1 block height of sunset phase
305-
pub sunset_end: u64,
306-
/// first block height of sunset phase
307-
pub sunset_start: u64,
308304
/// The auto unlock height for PoX v1 lockups before transition to PoX v2. This
309305
/// also defines the burn height at which PoX reward sets are calculated using
310306
/// PoX v2 rather than v1
@@ -319,30 +315,25 @@ impl PoxConstants {
319315
anchor_threshold: u32,
320316
pox_rejection_fraction: u64,
321317
pox_participation_threshold_pct: u64,
322-
sunset_start: u64,
323-
sunset_end: u64,
324318
v1_unlock_height: u32,
325319
) -> PoxConstants {
326320
assert!(anchor_threshold > (prepare_length / 2));
327321
assert!(prepare_length < reward_cycle_length);
328-
assert!(sunset_start <= sunset_end);
329322

330323
PoxConstants {
331324
reward_cycle_length,
332325
prepare_length,
333326
anchor_threshold,
334327
pox_rejection_fraction,
335328
pox_participation_threshold_pct,
336-
sunset_start,
337-
sunset_end,
338329
v1_unlock_height,
339330
_shadow: PhantomData,
340331
}
341332
}
342333
#[cfg(test)]
343334
pub fn test_default() -> PoxConstants {
344335
// 20 reward slots; 10 prepare-phase slots
345-
PoxConstants::new(10, 5, 3, 25, 5, 5000, 10000, u32::max_value())
336+
PoxConstants::new(10, 5, 3, 25, 5, u32::max_value())
346337
}
347338

348339
/// Returns the PoX contract that is "active" at the given burn block height
@@ -375,8 +366,6 @@ impl PoxConstants {
375366
80,
376367
25,
377368
5,
378-
BITCOIN_MAINNET_FIRST_BLOCK_HEIGHT + POX_SUNSET_START,
379-
BITCOIN_MAINNET_FIRST_BLOCK_HEIGHT + POX_SUNSET_END,
380369
POX_V1_MAINNET_EARLY_UNLOCK_HEIGHT,
381370
)
382371
}
@@ -388,23 +377,12 @@ impl PoxConstants {
388377
40,
389378
12,
390379
2,
391-
BITCOIN_TESTNET_FIRST_BLOCK_HEIGHT + POX_SUNSET_START,
392-
BITCOIN_TESTNET_FIRST_BLOCK_HEIGHT + POX_SUNSET_END,
393380
POX_V1_TESTNET_EARLY_UNLOCK_HEIGHT,
394381
) // total liquid supply is 40000000000000000 µSTX
395382
}
396383

397384
pub fn regtest_default() -> PoxConstants {
398-
PoxConstants::new(
399-
5,
400-
1,
401-
1,
402-
3333333333333333,
403-
1,
404-
BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT + POX_SUNSET_START,
405-
BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT + POX_SUNSET_END,
406-
1_000_000,
407-
)
385+
PoxConstants::new(5, 1, 1, 3333333333333333, 1, 1_000_000)
408386
}
409387
}
410388

src/chainstate/burn/db/processing.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a> SortitionHandleTx<'a> {
116116
let this_block_hash = block_header.block_hash.clone();
117117

118118
// make the burn distribution, and in doing so, identify the user burns that we'll keep
119-
let state_transition = BurnchainStateTransition::from_block_ops(self, burnchain, parent_snapshot, this_block_ops, missed_commits, burnchain.pox_constants.sunset_end)
119+
let state_transition = BurnchainStateTransition::from_block_ops(self, burnchain, parent_snapshot, this_block_ops, missed_commits)
120120
.map_err(|e| {
121121
error!("TRANSACTION ABORTED when converting {} blockstack operations in block {} ({}) to a burn distribution: {:?}", this_block_ops.len(), this_block_height, &this_block_hash, e);
122122
e
@@ -412,7 +412,6 @@ mod tests {
412412
};
413413

414414
let block_commit = LeaderBlockCommitOp {
415-
sunset_burn: 0,
416415
block_header_hash: BlockHeaderHash([0x22; 32]),
417416
new_seed: VRFSeed::from_hex(
418417
"3333333333333333333333333333333333333333333333333333333333333333",

0 commit comments

Comments
 (0)