Skip to content

Conversation

@Fraser999
Copy link
Contributor

Summary

Added a lazily-initialized field address_bytes to VerificationKey.

Background

Testing showed that address_bytes was called multiple times on a given VerificationKey (up to 11 times in some cases). Each time the key's bytes were being hashed, so this change ensures that hashing only happens once for a given verification key instance.

Note that this was implemented previously in #1111 and was then reverted in #1124. However, when reverted, the manual impls of PartialEq, Eq, PartialOrd, Ord and Hash were left as-is, as were the unit tests for these. Hence this PR doesn't need to make any changes to these trait impls or tests.

Changes

  • Added address_bytes: OnceLock<[u8; ADDRESS_LEN]> to VerificiationKey.

Testing

No new tests required.

Related Issues

Closes #1351.

@Fraser999 Fraser999 requested a review from a team as a code owner September 4, 2024 12:06
@github-actions github-actions bot added the sequencer pertaining to the astria-sequencer crate label Sep 4, 2024
Copy link
Contributor

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

High level comment on this memoization:

Is there a more explicit way to memoize the address bytes, for example by calculating address_bytes once and storing them near the call site?

This change is relatively minimal for the user (minus the Copy trait, although we don't seem to make ause of it).

But introducing syncing primitives into a relatively innocent newtype wrapper makes me uneasy.

@Fraser999
Copy link
Contributor Author

Is there a more explicit way to memoize the address bytes, for example by calculating address_bytes once and storing them near the call site?

This change is relatively minimal for the user (minus the Copy trait, although we don't seem to make ause of it).

I think doing that means the change would have an impact on callers, which isn't the intent here.

But introducing syncing primitives into a relatively innocent newtype wrapper makes me uneasy.

Well, I guess for my money, the need for hand-rolled equality/ordering/hash traits is the biggest drawback here, rather than the fact the new field is a synchronization primitive.

@Fraser999 Fraser999 added this pull request to the merge queue Sep 4, 2024
Merged via the queue into main with commit e9d5f0f Sep 4, 2024
@Fraser999 Fraser999 deleted the fraser/memoize-address-bytes branch September 4, 2024 14:52
jbowen93 pushed a commit that referenced this pull request Sep 6, 2024
## Summary
Added a lazily-initialized field `address_bytes` to `VerificationKey`.

## Background
Testing showed that `address_bytes` was called multiple times on a given
`VerificationKey` (up to 11 times in some cases). Each time the key's
bytes were being hashed, so this change ensures that hashing only
happens once for a given verification key instance.

Note that this was implemented previously in #1111 and was then reverted
in #1124. However, when reverted, the manual impls of `PartialEq`, `Eq`,
`PartialOrd`, `Ord` and `Hash` were left as-is, as were the unit tests
for these. Hence this PR doesn't need to make any changes to these trait
impls or tests.

## Changes
- Added `address_bytes: OnceLock<[u8; ADDRESS_LEN]>` to
`VerificiationKey`.

## Testing
No new tests required.  

## Related Issues
Closes #1351.
steezeburger added a commit that referenced this pull request Sep 23, 2024
* main:
  feat(sequencer): make mempool balance aware (#1408)
  chore(sequencer): change test addresses to versions with known private keys (#1487)
  chore(chart): update geth tag (#1485)
  feat(sequencer): report deposit events (#1447)
  feat(proto, core, sequencer)!: add traceability to rollup deposits (#1410)
  fix(bridge-withdrawer, cli, sequencer-client): migrate from `broadcast_tx_commit` to `broadcast_tx_sync` (#1376)
  fix(sequencer): add `end_block` to `app_execute_transaction_with_every_action_snapshot` (#1455)
  release: end of iteration release cuts (#1456)
  chore(charts): rollupName templates (#1458)
  chore(sequencer-relayer): Add instrumentation (#1375)
  feat(proto, core, sequencer)!: permit bech32 compatible addresses (#1425)
  chore: memoize `address_bytes` of verification key (#1444)
  chore(ci): include `ibc-bridge-test` in `docker` CI target (#1438)
  chore(charts): bump celestia versions (#1431)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sequencer pertaining to the astria-sequencer crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assess and memoize (if appropriate) VerificationKey::address_bytes

3 participants