Skip to content

Commit 5f8a390

Browse files
committed
Merge branch 'develop' into feat/clarity-wasm-develop
2 parents 4eaeabe + b723ac1 commit 5f8a390

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2412
-825
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jobs:
9898
- tests::signer::v0::miner_forking
9999
- tests::signer::v0::reloads_signer_set_in
100100
- tests::signer::v0::signers_broadcast_signed_blocks
101+
- tests::signer::v0::min_gap_between_blocks
101102
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
102103
- tests::nakamoto_integrations::check_block_heights
103104
- tests::nakamoto_integrations::clarity_burn_state

.github/workflows/pr-differences-mutants.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,34 @@ on:
99
- ready_for_review
1010
paths:
1111
- '**.rs'
12+
workflow_dispatch:
1213

1314
concurrency:
1415
group: pr-differences-${{ github.head_ref || github.ref || github.run_id }}
1516
# Always cancel duplicate jobs
1617
cancel-in-progress: true
1718

1819
jobs:
20+
check-access-permissions:
21+
name: Check Access Permissions
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Check Access Permissions To Trigger This
26+
id: check_access_permissions
27+
uses: stacks-network/actions/team-membership@main
28+
with:
29+
username: ${{ github.actor }}
30+
team: 'blockchain-team'
31+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
32+
33+
outputs:
34+
ignore_timeout: ${{ steps.check_access_permissions.outputs.is_team_member == 'true' && github.event_name == 'workflow_dispatch' }}
35+
1936
# Check and output whether to run big (`stacks-node`/`stackslib`) or small (others) packages with or without shards
2037
check-big-packages-and-shards:
2138
name: Check Packages and Shards
39+
needs: check-access-permissions
2240

2341
runs-on: ubuntu-latest
2442

@@ -30,10 +48,13 @@ jobs:
3048
run_small_packages: ${{ steps.check_packages_and_shards.outputs.run_small_packages }}
3149
small_packages_with_shards: ${{ steps.check_packages_and_shards.outputs.small_packages_with_shards }}
3250
run_stacks_signer: ${{ steps.check_packages_and_shards.outputs.run_stacks_signer }}
51+
too_many_mutants: ${{ steps.check_packages_and_shards.outputs.too_many_mutants }}
3352

3453
steps:
3554
- id: check_packages_and_shards
3655
uses: stacks-network/actions/stacks-core/mutation-testing/check-packages-and-shards@main
56+
with:
57+
ignore_timeout: ${{ needs.check-access-permissions.outputs.ignore_timeout }}
3758

3859
# Mutation testing - Execute on PR on small packages that have functions modified (normal run, no shards)
3960
pr-differences-mutants-small-normal:
@@ -220,3 +241,4 @@ jobs:
220241
small_packages: ${{ needs.check-big-packages-and-shards.outputs.run_small_packages }}
221242
shards_for_small_packages: ${{ needs.check-big-packages-and-shards.outputs.small_packages_with_shards }}
222243
stacks_signer: ${{ needs.check-big-packages-and-shards.outputs.run_stacks_signer }}
244+
too_many_mutants: ${{ needs.check-big-packages-and-shards.outputs.too_many_mutants }}

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stacks-common/src/types/chainstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ impl_byte_array_serde!(TrieHash);
2828

2929
pub const TRIEHASH_ENCODED_SIZE: usize = 32;
3030

31+
#[derive(Serialize, Deserialize)]
3132
pub struct BurnchainHeaderHash(pub [u8; 32]);
3233
impl_array_newtype!(BurnchainHeaderHash, u8, 32);
3334
impl_array_hexstring_fmt!(BurnchainHeaderHash);
3435
impl_byte_array_newtype!(BurnchainHeaderHash, u8, 32);
35-
impl_byte_array_serde!(BurnchainHeaderHash);
3636

3737
pub struct BlockHeaderHash(pub [u8; 32]);
3838
impl_array_newtype!(BlockHeaderHash, u8, 32);

stacks-common/src/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub enum StacksEpochId {
8282
Epoch30 = 0x03000,
8383
}
8484

85+
#[derive(Debug)]
8586
pub enum MempoolCollectionBehavior {
8687
ByStacksHeight,
8788
ByReceiveTime,

stackslib/src/burnchains/burnchain.rs

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -549,47 +549,43 @@ impl Burnchain {
549549
.expect("Overflowed u64 in calculating expected sunset_burn")
550550
}
551551

552+
/// Is this the first block to receive rewards in its cycle?
553+
/// This is the mod 1 block. Note: in nakamoto, the signer set for cycle N signs
554+
/// the mod 0 block.
552555
pub fn is_reward_cycle_start(&self, burn_height: u64) -> bool {
553556
self.pox_constants
554557
.is_reward_cycle_start(self.first_block_height, burn_height)
555558
}
556559

560+
/// Is this the first block to be signed by the signer set in cycle N?
561+
/// This is the mod 0 block.
562+
pub fn is_naka_signing_cycle_start(&self, burn_height: u64) -> bool {
563+
self.pox_constants
564+
.is_naka_signing_cycle_start(self.first_block_height, burn_height)
565+
}
566+
567+
/// return the first burn block which receives reward in `reward_cycle`.
568+
/// this is the modulo 1 block
557569
pub fn reward_cycle_to_block_height(&self, reward_cycle: u64) -> u64 {
558570
self.pox_constants
559571
.reward_cycle_to_block_height(self.first_block_height, reward_cycle)
560572
}
561573

562-
/// Compute the reward cycle ID of the PoX reward set which is active as of this burn_height.
563-
/// The reward set is calculated at reward cycle index 1, so if this block height is at or after
564-
/// reward cycle index 1, then this behaves like `block_height_to_reward_cycle()`. However,
565-
/// if it's reward cycle index is 0, then it belongs to the previous reward cycle.
566-
pub fn pox_reward_cycle(&self, block_height: u64) -> Option<u64> {
567-
let cycle = self.block_height_to_reward_cycle(block_height)?;
568-
let effective_height = block_height.checked_sub(self.first_block_height)?;
569-
if effective_height % u64::from(self.pox_constants.reward_cycle_length) == 0 {
570-
Some(cycle.saturating_sub(1))
571-
} else {
572-
Some(cycle)
573-
}
574+
/// the first burn block that must be *signed* by the signer set of `reward_cycle`.
575+
/// this is the modulo 0 block
576+
pub fn nakamoto_first_block_of_cycle(&self, reward_cycle: u64) -> u64 {
577+
self.pox_constants
578+
.nakamoto_first_block_of_cycle(self.first_block_height, reward_cycle)
574579
}
575580

581+
/// What is the reward cycle for this block height?
582+
/// This considers the modulo 0 block to be in reward cycle `n`, even though
583+
/// rewards for cycle `n` do not begin until modulo 1.
576584
pub fn block_height_to_reward_cycle(&self, block_height: u64) -> Option<u64> {
577585
self.pox_constants
578586
.block_height_to_reward_cycle(self.first_block_height, block_height)
579587
}
580588

581-
pub fn static_block_height_to_reward_cycle(
582-
block_height: u64,
583-
first_block_height: u64,
584-
reward_cycle_length: u64,
585-
) -> Option<u64> {
586-
PoxConstants::static_block_height_to_reward_cycle(
587-
block_height,
588-
first_block_height,
589-
reward_cycle_length,
590-
)
591-
}
592-
593589
/// Is this block either the first block in a reward cycle or
594590
/// right before the reward phase starts? This is the mod 0 or mod 1
595591
/// block. Reward cycle start events (like auto-unlocks) process *after*
@@ -607,27 +603,19 @@ impl Burnchain {
607603
(effective_height % reward_cycle_length) <= 1
608604
}
609605

610-
pub fn static_is_in_prepare_phase(
611-
first_block_height: u64,
612-
reward_cycle_length: u64,
613-
prepare_length: u64,
614-
block_height: u64,
615-
) -> bool {
616-
PoxConstants::static_is_in_prepare_phase(
617-
first_block_height,
618-
reward_cycle_length,
619-
prepare_length,
620-
block_height,
621-
)
606+
/// Does this block include reward slots?
607+
/// This is either in the last prepare_phase_length blocks of the cycle
608+
/// or the modulo 0 block
609+
pub fn is_in_prepare_phase(&self, block_height: u64) -> bool {
610+
self.pox_constants
611+
.is_in_prepare_phase(self.first_block_height, block_height)
622612
}
623613

624-
pub fn is_in_prepare_phase(&self, block_height: u64) -> bool {
625-
Self::static_is_in_prepare_phase(
626-
self.first_block_height,
627-
self.pox_constants.reward_cycle_length as u64,
628-
self.pox_constants.prepare_length.into(),
629-
block_height,
630-
)
614+
/// The prepare phase is the last prepare_phase_length blocks of the cycle
615+
/// This cannot include the 0 block for nakamoto
616+
pub fn is_in_naka_prepare_phase(&self, block_height: u64) -> bool {
617+
self.pox_constants
618+
.is_in_naka_prepare_phase(self.first_block_height, block_height)
631619
}
632620

633621
pub fn regtest(working_dir: &str) -> Burnchain {

stackslib/src/burnchains/mod.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl PoxConstants {
517517
}
518518
}
519519

520-
/// What's the first block in the prepare phase
520+
/// The first block of the prepare phase during `reward_cycle`. This is the prepare phase _for the next cycle_.
521521
pub fn prepare_phase_start(&self, first_block_height: u64, reward_cycle: u64) -> u64 {
522522
let reward_cycle_start =
523523
self.reward_cycle_to_block_height(first_block_height, reward_cycle);
@@ -526,18 +526,37 @@ impl PoxConstants {
526526
prepare_phase_start
527527
}
528528

529+
/// Is this the first block to receive rewards in its cycle?
530+
/// This is the mod 1 block. Note: in nakamoto, the signer set for cycle N signs
531+
/// the mod 0 block.
529532
pub fn is_reward_cycle_start(&self, first_block_height: u64, burn_height: u64) -> bool {
530533
let effective_height = burn_height - first_block_height;
531534
// first block of the new reward cycle
532535
(effective_height % u64::from(self.reward_cycle_length)) == 1
533536
}
534537

538+
/// Is this the first block to be signed by the signer set in cycle N?
539+
/// This is the mod 0 block.
540+
pub fn is_naka_signing_cycle_start(&self, first_block_height: u64, burn_height: u64) -> bool {
541+
let effective_height = burn_height - first_block_height;
542+
// first block of the new reward cycle
543+
(effective_height % u64::from(self.reward_cycle_length)) == 0
544+
}
545+
546+
/// return the first burn block which receives reward in `reward_cycle`.
547+
/// this is the modulo 1 block
535548
pub fn reward_cycle_to_block_height(&self, first_block_height: u64, reward_cycle: u64) -> u64 {
536549
// NOTE: the `+ 1` is because the height of the first block of a reward cycle is mod 1, not
537550
// mod 0.
538551
first_block_height + reward_cycle * u64::from(self.reward_cycle_length) + 1
539552
}
540553

554+
/// the first burn block that must be *signed* by the signer set of `reward_cycle`.
555+
/// this is the modulo 0 block
556+
pub fn nakamoto_first_block_of_cycle(&self, first_block_height: u64, reward_cycle: u64) -> u64 {
557+
first_block_height + reward_cycle * u64::from(self.reward_cycle_length)
558+
}
559+
541560
pub fn reward_cycle_index(&self, first_block_height: u64, burn_height: u64) -> Option<u64> {
542561
let effective_height = burn_height.checked_sub(first_block_height)?;
543562
Some(effective_height % u64::from(self.reward_cycle_length))
@@ -609,6 +628,35 @@ impl PoxConstants {
609628
}
610629
}
611630

631+
/// The prepare phase is the last prepare_phase_length blocks of the cycle
632+
/// This cannot include the 0 block for nakamoto
633+
pub fn is_in_naka_prepare_phase(&self, first_block_height: u64, block_height: u64) -> bool {
634+
Self::static_is_in_naka_prepare_phase(
635+
first_block_height,
636+
u64::from(self.reward_cycle_length),
637+
u64::from(self.prepare_length),
638+
block_height,
639+
)
640+
}
641+
642+
/// The prepare phase is the last prepare_phase_length blocks of the cycle
643+
/// This cannot include the 0 block for nakamoto
644+
pub fn static_is_in_naka_prepare_phase(
645+
first_block_height: u64,
646+
reward_cycle_length: u64,
647+
prepare_length: u64,
648+
block_height: u64,
649+
) -> bool {
650+
if block_height <= first_block_height {
651+
// not a reward cycle start if we're the first block after genesis.
652+
false
653+
} else {
654+
let effective_height = block_height - first_block_height;
655+
let reward_index = effective_height % reward_cycle_length;
656+
reward_index > u64::from(reward_cycle_length - prepare_length)
657+
}
658+
}
659+
612660
/// Returns the active reward cycle at the given burn block height
613661
/// * `first_block_ht` - the first burn block height that the Stacks network monitored
614662
/// * `reward_cycle_len` - the length of each reward cycle in the network.

0 commit comments

Comments
 (0)