Skip to content

Commit 2ea875a

Browse files
authored
Merge pull request #5867 from stacks-network/fix/decoding-old-response
Fix: properly handle decoding older block responses
2 parents dcbc7f4 + fa9c411 commit 2ea875a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

libsigner/src/v0/messages.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,9 @@ impl StacksMessageCodec for RejectReason {
13301330
}
13311331

13321332
fn consensus_deserialize<R: Read>(fd: &mut R) -> Result<Self, CodecError> {
1333-
let type_prefix_byte = read_next::<u8, _>(fd)?;
1333+
let Ok(type_prefix_byte) = read_next::<u8, _>(fd) else {
1334+
return Ok(RejectReason::Unknown(RejectReasonPrefix::Unknown as u8));
1335+
};
13341336
let type_prefix = RejectReasonPrefix::from(type_prefix_byte);
13351337
let code = match type_prefix {
13361338
RejectReasonPrefix::ValidationFailed => RejectReason::ValidationFailed(
@@ -1963,4 +1965,20 @@ mod test {
19631965
assert_eq!(block_accepted.signature, block_accepted_old.signature);
19641966
assert_eq!(block_accepted.metadata, block_accepted_old.metadata);
19651967
}
1968+
1969+
#[test]
1970+
fn test_deserialize_old_block_response() {
1971+
// Fixture of an older version of a block response that has a tenure_extend_timestamp
1972+
// but _not_ a reject_reason.
1973+
let hex_str = "01006dc371d2313be71f93ac759f3302e5a0e4ff77dd0e73f13bb491936b5489d5390032208fc53bd0984c84abaac44ecd777e473e3e325066217e9d7314baa5cdfe1847363e1036f364b4bf7982f4d103079b17c19bf8a19904e822c2d62a5021c19700000036737461636b732d7369676e657220302e302e3120283a2c2072656c65617365206275696c642c206c696e7578205b7838365f36345d290200000008000000006751c76e";
1974+
let bytes = hex_bytes(hex_str).unwrap();
1975+
let block_response = read_next::<SignerMessage, _>(&mut &bytes[..]).unwrap();
1976+
let SignerMessage::BlockResponse(BlockResponse::Accepted(accepted)) = block_response else {
1977+
panic!("Expected BlockResponse::Accepted");
1978+
};
1979+
assert_eq!(
1980+
accepted.response_data.reject_reason,
1981+
RejectReason::Unknown(RejectReasonPrefix::Unknown as u8)
1982+
);
1983+
}
19661984
}

0 commit comments

Comments
 (0)