Skip to content
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

Feat/cap discount mining #3135

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d019448
feat: track the burns of all winning block-commits in the prepare pha…
jcnelson May 9, 2022
ff3c978
feat: tool to analyze spends in the prepare and reward phases of a re…
jcnelson May 9, 2022
bcb76b8
chore: pass current epoch into sortition-processing so we can properl…
jcnelson May 14, 2022
30e235d
fix: count the total spend of a block-commit (PoX payout + destoroyed…
jcnelson May 14, 2022
b8492dd
fix: use the sortition_spend() of a block-commit (which is epoch-gate…
jcnelson May 14, 2022
ec5ceb9
feat: at the start of each reward cycle, calculate the PoX cutoff. An…
jcnelson May 14, 2022
54c8e8e
feat: when calculating the burn distribution, gate the logic to deter…
jcnelson May 14, 2022
17b262d
feat: in epoch 2.1, a block-commit must burn the difference between i…
jcnelson May 14, 2022
4c7ed76
chore: add error variants for PoX over/underpay
jcnelson May 14, 2022
dfe6f17
chore: track PoX cutoff in our reward cycle info structure
jcnelson May 14, 2022
fc169d0
chore: plumb through new `destroyed` field
jcnelson May 14, 2022
ef43d89
chore: plumb through `destroyed` field
jcnelson May 14, 2022
b7e7459
chore: update test to use `total_spend()` instead of `burn_fee`
jcnelson May 14, 2022
e9838dc
chore: update docstring to explain why the PoX cutoff calculation log…
jcnelson May 14, 2022
b7b9bb1
fix: when calculating the total burn for a sortition, consider the ep…
jcnelson May 14, 2022
9c13cce
chore: report the `.sortition_spend()` of a block_commit, which is ga…
jcnelson May 14, 2022
9c1d705
use `.total_spend()` in determining a reward cycle's block-commit spends
jcnelson May 14, 2022
0238053
fix: use the right contract ID in `/v2/pox` so that when `.pox-2` act…
jcnelson May 14, 2022
6e0d4e8
chore: track the `destroyed` BTC the way we used to track the `sunset…
jcnelson May 14, 2022
b8bdd43
chore: mock `destroyed` as 0
jcnelson May 14, 2022
8e8656f
chore: load the PoX cutoff and use it to deduce how much BTC to burn …
jcnelson May 14, 2022
44e00c4
chore: mock `destoyred` as 0
jcnelson May 14, 2022
0de1326
chore: `destroyed: 0`
jcnelson May 14, 2022
affc5aa
feat: integration test to verify that a block-commit that overpays it…
jcnelson May 14, 2022
fd6fbcc
chore: expose get_pox_info()
jcnelson May 14, 2022
a2fae00
chore: add new epoch_21 tests to CI
jcnelson May 14, 2022
8bdb4af
fix: loosen acceptance tests for microblock integration test to make …
jcnelson May 16, 2022
44ef72a
Merge branch 'next' into feat/cap-discount-mining
jcnelson May 16, 2022
be7b63f
fix: failing unit test from merge
jcnelson May 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ jobs:
- tests::epoch_205::test_cost_limit_switch_version205
- tests::epoch_205::test_exact_block_costs
- tests::epoch_205::bigger_microblock_streams_in_2_05
- tests::epoch_21::transition_fixes_utxo_chaining
- tests::epoch_21::transition_adds_burn_block_height
- tests::epoch_21::transition_caps_discount_mining_upside
steps:
- uses: actions/checkout@v2
- name: Download docker image
Expand Down
28 changes: 25 additions & 3 deletions src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ impl BurnchainStateTransition {
let mut block_commits: Vec<LeaderBlockCommitOp> = vec![];
let mut user_burns: Vec<UserBurnSupportOp> = vec![];
let mut accepted_ops = Vec::with_capacity(block_ops.len());
let epoch = SortitionDB::get_stacks_epoch(sort_tx, parent_snapshot.block_height + 1)?
.expect(&format!(
"FATAL: no epoch known at burn height {}",
parent_snapshot.block_height + 1
));

assert!(Burnchain::ops_are_sorted(block_ops));

Expand Down Expand Up @@ -240,6 +245,7 @@ impl BurnchainStateTransition {
// calculate the burn distribution from these operations.
// The resulting distribution will contain the user burns that match block commits
let burn_dist = BurnSamplePoint::make_min_median_distribution(
epoch.epoch_id,
windowed_block_commits,
windowed_missed_commits,
burn_blocks,
Expand Down Expand Up @@ -461,10 +467,22 @@ impl Burnchain {
(effective_height % (self.pox_constants.reward_cycle_length as u64)) == 1
}

pub fn reward_cycle_to_block_height(&self, reward_cycle: u64) -> u64 {
pub fn static_reward_cycle_to_block_height(
reward_cycle: u64,
first_block_ht: u64,
reward_cycle_len: u64,
) -> u64 {
// NOTE: the `+ 1` is because the height of the first block of a reward cycle is mod 1, not
// mod 0.
self.first_block_height + reward_cycle * (self.pox_constants.reward_cycle_length as u64) + 1
first_block_ht + reward_cycle * reward_cycle_len + 1
}

pub fn reward_cycle_to_block_height(&self, reward_cycle: u64) -> u64 {
Self::static_reward_cycle_to_block_height(
reward_cycle,
self.first_block_height,
self.pox_constants.reward_cycle_length.into(),
)
}

/// Returns the active reward cycle at the given burn block height
Expand Down Expand Up @@ -1834,6 +1852,7 @@ pub mod tests {
memo: vec![0x80],

burn_fee: 12345,
destroyed: 0,
input: (Txid([0; 32]), 0),
apparent_sender: BurnchainSigner {
public_keys: vec![StacksPublicKey::from_hex(
Expand Down Expand Up @@ -1874,6 +1893,7 @@ pub mod tests {
memo: vec![0x80],

burn_fee: 12345,
destroyed: 0,
input: (Txid([0; 32]), 0),
apparent_sender: BurnchainSigner {
public_keys: vec![StacksPublicKey::from_hex(
Expand Down Expand Up @@ -1914,6 +1934,7 @@ pub mod tests {
memo: vec![0x80],

burn_fee: 23456,
destroyed: 0,
input: (Txid([0; 32]), 0),
apparent_sender: BurnchainSigner {
public_keys: vec![StacksPublicKey::from_hex(
Expand Down Expand Up @@ -2232,7 +2253,7 @@ pub mod tests {

let burn_total = block_ops_124.iter().fold(0u64, |mut acc, op| {
let bf = match op {
BlockstackOperationType::LeaderBlockCommit(ref op) => op.burn_fee,
BlockstackOperationType::LeaderBlockCommit(ref op) => op.total_spend(),
BlockstackOperationType::UserBurnSupport(ref op) => 0,
_ => 0,
};
Expand Down Expand Up @@ -2480,6 +2501,7 @@ pub mod tests {
memo: vec![i],

burn_fee: i as u64,
destroyed: 0,
input: (Txid([0; 32]), 0),
apparent_sender: BurnchainSigner {
public_keys: vec![StacksPublicKey::from_hex(
Expand Down
12 changes: 11 additions & 1 deletion src/chainstate/burn/db/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use crate::burnchains::{
Burnchain, BurnchainBlockHeader, BurnchainStateTransition, Error as BurnchainError,
};
use crate::chainstate::burn::db::sortdb::SortitionDB;
use crate::chainstate::burn::db::sortdb::{InitialMiningBonus, SortitionHandleTx};
use crate::chainstate::burn::operations::{
leader_block_commit::{MissedBlockCommit, RewardSetInfo},
Expand Down Expand Up @@ -114,6 +115,12 @@ impl<'a> SortitionHandleTx<'a> {
) -> Result<(BlockSnapshot, BurnchainStateTransition), BurnchainError> {
let this_block_height = block_header.block_height;
let this_block_hash = block_header.block_hash.clone();
let epoch = SortitionDB::get_stacks_epoch(self, parent_snapshot.block_height + 1)?.expect(
&format!(
"FATAL: no epoch known at burn height {}",
parent_snapshot.block_height + 1
),
);

// make the burn distribution, and in doing so, identify the user burns that we'll keep
let state_transition = BurnchainStateTransition::from_block_ops(self, burnchain, parent_snapshot, this_block_ops, missed_commits)
Expand All @@ -128,7 +135,9 @@ impl<'a> SortitionHandleTx<'a> {
.fold(Some(0u64), |acc, op| {
if let Some(acc) = acc {
let bf = match op {
BlockstackOperationType::LeaderBlockCommit(ref op) => op.burn_fee,
BlockstackOperationType::LeaderBlockCommit(ref op) => {
op.sortition_spend(epoch.epoch_id)
}
BlockstackOperationType::UserBurnSupport(ref op) => op.burn_fee,
_ => 0,
};
Expand Down Expand Up @@ -425,6 +434,7 @@ mod tests {

commit_outs: vec![],
burn_fee: 12345,
destroyed: 0,
input: (Txid([0; 32]), 0),
apparent_sender: BurnchainSigner {
public_keys: vec![StacksPublicKey::from_hex(
Expand Down
Loading