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

Mutants next/stackslib 8 shards 2/source #40

Open
wants to merge 20 commits into
base: mutants-next/stackslib-8-shards-2/base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cfd1a12
feat: add nakamoto_node, nakamoto-neon mode
kantai Dec 4, 2023
c0ab89f
expand first nakamoto-neon test, update block commit logic to issue c…
kantai Dec 7, 2023
7b7a510
feat: add boot_nakamoto to wrap the 2.x/3.x node handoff
kantai Dec 9, 2023
50a6a11
add copyright headers, some code cleanup
kantai Dec 9, 2023
f075a99
chore: comments, cleanup unused functions
kantai Dec 10, 2023
5491610
chore: handle merge/rebase artifacts, address PR feedback
kantai Dec 12, 2023
1ec878f
remove unconfirmed tx handling in nakamoto RelayerThread
kantai Dec 12, 2023
be055d1
add epoch-3.0 burnchain configuration assertions
kantai Dec 12, 2023
6362307
requirements for configuring nakamoto-neon via CLI/toml
kantai Dec 12, 2023
02c6457
hashmap -> hashset
kantai Dec 13, 2023
52a5cd3
fix: mockamoto config must pass config assertions
kantai Dec 13, 2023
e26c1fe
ci: add tests::nakamoto_integrations::simple_neon_integration to the CI
kantai Dec 13, 2023
d37bf3b
fix: change PANIC_TIMEOUT_SECS back to original setting, move the nak…
kantai Dec 13, 2023
a7aa3f5
chore: only check config settings in nakamoto-neon, mockamoto
kantai Dec 13, 2023
e71444a
Merge pull request #4133 from stacks-network/feat/naka-neon
kantai Dec 13, 2023
9f59944
feat: ready source branch
ASuciuX Dec 20, 2023
b70810f
feat: run again with `cargo test --test-threads` arg
ASuciuX Dec 22, 2023
cf582b8
feat: re-run ci
ASuciuX Dec 28, 2023
71de94b
feat: re-run ci
ASuciuX Dec 28, 2023
6ff5931
feat: run again
ASuciuX Dec 28, 2023
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
File renamed without changes.
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