Skip to content

Commit

Permalink
fix: Decode block wrappers correctly (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jul 3, 2022
1 parent fa3281f commit 5748328
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/mapper/byron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::model::{BlockRecord, Era, EventData, TransactionRecord, TxInputRecord
use crate::{model::EventContext, Error};

use pallas::crypto::hash::Hash;
use pallas::ledger::primitives::{byron, Fragment, ToHash};
use pallas::ledger::primitives::{byron, ToHash};

impl EventWriter {
fn to_byron_input_record(&self, source: &byron::TxIn) -> Option<TxInputRecord> {
Expand Down Expand Up @@ -285,7 +285,7 @@ impl EventWriter {
/// Entry-point to start crawling a blocks for events. Meant to be used when
/// we haven't decoded the CBOR yet (for example, N2N).
pub fn crawl_from_byron_cbor(&self, cbor: &[u8]) -> Result<(), Error> {
let block = byron::MintedBlock::decode_fragment(cbor)?;
let (_, block): (u16, byron::MintedBlock) = pallas::codec::minicbor::decode(cbor)?;
self.crawl_byron_with_cbor(&block, cbor)
}

Expand All @@ -312,4 +312,13 @@ impl EventWriter {

Ok(())
}

/// Mapper entry-point for raw EBB cbor blocks
///
/// Entry-point to start crawling a blocks for events. Meant to be used when
/// we haven't decoded the CBOR yet (for example, N2N).
pub fn crawl_from_ebb_cbor(&self, cbor: &[u8]) -> Result<(), Error> {
let (_, block): (u16, byron::EbBlock) = pallas::codec::minicbor::decode(cbor)?;
self.crawl_ebb_with_cbor(&block, cbor)
}
}
4 changes: 2 additions & 2 deletions src/sources/n2c/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'b> CborHolder {
let block = match probe::block_era(&self.0) {
probe::Outcome::Matched(era) => match era {
Era::Byron => {
let block = decode(&self.0)?;
let (_, block): (u16, byron::MintedBlock) = decode(&self.0)?;
MultiEraBlock::Byron(Box::new(block))
}
Era::Shelley | Era::Allegra | Era::Mary | Era::Alonzo => {
Expand All @@ -34,7 +34,7 @@ impl<'b> CborHolder {
}
},
probe::Outcome::EpochBoundary => {
let block = decode(&self.0)?;
let (_, block): (u16, byron::EbBlock) = decode(&self.0)?;
MultiEraBlock::EpochBoundary(Box::new(block))
}
probe::Outcome::Inconclusive => {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/n2n/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl blockfetch::Observer for Block2EventMapper {
},
probe::Outcome::EpochBoundary => {
writer
.crawl_from_byron_cbor(&body)
.crawl_from_ebb_cbor(&body)
.ok_or_warn("error crawling block for events");
}
probe::Outcome::Inconclusive => {
Expand Down

0 comments on commit 5748328

Please sign in to comment.