-
Notifications
You must be signed in to change notification settings - Fork 104
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
Time-invariant event log #2382
Closed
Closed
Time-invariant event log #2382
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,16 @@ const contractName = "eventlog" | |
const logCmd = "log" | ||
|
||
// Set a relatively low time for bucketMaxAge: during peak message arrival | ||
// this will pretect the buckets from getting too big. During low message | ||
// this will protect the buckets from getting too big. During low message | ||
// arrival (< 1 per 5 sec) it does not create extra buckets, because time | ||
// periods with no events do not need buckets created for them. | ||
const bucketMaxAge = 5 * time.Second | ||
|
||
// eventDelayTolerance indicates how much time after the event timestamp | ||
// we are stilling willing to accept an event as genuine and contemporaneous, | ||
// and hence as valid. Expressed in [ns] | ||
const eventDelayTolerance = time.Duration(-60 * 1e9) | ||
|
||
func init() { | ||
var err error | ||
sid, err = onet.RegisterNewService(ServiceName, newService) | ||
|
@@ -143,12 +148,11 @@ filter: | |
return reply, nil | ||
} | ||
|
||
func decodeAndCheckEvent(coll byzcoin.ReadOnlyStateTrie, eventBuf []byte) (*Event, error) { | ||
// Check the timestamp of the event: it should never be in the future, | ||
// and it should not be more than 30 seconds in the past. (Why 30 sec | ||
// and not something more auto-scaling like blockInterval * 30? | ||
// Because a # of blocks limit is too fragile when using fast blocks for | ||
// tests.) | ||
func decodeAndCheckEvent(rst byzcoin.ReadOnlyStateTrie, eventBuf []byte) (*Event, error) { | ||
// Check the timestamp of the event: it should never be in the future beyond the current block, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you accept |
||
// and it should not be more than 30 seconds in the past before the current block. | ||
// (Why 30 sec and not something more auto-scaling like blockInterval * 30? | ||
// Because a # of blocks limit is too fragile when using fast blocks for tests.) | ||
// | ||
// Also: An event a few seconds into the future is OK because there might be | ||
// time skew between a legitimate event producer and the network. See issue #1331. | ||
|
@@ -158,12 +162,29 @@ func decodeAndCheckEvent(coll byzcoin.ReadOnlyStateTrie, eventBuf []byte) (*Even | |
return nil, err | ||
} | ||
when := time.Unix(0, event.When) | ||
now := time.Now() | ||
if when.Before(now.Add(-30 * time.Second)) { | ||
return nil, fmt.Errorf("event timestamp too long ago - when=%v, now=%v", when, now) | ||
|
||
config, err := rst.LoadConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tr, ok := rst.(byzcoin.TimeReader) | ||
if !ok { | ||
return nil, fmt.Errorf("internal error: cannot convert ReadOnlyStateTrie to TimeReader") | ||
} | ||
|
||
currentBlockTs := time.Unix(0, tr.GetCurrentBlockTimestamp()) | ||
|
||
lowerBound := currentBlockTs.Add(eventDelayTolerance) | ||
|
||
// Acceptable positive clock skew in the system, mirroring block acceptance criteria. | ||
upperBound := currentBlockTs.Add(4 * config.BlockInterval) | ||
|
||
if when.Before(lowerBound) { | ||
return nil, fmt.Errorf("event timestamp too long ago - when=%v, current block=%v", when, currentBlockTs) | ||
} | ||
if when.After(now.Add(5 * time.Second)) { | ||
return nil, errors.New("event timestamp is too far in the future") | ||
if when.After(upperBound) { | ||
return nil, fmt.Errorf("event timestamp is too far in the future - when=%v, current block=%v", when, currentBlockTs) | ||
} | ||
return event, nil | ||
} | ||
|
Oops, something went wrong.
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.
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.
And reverse the comment to say before, as well as changing the code.