feat(traverse): Decode Conway block headers properly (#466)
This commit is contained in:
parent
69de222dbe
commit
0c36f3803e
5 changed files with 31 additions and 31 deletions
|
|
@ -78,7 +78,7 @@ async fn do_chainsync(
|
|||
tracing::info!("epoch boundary");
|
||||
None
|
||||
}
|
||||
MultiEraHeader::AlonzoCompatible(_) | MultiEraHeader::Babbage(_) => {
|
||||
MultiEraHeader::ShelleyCompatible(_) | MultiEraHeader::BabbageCompatible(_) => {
|
||||
if next_log.elapsed().as_secs() > 1 {
|
||||
tracing::info!("chainsync block header: {}", number);
|
||||
next_log = Instant::now();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::net::SocketAddr;
|
|||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error;
|
||||
use tracing::{debug, error, warn};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use tokio::net::{TcpListener, ToSocketAddrs};
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ impl KeepAliveLoop {
|
|||
|
||||
loop {
|
||||
interval.tick().await;
|
||||
warn!("sending keepalive request");
|
||||
debug!("sending keepalive request");
|
||||
|
||||
client
|
||||
.keepalive_roundtrip()
|
||||
|
|
|
|||
|
|
@ -90,10 +90,10 @@ impl<'b> MultiEraBlock<'b> {
|
|||
}
|
||||
MultiEraBlock::Byron(x) => MultiEraHeader::Byron(Cow::Borrowed(&x.header)),
|
||||
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::Conway(x) => MultiEraHeader::Babbage(Cow::Borrowed(&x.header)),
|
||||
MultiEraBlock::Babbage(x) => MultiEraHeader::BabbageCompatible(Cow::Borrowed(&x.header)),
|
||||
MultiEraBlock::Conway(x) => MultiEraHeader::BabbageCompatible(Cow::Borrowed(&x.header)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ impl<'b> MultiEraHeader<'b> {
|
|||
Ok(MultiEraHeader::Byron(Cow::Owned(header)))
|
||||
}
|
||||
},
|
||||
5 => {
|
||||
1..=4 => {
|
||||
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)?;
|
||||
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] {
|
||||
match self {
|
||||
MultiEraHeader::EpochBoundary(x) => x.raw_cbor(),
|
||||
MultiEraHeader::AlonzoCompatible(x) => x.raw_cbor(),
|
||||
MultiEraHeader::Babbage(x) => x.raw_cbor(),
|
||||
MultiEraHeader::ShelleyCompatible(x) => x.raw_cbor(),
|
||||
MultiEraHeader::BabbageCompatible(x) => x.raw_cbor(),
|
||||
MultiEraHeader::Byron(x) => x.raw_cbor(),
|
||||
}
|
||||
}
|
||||
|
|
@ -48,16 +48,16 @@ impl<'b> MultiEraHeader<'b> {
|
|||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_default(),
|
||||
MultiEraHeader::AlonzoCompatible(x) => x.header_body.block_number,
|
||||
MultiEraHeader::Babbage(x) => x.header_body.block_number,
|
||||
MultiEraHeader::ShelleyCompatible(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(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn slot(&self) -> u64 {
|
||||
match self {
|
||||
MultiEraHeader::AlonzoCompatible(x) => x.header_body.slot,
|
||||
MultiEraHeader::Babbage(x) => x.header_body.slot,
|
||||
MultiEraHeader::ShelleyCompatible(x) => x.header_body.slot,
|
||||
MultiEraHeader::BabbageCompatible(x) => x.header_body.slot,
|
||||
MultiEraHeader::EpochBoundary(x) => {
|
||||
let genesis = GenesisValues::default();
|
||||
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> {
|
||||
match self {
|
||||
MultiEraHeader::EpochBoundary(x) => x.original_hash(),
|
||||
MultiEraHeader::AlonzoCompatible(x) => x.original_hash(),
|
||||
MultiEraHeader::Babbage(x) => x.original_hash(),
|
||||
MultiEraHeader::ShelleyCompatible(x) => x.original_hash(),
|
||||
MultiEraHeader::BabbageCompatible(x) => x.original_hash(),
|
||||
MultiEraHeader::Byron(x) => x.original_hash(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn previous_hash(&self) -> Option<Hash<32>> {
|
||||
match self {
|
||||
MultiEraHeader::AlonzoCompatible(x) => x.header_body.prev_hash,
|
||||
MultiEraHeader::Babbage(x) => x.header_body.prev_hash,
|
||||
MultiEraHeader::ShelleyCompatible(x) => x.header_body.prev_hash,
|
||||
MultiEraHeader::BabbageCompatible(x) => x.header_body.prev_hash,
|
||||
MultiEraHeader::EpochBoundary(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]> {
|
||||
match self {
|
||||
MultiEraHeader::AlonzoCompatible(x) => Some(x.header_body.vrf_vkey.as_ref()),
|
||||
MultiEraHeader::Babbage(x) => Some(x.header_body.vrf_vkey.as_ref()),
|
||||
MultiEraHeader::ShelleyCompatible(x) => Some(x.header_body.vrf_vkey.as_ref()),
|
||||
MultiEraHeader::BabbageCompatible(x) => Some(x.header_body.vrf_vkey.as_ref()),
|
||||
MultiEraHeader::EpochBoundary(_) => None,
|
||||
MultiEraHeader::Byron(_) => None,
|
||||
}
|
||||
|
|
@ -98,8 +98,8 @@ impl<'b> MultiEraHeader<'b> {
|
|||
|
||||
pub fn issuer_vkey(&self) -> Option<&[u8]> {
|
||||
match self {
|
||||
MultiEraHeader::AlonzoCompatible(x) => Some(x.header_body.issuer_vkey.as_ref()),
|
||||
MultiEraHeader::Babbage(x) => Some(x.header_body.issuer_vkey.as_ref()),
|
||||
MultiEraHeader::ShelleyCompatible(x) => Some(x.header_body.issuer_vkey.as_ref()),
|
||||
MultiEraHeader::BabbageCompatible(x) => Some(x.header_body.issuer_vkey.as_ref()),
|
||||
MultiEraHeader::EpochBoundary(_) => None,
|
||||
MultiEraHeader::Byron(_) => None,
|
||||
}
|
||||
|
|
@ -108,8 +108,8 @@ impl<'b> MultiEraHeader<'b> {
|
|||
pub fn leader_vrf_output(&self) -> Result<Vec<u8>, Error> {
|
||||
match self {
|
||||
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Era::Byron)),
|
||||
MultiEraHeader::AlonzoCompatible(x) => Ok(x.header_body.leader_vrf.0.to_vec()),
|
||||
MultiEraHeader::Babbage(x) => {
|
||||
MultiEraHeader::ShelleyCompatible(x) => Ok(x.header_body.leader_vrf.0.to_vec()),
|
||||
MultiEraHeader::BabbageCompatible(x) => {
|
||||
let mut leader_tagged_vrf: Vec<u8> = vec![0x4C_u8]; /* "L" */
|
||||
leader_tagged_vrf.extend(&*x.header_body.vrf_result.0);
|
||||
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> {
|
||||
match self {
|
||||
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Era::Byron)),
|
||||
MultiEraHeader::AlonzoCompatible(x) => Ok(x.header_body.nonce_vrf.0.to_vec()),
|
||||
MultiEraHeader::Babbage(x) => {
|
||||
MultiEraHeader::ShelleyCompatible(x) => Ok(x.header_body.nonce_vrf.0.to_vec()),
|
||||
MultiEraHeader::BabbageCompatible(x) => {
|
||||
let mut nonce_tagged_vrf: Vec<u8> = vec![0x4E_u8]; /* "N" */
|
||||
nonce_tagged_vrf.extend(&*x.header_body.vrf_result.0);
|
||||
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> {
|
||||
match self {
|
||||
MultiEraHeader::AlonzoCompatible(x) => Some(x.deref().deref()),
|
||||
MultiEraHeader::ShelleyCompatible(x) => Some(x.deref().deref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_babbage(&self) -> Option<&babbage::Header> {
|
||||
match self {
|
||||
MultiEraHeader::Babbage(x) => Some(x.deref().deref()),
|
||||
MultiEraHeader::BabbageCompatible(x) => Some(x.deref().deref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ pub enum Feature {
|
|||
#[derive(Debug)]
|
||||
pub enum MultiEraHeader<'b> {
|
||||
EpochBoundary(Cow<'b, KeepRaw<'b, byron::EbbHead>>),
|
||||
AlonzoCompatible(Cow<'b, KeepRaw<'b, alonzo::Header>>),
|
||||
Babbage(Cow<'b, KeepRaw<'b, babbage::Header>>),
|
||||
ShelleyCompatible(Cow<'b, KeepRaw<'b, alonzo::Header>>),
|
||||
BabbageCompatible(Cow<'b, KeepRaw<'b, babbage::Header>>),
|
||||
Byron(Cow<'b, KeepRaw<'b, byron::BlockHead>>),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue