Skip to content

Conversation

@Amxx
Copy link
Collaborator

@Amxx Amxx commented Jul 28, 2022

This PR includes quite a few things:

  • Procedural generation of the Checkpoint library, automating the support for various key/value lengths
    • Checkpoints.Checkpoint224: key is uint32 and value is uint224. Usecase: history checkpoints for voting
    • Checkpoints.Checkpoint160: key is uint96 and value is uint160. Usecase: Address sequence (for NFT batch minting)
  • For each Checkpoint type, functions availables are:
    • latest()
    • push(key, value)
    • lowerLookup(key): returns the c.value of the first checkpoint for which key <= c.key (or 0 if no such checkpoint exists)
    • upperLookup(key): returns the c.value of the last checkpoint for which key >= c.key (or 0 if no such checkpoint exists)
    • upperLookupRecent(key): same as upperLookup but optimised to look in recent checkpoints.
  • Checkpoint.History now uses the Checkpoints.Checkpoint224 structure, with block.number for keys.
    • getAtBlock now uses upperLookupRecent, optimizing for recent value lookup → delayed to further PR

Fixes #3585

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx
Copy link
Collaborator Author

Amxx commented Jul 29, 2022

Uses argotorg/solidity#9117 (comment) to skip checks

@Amxx Amxx force-pushed the feature/checkpoint branch from 66a2e82 to 28f6e6f Compare July 29, 2022 08:07
@Amxx Amxx requested a review from frangio July 29, 2022 17:04
@Amxx Amxx mentioned this pull request Aug 14, 2022
4 tasks
@frangio frangio changed the title Refactor the Checkpoint library, with new key/value balances and new lookup mechanisms Extend Checkpoints with new sizes and lookup mechanisms Aug 30, 2022
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Mostly minor comments. We can merge after this.

@Amxx Amxx requested a review from frangio August 30, 2022 13:27
@Amxx Amxx enabled auto-merge (squash) August 30, 2022 19:18
@Amxx Amxx disabled auto-merge August 30, 2022 19:32
@Amxx Amxx merged commit 71aaca2 into OpenZeppelin:master Aug 30, 2022
@Amxx Amxx deleted the feature/checkpoint branch August 30, 2022 19:32
JulissaDantes pushed a commit to JulissaDantes/openzeppelin-contracts that referenced this pull request Nov 3, 2022
JulissaDantes pushed a commit to JulissaDantes/openzeppelin-contracts that referenced this pull request Nov 4, 2022
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.

Add a Checkpoints lookup that optimizes for recency

2 participants