Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Babbage nonce/leader vrf extension #132

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

AndrewWestberg
Copy link
Collaborator

Please review thoroughly and give feedback. I probably didn't do this the most optimal way.

UnknownEra(u16),

#[error("Invalid era for request: {0}")]
InvalidEra(u16),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use the crate::Era struct for this particular error since it will be thrown from methods where the Era of the data is strictly known (the UnknownEra relies on u16 because it is used for errors during the parsing of the value).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -45,4 +46,57 @@ impl<'b> MultiEraHeader<'b> {
MultiEraHeader::Byron(x) => x.to_hash(),
}
}

pub fn leader_vrf_output(&self) -> Result<ByteVec, Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the fn name just leader_vrf? Or do you think that the output prefix provides more context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A VRF has two parts. There's the output and the proof. In this case, we only are extending to get the output part of it. If you call it something other than "output" in your code, we can maybe change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense now.

let mut leader_tagged_vrf: Vec<u8> = vec![0x4C_u8]; /* "L" */
leader_tagged_vrf.extend(&*x.header_body.vrf_result.0);
let h32 = Hasher::<256>::hash(&leader_tagged_vrf);
Ok(ByteVec::from(h32.to_vec()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip the ByteVec wrapper and just return a Hash<32>. The bytevec is a cbor-specific decoding struct which should remain as hidden as possible from the api surface.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with a simple Vec<u8>.

@scarmuega scarmuega merged commit fa12e45 into txpipe:feat/babbage Jun 20, 2022
scarmuega added a commit that referenced this pull request Jun 21, 2022
* 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>
@AndrewWestberg AndrewWestberg deleted the feat/babbage branch June 21, 2022 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants