Use precise cache duration for "future beacon" error responses#22
Open
alienx5499 wants to merge 1 commit intodrand:masterfrom
Open
Use precise cache duration for "future beacon" error responses#22alienx5499 wants to merge 1 commit intodrand:masterfrom
alienx5499 wants to merge 1 commit intodrand:masterfrom
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a client requests a round that is too far in the future, the relay returns a "Requested future beacon" (425 Too Early) response. The response was cached for the full chain period (
info.Period), even when the next valid round would become available sooner. That over-caches the error and can serve a stale "future beacon" response longer than necessary.Location:
routes_handler.go–getBeacon()whenround >= nextRound+1Previous behavior: Cache duration was always
-int64(info.Period)(full period in seconds).Impact:
Solution
Compute the exact time until the next round and use that as the cache duration. Round N is at
GenesisTime + (N-1)*Period; seconds from now until that time is used for the negativenextTime(cache duration) when returning the future-beacon error.SecondsUntilRound(round uint64) int64onJsonInfoV2ingrpc/grpc.go: returns seconds from now until the given round, or 0 if the round is in the past or round is 0.getBeacon(), whenround >= nextRound+1, useinfo.SecondsUntilRound(nextRound)instead ofinfo.Periodfor the cache duration.Changes
grpc/grpc.goSecondsUntilRound(round uint64) int64onJsonInfoV2: computes round time asGenesisTime + (round-1)*Period, returnsmax(0, roundTime - now).routes_handler.gopreciseCacheSeconds := info.SecondsUntilRound(nextRound)and return-preciseCacheSecondsinstead of-int64(info.Period).grpc/grpc_test.goTestSecondsUntilRound: next round in 5s, round 0 returns 0, round already passed returns 0, round in 30s.Testing
go test ./grpc/... -v -run TestSecondsUntilRoundgo test ./grpc/... -v -run TestNextBeaconTime(unchanged)go build ./...Notes