Skip to content

Commit

Permalink
Merge branch 'develop' into feat/clarity-wasm-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed Aug 29, 2024
2 parents 4eaeabe + b723ac1 commit 5f8a390
Show file tree
Hide file tree
Showing 50 changed files with 2,412 additions and 825 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
- tests::signer::v0::miner_forking
- tests::signer::v0::reloads_signer_set_in
- tests::signer::v0::signers_broadcast_signed_blocks
- tests::signer::v0::min_gap_between_blocks
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
- tests::nakamoto_integrations::check_block_heights
- tests::nakamoto_integrations::clarity_burn_state
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/pr-differences-mutants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,34 @@ on:
- ready_for_review
paths:
- '**.rs'
workflow_dispatch:

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

jobs:
check-access-permissions:
name: Check Access Permissions
runs-on: ubuntu-latest

steps:
- name: Check Access Permissions To Trigger This
id: check_access_permissions
uses: stacks-network/actions/team-membership@main
with:
username: ${{ github.actor }}
team: 'blockchain-team'
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

outputs:
ignore_timeout: ${{ steps.check_access_permissions.outputs.is_team_member == 'true' && github.event_name == 'workflow_dispatch' }}

# Check and output whether to run big (`stacks-node`/`stackslib`) or small (others) packages with or without shards
check-big-packages-and-shards:
name: Check Packages and Shards
needs: check-access-permissions

runs-on: ubuntu-latest

Expand All @@ -30,10 +48,13 @@ jobs:
run_small_packages: ${{ steps.check_packages_and_shards.outputs.run_small_packages }}
small_packages_with_shards: ${{ steps.check_packages_and_shards.outputs.small_packages_with_shards }}
run_stacks_signer: ${{ steps.check_packages_and_shards.outputs.run_stacks_signer }}
too_many_mutants: ${{ steps.check_packages_and_shards.outputs.too_many_mutants }}

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

# Mutation testing - Execute on PR on small packages that have functions modified (normal run, no shards)
pr-differences-mutants-small-normal:
Expand Down Expand Up @@ -220,3 +241,4 @@ jobs:
small_packages: ${{ needs.check-big-packages-and-shards.outputs.run_small_packages }}
shards_for_small_packages: ${{ needs.check-big-packages-and-shards.outputs.small_packages_with_shards }}
stacks_signer: ${{ needs.check-big-packages-and-shards.outputs.run_stacks_signer }}
too_many_mutants: ${{ needs.check-big-packages-and-shards.outputs.too_many_mutants }}
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion stacks-common/src/types/chainstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ impl_byte_array_serde!(TrieHash);

pub const TRIEHASH_ENCODED_SIZE: usize = 32;

#[derive(Serialize, Deserialize)]
pub struct BurnchainHeaderHash(pub [u8; 32]);
impl_array_newtype!(BurnchainHeaderHash, u8, 32);
impl_array_hexstring_fmt!(BurnchainHeaderHash);
impl_byte_array_newtype!(BurnchainHeaderHash, u8, 32);
impl_byte_array_serde!(BurnchainHeaderHash);

pub struct BlockHeaderHash(pub [u8; 32]);
impl_array_newtype!(BlockHeaderHash, u8, 32);
Expand Down
1 change: 1 addition & 0 deletions stacks-common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub enum StacksEpochId {
Epoch30 = 0x03000,
}

