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

Chore: Fix some CI tests #5218

Merged
merged 9 commits into from
Sep 23, 2024
12 changes: 6 additions & 6 deletions testnet/stacks-node/src/nakamoto_node/sign_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,6 @@ impl SignCoordinator {
);
continue;
}
if !gathered_signatures.contains_key(&slot_id) {
total_weight_signed = total_weight_signed
.checked_add(signer_entry.weight)
.expect("FATAL: total weight signed exceeds u32::MAX");
}

if Self::fault_injection_ignore_signatures() {
warn!("SignCoordinator: fault injection: ignoring well-formed signature for block";
Expand All @@ -906,6 +901,12 @@ impl SignCoordinator {
continue;
}

if !gathered_signatures.contains_key(&slot_id) {
total_weight_signed = total_weight_signed
.checked_add(signer_entry.weight)
.expect("FATAL: total weight signed exceeds u32::MAX");
}

info!("SignCoordinator: Signature Added to block";
"block_signer_sighash" => %block_sighash,
"signer_pubkey" => signer_pubkey.to_hex(),
Expand Down Expand Up @@ -986,7 +987,6 @@ impl SignCoordinator {
}
};
}

// After gathering all signatures, return them if we've hit the threshold
if total_weight_signed >= self.weight_threshold {
info!("SignCoordinator: Received enough signatures. Continuing.";
Expand Down
94 changes: 90 additions & 4 deletions testnet/stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use std::time::{Duration, Instant};

use clarity::boot_util::boot_code_id;
use clarity::vm::types::PrincipalData;
use libsigner::v0::messages::{BlockResponse, RejectCode, SignerMessage};
use libsigner::{SignerEntries, SignerEventTrait};
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
use stacks::chainstate::nakamoto::signer_set::NakamotoSigners;
Expand All @@ -46,7 +47,9 @@ use stacks::core::StacksEpoch;
use stacks::net::api::postblock_proposal::{
BlockValidateOk, BlockValidateReject, BlockValidateResponse,
};
use stacks::types::chainstate::StacksAddress;
use stacks::types::chainstate::{StacksAddress, StacksPublicKey};
use stacks::types::PublicKey;
use stacks::util::hash::MerkleHashFunc;
use stacks::util::secp256k1::{MessageSignature, Secp256k1PublicKey};
use stacks_common::codec::StacksMessageCodec;
use stacks_common::consts::SIGNER_SLOTS_PER_USER;
Expand Down Expand Up @@ -678,6 +681,76 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
assert!(signer.stop().is_none());
}
}

pub fn wait_for_block_acceptance(
&self,
timeout_secs: u64,
signer_signature_hash: &Sha512Trunc256Sum,
expected_signers: &[StacksPublicKey],
) -> Result<(), String> {
// Make sure that ALL signers accepted the block proposal
wait_for(timeout_secs, || {
let signatures = test_observer::get_stackerdb_chunks()
.into_iter()
.flat_map(|chunk| chunk.modified_slots)
.filter_map(|chunk| {
let message = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
.expect("Failed to deserialize SignerMessage");
match message {
SignerMessage::BlockResponse(BlockResponse::Accepted((
hash,
signature,
))) => {
if hash == *signer_signature_hash
&& expected_signers.iter().any(|pk| {
pk.verify(hash.bits(), &signature)
.expect("Failed to verify signature")
})
{
Some(signature)
} else {
None
}
}
_ => None,
}
})
.collect::<HashSet<_>>();
Ok(signatures.len() == expected_signers.len())
})
}

pub fn wait_for_block_rejections(
&self,
timeout_secs: u64,
expected_signers: &[StacksPublicKey],
) -> Result<(), String> {
wait_for(timeout_secs, || {
let stackerdb_events = test_observer::get_stackerdb_chunks();
let block_rejections = stackerdb_events
.into_iter()
.flat_map(|chunk| chunk.modified_slots)
.filter_map(|chunk| {
let message = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
.expect("Failed to deserialize SignerMessage");
match message {
SignerMessage::BlockResponse(BlockResponse::Rejected(rejection)) => {
let rejected_pubkey = rejection
.recover_public_key()
.expect("Failed to recover public key from rejection");
if expected_signers.contains(&rejected_pubkey) {
Some(rejection)
} else {
None
}
}
_ => None,
}
})
.collect::<Vec<_>>();
Ok(block_rejections.len() == expected_signers.len())
})
}
}

fn setup_stx_btc_node<G: FnMut(&mut NeonConfig) -> ()>(
Expand Down Expand Up @@ -748,9 +821,22 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig) -> ()>(
info!("Make new BitcoinRegtestController");
let mut btc_regtest_controller = BitcoinRegtestController::new(naka_conf.clone(), None);

info!("Bootstraping...");
// Should be 201 for other tests?
btc_regtest_controller.bootstrap_chain_to_pks(195, btc_miner_pubkeys);
let epoch_2_5_start = usize::try_from(
naka_conf
.burnchain
.epochs
.as_ref()
.unwrap()
.iter()
.find(|epoch| epoch.epoch_id == StacksEpochId::Epoch25)
.unwrap()
.start_height,
)
.expect("Failed to get epoch 2.5 start height");
let bootstrap_block = epoch_2_5_start - 6;

info!("Bootstraping to block {bootstrap_block}...");
btc_regtest_controller.bootstrap_chain_to_pks(bootstrap_block, btc_miner_pubkeys);

info!("Chain bootstrapped...");

Expand Down
Loading