Skip to content

Commit 181f276

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into feat/miner-constructs-replay-block-feature-gated
2 parents 174991d + 5b95fb7 commit 181f276

File tree

12 files changed

+543
-151
lines changed

12 files changed

+543
-151
lines changed

.github/CODEOWNERS

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# These owners will be the default owners for everything in
2+
# the repo. Unless a later match takes precedence,
3+
#
4+
# require both blockchain-team-codeowners and blockchain-team to review all PR's not specifically matched below
5+
* @stacks-network/blockchain-team-codeowners @stacks-network/blockchain-team
6+
7+
8+
# Signer code
9+
# require both blockchain-team-codeowners and blockchain-team-signer to review PR's for the signer folder(s)
10+
libsigner/**/*.rs @stacks-network/blockchain-team-codeowners @stacks-network/blockchain-team-signer
11+
stacks-signer/**/*.rs @stacks-network/blockchain-team-codeowners @stacks-network/blockchain-team-signer
12+
13+
# CI workflows
14+
# require both blockchain-team and blockchain-team-ci teams to review PR's modifying CI workflows
15+
/.github/workflows/ @stacks-network/blockchain-team @stacks-network/blockchain-team-ci
16+
/.github/actions/ @stacks-network/blockchain-team @stacks-network/blockchain-team-ci

.github/workflows/core-build-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Build the binaries
2525
id: build
2626
run: |
27-
cargo build --bin stacks-inspect
27+
cargo build
2828
- name: Dump constants JSON
2929
id: consts-dump
3030
run: cargo run --bin stacks-inspect -- dump-consts | tee out.json

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to the versioning scheme outlined in the [README.md](README.md).
77

8-
## [Unreleased]
8+
## [3.1.0.0.9]
99

1010
### Added
1111

CODEOWNERS

Lines changed: 0 additions & 20 deletions
This file was deleted.

stacks-signer/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to the versioning scheme outlined in the [README.md](README.md).
77

8-
## [Unreleased]
8+
## [3.1.0.0.9.0]
99

1010
### Changed
1111

stacks-signer/src/v0/signer.rs

Lines changed: 51 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,8 @@ impl Signer {
408408
block_response,
409409
sortition_state,
410410
),
411-
SignerMessage::StateMachineUpdate(update) => {
412-
self.handle_state_machine_update(
413-
signer_public_key,
414-
update,
415-
received_time,
416-
);
417-
}
411+
SignerMessage::StateMachineUpdate(update) => self
412+
.handle_state_machine_update(signer_public_key, update, received_time),
418413
_ => {}
419414
}
420415
}
@@ -670,22 +665,43 @@ impl Signer {
670665

671666
/// The actual `send_block_response` implementation. Declared so that we do
672667
/// not need to duplicate in testing.
673-
fn impl_send_block_response(&mut self, block_response: BlockResponse) {
674-
let res = self
668+
fn impl_send_block_response(
669+
&mut self,
670+
block: Option<&NakamotoBlock>,
671+
block_response: BlockResponse,
672+
) {
673+
info!(
674+
"{self}: Broadcasting a block response to stacks node: {block_response:?}";
675+
);
676+
let accepted = matches!(block_response, BlockResponse::Accepted(..));
677+
match self
675678
.stackerdb
676-
.send_message_with_retry::<SignerMessage>(block_response.clone().into());
677-
match res {
678-
Err(e) => warn!("{self}: Failed to send block rejection to stacker-db: {e:?}"),
679-
Ok(ack) if !ack.accepted => warn!(
680-
"{self}: Block rejection not accepted by stacker-db: {:?}",
681-
ack.reason
682-
),
683-
Ok(_) => debug!("{self}: Block rejection accepted by stacker-db"),
679+
.send_message_with_retry::<SignerMessage>(block_response.into())
680+
{
681+
Ok(ack) => {
682+
if !ack.accepted {
683+
warn!(
684+
"{self}: Block response not accepted by stacker-db: {:?}",
685+
ack.reason
686+
);
687+
}
688+
crate::monitoring::actions::increment_block_responses_sent(accepted);
689+
if let Some(block) = block {
690+
crate::monitoring::actions::record_block_response_latency(block);
691+
}
692+
}
693+
Err(e) => {
694+
warn!("{self}: Failed to send block response to stacker-db: {e:?}",);
695+
}
684696
}
685697
}
686698

687699
#[cfg(any(test, feature = "testing"))]
688-
fn send_block_response(&mut self, block_response: BlockResponse) {
700+
fn send_block_response(
701+
&mut self,
702+
block: Option<&NakamotoBlock>,
703+
block_response: BlockResponse,
704+
) {
689705
const NUM_REPEATS: usize = 1;
690706
let mut count = 0;
691707
let public_keys = TEST_REPEAT_PROPOSAL_RESPONSE.get();
@@ -695,16 +711,20 @@ impl Signer {
695711
count = NUM_REPEATS;
696712
}
697713
while count <= NUM_REPEATS {
698-
self.impl_send_block_response(block_response.clone());
714+
self.impl_send_block_response(block, block_response.clone());
699715

700716
count += 1;
701717
sleep_ms(1000);
702718
}
703719
}
704720

705721
#[cfg(not(any(test, feature = "testing")))]
706-
fn send_block_response(&mut self, block_response: BlockResponse) {
707-
self.impl_send_block_response(block_response)
722+
fn send_block_response(
723+
&mut self,
724+
block: Option<&NakamotoBlock>,
725+
block_response: BlockResponse,
726+
) {
727+
self.impl_send_block_response(block, block_response)
708728
}
709729

710730
/// Handle signer state update message
@@ -834,8 +854,7 @@ impl Signer {
834854

835855
if let Some(block_response) = block_response {
836856
// We know proposal is invalid. Send rejection message, do not do further validation and do not store it.
837-
debug!("{self}: Broadcasting a block response to stacks node: {block_response:?}");
838-
self.send_block_response(block_response);
857+
self.send_block_response(Some(&block_info.block), block_response);
839858
} else {
840859
// Just in case check if the last block validation submission timed out.
841860
self.check_submitted_block_proposal();
@@ -889,19 +908,7 @@ impl Signer {
889908
return;
890909
};
891910

892-
// Submit a proposal response to the .signers contract for miners
893-
debug!("{self}: Broadcasting a block response to stacks node: {block_response:?}");
894-
895-
let accepted = matches!(block_response, BlockResponse::Accepted(..));
896-
if let Err(e) = self
897-
.stackerdb
898-
.send_message_with_retry::<SignerMessage>(block_response.into())
899-
{
900-
warn!("{self}: Failed to send block response to stacker-db: {e:?}");
901-
} else {
902-
crate::monitoring::actions::increment_block_responses_sent(accepted);
903-
crate::monitoring::actions::record_block_response_latency(&block_info.block);
904-
}
911+
self.impl_send_block_response(Some(&block_info.block), block_response);
905912
}
906913

907914
/// Handle block response messages from a signer
@@ -1037,21 +1044,7 @@ impl Signer {
10371044
warn!("{self}: Failed to mark block as locally rejected: {e:?}");
10381045
}
10391046
};
1040-
debug!("{self}: Broadcasting a block response to stacks node: {block_response:?}");
1041-
let res = self
1042-
.stackerdb
1043-
.send_message_with_retry::<SignerMessage>(block_response.into());
1044-
1045-
crate::monitoring::actions::record_block_response_latency(&block_info.block);
1046-
1047-
match res {
1048-
Err(e) => warn!("{self}: Failed to send block rejection to stacker-db: {e:?}"),
1049-
Ok(ack) if !ack.accepted => warn!(
1050-
"{self}: Block rejection not accepted by stacker-db: {:?}",
1051-
ack.reason
1052-
),
1053-
Ok(_) => debug!("{self}: Block rejection accepted by stacker-db"),
1054-
}
1047+
self.impl_send_block_response(Some(&block_info.block), block_response);
10551048
self.signer_db
10561049
.insert_block(&block_info)
10571050
.unwrap_or_else(|e| self.handle_insert_block_error(e));
@@ -1158,30 +1151,12 @@ impl Signer {
11581151
.unwrap_or_else(|e| warn!("{self}: Failed to remove pending block validation: {e:?}"));
11591152

11601153
if let Some(response) = block_response {
1161-
// Submit a proposal response to the .signers contract for miners
1162-
info!(
1163-
"{self}: Broadcasting a block response to stacks node: {response:?}";
1164-
);
1165-
let accepted = matches!(response, BlockResponse::Accepted(..));
1166-
match self
1167-
.stackerdb
1168-
.send_message_with_retry::<SignerMessage>(response.into())
1169-
{
1170-
Ok(_) => {
1171-
crate::monitoring::actions::increment_block_responses_sent(accepted);
1172-
if let Ok(Some(block_info)) = self
1173-
.signer_db
1174-
.block_lookup(&block_validate_response.signer_signature_hash())
1175-
{
1176-
crate::monitoring::actions::record_block_response_latency(
1177-
&block_info.block,
1178-
);
1179-
}
1180-
}
1181-
Err(e) => {
1182-
warn!("{self}: Failed to send block rejection to stacker-db: {e:?}",);
1183-
}
1184-
}
1154+
let block = self
1155+
.signer_db
1156+
.block_lookup(&signer_sig_hash)
1157+
.unwrap_or_default()
1158+
.map(|info| info.block);
1159+
self.impl_send_block_response(block.as_ref(), response);
11851160
};
11861161

11871162
// Check if there is a pending block validation that we need to submit to the node
@@ -1274,21 +1249,7 @@ impl Signer {
12741249
warn!("{self}: Failed to mark block as locally rejected: {e:?}");
12751250
}
12761251
};
1277-
debug!("{self}: Broadcasting a block response to stacks node: {rejection:?}");
1278-
let res = self
1279-
.stackerdb
1280-
.send_message_with_retry::<SignerMessage>(rejection.into());
1281-
1282-
crate::monitoring::actions::record_block_response_latency(&block_info.block);
1283-
1284-
match res {
1285-
Err(e) => warn!("{self}: Failed to send block rejection to stacker-db: {e:?}"),
1286-
Ok(ack) if !ack.accepted => warn!(
1287-
"{self}: Block rejection not accepted by stacker-db: {:?}",
1288-
ack.reason
1289-
),
1290-
Ok(_) => debug!("{self}: Block rejection accepted by stacker-db"),
1291-
}
1252+
self.impl_send_block_response(Some(&block_info.block), rejection);
12921253

12931254
self.signer_db
12941255
.insert_block(&block_info)

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,13 +1264,25 @@ impl<'a> SortitionHandleTx<'a> {
12641264
burn_header_hash: &BurnchainHeaderHash,
12651265
chain_tip: &SortitionId,
12661266
) -> Result<Option<BlockSnapshot>, db_error> {
1267+
let Some(sortition_id) = self.get_sortition_id_for_bhh(burn_header_hash, chain_tip)? else {
1268+
return Ok(None);
1269+
};
1270+
1271+
SortitionDB::get_block_snapshot(self.tx(), &sortition_id)
1272+
}
1273+
1274+
fn get_sortition_id_for_bhh(
1275+
&mut self,
1276+
burn_header_hash: &BurnchainHeaderHash,
1277+
chain_tip: &SortitionId,
1278+
) -> Result<Option<SortitionId>, db_error> {
12671279
let sortition_identifier_key = db_keys::sortition_id_for_bhh(burn_header_hash);
12681280
let sortition_id = match self.get_indexed(chain_tip, &sortition_identifier_key)? {
12691281
None => return Ok(None),
12701282
Some(x) => SortitionId::from_hex(&x).expect("FATAL: bad Sortition ID stored in DB"),
12711283
};
12721284

1273-
SortitionDB::get_block_snapshot(self.tx(), &sortition_id)
1285+
Ok(Some(sortition_id))
12741286
}
12751287

12761288
/// Get a leader key at a specific location in the burn chain's fork history, given the
@@ -6528,25 +6540,25 @@ impl SortitionHandleTx<'_> {
65286540
}
65296541

65306542
// must be an ancestor of this tip, or must be this tip
6531-
if let Some(sn) =
6532-
self.get_block_snapshot(&arrival_sn.burn_header_hash, &parent_tip.sortition_id)?
6543+
if let Some(sortition_id) = self
6544+
.get_sortition_id_for_bhh(&arrival_sn.burn_header_hash, &parent_tip.sortition_id)?
65336545
{
6534-
if !sn.pox_valid || sn != arrival_sn {
6546+
if sortition_id != arrival_sn.sortition_id {
65356547
continue;
65366548
}
65376549

65386550
debug!(
65396551
"New Stacks anchored block arrived: block {}/{} ({}) ari={} tip={}",
6540-
&sn.consensus_hash,
6541-
&sn.winning_stacks_block_hash,
6542-
sn.stacks_block_height,
6552+
&arrival_sn.consensus_hash,
6553+
&arrival_sn.winning_stacks_block_hash,
6554+
arrival_sn.stacks_block_height,
65436555
ari,
65446556
&parent_tip.burn_header_hash
65456557
);
65466558
new_block_arrivals.push((
6547-
sn.consensus_hash,
6548-
sn.winning_stacks_block_hash,
6549-
sn.stacks_block_height,
6559+
arrival_sn.consensus_hash,
6560+
arrival_sn.winning_stacks_block_hash,
6561+
arrival_sn.stacks_block_height,
65506562
));
65516563
} else {
65526564
// this block did not arrive on an ancestor block

0 commit comments

Comments
 (0)