Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stacks-network/stacks-core
Browse files Browse the repository at this point in the history
… into fix/clippy-ci-stacks-lib-useless-vec
  • Loading branch information
jferrant committed Jan 9, 2025
2 parents dda5463 + a70b3d5 commit 949fc9a
Show file tree
Hide file tree
Showing 58 changed files with 363 additions and 222 deletions.
14 changes: 5 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
### Added

- Add `tenure_timeout_secs` to the miner for determining when a time-based tenure extend should be attempted.
- Added configuration option `block_proposal_max_age_secs` under `[connection_options]` to prevent processing stale block proposals

### Changed
- The RPC endpoint `/v3/block_proposal` no longer will evaluate block proposals more than `block_proposal_max_age_secs` old

- When a transaction is dropped due to replace-by-fee, the `/drop_mempool_tx` event observer payload now includes `new_txid`, which is the transaction that replaced this dropped transaction. When a transaction is dropped for other reasons, `new_txid` is `null`. [#5381](https://github.com/stacks-network/stacks-core/pull/5381)
- Nodes will assume that all PoX anchor blocks exist by default, and stall initial block download indefinitely to await their arrival (#5502)

## [3.1.0.0.1]

### Added

- A miner will now generate a tenure-extend when at least 70% of the signers have confirmed that they are willing to allow one, via the new timestamp included in block responses. This allows the miner to refresh its budget in between Bitcoin blocks. ([#5476](https://github.com/stacks-network/stacks-core/discussions/5476))

### Changed

## [3.1.0.0.0]
## [3.1.0.0.2]

### Added

Expand All @@ -33,6 +27,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
- `/v2/clarity/marf/:marf_key_hash`
- `/v2/clarity/metadata/:principal/:contract_name/:clarity_metadata_key`
- When a proposed block is validated by a node, the block can be validated even when the block version is different than the node's default ([#5539](https://github.com/stacks-network/stacks-core/pull/5539))
- A miner will now generate a tenure-extend when at least 70% of the signers have confirmed that they are willing to allow one, via the new timestamp included in block responses. This allows the miner to refresh its budget in between Bitcoin blocks. ([#5476](https://github.com/stacks-network/stacks-core/discussions/5476))
- Set the epoch to 3.1 in the Clarity DB upon activation.

### Changed

Expand Down
4 changes: 2 additions & 2 deletions sample/conf/testnet-follower-conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ start_height = 6

[[burnchain.epochs]]
epoch_name = "3.0"
start_height = 56_457
start_height = 1900

[[burnchain.epochs]]
epoch_name = "3.1"
start_height = 77_770
start_height = 2000
4 changes: 2 additions & 2 deletions sample/conf/testnet-miner-conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ start_height = 6

[[burnchain.epochs]]
epoch_name = "3.0"
start_height = 56_457
start_height = 1900

[[burnchain.epochs]]
epoch_name = "3.1"
start_height = 77_770
start_height = 2000
6 changes: 5 additions & 1 deletion sample/conf/testnet-signer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ start_height = 6

[[burnchain.epochs]]
epoch_name = "3.0"
start_height = 56_457
start_height = 1900

[[burnchain.epochs]]
epoch_name = "3.1"
start_height = 2000
15 changes: 13 additions & 2 deletions stacks-signer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
- Improvements to the stale signer cleanup logic: deletes the prior signer if it has no remaining unprocessed blocks in its database
- Signers now listen to new block events from the stacks node to determine whether a block has been successfully appended to the chain tip

## [3.1.0.0.1.0]
# [3.1.0.0.2.1]

### Added
## Added

## Changed

- Prevent old reward cycle signers from processing block validation response messages that do not apply to blocks from their cycle.

## [3.1.0.0.2.0]

## Added

- **SIP-029 consensus rules, activating in epoch 3.1 at block 875,000** (see [SIP-029](https://github.com/will-corcoran/sips/blob/feat/sip-029-halving-alignment/sips/sip-029/sip-029-halving-alignment.md) for details)

### Changed

- Added tenure extend timestamp to signer block responses
- Added tenure_idle_timeout_secs configuration option for determining when a time-based tenure extend will be accepted


## [3.1.0.0.0.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::path::PathBuf;
use std::time::Duration;

use blockstack_lib::chainstate::stacks::TransactionVersion;
use blockstack_lib::net::connection::DEFAULT_BLOCK_PROPOSAL_MAX_AGE_SECS;
use clarity::util::hash::to_hex;
use libsigner::SignerEntries;
use serde::Deserialize;
Expand All @@ -39,7 +40,6 @@ const BLOCK_PROPOSAL_VALIDATION_TIMEOUT_MS: u64 = 120_000;
const DEFAULT_FIRST_PROPOSAL_BURN_BLOCK_TIMING_SECS: u64 = 60;
const DEFAULT_TENURE_LAST_BLOCK_PROPOSAL_TIMEOUT_SECS: u64 = 30;
const TENURE_IDLE_TIMEOUT_SECS: u64 = 300;
const DEFAULT_BLOCK_PROPOSAL_MAX_AGE_SECS: u64 = 600;

#[derive(thiserror::Error, Debug)]
/// An error occurred parsing the provided configuration
Expand Down
16 changes: 16 additions & 0 deletions stacks-signer/src/v0/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,14 @@ impl Signer {
// For mutability reasons, we need to take the block_info out of the map and add it back after processing
let mut block_info = match self.signer_db.block_lookup(&signer_signature_hash) {
Ok(Some(block_info)) => {
if block_info.reward_cycle != self.reward_cycle {
// We are not signing for this reward cycle. Ignore the block.
debug!(
"{self}: Received a block validation response for a different reward cycle. Ignore it.";
"requested_reward_cycle" => block_info.reward_cycle,
);
return None;
}
if block_info.is_locally_finalized() {
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
return None;
Expand Down Expand Up @@ -744,6 +752,14 @@ impl Signer {
}
let mut block_info = match self.signer_db.block_lookup(&signer_signature_hash) {
Ok(Some(block_info)) => {
if block_info.reward_cycle != self.reward_cycle {
// We are not signing for this reward cycle. Ignore the block.
debug!(
"{self}: Received a block validation response for a different reward cycle. Ignore it.";
"requested_reward_cycle" => block_info.reward_cycle,
);
return None;
}
if block_info.is_locally_finalized() {
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
return None;
Expand Down
2 changes: 1 addition & 1 deletion stackslib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = [ "stacks", "stx", "bitcoin", "crypto", "blockstack", "decentralized"
readme = "README.md"
resolver = "2"
edition = "2021"
rust-version = "1.61"
rust-version = "1.80"

[lib]
name = "blockstack_lib"
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/bitcoin/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl BitcoinMessageHandler for BitcoinBlockDownloader {
None => panic!("No block header set"),
Some(ref ipc_header) => {
let block_hash = ipc_header.block_header.header.bitcoin_hash().clone();
indexer.send_getdata(&[block_hash]).and_then(|_r| Ok(true))
indexer.send_getdata(&[block_hash]).map(|_r| true)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl BitcoinIndexer {
}
spv_client
.run(self)
.and_then(|_r| Ok(spv_client.end_block_height.unwrap()))
.map(|_r| spv_client.end_block_height.unwrap())
}

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions stackslib/src/burnchains/bitcoin/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ impl BitcoinIndexer {
// classify the message here, so we can pass it along to the handler explicitly
match message {
btc_message::NetworkMessage::Version(..) => {
return self.handle_version(message).and_then(|_r| Ok(true));
return self.handle_version(message).map(|_r| true);
}
btc_message::NetworkMessage::Verack => {
return self.handle_verack(message).and_then(|_r| Ok(true));
return self.handle_verack(message).map(|_r| true);
}
btc_message::NetworkMessage::Ping(..) => {
return self.handle_ping(message).and_then(|_r| Ok(true));
return self.handle_ping(message).map(|_r| true);
}
btc_message::NetworkMessage::Pong(..) => {
return self.handle_pong(message).and_then(|_r| Ok(true));
return self.handle_pong(message).map(|_r| true);
}
_ => match handler {
Some(custom_handler) => custom_handler.handle_message(self, message),
Expand Down
10 changes: 5 additions & 5 deletions stackslib/src/burnchains/bitcoin/spv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl SpvClient {
tx.execute("UPDATE db_config SET version = ?1", &[version])
.map_err(db_error::SqliteError)
.map_err(|e| e.into())
.and_then(|_| Ok(()))
.map(|_| ())
}

#[cfg(test)]
Expand Down Expand Up @@ -354,7 +354,7 @@ impl SpvClient {
pub fn is_initialized(&self) -> Result<(), btc_error> {
fs::metadata(&self.headers_path)
.map_err(btc_error::FilesystemError)
.and_then(|_m| Ok(()))
.map(|_m| ())
}

/// Get the block range to scan
Expand Down Expand Up @@ -762,7 +762,7 @@ impl SpvClient {

tx.execute(sql, args)
.map_err(|e| btc_error::DBError(db_error::SqliteError(e)))
.and_then(|_x| Ok(()))
.map(|_x| ())
}

/// Initialize the block headers file with the genesis block hash.
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl BitcoinMessageHandler for SpvClient {

indexer.runtime.last_getheaders_send_time = get_epoch_time_secs();
self.send_next_getheaders(indexer, start_height)
.and_then(|_r| Ok(true))
.map(|_r| true)
}

/// Trait message handler
Expand Down Expand Up @@ -1298,7 +1298,7 @@ impl BitcoinMessageHandler for SpvClient {
);
}
self.send_next_getheaders(indexer, block_height)
.and_then(|_| Ok(true))
.map(|_| true)
}
x => Err(btc_error::UnhandledMessage(x)),
}
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/tests/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ pub fn make_reward_cycle_with_vote(
new_commits.push(commits.clone());
commits
.into_iter()
.filter_map(|cmt| cmt)
.flatten()
.map(|cmt| BlockstackOperationType::LeaderBlockCommit(cmt))
.collect()
};
Expand Down
8 changes: 3 additions & 5 deletions stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3936,7 +3936,7 @@ impl SortitionDBConn<'_> {
tip,
reward_cycle_id,
)
.and_then(|(reward_cycle_info, _anchor_sortition_id)| Ok(reward_cycle_info))
.map(|(reward_cycle_info, _anchor_sortition_id)| reward_cycle_info)
}

/// Get the prepare phase start sortition ID of a reward cycle. This is the first prepare
Expand Down Expand Up @@ -4048,25 +4048,23 @@ impl SortitionDB {
}

fn parse_last_anchor_block_hash(s: Option<String>) -> Option<BlockHeaderHash> {
s.map(|s| {
s.and_then(|s| {
if s.is_empty() {
None
} else {
Some(BlockHeaderHash::from_hex(&s).expect("BUG: Bad BlockHeaderHash stored in DB"))
}
})
.flatten()
}

fn parse_last_anchor_block_txid(s: Option<String>) -> Option<Txid> {
s.map(|s| {
s.and_then(|s| {
if s.is_empty() {
None
} else {
Some(Txid::from_hex(&s).expect("BUG: Bad Txid stored in DB"))
}
})
.flatten()
}

/// Mark a Stacks block snapshot as valid again, but update its memoized canonical Stacks tip
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/burn/operations/delegate_stx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl StacksMessageCodec for DelegateStxOp {
} else {
fd.write_all(&0_u8.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
fd.write_all(&0_u8.to_be_bytes())
fd.write_all(&0_u32.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl LeaderKeyRegisterOp {
/// Interpret the first 20 bytes of the key registration's memo field as the Hash160 of
/// of the public key that will sign this miner's nakamoto blocks.
pub fn interpret_nakamoto_signing_key(&self) -> Option<Hash160> {
self.memo.get(0..20).map(Hash160::from_bytes).flatten()
self.memo.get(0..20).and_then(Hash160::from_bytes)
}

/// Set the miner public key hash160 for block-signing
Expand Down
3 changes: 1 addition & 2 deletions stackslib/src/chainstate/burn/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,7 @@ impl BlockSnapshot {
winning_block.key_vtxindex.into(),
&parent_snapshot.sortition_id,
)?
.map(|key_op| key_op.interpret_nakamoto_signing_key())
.flatten();
.and_then(|key_op| key_op.interpret_nakamoto_signing_key());

Ok(BlockSnapshot {
block_height,
Expand Down
12 changes: 6 additions & 6 deletions stackslib/src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2411,11 +2411,11 @@ impl<
// burnchain has not yet advanced to epoch 3.0
return self
.handle_new_epoch2_burnchain_block(&mut HashSet::new())
.and_then(|block_hash_opt| {
.map(|block_hash_opt| {
if let Some(block_hash) = block_hash_opt {
Ok(NewBurnchainBlockStatus::WaitForPox2x(block_hash))
NewBurnchainBlockStatus::WaitForPox2x(block_hash)
} else {
Ok(NewBurnchainBlockStatus::Ready)
NewBurnchainBlockStatus::Ready
}
});
}
Expand Down Expand Up @@ -2444,12 +2444,12 @@ impl<

// proceed to process sortitions in epoch 3.0
self.handle_new_nakamoto_burnchain_block()
.and_then(|can_proceed| {
.map(|can_proceed| {
if can_proceed {
Ok(NewBurnchainBlockStatus::Ready)
NewBurnchainBlockStatus::Ready
} else {
// missing PoX anchor block, but unlike in 2.x, we don't know what it is!
Ok(NewBurnchainBlockStatus::WaitForPoxNakamoto)
NewBurnchainBlockStatus::WaitForPoxNakamoto
}
})
}
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 @@ -596,7 +596,7 @@ impl NakamotoBlockBuilder {
tenure_info.coinbase_tx.clone(),
]
.into_iter()
.filter_map(|x| x)
.flatten()
.collect();

// TODO: update this mempool check to prioritize signer vote transactions over other transactions
Expand Down
Loading

0 comments on commit 949fc9a

Please sign in to comment.