Skip to content
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

fix: Fix n2n babbage header parsing #355

Merged
merged 1 commit into from
Jul 4, 2022
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: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/sources/n2n/headers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pallas::{
codec::minicbor::decode,
ledger::primitives::{alonzo, byron, ToHash},
ledger::primitives::{alonzo, babbage, byron, ToHash},
network::miniprotocols::{chainsync::HeaderContent, Point},
};

Expand All @@ -11,6 +11,7 @@ pub enum MultiEraHeader {
ByronBoundary(byron::EbbHead),
Byron(byron::BlockHead),
AlonzoCompatible(alonzo::Header),
Babbage(babbage::Header),
}

impl TryFrom<HeaderContent> for MultiEraHeader {
Expand All @@ -28,10 +29,17 @@ impl TryFrom<HeaderContent> for MultiEraHeader {
Ok(MultiEraHeader::Byron(header))
}
},
_ => {
1 | 2 | 3 | 4 => {
let header = decode(&value.cbor)?;
Ok(MultiEraHeader::AlonzoCompatible(header))
}
5 => {
let header = decode(&value.cbor)?;
Ok(MultiEraHeader::Babbage(header))
}
x => {
return Err(format!("This version of Oura can't handle era: {}", x).into());
}
}
}
}
Expand All @@ -53,6 +61,10 @@ impl MultiEraHeader {
let hash = x.to_hash();
Ok(Point::Specific(x.header_body.slot, hash.to_vec()))
}
MultiEraHeader::Babbage(x) => {
let hash = x.to_hash();
Ok(Point::Specific(x.header_body.slot, hash.to_vec()))
}
}
}
}