Skip to content
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

VRF-392 Change lookbackblocks type to uint64 #8688

Merged
merged 5 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/scripts/ocr2vrf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func main() {
coordinatorOverhead := cmd.Int64("coordinator-overhead", 50_000, "coordinator overhead")
callbackOverhead := cmd.Int64("callback-overhead", 50_000, "callback overhead")
blockGasOverhead := cmd.Int64("block-gas-overhead", 50_000, "block gas overhead")
lookbackBlocks := cmd.Int64("lookback-blocks", 1000, "lookback blocks")
lookbackBlocks := cmd.Uint64("lookback-blocks", 1000, "lookback blocks")
maxRounds := cmd.Uint("max-rounds", 3, "maximum number of rounds")
maxDurationQuery := cmd.Duration("max-duration-query", 10*time.Millisecond, "maximum duration of query")
maxDurationObservation := cmd.Duration("max-duration-observation", 10*time.Second, "maximum duration of observation method")
Expand Down
31 changes: 14 additions & 17 deletions core/services/ocr2/plugins/ocr2vrf/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type coordinator struct {
toBeTransmittedBlocks *ocrCache[blockInReport]
// set of request id's that have been scheduled for transmission.
toBeTransmittedCallbacks *ocrCache[callbackInReport]
blockhashLookback int64
blockhashLookback uint64
coordinatorConfig *ocr2vrftypes.CoordinatorConfig
}

Expand Down Expand Up @@ -187,7 +187,7 @@ func New(

cacheEvictionWindowSeconds := int64(60)
cacheEvictionWindow := time.Duration(cacheEvictionWindowSeconds * int64(time.Second))
lookbackBlocks := int64(1_000)
lookbackBlocks := uint64(1_000)

return &coordinator{
onchainRouter: onchainRouter,
Expand Down Expand Up @@ -318,12 +318,11 @@ func (c *coordinator) ReportBlocks(
currentBatchGasLimit := c.coordinatorConfig.CoordinatorOverhead

// TODO: use head broadcaster instead?
ch, err := c.CurrentChainHeight(ctx)
currentHeight, err := c.CurrentChainHeight(ctx)
if err != nil {
err = errors.Wrap(err, "header by number")
return
}
currentHeight := int64(ch)

// Evict expired items from the cache.
c.toBeTransmittedBlocks.EvictExpiredItems(now)
Expand All @@ -332,8 +331,8 @@ func (c *coordinator) ReportBlocks(
c.lggr.Infow("current chain height", "currentHeight", currentHeight)

logs, err := c.lp.LogsWithSigs(
currentHeight-c.coordinatorConfig.LookbackBlocks,
currentHeight,
int64(currentHeight-c.coordinatorConfig.LookbackBlocks),
int64(currentHeight),
[]common.Hash{
c.randomnessRequestedTopic,
c.randomnessFulfillmentRequestedTopic,
Expand Down Expand Up @@ -370,7 +369,7 @@ func (c *coordinator) ReportBlocks(
// Get start height for recent blockhashes.
recentBlockHashesStartHeight = uint64(0)
if currentHeight >= c.blockhashLookback {
recentBlockHashesStartHeight = uint64(currentHeight - c.blockhashLookback + 1)
recentBlockHashesStartHeight = currentHeight - c.blockhashLookback + 1
}

// Get blockhashes that pertain to requested blocks.
Expand Down Expand Up @@ -463,7 +462,7 @@ func (c *coordinator) getBlockhashesMappingFromRequests(
ctx context.Context,
randomnessRequestedLogs []*vrf_wrapper.VRFCoordinatorRandomnessRequested,
randomnessFulfillmentRequestedLogs []*vrf_wrapper.VRFCoordinatorRandomnessFulfillmentRequested,
currentHeight int64,
currentHeight uint64,
recentBlockHashesStartHeight uint64,
) (blockhashesMapping map[uint64]common.Hash, err error) {

Expand Down Expand Up @@ -570,7 +569,7 @@ func (c *coordinator) filterUnfulfilledCallbacks(
callbacksRequested []*vrf_wrapper.VRFCoordinatorRandomnessFulfillmentRequested,
fulfilledRequestIDs map[uint64]struct{},
confirmationDelays map[uint32]struct{},
currentHeight int64,
currentHeight uint64,
currentBatchGasLimit int64,
) (callbacks []ocr2vrftypes.AbstractCostedCallbackRequest) {

Expand Down Expand Up @@ -647,7 +646,7 @@ func (c *coordinator) filterUnfulfilledCallbacks(
func (c *coordinator) filterEligibleCallbacks(
randomnessFulfillmentRequestedLogs []*vrf_wrapper.VRFCoordinatorRandomnessFulfillmentRequested,
confirmationDelays map[uint32]struct{},
currentHeight int64,
currentHeight uint64,
blockhashesMapping map[uint64]common.Hash,
) (callbacks []*vrf_wrapper.VRFCoordinatorRandomnessFulfillmentRequested, unfulfilled []block, err error) {

Expand Down Expand Up @@ -695,7 +694,7 @@ func (c *coordinator) filterEligibleCallbacks(
func (c *coordinator) filterEligibleRandomnessRequests(
randomnessRequestedLogs []*vrf_wrapper.VRFCoordinatorRandomnessRequested,
confirmationDelays map[uint32]struct{},
currentHeight int64,
currentHeight uint64,
blockhashesMapping map[uint64]common.Hash,
) (unfulfilled []block, err error) {

Expand Down Expand Up @@ -1001,9 +1000,9 @@ func (c *coordinator) KeyID(ctx context.Context) (dkg.KeyID, error) {
// NextBeaconOutputHeight is always greater than the request block, therefore
// a number of confirmations on the beacon block is always enough confirmations
// for the request block.
func isBlockEligible(nextBeaconOutputHeight uint64, confDelay *big.Int, currentHeight int64) bool {
cond := confDelay.Int64() < currentHeight // Edge case: for simulated chains with low block numbers
cond = cond && (nextBeaconOutputHeight+confDelay.Uint64()) < uint64(currentHeight)
func isBlockEligible(nextBeaconOutputHeight uint64, confDelay *big.Int, currentHeight uint64) bool {
cond := confDelay.Uint64() < currentHeight // Edge case: for simulated chains with low block numbers
cond = cond && (nextBeaconOutputHeight+confDelay.Uint64()) < currentHeight
return cond
}

Expand Down Expand Up @@ -1071,9 +1070,7 @@ func (c *coordinator) SetOffChainConfig(b []byte) error {
c.toBeTransmittedBlocks.SetEvictonWindow(cacheEvictionWindow)
c.toBeTransmittedCallbacks.SetEvictonWindow(cacheEvictionWindow)

c.blockhashLookback = int64(
mathutil.Min(256, uint64(c.coordinatorConfig.LookbackBlocks)),
)
c.blockhashLookback = mathutil.Min(256, c.coordinatorConfig.LookbackBlocks)
c.lggr.Infow("set offchain config",
offchainConfigFields(c.coordinatorConfig)...,
)
Expand Down
Loading