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/stackerdb miners contract #4188

Merged
merged 25 commits into from
Jan 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2d9577a
feat: .miners contract
jcnelson Dec 18, 2023
21e3000
fix: boost chunk size to 16MB, which is the maximum block size
jcnelson Dec 18, 2023
5dcaf59
feat: add method to generate a stackerdb chunk for the miner
jcnelson Dec 18, 2023
70ef39c
chore: log an error if the miner isn't in the .miners stackerdb
jcnelson Dec 18, 2023
e293848
feat: synthesize a stackerdb config for the .miners contract using th…
jcnelson Dec 18, 2023
befd7c4
feat: unit tests for stackerdb config generation and stackerdb chunk …
jcnelson Dec 18, 2023
c7cd4af
feat: boot code for .miners
jcnelson Dec 18, 2023
180a519
chore: instantiate .miners with pox-4, and also, clean up and consoli…
jcnelson Dec 18, 2023
9b7cd92
fix: only announce stackerdb DBs when not in IBD
jcnelson Dec 18, 2023
16ff7e5
feat: synthesize a .miners stackerdb directly every Bitcoin block
jcnelson Dec 18, 2023
e5a4ed2
chore: fix failing unit tests
jcnelson Dec 19, 2023
b1705d4
Retrieve slot version and id from stacker db directly and propose a b…
jferrant Dec 28, 2023
20518f5
Add naka integration test to check block written to stacker db .miner…
jferrant Jan 2, 2024
71edfd5
CRC: failing to make the stackerdb should fail refreshing the burncha…
jferrant Jan 2, 2024
e053b8d
CRC: replace dup code with boot_code_tx_auth in clarity.rs
jferrant Jan 3, 2024
786fafa
CRC: cleanup make_miners_stackerdb_config indexing
jferrant Jan 3, 2024
ddad5a3
CRC: the first ever miner config should include the test peer miner p…
jferrant Jan 3, 2024
f9036f4
Always create stacker dbs if they don't exist
jferrant Jan 5, 2024
b2662d7
CRC: do not store miners_stackerdb in miner
jferrant Jan 5, 2024
c3d3884
CRC: Subscribe to MinedBlocks and zero out the signatures to ensure t…
jferrant Jan 8, 2024
5520a30
CRC: add .miners to NodeConfig if is a miner neon node
jferrant Jan 9, 2024
4d111e4
BUG: fix stacker db refresh logic
jferrant Jan 9, 2024
c7eb461
BUG: fix tests setup_stackerdb to reconfigure rather than create
jferrant Jan 9, 2024
b701acb
CRC: move tip calculation to outer loop to minimize IO
jferrant Jan 9, 2024
3cb02e0
CRC: rip out .miners dummy contract
jferrant Jan 9, 2024
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
Prev Previous commit
Next Next commit
CRC: cleanup make_miners_stackerdb_config indexing
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jan 9, 2024
commit 786fafa34aa2ddc10b72818622707625286273b8
52 changes: 27 additions & 25 deletions stackslib/src/chainstate/nakamoto/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ fn test_make_miners_stackerdb_config() {
test_signers.aggregate_public_key.clone(),
);

