Skip to content

Commit

Permalink
chore: Update Pallas to version 0.5.0-alpha.3 (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored and rvcas committed Feb 18, 2022
1 parent 8092adb commit 69087e5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>"]


[dependencies]
pallas = "0.5.0-alpha.2"
pallas = "0.5.0-alpha.3"
# pallas = { path = "../pallas/pallas" }
hex = "0.4.3"
net2 = "0.2.37"
Expand Down
26 changes: 14 additions & 12 deletions src/sources/n2c/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Error;
#[derive(Debug)]
pub(crate) enum MultiEraBlock {
Byron(Box<byron::Block>),
Shelley(Box<alonzo::Block>),
AlonzoCompatible(Box<alonzo::Block>),
}

impl TryFrom<BlockContent> for MultiEraBlock {
Expand All @@ -19,16 +19,18 @@ impl TryFrom<BlockContent> for MultiEraBlock {
fn try_from(value: BlockContent) -> Result<Self, Self::Error> {
let bytes = value.deref();

match probing::probe_block_cbor(bytes) {
probing::BlockInference::Byron => {
let block = minicbor::decode(bytes)?;
Ok(MultiEraBlock::Byron(Box::new(block)))
}
probing::BlockInference::Shelley => {
let alonzo::BlockWrapper(_, block) = minicbor::decode(bytes)?;
Ok(MultiEraBlock::Shelley(Box::new(block)))
}
probing::BlockInference::Inconclusive => {
match probing::probe_block_cbor_era(bytes) {
probing::Outcome::Matched(era) => match era {
pallas::ledger::primitives::Era::Byron => {
let block = minicbor::decode(bytes)?;
Ok(MultiEraBlock::Byron(Box::new(block)))
}
_ => {
let alonzo::BlockWrapper(_, block) = minicbor::decode(bytes)?;
Ok(MultiEraBlock::AlonzoCompatible(Box::new(block)))
}
},
probing::Outcome::Inconclusive => {
log::error!("CBOR hex for debubbing: {}", hex::encode(bytes));
Err("can't infer primitive block from cbor, inconslusive probing".into())
}
Expand All @@ -51,7 +53,7 @@ impl MultiEraBlock {
Ok(Point(slot, hash.to_vec()))
}
},
MultiEraBlock::Shelley(x) => {
MultiEraBlock::AlonzoCompatible(x) => {
let hash = alonzo::crypto::hash_block_header(&x.header);
Ok(Point(x.header.header_body.slot, hash.to_vec()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/sources/n2c/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl chainsync::Observer<chainsync::BlockContent> for ChainObserver {
MultiEraBlock::Byron(model) => {
self.event_writer.crawl_byron_with_cbor(&model, &cbor)?
}
MultiEraBlock::Shelley(model) => {
MultiEraBlock::AlonzoCompatible(model) => {
self.event_writer.crawl_shelley_with_cbor(&model, &cbor)?
}
};
Expand Down
20 changes: 10 additions & 10 deletions src/sources/n2n/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ use crate::Error;
pub enum MultiEraHeader {
ByronBoundary(byron::EbbHead),
Byron(byron::BlockHead),
Shelley(alonzo::Header),
AlonzoCompatible(alonzo::Header),
}

impl TryFrom<HeaderContent> for MultiEraHeader {
type Error = Error;

fn try_from(value: HeaderContent) -> Result<Self, Self::Error> {
match value {
HeaderContent::Byron(variant, _, bytes) => match variant {
0 => {
let header = minicbor::decode(&bytes)?;
match value.variant {
0 => match value.byron_prefix {
Some((0, _)) => {
let header = minicbor::decode(&value.cbor)?;
Ok(MultiEraHeader::ByronBoundary(header))
}
_ => {
let header = minicbor::decode(&bytes)?;
let header = minicbor::decode(&value.cbor)?;
Ok(MultiEraHeader::Byron(header))
}
},
HeaderContent::Shelley(bytes) => {
let header = minicbor::decode(&bytes)?;
Ok(MultiEraHeader::Shelley(header))
_ => {
let header = minicbor::decode(&value.cbor)?;
Ok(MultiEraHeader::AlonzoCompatible(header))
}
}
}
Expand All @@ -48,7 +48,7 @@ impl MultiEraHeader {
let slot = x.consensus_data.0.to_abs_slot();
Ok(Point(slot, hash.to_vec()))
}
MultiEraHeader::Shelley(x) => {
MultiEraHeader::AlonzoCompatible(x) => {
let hash = alonzo::crypto::hash_block_header(x);
Ok(Point(x.header_body.slot, hash.to_vec()))
}
Expand Down
28 changes: 15 additions & 13 deletions src/sources/n2n/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

use pallas::{
ledger::primitives::probing,
ledger::primitives::{probing, Era},
network::{
miniprotocols::{blockfetch, chainsync, run_agent, Point},
multiplexer::Channel,
Expand All @@ -26,18 +26,20 @@ impl blockfetch::Observer for Block2EventMapper {
fn on_block_received(&self, body: Vec<u8>) -> Result<(), Error> {
let Self(writer) = self;

match probing::probe_block_cbor(&body) {
probing::BlockInference::Byron => {
writer
.crawl_from_byron_cbor(&body)
.ok_or_warn("error crawling block for events");
}
probing::BlockInference::Shelley => {
writer
.crawl_from_shelley_cbor(&body)
.ok_or_warn("error crawling block for events");
}
probing::BlockInference::Inconclusive => {
match probing::probe_block_cbor_era(&body) {
probing::Outcome::Matched(era) => match era {
Era::Byron => {
writer
.crawl_from_byron_cbor(&body)
.ok_or_warn("error crawling block for events");
}
_ => {
writer
.crawl_from_shelley_cbor(&body)
.ok_or_warn("error crawling block for events");
}
},
probing::Outcome::Inconclusive => {
log::error!("can't infer primitive block from cbor, inconslusive probing. CBOR hex for debubbing: {}", hex::encode(body));
}
}
Expand Down

0 comments on commit 69087e5

Please sign in to comment.