Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Mutants next/test stackslib with shards 2/source #36

Open
wants to merge 17 commits into
base: mutants-next/test-stackslib-with-shards-2/base
Choose a base branch
from
Open
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 @@ -69,6 +69,7 @@ jobs:
- tests::neon_integrations::test_problematic_txs_are_not_stored
- tests::neon_integrations::use_latest_tip_integration_test
- tests::should_succeed_handling_malformed_and_valid_txs
- tests::nakamoto_integrations::simple_neon_integration
steps:
## Setup test environment
- name: Setup Test Environment
Expand Down
7 changes: 5 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ members = [
# Dependencies we want to keep the same between workspace members
[workspace.dependencies]
wsts = "5.0"
rand_core = "0.6"
rand = "0.8"

# Use a bit more than default optimization for
# dev builds to speed up test execution
Expand Down
2 changes: 1 addition & 1 deletion clarity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resolver = "2"

[lib]
name = "clarity"
path = "./src/libclarity.rs"
path = "./src/lib.rs"

[dependencies]
rand = "0.7.3"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion libsigner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"

[lib]
name = "libsigner"
path = "./src/libsigner.rs"
path = "./src/lib.rs"

[dependencies]
clarity = { path = "../clarity" }
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion stacks-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2021"

[lib]
name = "stacks_common"
path = "./src/libcommon.rs"
path = "./src/lib.rs"

[dependencies]
rand = "0.7.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![allow(non_upper_case_globals)]
#![cfg_attr(test, allow(unused_variables, unused_assignments))]
#![allow(clippy::assertions_on_constants)]

// test to re-run mutants trigger
#[macro_use(o, slog_log, slog_trace, slog_debug, slog_info, slog_warn, slog_error)]
extern crate slog;

Expand Down
13 changes: 4 additions & 9 deletions stackslib/src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ use crate::burnchains::{
Burnchain, BurnchainBlockHeader, Error as burnchain_error, MagicBytes, BLOCKSTACK_MAGIC_MAINNET,
};
use crate::core::{
StacksEpoch, STACKS_EPOCHS_MAINNET, STACKS_EPOCHS_REGTEST, STACKS_EPOCHS_TESTNET,
StacksEpoch, StacksEpochExtension, STACKS_EPOCHS_MAINNET, STACKS_EPOCHS_REGTEST,
STACKS_EPOCHS_TESTNET,
};
use crate::util_lib::db::Error as DBError;

Expand Down Expand Up @@ -91,7 +92,7 @@ impl TryFrom<u32> for BitcoinNetworkType {
/// Get the default epochs definitions for the given BitcoinNetworkType.
/// Should *not* be used except by the BitcoinIndexer when no epochs vector
/// was specified.
fn get_bitcoin_stacks_epochs(network_id: BitcoinNetworkType) -> Vec<StacksEpoch> {
pub fn get_bitcoin_stacks_epochs(network_id: BitcoinNetworkType) -> Vec<StacksEpoch> {
match network_id {
BitcoinNetworkType::Mainnet => STACKS_EPOCHS_MAINNET.to_vec(),
BitcoinNetworkType::Testnet => STACKS_EPOCHS_TESTNET.to_vec(),
Expand Down Expand Up @@ -1030,13 +1031,7 @@ impl BurnchainIndexer for BitcoinIndexer {
///
/// It is an error (panic) to set custom epochs if running on `Mainnet`.
fn get_stacks_epochs(&self) -> Vec<StacksEpoch> {
match self.config.epochs {
Some(ref epochs) => {
assert!(self.runtime.network_id != BitcoinNetworkType::Mainnet);
epochs.clone()
}
None => get_bitcoin_stacks_epochs(self.runtime.network_id),
}
StacksEpoch::get_epochs(self.runtime.network_id, self.config.epochs.as_ref())
}

/// Read downloaded headers within a range
Expand Down
40 changes: 29 additions & 11 deletions stackslib/src/chainstate/nakamoto/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn get_nakamoto_reward_cycle_info<U: RewardSetProvider>(
.epoch_id;

assert!(
epoch_at_height >= StacksEpochId::Epoch30,
epoch_at_height >= StacksEpochId::Epoch25,
"FATAL: called a nakamoto function outside of epoch 3"
);

Expand Down Expand Up @@ -216,22 +216,40 @@ pub fn get_nakamoto_reward_cycle_info<U: RewardSetProvider>(
}

// find the first Stacks block processed in the prepare phase
let Some(prepare_start_block_header) =
let parent_block_id = if let Some(nakamoto_start_block) =
NakamotoChainState::get_nakamoto_tenure_start_block_header(
chain_state.db(),
&sn.consensus_hash,
)? {
nakamoto_start_block
.anchored_header
.as_stacks_nakamoto()
// TODO: maybe `get_nakamoto_tenure_start_block_header` should
// return a type that doesn't require this unwrapping?
.expect("FATAL: queried non-Nakamoto tenure start header")
.parent_block_id
} else {
let Some(block_header) =
StacksChainState::get_stacks_block_header_info_by_consensus_hash(
chain_state.db(),
&sn.consensus_hash,
)?
else {
// no header for this snapshot (possibly invalid)
debug!("Failed to find block by consensus hash"; "consensus_hash" => %sn.consensus_hash);
continue;
};
let Some(parent_block_id) = StacksChainState::get_parent_block_id(
chain_state.db(),
&block_header.index_block_hash(),
)?
else {
// no header for this snapshot (possibly invalid)
continue;
else {
debug!("Failed to get parent block"; "block_id" => %block_header.index_block_hash());
continue;
};
parent_block_id
};

let parent_block_id = &prepare_start_block_header
.anchored_header
.as_stacks_nakamoto()
.expect("FATAL: queried non-Nakamoto tenure start header")
.parent_block_id;

// find the tenure-start block of the tenure of the parent of this Stacks block.
// in epoch 2, this is the preceding anchor block
// in nakamoto, this is the tenure-start block of the preceding tenure
Expand Down
12 changes: 9 additions & 3 deletions stackslib/src/chainstate/nakamoto/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ impl NakamotoBlockBuilder {
state_root_hash
);

info!(
debug!(
"Miner: mined Nakamoto block";
"consensus_hash" => %block.header.consensus_hash,
"block_hash" => %block.header.block_hash(),
Expand Down Expand Up @@ -570,13 +570,19 @@ impl NakamotoBlockBuilder {
.block_limit()
.expect("Failed to obtain block limit from miner's block connection");

let initial_txs: Vec<_> = [
tenure_info.tenure_change_tx.clone(),
tenure_info.coinbase_tx.clone(),
]
.into_iter()
.filter_map(|x| x)
.collect();
let (blocked, tx_events) = match StacksBlockBuilder::select_and_apply_transactions(
&mut tenure_tx,
&mut builder,
mempool,
parent_stacks_header.stacks_block_height,
tenure_info.tenure_change_tx(),
tenure_info.coinbase_tx(),
&initial_txs,
settings,
event_observer,
ASTRules::PrecheckSize,
Expand Down
17 changes: 4 additions & 13 deletions stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2139,8 +2139,7 @@ impl StacksBlockBuilder {
builder: &mut B,
mempool: &mut MemPoolDB,
tip_height: u64,
tenure_change_tx: Option<&StacksTransaction>,
coinbase_tx: Option<&StacksTransaction>,
initial_txs: &[StacksTransaction],
settings: BlockBuilderSettings,
event_observer: Option<&dyn MemPoolEventDispatcher>,
ast_rules: ASTRules,
Expand All @@ -2155,17 +2154,10 @@ impl StacksBlockBuilder {

let mut tx_events = Vec::new();

if let Some(tenure_tx) = tenure_change_tx {
for initial_tx in initial_txs.iter() {
tx_events.push(
builder
.try_mine_tx(epoch_tx, tenure_tx, ast_rules.clone())?
.convert_to_event(),
);
}
if let Some(coinbase_tx) = coinbase_tx {
tx_events.push(
builder
.try_mine_tx(epoch_tx, coinbase_tx, ast_rules.clone())?
.try_mine_tx(epoch_tx, initial_tx, ast_rules.clone())?
.convert_to_event(),
);
}
Expand Down Expand Up @@ -2442,8 +2434,7 @@ impl StacksBlockBuilder {
&mut builder,
mempool,
parent_stacks_header.stacks_block_height,
None,
Some(coinbase_tx),
&[coinbase_tx.clone()],
settings,
event_observer,
ast_rules,
Expand Down
27 changes: 27 additions & 0 deletions stackslib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub use stacks_common::types::StacksEpochId;
use stacks_common::util::log;

pub use self::mempool::MemPoolDB;
use crate::burnchains::bitcoin::indexer::get_bitcoin_stacks_epochs;
use crate::burnchains::bitcoin::BitcoinNetworkType;
use crate::burnchains::{Burnchain, Error as burnchain_error};
use crate::chainstate::burn::ConsensusHash;
pub mod mempool;
Expand Down Expand Up @@ -604,9 +606,34 @@ pub trait StacksEpochExtension {
epoch_2_1_block_height: u64,
) -> Vec<StacksEpoch>;
fn validate_epochs(epochs: &[StacksEpoch]) -> Vec<StacksEpoch>;
/// This method gets the epoch vector.
///
/// Choose according to:
/// 1) Use the custom epochs defined on the underlying `BitcoinIndexerConfig`, if they exist.
/// 2) Use hard-coded static values, otherwise.
///
/// It is an error (panic) to set custom epochs if running on `Mainnet`.
///
fn get_epochs(
bitcoin_network: BitcoinNetworkType,
configured_epochs: Option<&Vec<StacksEpoch>>,
) -> Vec<StacksEpoch>;
}

impl StacksEpochExtension for StacksEpoch {
fn get_epochs(
bitcoin_network: BitcoinNetworkType,
configured_epochs: Option<&Vec<StacksEpoch>>,
) -> Vec<StacksEpoch> {
match configured_epochs {
Some(epochs) => {
assert!(bitcoin_network != BitcoinNetworkType::Mainnet);
epochs.clone()
}
None => get_bitcoin_stacks_epochs(bitcoin_network),
}
}

#[cfg(test)]
fn unit_test_pre_2_05(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
Expand Down
3 changes: 1 addition & 2 deletions testnet/stacks-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ rust-version = "1.61"
[dependencies]
lazy_static = "1.4.0"
pico-args = "0.3.1"
rand = "0.7.3"
serde = "1"
serde_derive = "1"
serde_json = { version = "1.0", features = ["arbitrary_precision", "raw_value"] }
Expand All @@ -29,7 +28,7 @@ chrono = "0.4.19"
regex = "1"
libsigner = { path = "../../libsigner" }
wsts = { workspace = true }
rand_core = "0.6"
rand = { workspace = true }

[dev-dependencies]
ring = "0.16.19"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use async_h1::client;
use async_std::io::ReadExt;
use async_std::net::TcpStream;
use base64::encode;
use clarity::vm::types::PrincipalData;
use http_types::{Method, Request, Url};
use serde::Serialize;
use serde_json::json;
Expand Down Expand Up @@ -50,7 +49,7 @@ use stacks_common::deps_common::bitcoin::network::encodable::ConsensusEncodable;
use stacks_common::deps_common::bitcoin::network::serialize::deserialize as btc_deserialize;
use stacks_common::deps_common::bitcoin::network::serialize::RawEncoder;
use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash;
use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksAddress};
use stacks_common::types::chainstate::BurnchainHeaderHash;
use stacks_common::util::hash::{hex_bytes, Hash160};
use stacks_common::util::secp256k1::Secp256k1PublicKey;
use stacks_common::util::sleep_ms;
Expand Down
Loading
Loading