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: Mockamoto + coordinator integration #4098

Merged
merged 6 commits into from
Dec 1, 2023
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
26 changes: 20 additions & 6 deletions stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4601,12 +4601,20 @@ impl SortitionDB {

if cur_epoch.epoch_id >= StacksEpochId::Epoch30 {
// nakamoto behavior -- look to the stacks_chain_tip table
let res: Result<_, db_error> = conn.query_row_and_then(
"SELECT consensus_hash,block_hash FROM stacks_chain_tips WHERE sortition_id = ?",
&[&sn.sortition_id],
|row| Ok((row.get_unwrap(0), row.get_unwrap(1))),
);
return res;
// if the chain tip of the current sortition hasn't been set, have to iterate to parent
let mut cursor = sn;
loop {
let result_at_tip = conn.query_row_and_then(
"SELECT consensus_hash,block_hash FROM stacks_chain_tips WHERE sortition_id = ?",
&[&cursor.sortition_id],
|row| Ok((row.get_unwrap(0), row.get_unwrap(1))),
).optional()?;
if let Some(stacks_tip) = result_at_tip {
return Ok(stacks_tip);
}
cursor = SortitionDB::get_block_snapshot(conn, &cursor.parent_sortition_id)?
.ok_or_else(|| db_error::NotFoundError)?;
}
}

// epoch 2.x behavior -- look at the snapshot itself
Expand Down Expand Up @@ -5281,6 +5289,12 @@ impl<'a> SortitionHandleTx<'a> {
canonical_stacks_tip_block_hash,
canonical_stacks_tip_height,
) = res?;
info!(
"Setting initial stacks_chain_tips values";
"stacks_tip_height" => canonical_stacks_tip_height,
"stacks_tip_hash" => %canonical_stacks_tip_block_hash,
"stacks_tip_consensus" => %canonical_stacks_tip_consensus_hash
);
sn.canonical_stacks_tip_height = canonical_stacks_tip_height;
sn.canonical_stacks_tip_hash = canonical_stacks_tip_block_hash;
sn.canonical_stacks_tip_consensus_hash = canonical_stacks_tip_consensus_hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use crate::core::{
use crate::net::Error as net_error;

// return type from parse_data below
#[derive(Debug)]
struct ParsedData {
block_header_hash: BlockHeaderHash,
new_seed: VRFSeed,
Expand Down Expand Up @@ -884,7 +885,8 @@ impl LeaderBlockCommitOp {

let is_already_committed = tx.expects_stacks_block_in_fork(&self.block_header_hash)?;

if is_already_committed {
// in Epoch3.0+, block commits can include Stacks blocks already accepted in the fork.
jcnelson marked this conversation as resolved.
Show resolved Hide resolved
if is_already_committed && epoch_id < StacksEpochId::Epoch30 {
warn!(
"Invalid block commit: already committed to {}",
self.block_header_hash;
Expand Down
8 changes: 8 additions & 0 deletions stackslib/src/chainstate/nakamoto/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,14 @@ impl<
header.block_height, reward_cycle, &self.burnchain.working_dir,
);

info!(
"Process burn block {} reward cycle {} in {}",
header.block_height, reward_cycle, &self.burnchain.working_dir;
"in_prepare_phase" => self.burnchain.is_in_prepare_phase(header.block_height),
"is_rc_start" => self.burnchain.is_reward_cycle_start(header.block_height),
"is_prior_in_prepare_phase" => self.burnchain.is_in_prepare_phase(header.block_height.saturating_sub(2)),
);

// calculate paid rewards during this burnchain block if we announce
// to an events dispatcher
let paid_rewards = if self.dispatcher.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/nakamoto/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl NakamotoBlockBuilder {
&mut tenure_tx,
&mut builder,
mempool,
parent_stacks_header,
parent_stacks_header.stacks_block_height,
new_tenure_info.as_ref().map(|info| &info.coinbase_tx),
settings,
event_observer,
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,9 @@ impl StacksChainState {
let reward_cycle = burnchain
.block_height_to_reward_cycle(current_burn_height)
.ok_or(Error::PoxNoRewardCycle)?;

self.get_reward_addresses_in_cycle(burnchain, sortdb, reward_cycle, block_id)
}

/// Get the sequence of reward addresses, as well as the PoX-specified hash mode (which gets
/// lost in the conversion to StacksAddress)
/// Each address will have at least (get-stacking-minimum) tokens.
Expand Down
12 changes: 4 additions & 8 deletions stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2138,15 +2138,14 @@ impl StacksBlockBuilder {
epoch_tx: &mut ClarityTx,
builder: &mut B,
mempool: &mut MemPoolDB,
parent_stacks_header: &StacksHeaderInfo,
tip_height: u64,
coinbase_tx: Option<&StacksTransaction>,
settings: BlockBuilderSettings,
event_observer: Option<&dyn MemPoolEventDispatcher>,
ast_rules: ASTRules,
) -> Result<(bool, Vec<TransactionEvent>), Error> {
let max_miner_time_ms = settings.max_miner_time_ms;
let mempool_settings = settings.mempool_settings.clone();
let tip_height = parent_stacks_header.stacks_block_height;
let ts_start = get_epoch_time_ms();
let stacks_epoch_id = epoch_tx.get_epoch();
let block_limit = epoch_tx
Expand Down Expand Up @@ -2178,10 +2177,7 @@ impl StacksBlockBuilder {
let mut num_txs = 0;
let mut blocked = false;

debug!(
"Block transaction selection begins (child of {})",
&parent_stacks_header.anchored_header.block_hash()
);
debug!("Block transaction selection begins (parent height = {tip_height})");
let result = {
let mut intermediate_result: Result<_, Error> = Ok(0);
while block_limit_hit != BlockLimitFunction::LIMIT_REACHED {
Expand Down Expand Up @@ -2354,7 +2350,7 @@ impl StacksBlockBuilder {
break;
}
}
debug!("Block transaction selection finished (child of {}): {} transactions selected ({} considered)", &parent_stacks_header.anchored_header.block_hash(), num_txs, considered.len());
debug!("Block transaction selection finished (parent height {}): {} transactions selected ({} considered)", &tip_height, num_txs, considered.len());
intermediate_result
};

Expand Down Expand Up @@ -2437,7 +2433,7 @@ impl StacksBlockBuilder {
&mut epoch_tx,
&mut builder,
mempool,
parent_stacks_header,
parent_stacks_header.stacks_block_height,
Some(coinbase_tx),
settings,
event_observer,
Expand Down
6 changes: 4 additions & 2 deletions stackslib/src/core/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::burnchains::Txid;
use crate::chainstate::burn::db::sortdb::SortitionDB;
use crate::chainstate::burn::ConsensusHash;
use crate::chainstate::nakamoto::NakamotoBlock;
use crate::chainstate::nakamoto::NakamotoChainState;
use crate::chainstate::stacks::db::blocks::MemPoolRejection;
use crate::chainstate::stacks::db::{ClarityTx, StacksChainState};
use crate::chainstate::stacks::events::StacksTransactionReceipt;
Expand Down Expand Up @@ -2159,8 +2160,9 @@ impl MemPoolDB {
block_hash
);

let height = match chainstate.get_stacks_block_height(consensus_hash, block_hash) {
Ok(Some(h)) => h,
let block_id = StacksBlockId::new(consensus_hash, block_hash);
let height = match NakamotoChainState::get_block_header(chainstate.db(), &block_id) {
Ok(Some(header)) => header.stacks_block_height,
Ok(None) => {
if *consensus_hash == FIRST_BURNCHAIN_CONSENSUS_HASH {
0
Expand Down
Loading