Skip to content

Update ValidateRejectCode from InvalidBlock to UnknownParent where appropriate and add additional reject codes #6027

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

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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE

## [Unreleased]

### Added

- Added new `ValidateRejectCode` values to the `/v3/block_proposal` endpoint

### Changed

- Reduce the default `block_rejection_timeout_steps` configuration so that miners will retry faster when blocks fail to reach 70% approved or 30% rejected.
Expand Down
17 changes: 10 additions & 7 deletions stackslib/src/net/api/postblock_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ define_u8_enum![ValidateRejectCode {
UnknownParent = 4,
NonCanonicalTenure = 5,
NoSuchTenure = 6,
InvalidTransactionReplay = 7
InvalidTransactionReplay = 7,
InvalidParentBlock = 8,
InvalidTimestamp = 9,
NetworkChainMismatch = 10
}];

pub static TOO_MANY_REQUESTS_STATUS: u16 = 429;
Expand Down Expand Up @@ -300,7 +303,7 @@ impl NakamotoBlockProposal {
"highest_header.height" => highest_header.anchored_header.height(),
);
return Err(BlockValidateRejectReason {
reason_code: ValidateRejectCode::InvalidBlock,
reason_code: ValidateRejectCode::InvalidParentBlock,
reason: "Block is not higher than the highest block in its tenure".into(),
});
}
Expand Down Expand Up @@ -423,7 +426,7 @@ impl NakamotoBlockProposal {
"received_mainnet" => mainnet,
);
return Err(BlockValidateRejectReason {
reason_code: ValidateRejectCode::InvalidBlock,
reason_code: ValidateRejectCode::NetworkChainMismatch,
reason: "Wrong network/chain_id".into(),
});
}
Expand All @@ -446,8 +449,8 @@ impl NakamotoBlockProposal {
&self.block.header.parent_block_id,
)?
.ok_or_else(|| BlockValidateRejectReason {
reason_code: ValidateRejectCode::InvalidBlock,
reason: "Invalid parent block".into(),
reason_code: ValidateRejectCode::UnknownParent,
reason: "Unknown parent block".into(),
})?;

let burn_view_consensus_hash =
Expand Down Expand Up @@ -512,7 +515,7 @@ impl NakamotoBlockProposal {
"parent_block_timestamp" => parent_nakamoto_header.timestamp,
);
return Err(BlockValidateRejectReason {
reason_code: ValidateRejectCode::InvalidBlock,
reason_code: ValidateRejectCode::InvalidTimestamp,
reason: "Block timestamp is not greater than parent block".into(),
});
}
Expand All @@ -525,7 +528,7 @@ impl NakamotoBlockProposal {
"current_time" => get_epoch_time_secs(),
);
return Err(BlockValidateRejectReason {
reason_code: ValidateRejectCode::InvalidBlock,
reason_code: ValidateRejectCode::InvalidTimestamp,
reason: "Block timestamp is too far into the future".into(),
});
}
Expand Down
4 changes: 2 additions & 2 deletions stackslib/src/net/api/tests/postblock_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ fn test_try_make_response() {
reason,
..
}) => {
assert_eq!(reason_code, ValidateRejectCode::InvalidBlock);
assert_eq!(reason_code, ValidateRejectCode::InvalidTimestamp);
assert_eq!(reason, "Block timestamp is not greater than parent block");
}
}
Expand All @@ -469,7 +469,7 @@ fn test_try_make_response() {
reason,
..
}) => {
assert_eq!(reason_code, ValidateRejectCode::InvalidBlock);
assert_eq!(reason_code, ValidateRejectCode::InvalidTimestamp);
assert_eq!(reason, "Block timestamp is too far into the future");
}
}
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3135,7 +3135,7 @@ fn block_proposal_api_endpoint() {
sign(&p)
},
HTTP_ACCEPTED,
Some(Err(ValidateRejectCode::InvalidBlock)),
Some(Err(ValidateRejectCode::NetworkChainMismatch)),
),
(
"Invalid `miner_signature`",
Expand Down
4 changes: 2 additions & 2 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ fn block_proposal_rejection() {
signer_test.wait_for_validate_reject_response(short_timeout, block_signer_signature_hash_2);
assert!(matches!(
reject.reason_code,
ValidateRejectCode::InvalidBlock
ValidateRejectCode::UnknownParent
));

let start_polling = Instant::now();
Expand Down Expand Up @@ -1542,7 +1542,7 @@ fn block_proposal_rejection() {
found_signer_signature_hash_2 = true;
assert!(matches!(
reason_code,
RejectCode::ValidationFailed(ValidateRejectCode::InvalidBlock)
RejectCode::ValidationFailed(ValidateRejectCode::UnknownParent)
));
} else {
continue;
Expand Down
Loading