Last active
April 9, 2020 23:57
-
-
Save ZenGround0/61fba9ac3ea34da76a6b695c139597b4 to your computer and use it in GitHub Desktop.
non-contiguous round DRAND integration notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Protocol Constants | |
// Time Drand network starts at | |
DRAND_START_ROUND | |
// Time of one DRAND Round | |
DRAND_ROUND_TIME | |
// Number of epochs in the past that a filecoin block should sample DRAND entries from | |
DRANDLookback = 2 // might change to 5 for availability reasons | |
func ValidateBlock(b BlockHeader) { | |
prevEntry := latestDrand(b) | |
numEntries := len(b.DRANDEntries) | |
// Handle case where there is no drand in the header | |
if numEntries == 0 { | |
nextDRANDTime := DRAND_START_ROUND + DRAND_ROUND_TIME * ( prevEntry.Round + 1) | |
assert(filecoinEpochFromTime(nextDRANDTime) > b.Height - DRANDLookback) | |
validateElectionFromBeaconEntry(prevEntry, b) | |
} | |
// Handle case where there is a drand entry in header | |
// Validate Drand entries link up | |
validateDRANDParentChild(prevEntry, b.DRANDEntries[0]) | |
for i := 0; i < numEntries-1; i++ { | |
validateDRANDIsParentChild(b.DRANDEntries[i], b.DRANDEntries[i+1]) | |
} | |
// Validate that last Drand entry in block is last possible | |
nextDRANDTime := DRAND_START_ROUND + DRAND_ROUND_TIME * (b.DRANDEntries[numEntries-1].Round + 1) | |
assert(filecoinEpochFromTime(nextDRANDTime) > b.Height - DRANDLookback) | |
validateElectionFromBeaconEntry(b.DRANDEntries[numEntries-1], b) | |
} | |
func latestDrand(b BlockHeader) drand.Entry { | |
for { | |
b := getParent(b) | |
if len(b.DRANDEntries) > 0 { | |
return b.DRANDEntries[len(b.DRANDEntries) -1] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment