Skip to content

Commit 6c58b72

Browse files
committed
added RejectCode::ReorgNotAllowed
1 parent d235b8c commit 6c58b72

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

libsigner/src/v0/messages.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,9 @@ RejectCodeTypePrefix {
539539
/// The block was rejected due to a mismatch with expected sortition view
540540
SortitionViewMismatch = 4,
541541
/// The block was rejected due to a testing directive
542-
TestingDirective = 5
542+
TestingDirective = 5,
543+
/// The block was rejected due to an invalid reorg attempt
544+
ReorgNotAllowed = 6
543545
});
544546

545547
impl TryFrom<u8> for RejectCodeTypePrefix {
@@ -560,6 +562,7 @@ impl From<&RejectCode> for RejectCodeTypePrefix {
560562
RejectCode::NoSortitionView => RejectCodeTypePrefix::NoSortitionView,
561563
RejectCode::SortitionViewMismatch => RejectCodeTypePrefix::SortitionViewMismatch,
562564
RejectCode::TestingDirective => RejectCodeTypePrefix::TestingDirective,
565+
RejectCode::ReorgNotAllowed => RejectCodeTypePrefix::ReorgNotAllowed,
563566
}
564567
}
565568
}
@@ -602,6 +605,8 @@ pub enum RejectCode {
602605
SortitionViewMismatch,
603606
/// The block was rejected due to a testing directive
604607
TestingDirective,
608+
/// The block was rejected due to an invalid reorg attempt
609+
ReorgNotAllowed,
605610
}
606611

607612
impl From<&RejectReason> for RejectCode {
@@ -615,6 +620,7 @@ impl From<&RejectReason> for RejectCode {
615620
RejectReason::RejectedInPriorRound => RejectCode::RejectedInPriorRound,
616621
RejectReason::SortitionViewMismatch => RejectCode::SortitionViewMismatch,
617622
RejectReason::TestingDirective => RejectCode::TestingDirective,
623+
RejectReason::ReorgNotAllowed => RejectCode::ReorgNotAllowed,
618624
// Newer reject reasons were expanded from SortitionViewMismatch
619625
_ => RejectCode::SortitionViewMismatch,
620626
}
@@ -761,6 +767,7 @@ impl From<&RejectCode> for RejectReason {
761767
RejectCode::NoSortitionView => RejectReason::NoSortitionView,
762768
RejectCode::SortitionViewMismatch => RejectReason::SortitionViewMismatch,
763769
RejectCode::TestingDirective => RejectReason::TestingDirective,
770+
RejectCode::ReorgNotAllowed => RejectReason::ReorgNotAllowed,
764771
}
765772
}
766773
}
@@ -1271,7 +1278,8 @@ impl StacksMessageCodec for RejectCode {
12711278
| RejectCode::RejectedInPriorRound
12721279
| RejectCode::NoSortitionView
12731280
| RejectCode::SortitionViewMismatch
1274-
| RejectCode::TestingDirective => {
1281+
| RejectCode::TestingDirective
1282+
| RejectCode::ReorgNotAllowed => {
12751283
// No additional data to serialize / deserialize
12761284
}
12771285
};
@@ -1297,6 +1305,7 @@ impl StacksMessageCodec for RejectCode {
12971305
RejectCodeTypePrefix::NoSortitionView => RejectCode::NoSortitionView,
12981306
RejectCodeTypePrefix::SortitionViewMismatch => RejectCode::SortitionViewMismatch,
12991307
RejectCodeTypePrefix::TestingDirective => RejectCode::TestingDirective,
1308+
RejectCodeTypePrefix::ReorgNotAllowed => RejectCode::ReorgNotAllowed,
13001309
};
13011310
Ok(code)
13021311
}
@@ -1388,6 +1397,9 @@ impl std::fmt::Display for RejectCode {
13881397
RejectCode::TestingDirective => {
13891398
write!(f, "The block was rejected due to a testing directive.")
13901399
}
1400+
RejectCode::ReorgNotAllowed => {
1401+
write!(f, "The block was rejected due to an invalid reorg attempt.")
1402+
}
13911403
}
13921404
}
13931405
}

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,40 @@ fn wait_for_block_global_rejection(
10631063
})
10641064
}
10651065

1066+
/// Waits for >30% of num_signers block rejection to be observed in the test_observer stackerdb chunks for a block
1067+
/// with the provided signer signature hash and the specified reject_code
1068+
fn wait_for_block_global_rejection_with_reject_code(
1069+
timeout_secs: u64,
1070+
block_signer_signature_hash: Sha512Trunc256Sum,
1071+
num_signers: usize,
1072+
reject_code: RejectCode,
1073+
) -> Result<(), String> {
1074+
let mut found_rejections = HashSet::new();
1075+
wait_for(timeout_secs, || {
1076+
let chunks = test_observer::get_stackerdb_chunks();
1077+
for chunk in chunks.into_iter().flat_map(|chunk| chunk.modified_slots) {
1078+
let Ok(message) = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
1079+
else {
1080+
continue;
1081+
};
1082+
if let SignerMessage::BlockResponse(BlockResponse::Rejected(BlockRejection {
1083+
signer_signature_hash,
1084+
signature,
1085+
reason_code,
1086+
..
1087+
})) = message
1088+
{
1089+
if signer_signature_hash == block_signer_signature_hash
1090+
&& reason_code == reject_code
1091+
{
1092+
found_rejections.insert(signature);
1093+
}
1094+
}
1095+
}
1096+
Ok(found_rejections.len() >= num_signers * 3 / 10)
1097+
})
1098+
}
1099+
10661100
/// Waits for the provided number of block rejections to be observed in the test_observer stackerdb chunks for a block
10671101
/// with the provided signer signature hash
10681102
fn wait_for_block_rejections(
@@ -10282,12 +10316,13 @@ fn disallow_reorg_within_first_proposal_burn_block_timing_secs_but_more_than_one
1028210316
let proposed_block = wait_for_block_proposal(30, block_n_height + 1, &miner_pk_1)
1028310317
.expect("Timed out waiting for block proposal");
1028410318
// check it has been rejected
10285-
wait_for_block_global_rejection(
10319+
wait_for_block_global_rejection_with_reject_code(
1028610320
30,
1028710321
proposed_block.header.signer_signature_hash(),
1028810322
num_signers,
10323+
RejectCode::ReorgNotAllowed,
1028910324
)
10290-
.expect("Timed out waiting for a block proposal to be rejected");
10325+
.expect("Timed out waiting for a block proposal to be rejected due to invalid reorg");
1029110326

1029210327
// check only 1 block from miner1 has been added after the epoch3 boot
1029310328
let miner1_blocks_after_boot_to_epoch3 = get_nakamoto_headers(&conf_1)

0 commit comments

Comments
 (0)