let miner_keys: Vec<_> = (3..13).map(|_| StacksPrivateKey::new()).collect();
let miner_keys: Vec<_> = (0..10).map(|_| StacksPrivateKey::new()).collect();
let miner_hash160s: Vec<_> = miner_keys
.iter()
.map(|miner_privkey| {
Expand All @@ -1684,17 +1684,18 @@ fn test_make_miners_stackerdb_config() {
let stackerdbs = peer.network.stackerdbs;
let miners_contract_id = boot_code_id(MINERS_NAME, false);

// make two leader keys (miner 1 and miner 2)
// make leader keys for each miner
let mut miners = vec![];
for i in 3..13 {
for (i, miner_hash160) in miner_hash160s.iter().enumerate() {
let id = i as u8 + 1; // Add 1 to avoid 0-ed Txid.
let vrf_privkey = VRFPrivateKey::new();
let vrf_pubkey = VRFPublicKey::from_private(&vrf_privkey);
let miner = LeaderKeyRegisterOp {
consensus_hash: last_snapshot.consensus_hash.clone(),
public_key: vrf_pubkey,
memo: miner_hash160s[i - 3].0.to_vec(),
txid: Txid([i as u8; 32]),
vtxindex: 1 + (i as u32),
memo: miner_hash160.0.to_vec(),
txid: Txid([id; 32]),
vtxindex: 1 + (id as u32),
block_height: last_snapshot.block_height + 1,
burn_header_hash: last_snapshot.burn_header_hash.clone(),
};
Expand All @@ -1705,29 +1706,30 @@ fn test_make_miners_stackerdb_config() {
let mut stackerdb_chunks = vec![];

// synthesize some sortitions and corresponding winning block-commits
for i in 3..13 {
for (i, miner) in miners.iter().enumerate() {
// no winner every 3rd sortition
let sortition = i > 3 && i % 3 != 0;
let sortition = i % 3 != 0;
let id = i as u8 + 1; // Add 1 to avoid 0-ed IDs.
let winning_txid = if sortition {
Txid([(i as u8); 32])
Txid([id; 32])
} else {
Txid([0x00; 32])
};
let winning_block_hash = BlockHeaderHash([(i as u8); 32]);
let winning_block_hash = BlockHeaderHash([id; 32]);
let snapshot = BlockSnapshot {
accumulated_coinbase_ustx: 0,
pox_valid: true,
block_height: last_snapshot.block_height + 1,
burn_header_timestamp: get_epoch_time_secs(),
burn_header_hash: BurnchainHeaderHash([(i as u8); 32]),
sortition_id: SortitionId([(i as u8); 32]),
burn_header_hash: BurnchainHeaderHash([id; 32]),
sortition_id: SortitionId([id; 32]),
parent_sortition_id: last_snapshot.sortition_id.clone(),
parent_burn_header_hash: last_snapshot.burn_header_hash.clone(),
consensus_hash: ConsensusHash([(i as u8); 20]),
ops_hash: OpsHash([(i as u8); 32]),
consensus_hash: ConsensusHash([id; 20]),
ops_hash: OpsHash([id; 32]),
total_burn: 0,
sortition,
sortition_hash: SortitionHash([(i as u8); 32]),
sortition_hash: SortitionHash([id; 32]),
winning_block_txid: winning_txid.clone(),
winning_stacks_block_hash: winning_block_hash.clone(),
index_root: TrieHash([0u8; 32]),
Expand All @@ -1736,19 +1738,19 @@ fn test_make_miners_stackerdb_config() {
stacks_block_height: last_snapshot.stacks_block_height,
arrival_index: 0,
canonical_stacks_tip_height: last_snapshot.canonical_stacks_tip_height + 10,
canonical_stacks_tip_hash: BlockHeaderHash([((i + 1) as u8); 32]),
canonical_stacks_tip_consensus_hash: ConsensusHash([((i + 1) as u8); 20]),
canonical_stacks_tip_hash: BlockHeaderHash([id; 32]),
canonical_stacks_tip_consensus_hash: ConsensusHash([id; 20]),
miner_pk_hash: None,
};
let winning_block_commit = LeaderBlockCommitOp {
sunset_burn: 0,
block_header_hash: BlockHeaderHash([(i as u8); 32]),
new_seed: VRFSeed([(i as u8); 32]),
block_header_hash: BlockHeaderHash([id; 32]),
new_seed: VRFSeed([id; 32]),
parent_block_ptr: last_snapshot.block_height as u32,
parent_vtxindex: 1,
// miners take turns winning
key_block_ptr: miners[i - 3].block_height as u32,
key_vtxindex: miners[i - 3].vtxindex as u16,
key_block_ptr: miner.block_height as u32,
key_vtxindex: miner.vtxindex as u16,
memo: vec![STACKS_EPOCH_3_0_MARKER],
commit_outs: vec![],

Expand All @@ -1770,7 +1772,7 @@ fn test_make_miners_stackerdb_config() {
burn_header_hash: snapshot.burn_header_hash.clone(),
};

let winning_ops = if i == 3 {
let winning_ops = if i == 0 {
// first snapshot includes leader keys
miners
.clone()
Expand Down Expand Up @@ -1815,7 +1817,7 @@ fn test_make_miners_stackerdb_config() {
.unwrap()
.unwrap();

if i > 3 {
if i > 0 {
// have block-commit
// check the stackerdb config as of this chain tip
let stackerdb_config =
Expand Down Expand Up @@ -1848,7 +1850,7 @@ fn test_make_miners_stackerdb_config() {
&sort_db,
&stackerdbs,
&block,
&miner_keys[i - 3],
&miner_keys[i],
&miners_contract_id,
)
.unwrap()
Expand All @@ -1861,7 +1863,7 @@ fn test_make_miners_stackerdb_config() {
&sort_db,
&stackerdbs,
&block,
&miner_keys[i - 3],
&miner_keys[i],
&miners_contract_id,
)
.unwrap()
Expand Down