-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat(core)!: use newtype sequencer block hashes #1884
base: main
Are you sure you want to change the base?
Conversation
ad21f02
to
e4e4167
Compare
e4e4167
to
3179682
Compare
3179682
to
73dcc88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple nits but otherwise LGTM. I don't foresee these changes being breaking since the storage types remain the same, but it may be worthwhile to double check this by starting a sync with main
, stopping midway and building with this PR, then continuing with the sync.
/// | ||
/// Note that hex based `Display` impl of [`Hash`] does not follow the pbjson | ||
/// convention to display protobuf `bytes` using base64 encoding. To get the | ||
/// display formatting faithful to pbjson convetion use the alternative formatting selector, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// display formatting faithful to pbjson convetion use the alternative formatting selector, | |
/// display formatting faithful to pbjson convention use the alternative formatting selector, |
// TODO: use the block hash's Display impl for this | ||
state.serialize_field(FIELDS[1], &base64(&*self.0.block_hash))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this can't be done now?
// TODO: use the block hash's Display impl for this | |
state.serialize_field(FIELDS[1], &base64(&*self.0.block_hash))?; | |
state.serialize_field(FIELDS[1], &self.0.block_hash.to_string())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, no, thanks for pointing that out! I updated the lines without thinking about about them.
Summary
Adds a newtype
astria_core::sequencerblock::v1::block::Hash
to represent Sequencer block hash (an array of 32 bytes).The standard formatting of the newtype's
std::format:Display
implementation uses lower case hex, while its alternative selector uses standard base64. Note that the latter was introduced to provide a way to format the hash using the same conventions as pbjson for the protobuf wire types.Background
During work on the Astria Auctioneer it was discovered that representing Sequencer Block Hashes with a distinct type is desirable for two reasons:
[u8; 32]
) that show up in the Astria ecosystem, for example Rollup block hashes.std::format::Display
implementation for all Astria block hashes using a hexadecimal representation.Changes
astria_core::sequencerblock::v1::block::Hash
newtype for[u8; 32]
objects representing Astria block hashes, and replace all domain types with it.Testing
Added doc tests for the
Hash
constructor and normal and alternative display impl.Changelogs
Changelogs updated.
Breaking Changelist
astria-core
but not in any of the services (because the return value of public getters was changed).