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/nakamoto coordinator #4009

Merged
merged 124 commits into from Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 123 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
7045a4d
chore: pull thru is_prepare_phase_start
jcnelson Oct 24, 2023
8b4fc43
feat: add is_prepare_phase_start to PoxConstants
jcnelson Oct 24, 2023
6479175
feat: track last processed reward cycle in sortition DB MARF
jcnelson Oct 24, 2023
35c0fd3
refactor: add support for both epoch2 and epoch3 processing to Chains…
jcnelson Oct 24, 2023
e7a17c3
chore: use StacksBlockEventData instead of StacksBlock for event handler
jcnelson Oct 24, 2023
9e02660
feat: only track consensus_hash and parent_block_id in Nakamoto block…
jcnelson Oct 24, 2023
5c55d04
chore: update Nakamoto block tests to reflect new structs
jcnelson Oct 24, 2023
0eed15a
feat: is_first_index_block_hash
jcnelson Oct 24, 2023
18de400
feat: remove get_stacks_chain_tip() in favor of new Nakamoto-aware ge…
jcnelson Oct 24, 2023
defd316
chore: document StacksHeaderInfo fields, and add accessor for nakamot…
jcnelson Oct 24, 2023
489f385
feat: capture event observer data in StacksBlockEventData, which is c…
jcnelson Oct 24, 2023
28eedab
chore: remove compiler warning
jcnelson Oct 24, 2023
0337f1e
chore: remove nakamoto acceptance period
jcnelson Oct 24, 2023
1895e45
chore: remove `analyze-fees` directive (since it's only compatible wi…
jcnelson Oct 24, 2023
30331a7
chore: use get_canonical_block_header
jcnelson Oct 24, 2023
e47ab75
chore: use get_canonical_block_header() and document test methods
jcnelson Oct 24, 2023
7e75e42
chore: use get_canonical_block_header
jcnelson Oct 24, 2023
144de2d
chore: use get_canonical_block_header
jcnelson Oct 24, 2023
a7ab086
feat: use get_canonical_block_header
jcnelson Oct 24, 2023
7705961
chore: use StacksBlockEventData
jcnelson Oct 24, 2023
d4b68a3
chore: use get_canonical_block_header
jcnelson Oct 24, 2023
11b2bb6
chore: use StacksBlockEventData
jcnelson Oct 24, 2023
85f925d
feat: WIP initial coordinator implementation for Nakamoto
jcnelson Oct 24, 2023
b59e27b
chore: run stacker dkg test as part of integration test battery
jcnelson Nov 2, 2023
e4d8bed
chore: add Epoch25
jcnelson Nov 2, 2023
97ed00d
chore: Epoch25
jcnelson Nov 2, 2023
c55e217
feat: add pox-3 unlock and pox-4 activation
jcnelson Nov 2, 2023
db59dcd
feat: add pox-4 unlock
jcnelson Nov 2, 2023
f10b817
chore: add v3 unlock and pox-4 activation
jcnelson Nov 2, 2023
d04fa76
chore: add Epoch25, pox-3 unlock, and pox-4 activation
jcnelson Nov 2, 2023
e98fe51
chore: add v3 unlock and pox-4 activation
jcnelson Nov 2, 2023
b25e422
chore: add Epoch25
jcnelson Nov 2, 2023
2995451
chore: Epoch25
jcnelson Nov 2, 2023
467e893
chore: add pox-3 unlock and pox-4 activation height to pox constants
jcnelson Nov 2, 2023
e2e9413
chore: mock pox-3 unlock and pox-4 activation
jcnelson Nov 2, 2023
d8074ed
feat: add nakamoto miner hash160 to leader block commits and refactor…
jcnelson Nov 2, 2023
afc54fe
feat: store the serialized PoX reward set information as JSON, paired…
jcnelson Nov 2, 2023
b7000b0
feat: add epoch 2.5 marker and add converstion for block header hash …
jcnelson Nov 2, 2023
d7057b7
feat: add setter for nakamoto miner key hash160, and document where i…
jcnelson Nov 2, 2023
2fe7e8b
feat: store reward set info by first prepare-phase sortition so that …
jcnelson Nov 2, 2023
1a95fd1
chore: fill in mocked pox-3 unlock and pox-4 activation
jcnelson Nov 2, 2023
abb66ba
feat: store preprocessed reward set info from start of prepare phase,…
jcnelson Nov 2, 2023
66249f4
feat: MVP TestPeer test to create a single non-empty Nakamoto tenure,…
jcnelson Nov 2, 2023
e2313b3
feat: nakamoto block header constructors; verify the miner signature …
jcnelson Nov 2, 2023
eb028aa
feat: add Nakamoto features to TestBurnchainBlock, TestStacksNode, an…
jcnelson Nov 2, 2023
9512c7a
chore: create nakamoto/tests/ directory
jcnelson Nov 2, 2023
9b31de9
feat: static checks on Nakamoto coinbase and tenure change transactio…
jcnelson Nov 2, 2023
881b0a0
chore: add v3 unlock and pox-4 activation
jcnelson Nov 2, 2023
cad3de1
feat: stubbed pox-4 reward set handlers and testing stack-stx impleme…
jcnelson Nov 2, 2023
f9c8d09
chore: extend invariant tests for epoch 2.5, and add v3 unlock
jcnelson Nov 2, 2023
8baf2d3
chore: mock v3 unlock and pox-4 activation
jcnelson Nov 2, 2023
676dca2
feat: add pox-4 activation for epoch 2.5
jcnelson Nov 2, 2023
d30cb60
chore: epoch2.5
jcnelson Nov 2, 2023
f6ba0c1
chore: use v3 unlock and pox-4 activation
jcnelson Nov 2, 2023
28ad529
feat: add BlockBuilder trait for mining transactions so Nakamoto can …
jcnelson Nov 2, 2023
cb31648
feat: Nakamoto Coinbase contains the VRF proof, so add variants for i…
jcnelson Nov 2, 2023
f85d80b
chore: new coinbase variant
jcnelson Nov 2, 2023
89b4e5e
chore: v3 unlock height
jcnelson Nov 2, 2023
3355347
chore: add nakamoto state to TestStacksNode
jcnelson Nov 2, 2023
ed1b62b
feat: add new codec for Nakamoto coinbase
jcnelson Nov 2, 2023
664e09e
feat: add epoch 2.5 / pox-4 activation
jcnelson Nov 2, 2023
24e19f5
chore: add v3 unlock and pox-4 activation height
jcnelson Nov 2, 2023
49b44e7
feat: mined_naakmoto_block_event trait
jcnelson Nov 2, 2023
32e69a3
feat: epoch 2.5 definitions
jcnelson Nov 2, 2023
2fb821a
chore: new Coinbase variant
jcnelson Nov 2, 2023
e56f3e2
chore: new coinbase variant
jcnelson Nov 2, 2023
096b6dc
chore: mock pox-3 unlock and pox-4 activation
jcnelson Nov 2, 2023
4f7c8d3
chore: update TestPeer to use the right burn block handler (temporary)
jcnelson Nov 2, 2023
7f60bfa
feat: add handler for processing new nakamoto blocks
jcnelson Nov 2, 2023
61becfc
chore: report pox-4 in /v2/info
jcnelson Nov 2, 2023
e964784
feat: initial implementation of the Nakamoto miner
jcnelson Nov 2, 2023
3de4117
feat: pox-4 stub (just a copy of pox-3 for now)
jcnelson Nov 2, 2023
d4640a8
feat: plumb through nakamoto block-mined event handler
jcnelson Nov 2, 2023
8341cf4
chore: new coinbase variant
jcnelson Nov 2, 2023
5f3431f
chore: new coinbase variant
jcnelson Nov 2, 2023
4fcd30a
chore: mock v3 unlock and pox-4 activation
jcnelson Nov 2, 2023
ee535b5
chore: new coinbase variant
jcnelson Nov 2, 2023
fd2d51d
feat: event observer for mined nakamoto blocks
jcnelson Nov 2, 2023
11da1b6
Merge branch 'next' into feat/nakamoto-coordinator
jcnelson Nov 2, 2023
1a773bd
chore: cargo fmt
jcnelson Nov 7, 2023
9c9032c
chore: cargo fmt
jcnelson Nov 7, 2023
1821425
chore: cargo fmt
jcnelson Nov 7, 2023
64c9451
refactor: when generating a block-commit, take an optionally-given VR…
jcnelson Nov 7, 2023
53688a4
fix: track the canonical Stacks chain tips in a dedicated DB table, w…
jcnelson Nov 7, 2023
4de3440
fix: off-by-one error in loading the preprocessed reward cycle info (…
jcnelson Nov 7, 2023
1acaa22
chore: cargo fmt
jcnelson Nov 7, 2023
32f7377
feat: the Nakamoto anchor block is the *tenure-start* block of the *l…
jcnelson Nov 7, 2023
3c4a201
chore: add/fix tenure tests -- in particular, test that we can produc…
jcnelson Nov 7, 2023
9cc8415
chore: cargo fmt
jcnelson Nov 7, 2023
80f7217
feat: verify the VRF of a Nakamoto tenure and verify Nakamoto block-c…
jcnelson Nov 7, 2023
c165f80
refactor: move `get_account()` helper and API sync
jcnelson Nov 7, 2023
5030e9b
fix: update the way we generate Nakamoto tenure information. In parti…
jcnelson Nov 7, 2023
5c389eb
feat: get Stacks 2.x header by its sortition's consensus hash (which …
jcnelson Nov 7, 2023
79f9c06
fix: use NakamotoChainState::get_canonical_block_header() for perform…
jcnelson Nov 7, 2023
5c3e24d
chore: use NakamotoChainState::get_canonical_block_header() wherever …
jcnelson Nov 7, 2023
8e53e69
fix: process affirmation maps in epoch 3
jcnelson Nov 7, 2023
cacf191
fix: off-by-one error when checking for Nakamoto block acceptance (al…
jcnelson Nov 7, 2023
3acb3db
chore: API sync
jcnelson Nov 7, 2023
96a9ca6
refactor: accept @kantai's change
jcnelson Nov 7, 2023
e6df731
fix: `processed_block` should check that the `consensus_hash` is in t…
jcnelson Nov 7, 2023
e3208ac
chore: add first_mined() helper
jcnelson Nov 11, 2023
4da825a
chore: remove dead code (which was buggy)
jcnelson Nov 11, 2023
3a23919
feat: add prepare_phase_start() helper
jcnelson Nov 11, 2023
8062ac4
fix: only acknowledge the stackers' aggregate public key in a query i…
jcnelson Nov 11, 2023
c091471
chore: clean up unneeded indentations
jcnelson Nov 11, 2023
a9d0e24
fix: take block event struct by reference
jcnelson Nov 11, 2023
a51845b
fix: address PR feedback and fix a couple bugs -- (1) process the nex…
jcnelson Nov 11, 2023
cb5fa06
feat: test each tenure runs' chain tips, and test that we can replay …
jcnelson Nov 11, 2023
a7c13ad
chore: address PR feedback
jcnelson Nov 11, 2023
6a2b166
chore: add unit tests to most of the NakamotoChainState helpers and a…
jcnelson Nov 11, 2023
3b9009f
chore: always test that the chain tip advances if we accept and proce…
jcnelson Nov 11, 2023
c2696d4
chore: remove dead code
jcnelson Nov 11, 2023
d1a4705
chore: pass block event data by reference
jcnelson Nov 11, 2023
d799ce5
chore: add codec tests for nakamoto transactions
jcnelson Nov 11, 2023
58495fc
fix: deterministic microblock keypairs (so we can replay state from o…
jcnelson Nov 11, 2023
91d2ffb
fix: pass event data by reference
jcnelson Nov 11, 2023
a539d2f
Merge branch 'feat/nakamoto-coordinator' of https://github.com/stacks…
jcnelson Nov 11, 2023
bef3db0
chore: cargo fmt
jcnelson Nov 11, 2023
94ff8cd
fix: fix regression in static block validation check -- versioned sma…
jcnelson Nov 12, 2023
6bd1ca2
fix: special-case handling for choosing the parent block pointer in t…
jcnelson Nov 12, 2023
6d6e00b
fix: update comments in pox-4 to reflect that it is pox-4, not pox-3
jcnelson Nov 12, 2023
c436098
fix: cover epoch 2.4 and epoch 3.0
jcnelson Nov 12, 2023
a6e9b4c
fix: fix another test that explicitly panics on epochs 2.5 and 3.0
jcnelson Nov 13, 2023
7cf69c7
chore: address PR feedback; use explicit integer conversions (but thi…
jcnelson Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/bitcoin-tests.yml
Expand Up @@ -142,6 +142,7 @@ jobs:
- tests::epoch_24::verify_auto_unlock_behavior
- tests::stackerdb::test_stackerdb_load_store
- tests::stackerdb::test_stackerdb_event_observer
- tests::signer::test_stackerdb_dkg
steps:
- name: Checkout the latest code
id: git_checkout
Expand Down
1 change: 1 addition & 0 deletions clarity/src/vm/analysis/mod.rs
Expand Up @@ -141,6 +141,7 @@ pub fn run_analysis(
| StacksEpochId::Epoch22
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
jbencin marked this conversation as resolved.
Show resolved Hide resolved
| StacksEpochId::Epoch30 => {
TypeChecker2_1::run_pass(&epoch, &mut contract_analysis, db)
}
Expand Down
2 changes: 2 additions & 0 deletions clarity/src/vm/analysis/type_checker/mod.rs
Expand Up @@ -53,6 +53,7 @@ impl FunctionType {
| StacksEpochId::Epoch22
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30 => self.check_args_2_1(accounting, args, clarity_version),
StacksEpochId::Epoch10 => unreachable!("Epoch10 is not supported"),
}
Expand All @@ -73,6 +74,7 @@ impl FunctionType {
| StacksEpochId::Epoch22
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30 => {
self.check_args_by_allowing_trait_cast_2_1(db, clarity_version, func_args)
}
Expand Down
1 change: 1 addition & 0 deletions clarity/src/vm/costs/mod.rs
Expand Up @@ -724,6 +724,7 @@ impl LimitedCostTracker {
| StacksEpochId::Epoch22
| StacksEpochId::Epoch23
| StacksEpochId::Epoch24
| StacksEpochId::Epoch25
| StacksEpochId::Epoch30 => COSTS_3_NAME.to_string(),
}
}
Expand Down
41 changes: 37 additions & 4 deletions clarity/src/vm/database/clarity_db.rs
Expand Up @@ -112,7 +112,9 @@ pub trait HeadersDB {
pub trait BurnStateDB {
fn get_v1_unlock_height(&self) -> u32;
fn get_v2_unlock_height(&self) -> u32;
fn get_v3_unlock_height(&self) -> u32;
fn get_pox_3_activation_height(&self) -> u32;
fn get_pox_4_activation_height(&self) -> u32;

/// Returns the *burnchain block height* for the `sortition_id` is associated with.
fn get_burn_block_height(&self, sortition_id: &SortitionId) -> Option<u32>;
Expand Down Expand Up @@ -201,10 +203,18 @@ impl BurnStateDB for &dyn BurnStateDB {
(*self).get_v2_unlock_height()
}

fn get_v3_unlock_height(&self) -> u32 {
(*self).get_v3_unlock_height()
}

fn get_pox_3_activation_height(&self) -> u32 {
(*self).get_pox_3_activation_height()
}

fn get_pox_4_activation_height(&self) -> u32 {
(*self).get_pox_4_activation_height()
}

fn get_burn_block_height(&self, sortition_id: &SortitionId) -> Option<u32> {
(*self).get_burn_block_height(sortition_id)
}
Expand Down Expand Up @@ -379,10 +389,18 @@ impl BurnStateDB for NullBurnStateDB {
u32::MAX
}

fn get_v3_unlock_height(&self) -> u32 {
u32::MAX
}

fn get_pox_3_activation_height(&self) -> u32 {
u32::MAX
}

fn get_pox_4_activation_height(&self) -> u32 {
u32::MAX
}

fn get_pox_prepare_length(&self) -> u32 {
panic!("NullBurnStateDB should not return PoX info");
}
Expand Down Expand Up @@ -820,6 +838,11 @@ impl<'a> ClarityDatabase<'a> {
self.burn_state_db.get_pox_3_activation_height()
}

/// Return the height for PoX 4 activation from the burn state db
pub fn get_pox_4_activation_height(&self) -> u32 {
self.burn_state_db.get_pox_4_activation_height()
}

/// Return the height for PoX v2 -> v3 auto unlocks
/// from the burn state db
pub fn get_v2_unlock_height(&mut self) -> u32 {
Expand All @@ -830,6 +853,16 @@ impl<'a> ClarityDatabase<'a> {
}
}

/// Return the height for PoX v3 -> v4 auto unlocks
/// from the burn state db
pub fn get_v3_unlock_height(&mut self) -> u32 {
if self.get_clarity_epoch_version() >= StacksEpochId::Epoch24 {
self.burn_state_db.get_v3_unlock_height()
} else {
u32::MAX
}
}

/// Get the last-known burnchain block height.
/// Note that this is _not_ the burnchain height in which this block was mined!
/// This is the burnchain block height of the parent of the Stacks block at the current Stacks
Expand Down Expand Up @@ -1906,8 +1939,8 @@ impl<'a> ClarityDatabase<'a> {
stx_balance.amount_locked(),
stx_balance.unlock_height(),
cur_burn_height,
stx_balance.get_available_balance_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height()),
stx_balance.has_unlockable_tokens_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height()));
stx_balance.get_available_balance_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height(), self.get_v3_unlock_height()),
stx_balance.has_unlockable_tokens_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height(), self.get_v3_unlock_height()));

STXBalanceSnapshot::new(principal, stx_balance, cur_burn_height, self)
}
Expand All @@ -1925,8 +1958,8 @@ impl<'a> ClarityDatabase<'a> {
stx_balance.amount_locked(),
stx_balance.unlock_height(),
cur_burn_height,
stx_balance.get_available_balance_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height()),
stx_balance.has_unlockable_tokens_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height()));
stx_balance.get_available_balance_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height(), self.get_v3_unlock_height()),
stx_balance.has_unlockable_tokens_at_burn_block(cur_burn_height, self.get_v1_unlock_height(), self.get_v2_unlock_height(), self.get_v3_unlock_height()));

STXBalanceSnapshot::new(principal, stx_balance, cur_burn_height, self)
}
Expand Down