Skip to content

Commit

Permalink
fix(primitives): Handle alonzo headers without prev-hash (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Aug 6, 2022
1 parent 3e8314e commit 22b7467
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
25 changes: 23 additions & 2 deletions pallas-primitives/src/alonzo/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct HeaderBody {
pub slot: u64,

#[n(2)]
pub prev_hash: Hash<32>,
pub prev_hash: Option<Hash<32>>,

#[n(3)]
pub issuer_vkey: ByteVec,
Expand Down Expand Up @@ -1395,7 +1395,7 @@ pub struct MintedTx<'b> {
mod tests {
use pallas_codec::minicbor::{self, to_vec};

use super::MintedBlock;
use super::{Header, MintedBlock};

type BlockWrapper<'b> = (u16, MintedBlock<'b>);

Expand Down Expand Up @@ -1458,4 +1458,25 @@ mod tests {
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
}
}

#[test]
fn header_isomorphic_decoding_encoding() {
let test_headers = vec![
// peculiar alonzo header used as origin for a vasil devnet
include_str!("../../../test_data/alonzo26.header"),
];

for (idx, header_str) in test_headers.iter().enumerate() {
println!("decoding test header {}", idx + 1);
let bytes = hex::decode(header_str).expect(&format!("bad header file {}", idx));

let header: Header = minicbor::decode(&bytes[..])
.expect(&format!("error decoding cbor for file {}", idx));

let bytes2 =
to_vec(header).expect(&format!("error encoding header cbor for file {}", idx));

assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
}
}
}
2 changes: 1 addition & 1 deletion pallas-primitives/src/babbage/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct HeaderBody {
pub slot: u64,

#[n(2)]
pub prev_hash: Hash<32>,
pub prev_hash: Option<Hash<32>>,

#[n(3)]
pub issuer_vkey: ByteVec,
Expand Down
1 change: 1 addition & 0 deletions test_data/alonzo26.header
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
828f0000f658206907a24fc62affc690ae4c61044d4874c7c013333a5e94d4669a69dba7a0201f582029b2880af81ef578e7506bd7e840db694b08647dc803ee99b25ae9dd3c4e221082584057768126fd510b5ebf4555725cc04cb8d582c865d41c52aa26fc78583a384820de2d561dc864650a5d70f476eeaaee1472ed6d17cde3d40bbba835cbc3726acf58506b77911a16a65a8873c86dafa4017227bbcc56b7ddbee2a12d28366f2b9e6aa0212591d9a47d71cd82e6749027a69b66655b2cedb8277ead6573db8e4c0d627429f6bc56c5be2a8332854edb1ed35d00825840644696bd766ee07a357559282ffa3001b70115a78c4f20a011a611a4a2b23621039f462913c0deb95e50d3652b1897f06012cd42c1082f213b13e13e547d08b15850bc20d89f10c103836d264284e35b8affc6defc7cfece3105b9b9e5e63025bada42272ea8e43ab65a9371175566e51fed8a3adb803426e5f8a896bbb93937e5f2562df4b144d3eef57d8eb364bd77250b04582029571d16f081709b3c48651860077bebf9340abb3fc7133443c54f1f5a5edcf1582012963cf7b37ed0cbcd39f8d45c3bc7911137be765944daf77288e369dfaf3adb00005840e2e734e33cc23cd86a11180b9f6e71eecdfef519ec0b067f0b2703a2dc4edafb652c77544c7f383e0f3c8355c7cbbefe35933c6ffa7aedb7861fee5065793a0707025901c029fbfaadbf4656c60ed5e1a772b4879cf4fb04b87c375ef9681849faec7766b7a11b580541945aecaeeb84e27afcf1f64e2dc7d6299ee4cc2548be0450ae060ddef15249e0ec1779047bfc7483b8422dd3275bb48aa6a187dc8d75b07e727628423165c40dd6a995aa4378f82802aace6cd008cb710ea11f614d4818eb5075f51f74c2310ab48176f2aa1adcc1dbef0562b944ab809b6fa1380133ab38776e52a34ff3909c05bb8b3ae4118262f430679d0d58d0323eef159407f3a430c4baa9f6cd78fbab647abfde4c01a313389cfe6cd6bf8634142fe81af6c638c7dc77d677a9894bb6f444815b4aa6c2a24da64b702f46e58ce8fa93b0061fa2f412ba375831607fb315f6d7823b64e8af135c666d54315b5977484494eb97db70da0398e93494988cb7b97d679cac4ccce6bd5b22e3b687fbc62e613aa4cdb2e1bea64715e7da5c1c8c839d629e07274bca48736f1d97fcf29eda46c4a8aef14f84fb7361ae32324a562f79070eeee0794c1751da919829971797b2683007c9bba4a9903fc60eed1cff1cd755ee98b0099db8aebbec26a3ff918f6730dcfbe5f24de6edcd3aeff3b2f62a14c01d9a2a33e232cffc95f26abb20e6bb9fc461a176adca50

0 comments on commit 22b7467

Please sign in to comment.