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
Show file tree
Hide file tree
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
Add naka integration test to check block written to stacker db .miner…
…s instance

Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jan 9, 2024
commit 20518f57db73ee0afc227d6ede285ccae656c37e
1 change: 1 addition & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
- tests::nakamoto_integrations::simple_neon_integration
- tests::nakamoto_integrations::mine_multiple_per_tenure_integration
- tests::nakamoto_integrations::block_proposal_api_endpoint
- tests::nakamoto_integrations::miner_writes_proposed_block_to_stackerdb
steps:
## Setup test environment
- name: Setup Test Environment
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions stackslib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ clarity = { path = "../clarity" }
stacks-common = { path = "../stacks-common" }
pox-locking = { path = "../pox-locking" }
libstackerdb = { path = "../libstackerdb" }
libsigner = { path = "../libsigner" }
siphasher = "0.3.7"
wsts = {workspace = true}
rand_core = {workspace = true}
Expand Down
120 changes: 118 additions & 2 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ use clarity::vm::ast::ASTRules;
use clarity::vm::costs::ExecutionCost;
use clarity::vm::types::PrincipalData;
use lazy_static::lazy_static;
use libsigner::{SignerSession, StackerDBSession};
use stacks::burnchains::MagicBytes;
use stacks::chainstate::burn::db::sortdb::SortitionDB;
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
use stacks::chainstate::nakamoto::miner::NakamotoBlockBuilder;
use stacks::chainstate::nakamoto::NakamotoChainState;
use stacks::chainstate::nakamoto::{NakamotoBlock, NakamotoChainState};
use stacks::chainstate::stacks::boot::MINERS_NAME;
use stacks::chainstate::stacks::db::StacksChainState;
use stacks::chainstate::stacks::miner::{BlockBuilder, BlockLimitFunction, TransactionResult};
use stacks::chainstate::stacks::{StacksTransaction, ThresholdSignature, TransactionPayload};
use stacks::chainstate::stacks::{StacksTransaction, TransactionPayload};
use stacks::core::{
StacksEpoch, StacksEpochId, BLOCK_LIMIT_MAINNET_10, HELIUM_BLOCK_LIMIT_20,
PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05,
Expand Down Expand Up @@ -1310,3 +1311,118 @@ fn block_proposal_api_endpoint() {

run_loop_thread.join().unwrap();
}

#[test]
#[ignore]
/// This test spins up a nakamoto-neon node and attempts to mine a single Nakamoto block.
/// It starts in Epoch 2.0, mines with `neon_node` to Epoch 3.0, and then switches
/// to Nakamoto operation (activating pox-4 by submitting a stack-stx tx). The BootLoop
/// struct handles the epoch-2/3 tear-down and spin-up.
/// This test makes the following assertions:
/// * The proposed Nakamoto block is written to the .miners stackerdb
fn miner_writes_proposed_block_to_stackerdb() {
if env::var("BITCOIND_TEST") != Ok("1".into()) {
return;
}

let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1000);
let sender_sk = Secp256k1PrivateKey::new();
// setup sender + recipient for a test stx transfer
let sender_addr = tests::to_addr(&sender_sk);
let send_amt = 1000;
let send_fee = 100;
naka_conf.add_initial_balance(
PrincipalData::from(sender_addr.clone()).to_string(),
send_amt + send_fee,
);
let stacker_sk = setup_stacker(&mut naka_conf);

test_observer::spawn();
let observer_port = test_observer::EVENT_OBSERVER_PORT;
naka_conf.events_observers.insert(EventObserverConfig {
endpoint: format!("localhost:{observer_port}"),
events_keys: vec![EventKeyType::AnyEvent],
});

let mut btcd_controller = BitcoinCoreController::new(naka_conf.clone());
btcd_controller
.start_bitcoind()
.expect("Failed starting bitcoind");
let mut btc_regtest_controller = BitcoinRegtestController::new(naka_conf.clone(), None);
btc_regtest_controller.bootstrap_chain(201);

let mut run_loop = boot_nakamoto::BootRunLoop::new(naka_conf.clone()).unwrap();
let run_loop_stopper = run_loop.get_termination_switch();
let Counters {
blocks_processed,
naka_submitted_vrfs: vrfs_submitted,
naka_submitted_commits: commits_submitted,
..
} = run_loop.counters();

let coord_channel = run_loop.coordinator_channels();

let run_loop_thread = thread::spawn(move || run_loop.start(None, 0));
wait_for_runloop(&blocks_processed);
boot_to_epoch_3(
&naka_conf,
&blocks_processed,
stacker_sk,
StacksPublicKey::new(),
&mut btc_regtest_controller,
);
let rpc_sock = naka_conf
.node
.rpc_bind
.clone()
.parse()
.expect("Failed to parse socket");

info!("Nakamoto miner started...");
// first block wakes up the run loop, wait until a key registration has been submitted.
next_block_and(&mut btc_regtest_controller, 60, || {
let vrf_count = vrfs_submitted.load(Ordering::SeqCst);
Ok(vrf_count >= 1)
})
.unwrap();

// second block should confirm the VRF register, wait until a block commit is submitted
next_block_and(&mut btc_regtest_controller, 60, || {
let commits_count = commits_submitted.load(Ordering::SeqCst);
Ok(commits_count >= 1)
})
.unwrap();

// Mine 1 nakamoto tenure
next_block_and_mine_commit(
&mut btc_regtest_controller,
60,
&coord_channel,
&commits_submitted,
)
.unwrap();

let chunk = std::thread::spawn(move || {
let miner_contract_id = boot_code_id(MINERS_NAME, false);
let mut miners_stackerdb = StackerDBSession::new(rpc_sock, miner_contract_id);
miners_stackerdb
.get_latest_chunk(0)
.expect("Failed to get latest chunk from the miner slot ID")
.expect("No chunk found")
})
.join()
.expect("Failed to join chunk handle");
// We should now successfully deserialize a chunk
let _block = NakamotoBlock::consensus_deserialize(&mut &chunk[..])
.expect("Failed to deserialize chunk into block");
jferrant marked this conversation as resolved.
Show resolved Hide resolved

coord_channel
.lock()
.expect("Mutex poisoned")
.stop_chains_coordinator();

run_loop_stopper.store(false, Ordering::SeqCst);

run_loop_thread.join().unwrap();
}