#[derive(Debug)]
pub enum MempoolCollectionBehavior {
ByStacksHeight,
ByReceiveTime,
Expand Down
74 changes: 31 additions & 43 deletions stackslib/src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,47 +549,43 @@ impl Burnchain {
.expect("Overflowed u64 in calculating expected sunset_burn")
}

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

/// Is this the first block to be signed by the signer set in cycle N?
/// This is the mod 0 block.
pub fn is_naka_signing_cycle_start(&self, burn_height: u64) -> bool {
self.pox_constants
.is_naka_signing_cycle_start(self.first_block_height, burn_height)
}

/// return the first burn block which receives reward in `reward_cycle`.
/// this is the modulo 1 block
pub fn reward_cycle_to_block_height(&self, reward_cycle: u64) -> u64 {
self.pox_constants
.reward_cycle_to_block_height(self.first_block_height, reward_cycle)
}

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

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

pub fn static_block_height_to_reward_cycle(
block_height: u64,
first_block_height: u64,
reward_cycle_length: u64,
) -> Option<u64> {
PoxConstants::static_block_height_to_reward_cycle(
block_height,
first_block_height,
reward_cycle_length,
)
}

/// Is this block either the first block in a reward cycle or
/// right before the reward phase starts? This is the mod 0 or mod 1
/// block. Reward cycle start events (like auto-unlocks) process *after*
Expand All @@ -607,27 +603,19 @@ impl Burnchain {
(effective_height % reward_cycle_length) <= 1
}

pub fn static_is_in_prepare_phase(
first_block_height: u64,
reward_cycle_length: u64,
prepare_length: u64,
block_height: u64,
) -> bool {
PoxConstants::static_is_in_prepare_phase(
first_block_height,
reward_cycle_length,
prepare_length,
block_height,
)
/// Does this block include reward slots?
/// This is either in the last prepare_phase_length blocks of the cycle
/// or the modulo 0 block
pub fn is_in_prepare_phase(&self, block_height: u64) -> bool {
self.pox_constants
.is_in_prepare_phase(self.first_block_height, block_height)
}

pub fn is_in_prepare_phase(&self, block_height: u64) -> bool {
Self::static_is_in_prepare_phase(
self.first_block_height,
self.pox_constants.reward_cycle_length as u64,
self.pox_constants.prepare_length.into(),
block_height,
)
/// The prepare phase is the last prepare_phase_length blocks of the cycle
/// This cannot include the 0 block for nakamoto
pub fn is_in_naka_prepare_phase(&self, block_height: u64) -> bool {
self.pox_constants
.is_in_naka_prepare_phase(self.first_block_height, block_height)
}

pub fn regtest(working_dir: &str) -> Burnchain {
Expand Down
50 changes: 49 additions & 1 deletion stackslib/src/burnchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl PoxConstants {
}
}

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

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

/// Is this the first block to be signed by the signer set in cycle N?
/// This is the mod 0 block.
pub fn is_naka_signing_cycle_start(&self, first_block_height: u64, burn_height: u64) -> bool {
let effective_height = burn_height - first_block_height;
// first block of the new reward cycle
(effective_height % u64::from(self.reward_cycle_length)) == 0
}

/// return the first burn block which receives reward in `reward_cycle`.
/// this is the modulo 1 block
pub fn reward_cycle_to_block_height(&self, first_block_height: u64, reward_cycle: u64) -> u64 {
// NOTE: the `+ 1` is because the height of the first block of a reward cycle is mod 1, not
// mod 0.
first_block_height + reward_cycle * u64::from(self.reward_cycle_length) + 1
}

/// the first burn block that must be *signed* by the signer set of `reward_cycle`.
/// this is the modulo 0 block
pub fn nakamoto_first_block_of_cycle(&self, first_block_height: u64, reward_cycle: u64) -> u64 {
first_block_height + reward_cycle * u64::from(self.reward_cycle_length)
}

pub fn reward_cycle_index(&self, first_block_height: u64, burn_height: u64) -> Option<u64> {
let effective_height = burn_height.checked_sub(first_block_height)?;
Some(effective_height % u64::from(self.reward_cycle_length))
Expand Down Expand Up @@ -609,6 +628,35 @@ impl PoxConstants {
}
}

/// The prepare phase is the last prepare_phase_length blocks of the cycle
/// This cannot include the 0 block for nakamoto
pub fn is_in_naka_prepare_phase(&self, first_block_height: u64, block_height: u64) -> bool {
Self::static_is_in_naka_prepare_phase(
first_block_height,
u64::from(self.reward_cycle_length),
u64::from(self.prepare_length),
block_height,
)
}

/// The prepare phase is the last prepare_phase_length blocks of the cycle
/// This cannot include the 0 block for nakamoto
pub fn static_is_in_naka_prepare_phase(
first_block_height: u64,
reward_cycle_length: u64,
prepare_length: u64,
block_height: u64,
) -> bool {
if block_height <= first_block_height {
// not a reward cycle start if we're the first block after genesis.
false
} else {
let effective_height = block_height - first_block_height;
let reward_index = effective_height % reward_cycle_length;
reward_index > u64::from(reward_cycle_length - prepare_length)
}
}

/// Returns the active reward cycle at the given burn block height
/// * `first_block_ht` - the first burn block height that the Stacks network monitored
/// * `reward_cycle_len` - the length of each reward cycle in the network.
Expand Down
Loading

0 comments on commit 5f8a390

Please sign in to comment.