Skip to content

Commit 58cab7d

Browse files
authored
Merge pull request #6027 from jferrant/fix/reconsider-invalid-parent-block-proposals
Update ValidateRejectCode from InvalidBlock to UnknownParent where appropriate and add additional reject codes
2 parents 9c4a84b + aaabb90 commit 58cab7d

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added new `ValidateRejectCode` values to the `/v3/block_proposal` endpoint
13+
1014
### Changed
1115

1216
- Reduce the default `block_rejection_timeout_steps` configuration so that miners will retry faster when blocks fail to reach 70% approved or 30% rejected.

stackslib/src/net/api/postblock_proposal.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ define_u8_enum![ValidateRejectCode {
9898
UnknownParent = 4,
9999
NonCanonicalTenure = 5,
100100
NoSuchTenure = 6,
101-
InvalidTransactionReplay = 7
101+
InvalidTransactionReplay = 7,
102+
InvalidParentBlock = 8,
103+
InvalidTimestamp = 9,
104+
NetworkChainMismatch = 10
102105
}];
103106

104107
pub static TOO_MANY_REQUESTS_STATUS: u16 = 429;
@@ -300,7 +303,7 @@ impl NakamotoBlockProposal {
300303
"highest_header.height" => highest_header.anchored_header.height(),
301304
);
302305
return Err(BlockValidateRejectReason {
303-
reason_code: ValidateRejectCode::InvalidBlock,
306+
reason_code: ValidateRejectCode::InvalidParentBlock,
304307
reason: "Block is not higher than the highest block in its tenure".into(),
305308
});
306309
}
@@ -423,7 +426,7 @@ impl NakamotoBlockProposal {
423426
"received_mainnet" => mainnet,
424427
);
425428
return Err(BlockValidateRejectReason {
426-
reason_code: ValidateRejectCode::InvalidBlock,
429+
reason_code: ValidateRejectCode::NetworkChainMismatch,
427430
reason: "Wrong network/chain_id".into(),
428431
});
429432
}
@@ -446,8 +449,8 @@ impl NakamotoBlockProposal {
446449
&self.block.header.parent_block_id,
447450
)?
448451
.ok_or_else(|| BlockValidateRejectReason {
449-
reason_code: ValidateRejectCode::InvalidBlock,
450-
reason: "Invalid parent block".into(),
452+
reason_code: ValidateRejectCode::UnknownParent,
453+
reason: "Unknown parent block".into(),
451454
})?;
452455

453456
let burn_view_consensus_hash =
@@ -512,7 +515,7 @@ impl NakamotoBlockProposal {
512515
"parent_block_timestamp" => parent_nakamoto_header.timestamp,
513516
);
514517
return Err(BlockValidateRejectReason {
515-
reason_code: ValidateRejectCode::InvalidBlock,
518+
reason_code: ValidateRejectCode::InvalidTimestamp,
516519
reason: "Block timestamp is not greater than parent block".into(),
517520
});
518521
}
@@ -525,7 +528,7 @@ impl NakamotoBlockProposal {
525528
"current_time" => get_epoch_time_secs(),
526529
);
527530
return Err(BlockValidateRejectReason {
528-
reason_code: ValidateRejectCode::InvalidBlock,
531+
reason_code: ValidateRejectCode::InvalidTimestamp,
529532
reason: "Block timestamp is too far into the future".into(),
530533
});
531534
}

stackslib/src/net/api/tests/postblock_proposal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ fn test_try_make_response() {
456456
reason,
457457
..
458458
}) => {
459-
assert_eq!(reason_code, ValidateRejectCode::InvalidBlock);
459+
assert_eq!(reason_code, ValidateRejectCode::InvalidTimestamp);
460460
assert_eq!(reason, "Block timestamp is not greater than parent block");
461461
}
462462
}
@@ -469,7 +469,7 @@ fn test_try_make_response() {
469469
reason,
470470
..
471471
}) => {
472-
assert_eq!(reason_code, ValidateRejectCode::InvalidBlock);
472+
assert_eq!(reason_code, ValidateRejectCode::InvalidTimestamp);
473473
assert_eq!(reason, "Block timestamp is too far into the future");
474474
}
475475
}

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3135,7 +3135,7 @@ fn block_proposal_api_endpoint() {
31353135
sign(&p)
31363136
},
31373137
HTTP_ACCEPTED,
3138-
Some(Err(ValidateRejectCode::InvalidBlock)),
3138+
Some(Err(ValidateRejectCode::NetworkChainMismatch)),
31393139
),
31403140
(
31413141
"Invalid `miner_signature`",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ fn block_proposal_rejection() {
15651565
signer_test.wait_for_validate_reject_response(short_timeout, block_signer_signature_hash_2);
15661566
assert!(matches!(
15671567
reject.reason_code,
1568-
ValidateRejectCode::InvalidBlock
1568+
ValidateRejectCode::UnknownParent
15691569
));
15701570

15711571
let start_polling = Instant::now();
@@ -1595,7 +1595,7 @@ fn block_proposal_rejection() {
15951595
found_signer_signature_hash_2 = true;
15961596
assert!(matches!(
15971597
reason_code,
1598-
RejectCode::ValidationFailed(ValidateRejectCode::InvalidBlock)
1598+
RejectCode::ValidationFailed(ValidateRejectCode::UnknownParent)
15991599
));
16001600
} else {
16011601
continue;

0 commit comments

Comments
 (0)