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
SoR History update #416
SoR History update #416
Conversation
Move backfill updates to new Backfiller resource
// - `blockHeight` is the height where the backfill happened, it also defines the SoR used to backfill | ||
// - `gapStartHeight` is the height of the first backfilled entry | ||
// - `count` is the number of backfilled entries | ||
// Note that in very rare cases, the backfilled gap may not be contiguous. This event does not |
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.
The reason for adding 2 events and not only RandomHistoryBackfilled
is the edge case specifically mentioned in the comment.
If that edge case happens while only emitting RandomHistoryBackfilled
, there is no clear way to know what exact indices got backfilled.
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.
I copied the suggested event definition from https://github.com/bluesign/flow-core-contracts/blob/randomBackfill/contracts/RandomBeaconHistory.cdc
Are you planning on doing this upgrade before or after Cadence 1.0? If the answer is after, I would prefer that you make these changes based on the |
I don't know exactly when Cadence 1.0 will be on MN. This PR change should go as soon as the the PR is merged to fix a current on-chain issue, so I guess it's gonna be before Cadence 1.0 |
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.
Left a couple of minor comments and one question about the backfilled value guarantees
f84ef5c
to
8b78cad
Compare
Move correct SoR index discovery to Backfiller resource
contracts/RandomBeaconHistory.cdc
Outdated
// cache the array length in a local variable to avoid multiple calls to `length` | ||
// when the array is too large | ||
var arrayLength = UInt64(RandomBeaconHistory.randomSourceHistory.length) | ||
|
||
// if a new gap is detected, emit an event | ||
if correctIndex > arrayLength { |
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.
I confirmed with @turbolent in a discord thread that getting an array's length via arr.length
is constant time, so seems this comment's content isn't a concern as I thought it might be earlier.
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.
Since accessing the length is constant time and cheap, I added this minor optimization FYI e913f3a
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.
Nice!
f48385c
to
9e5d257
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.
9e5d257
to
75d3500
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.
LGTM!
@joshuahannan can you please have a look? I think the PR can only be merged after your approval. |
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.
After we merge this, you'll need to make an upgrade plan and post it in a forum post like we've done for previous upgrades.
Then you'll also need to make a branch based off of the stable-cadence
branch that includes these changes so that we can make sure the upgrades are working properly in the Cadence 1.0 migrations.
closes #414
The implementation:
backfiller
resource to track and backfill past empty entries in the array