feat: Add Vasil / Babbage compatibility (#126)

* feat: Bump n2n protocol versions for Babbage (#125)
* feat: Allow a specified timeout on tcp connection (#127)
* feat: Add Babbage primitives (#128)
* fix: Inaccurate header-body CDDL (#129)
* fix: Babbage CBOR codec issues (#130)
* feat: Include Babbage in traverse lib
* Parse Babbage headers (#131)
* Add Babbage nonce/leader vrf extension (#132)

Co-authored-by: Andrew Westberg <andrewwestberg@gmail.com>
This commit is contained in:
Santiago Carmuega 2022-06-20 22:09:42 -03:00 committed by GitHub
parent dd42b951a3
commit 4e08620bc4
22 changed files with 1826 additions and 90 deletions

View file

@ -1,7 +1,8 @@
use pallas_codec::minicbor;
use pallas_crypto::hash::Hash;
use pallas_crypto::hash::{Hash, Hasher};
use pallas_primitives::ToHash;
use crate::Era::Byron;
use crate::{Error, MultiEraHeader};
impl<'b> MultiEraHeader<'b> {
@ -17,6 +18,10 @@ impl<'b> MultiEraHeader<'b> {
Ok(MultiEraHeader::Byron(header))
}
},
5 => {
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?;
Ok(MultiEraHeader::Babbage(header))
}
_ => {
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?;
Ok(MultiEraHeader::AlonzoCompatible(header))
@ -28,6 +33,7 @@ impl<'b> MultiEraHeader<'b> {
match self {
MultiEraHeader::EpochBoundary(x) => x.to_abs_slot(),
MultiEraHeader::AlonzoCompatible(x) => x.header_body.slot,
MultiEraHeader::Babbage(x) => x.header_body.slot,
MultiEraHeader::Byron(x) => x.consensus_data.0.to_abs_slot(),
}
}
@ -36,7 +42,34 @@ impl<'b> MultiEraHeader<'b> {
match self {
MultiEraHeader::EpochBoundary(x) => x.to_hash(),
MultiEraHeader::AlonzoCompatible(x) => x.to_hash(),
MultiEraHeader::Babbage(x) => x.to_hash(),
MultiEraHeader::Byron(x) => x.to_hash(),
}
}
pub fn leader_vrf_output(&self) -> Result<Vec<u8>, Error> {
match self {
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Byron)),
MultiEraHeader::AlonzoCompatible(x) => Ok(x.header_body.leader_vrf.0.to_vec()),
MultiEraHeader::Babbage(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())
}
MultiEraHeader::Byron(_) => Err(Error::InvalidEra(Byron)),
}
}
pub fn nonce_vrf_output(&self) -> Result<Vec<u8>, Error> {
match self {
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(Byron)),
MultiEraHeader::AlonzoCompatible(x) => Ok(x.header_body.nonce_vrf.0.to_vec()),
MultiEraHeader::Babbage(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())
}
MultiEraHeader::Byron(_) => Err(Error::InvalidEra(Byron)),
}
}
}