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

End of tenure test #4919

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
- tests::nakamoto_integrations::nakamoto_attempt_time
- tests::signer::v0::block_proposal_rejection
- tests::signer::v0::miner_gather_signatures
- tests::signer::v0::mine_2_nakamoto_reward_cycles
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
- tests::nakamoto_integrations::check_block_heights
- tests::nakamoto_integrations::clarity_burn_state
Expand Down
21 changes: 21 additions & 0 deletions stackslib/src/net/api/postblock_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ use crate::net::{
};
use crate::util_lib::db::Error as DBError;

#[cfg(any(test, feature = "testing"))]
pub static TEST_VALIDATE_STALL: std::sync::Mutex<Option<bool>> = std::sync::Mutex::new(None);

// This enum is used to supply a `reason_code` for validation
// rejection responses. This is serialized as an enum with string
// type (in jsonschema terminology).
Expand Down Expand Up @@ -360,6 +363,24 @@ impl NakamotoBlockProposal {
});
}

#[cfg(any(test, feature = "testing"))]
{
if *TEST_VALIDATE_STALL.lock().unwrap() == Some(true) {
// Do an extra check just so we don't log EVERY time.
warn!("Block validation is stalled due to testing directive.";
"block_id" => %block.block_id(),
"height" => block.header.chain_length,
);
while *TEST_VALIDATE_STALL.lock().unwrap() == Some(true) {
std::thread::sleep(std::time::Duration::from_millis(10));
}
info!("Block validation is no longer stalled due to testing directive.";
"block_id" => %block.block_id(),
"height" => block.header.chain_length,
);
}
}

info!(
"Participant: validated anchored block";
"block_header_hash" => %computed_block_header_hash,
Expand Down
32 changes: 17 additions & 15 deletions testnet/stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ use std::thread;
use std::time::{Duration, Instant};

use clarity::boot_util::boot_code_id;
use clarity::vm::types::PrincipalData;
use libsigner::{SignerEntries, SignerEventTrait};
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
use stacks::chainstate::nakamoto::signer_set::NakamotoSigners;
use stacks::chainstate::stacks::boot::{NakamotoSignerEntry, SIGNERS_NAME};
use stacks::chainstate::stacks::{StacksPrivateKey, ThresholdSignature};
use stacks::core::StacksEpoch;
use stacks::net::api::postblock_proposal::BlockValidateResponse;
use stacks::types::chainstate::StacksAddress;
use stacks::util::secp256k1::MessageSignature;
use stacks_common::codec::StacksMessageCodec;
use stacks_common::consts::SIGNER_SLOTS_PER_USER;
Expand All @@ -51,7 +53,6 @@ use stacks_signer::client::{SignerSlotID, StacksClient};
use stacks_signer::config::{build_signer_config_tomls, GlobalConfig as SignerConfig, Network};
use stacks_signer::runloop::{SignerResult, State};
use stacks_signer::{Signer, SpawnedSigner};
use wsts::curve::point::Point;
use wsts::state_machine::PublicKeys;

use crate::config::{Config as NeonConfig, EventKeyType, EventObserverConfig, InitialBalance};
Expand All @@ -78,6 +79,8 @@ pub struct RunningNodes {
pub vrfs_submitted: Arc<AtomicU64>,
pub commits_submitted: Arc<AtomicU64>,
pub blocks_processed: Arc<AtomicU64>,
pub nakamoto_blocks_proposed: Arc<AtomicU64>,
pub nakamoto_blocks_mined: Arc<AtomicU64>,
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
pub conf: NeonConfig,
}
Expand All @@ -97,13 +100,20 @@ pub struct SignerTest<S> {
}

impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<SpawnedSigner<S, T>> {
fn new(num_signers: usize) -> Self {
fn new(num_signers: usize, initial_balances: Vec<(StacksAddress, u64)>) -> Self {
// Generate Signer Data
let signer_stacks_private_keys = (0..num_signers)
.map(|_| StacksPrivateKey::new())
.collect::<Vec<StacksPrivateKey>>();

let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);

// Add initial balances to the config
for (address, amount) in initial_balances.iter() {
naka_conf
.add_initial_balance(PrincipalData::from(address.clone()).to_string(), *amount);
}

// So the combination is... one, two, three, four, five? That's the stupidest combination I've ever heard in my life!
// That's the kind of thing an idiot would have on his luggage!
let password = "12345";
Expand Down Expand Up @@ -237,18 +247,6 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
reward_cycle_height.saturating_sub(current_block_height)
}

fn mine_and_verify_confirmed_naka_block(
&mut self,
agg_key: &Point,
timeout: Duration,
) -> MinedNakamotoBlockEvent {
let new_block = self.mine_nakamoto_block(timeout);
let signer_sighash = new_block.signer_signature_hash.clone();
let signature = self.wait_for_confirmed_block_v1(&signer_sighash, timeout);
assert!(signature.0.verify(&agg_key, signer_sighash.as_bytes()));
new_block
}

fn mine_nakamoto_block(&mut self, timeout: Duration) -> MinedNakamotoBlockEvent {
let commits_submitted = self.running_nodes.commits_submitted.clone();
let mined_block_time = Instant::now();
Expand Down Expand Up @@ -563,7 +561,7 @@ fn setup_stx_btc_node(
}
naka_conf.initial_balances.append(&mut initial_balances);
naka_conf.node.stacker = true;
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1000);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(5);

for signer_set in 0..2 {
for message_id in 0..SIGNER_SLOTS_PER_USER {
Expand Down Expand Up @@ -596,6 +594,8 @@ fn setup_stx_btc_node(
blocks_processed,
naka_submitted_vrfs: vrfs_submitted,
naka_submitted_commits: commits_submitted,
naka_proposed_blocks: naka_blocks_proposed,
naka_mined_blocks: naka_blocks_mined,
..
} = run_loop.counters();

Expand Down Expand Up @@ -626,6 +626,8 @@ fn setup_stx_btc_node(
vrfs_submitted: vrfs_submitted.0,
commits_submitted: commits_submitted.0,
blocks_processed: blocks_processed.0,
nakamoto_blocks_proposed: naka_blocks_proposed.0,
nakamoto_blocks_mined: naka_blocks_mined.0,
coord_channel,
conf: naka_conf,
}
Expand Down
Loading