feat(traverse): Decode Conway block headers properly (#466)

This commit is contained in:
Andrew Westberg 2024-05-24 16:25:24 -04:00 committed by GitHub
parent 3a83c1fdad
commit f4fd2600f1
5 changed files with 31 additions and 31 deletions

View file

@ -78,7 +78,7 @@ async fn do_chainsync(
tracing::info!("epoch boundary"); tracing::info!("epoch boundary");
None None
} }
MultiEraHeader::AlonzoCompatible(_) | MultiEraHeader::Babbage(_) => { MultiEraHeader::ShelleyCompatible(_) | MultiEraHeader::BabbageCompatible(_) => {
if next_log.elapsed().as_secs() > 1 { if next_log.elapsed().as_secs() > 1 {
tracing::info!("chainsync block header: {}", number); tracing::info!("chainsync block header: {}", number);
next_log = Instant::now(); next_log = Instant::now();

View file

@ -2,7 +2,7 @@ use std::net::SocketAddr;
use std::path::Path; use std::path::Path;
use std::time::Duration; use std::time::Duration;
use thiserror::Error; use thiserror::Error;
use tracing::{debug, error, warn}; use tracing::{debug, error};
use tokio::net::{TcpListener, ToSocketAddrs}; use tokio::net::{TcpListener, ToSocketAddrs};
@ -67,7 +67,7 @@ impl KeepAliveLoop {
loop { loop {
interval.tick().await; interval.tick().await;
warn!("sending keepalive request"); debug!("sending keepalive request");
client client
.keepalive_roundtrip() .keepalive_roundtrip()

View file

@ -90,10 +90,10 @@ impl<'b> MultiEraBlock<'b> {
} }
MultiEraBlock::Byron(x) => MultiEraHeader::Byron(Cow::Borrowed(&x.header)), MultiEraBlock::Byron(x) => MultiEraHeader::Byron(Cow::Borrowed(&x.header)),
MultiEraBlock::AlonzoCompatible(x, _) => { MultiEraBlock::AlonzoCompatible(x, _) => {
MultiEraHeader::AlonzoCompatible(Cow::Borrowed(&x.header)) MultiEraHeader::ShelleyCompatible(Cow::Borrowed(&x.header))
} }
MultiEraBlock::Babbage(x) => MultiEraHeader::Babbage(Cow::Borrowed(&x.header)), MultiEraBlock::Babbage(x) => MultiEraHeader::BabbageCompatible(Cow::Borrowed(&x.header)),
MultiEraBlock::Conway(x) => MultiEraHeader::Babbage(Cow::Borrowed(&x.header)), MultiEraBlock::Conway(x) => MultiEraHeader::BabbageCompatible(Cow::Borrowed(&x.header)),
} }
} }

View file

@ -20,13 +20,13 @@ impl<'b> MultiEraHeader<'b> {
Ok(MultiEraHeader::Byron(Cow::Owned(header))) Ok(MultiEraHeader::Byron(Cow::Owned(header)))
} }
}, },
5 => { 1..=4 => {
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?; let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?;
Ok(MultiEraHeader::Babbage(Cow::Owned(header))) Ok(MultiEraHeader::ShelleyCompatible(Cow::Owned(header)))
} }
_ => { _ => {
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?; let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?;
Ok(MultiEraHeader::AlonzoCompatible(Cow::Owned(header))) Ok(MultiEraHeader::BabbageCompatible(Cow::Owned(header)))
} }
} }
} }
@ -34,8 +34,8 @@ impl<'b> MultiEraHeader<'b> {
pub fn cbor(&self) -> &'b [u8] { pub fn cbor(&self) -> &'b [u8] {
match self { match self {
MultiEraHeader::EpochBoundary(x) => x.raw_cbor(), MultiEraHeader::EpochBoundary(x) => x.raw_cbor(),
MultiEraHeader::AlonzoCompatible(x) => x.raw_cbor(), MultiEraHeader::ShelleyCompatible(x) => x.raw_cbor(),
MultiEraHeader::Babbage(x) => x.raw_cbor(), MultiEraHeader::BabbageCompatible(x) => x.raw_cbor(),
MultiEraHeader::Byron(x) => x.raw_cbor(), MultiEraHeader::Byron(x) => x.raw_cbor(),
} }
} }
@ -48,16 +48,16 @@ impl<'b> MultiEraHeader<'b> {
.first() .first()
.cloned() .cloned()
.unwrap_or_default(), .unwrap_or_default(),
MultiEraHeader::AlonzoCompatible(x) => x.header_body.block_number, MultiEraHeader::ShelleyCompatible(x) => x.header_body.block_number,
MultiEraHeader::Babbage(x) => x.header_body.block_number, MultiEraHeader::BabbageCompatible(x) => x.header_body.block_number,
MultiEraHeader::Byron(x) => x.consensus_data.2.first().cloned().unwrap_or_default(), MultiEraHeader::Byron(x) => x.consensus_data.2.first().cloned().unwrap_or_default(),
} }
} }
pub fn slot(&self) -> u64 { pub fn slot(&self) -> u64 {
match self { match self {
MultiEraHeader::AlonzoCompatible(x) => x.header_body.slot, MultiEraHeader::ShelleyCompatible(x) => x.header_body.slot,
MultiEraHeader::Babbage(x) => x.header_body.slot, MultiEraHeader::BabbageCompatible(x) => x.header_body.slot,
MultiEraHeader::EpochBoundary(x) => { MultiEraHeader::EpochBoundary(x) => {
let genesis = GenesisValues::default(); let genesis = GenesisValues::default();
genesis.relative_slot_to_absolute(x.consensus_data.epoch_id, 0) genesis.relative_slot_to_absolute(x.consensus_data.epoch_id, 0)
@ -72,16 +72,16 @@ impl<'b> MultiEraHeader<'b> {
pub fn hash(&self) -> Hash<32> { pub fn hash(&self) -> Hash<32> {
match self { match self {
MultiEraHeader::EpochBoundary(x) => x.original_hash(), MultiEraHeader::EpochBoundary(x) => x.original_hash(),
MultiEraHeader::AlonzoCompatible(x) => x.original_hash(), MultiEraHeader::ShelleyCompatible(x) => x.original_hash(),
MultiEraHeader::Babbage(x) => x.original_hash(), MultiEraHeader::BabbageCompatible(x) => x.original_hash(),
MultiEraHeader::Byron(x) => x.original_hash(), MultiEraHeader::Byron(x) => x.original_hash(),
} }
} }
pub fn previous_hash(&self) -> Option<Hash<32>> { pub fn previous_hash(&self) -> Option<Hash<32>> {
match self { match self {
MultiEraHeader::AlonzoCompatible(x) => x.header_body.prev_hash, MultiEraHeader::ShelleyCompatible(x) => x.header_body.prev_hash,
MultiEraHeader::Babbage(x) => x.header_body.prev_hash, MultiEraHeader::BabbageCompatible(x) => x.header_body.prev_hash,
MultiEraHeader::EpochBoundary(x) => Some(x.prev_block), MultiEraHeader::EpochBoundary(x) => Some(x.prev_block),
MultiEraHeader::Byron(x) => Some(x.prev_block), MultiEraHeader::Byron(x) => Some(x.prev_block),
} }
@ -89,8 +89,8 @@ impl<'b> MultiEraHeader<'b> {
pub fn vrf_vkey(&self) -> Option<&[u8]> { pub fn vrf_vkey(&self) -> Option<&[u8]> {
match self { match self {
MultiEraHeader::AlonzoCompatible(x) => Some(x.header_body.vrf_vkey.as_ref()), MultiEraHeader::ShelleyCompatible(x) => Some(x.header_body.vrf_vkey.as_ref()),
MultiEraHeader::Babbage(x) => Some(x.header_body.vrf_vkey.as_ref()), MultiEraHeader::BabbageCompatible(x) => Some(x.header_body.vrf_vkey.as_ref()),
MultiEraHeader::EpochBoundary(_) => None, MultiEraHeader::EpochBoundary(_) => None,
MultiEraHeader::Byron(_) => None, MultiEraHeader::Byron(_) => None,
} }
@ -98,8 +98,8 @@ impl<'b> MultiEraHeader<'b> {
pub fn issuer_vkey(&self) -> Option<&[u8]> { pub fn issuer_vkey(&self) -> Option<&[u8]> {
match self { match self {
MultiEraHeader::AlonzoCompatible(x) => Some(x.header_body.issuer_vkey.as_ref()), MultiEraHeader::ShelleyCompatible(x) => Some(x.header_body.issuer_vkey.as_ref()),
MultiEraHeader::Babbage(x) => Some(x.header_body.issuer_vkey.as_ref()), MultiEraHeader::BabbageCompatible(x) => Some(x.header_body.issuer_vkey.as_ref()),
MultiEraHeader::EpochBoundary(_) => None, MultiEraHeader::EpochBoundary(_) => None,
MultiEraHeader::Byron(_) => None, MultiEraHeader::Byron(_) => None,
} }
@ -108,8 +108,8 @@ impl<'b> MultiEraHeader<'b> {
pub fn leader_vrf_output(&self) -> Result<Vec<u8>, Error> { pub fn leader_vrf_output(&self) -> Result<Vec<u8>, Error> {
match self { match self {
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Era::Byron)), MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Era::Byron)),
MultiEraHeader::AlonzoCompatible(x) => Ok(x.header_body.leader_vrf.0.to_vec()), MultiEraHeader::ShelleyCompatible(x) => Ok(x.header_body.leader_vrf.0.to_vec()),
MultiEraHeader::Babbage(x) => { MultiEraHeader::BabbageCompatible(x) => {
let mut leader_tagged_vrf: Vec<u8> = vec![0x4C_u8]; /* "L" */ let mut leader_tagged_vrf: Vec<u8> = vec![0x4C_u8]; /* "L" */
leader_tagged_vrf.extend(&*x.header_body.vrf_result.0); leader_tagged_vrf.extend(&*x.header_body.vrf_result.0);
Ok(Hasher::<256>::hash(&leader_tagged_vrf).to_vec()) Ok(Hasher::<256>::hash(&leader_tagged_vrf).to_vec())
@ -121,8 +121,8 @@ impl<'b> MultiEraHeader<'b> {
pub fn nonce_vrf_output(&self) -> Result<Vec<u8>, Error> { pub fn nonce_vrf_output(&self) -> Result<Vec<u8>, Error> {
match self { match self {
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Era::Byron)), MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Era::Byron)),
MultiEraHeader::AlonzoCompatible(x) => Ok(x.header_body.nonce_vrf.0.to_vec()), MultiEraHeader::ShelleyCompatible(x) => Ok(x.header_body.nonce_vrf.0.to_vec()),
MultiEraHeader::Babbage(x) => { MultiEraHeader::BabbageCompatible(x) => {
let mut nonce_tagged_vrf: Vec<u8> = vec![0x4E_u8]; /* "N" */ let mut nonce_tagged_vrf: Vec<u8> = vec![0x4E_u8]; /* "N" */
nonce_tagged_vrf.extend(&*x.header_body.vrf_result.0); nonce_tagged_vrf.extend(&*x.header_body.vrf_result.0);
Ok(Hasher::<256>::hash(&nonce_tagged_vrf).to_vec()) Ok(Hasher::<256>::hash(&nonce_tagged_vrf).to_vec())
@ -147,14 +147,14 @@ impl<'b> MultiEraHeader<'b> {
pub fn as_alonzo(&self) -> Option<&alonzo::Header> { pub fn as_alonzo(&self) -> Option<&alonzo::Header> {
match self { match self {
MultiEraHeader::AlonzoCompatible(x) => Some(x.deref().deref()), MultiEraHeader::ShelleyCompatible(x) => Some(x.deref().deref()),
_ => None, _ => None,
} }
} }
pub fn as_babbage(&self) -> Option<&babbage::Header> { pub fn as_babbage(&self) -> Option<&babbage::Header> {
match self { match self {
MultiEraHeader::Babbage(x) => Some(x.deref().deref()), MultiEraHeader::BabbageCompatible(x) => Some(x.deref().deref()),
_ => None, _ => None,
} }
} }

View file

@ -63,8 +63,8 @@ pub enum Feature {
#[derive(Debug)] #[derive(Debug)]
pub enum MultiEraHeader<'b> { pub enum MultiEraHeader<'b> {
EpochBoundary(Cow<'b, KeepRaw<'b, byron::EbbHead>>), EpochBoundary(Cow<'b, KeepRaw<'b, byron::EbbHead>>),
AlonzoCompatible(Cow<'b, KeepRaw<'b, alonzo::Header>>), ShelleyCompatible(Cow<'b, KeepRaw<'b, alonzo::Header>>),
Babbage(Cow<'b, KeepRaw<'b, babbage::Header>>), BabbageCompatible(Cow<'b, KeepRaw<'b, babbage::Header>>),
Byron(Cow<'b, KeepRaw<'b, byron::BlockHead>>), Byron(Cow<'b, KeepRaw<'b, byron::BlockHead>>),
} }