-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
New validation package #1494
New validation package #1494
Conversation
161ce6b
to
be61d7d
Compare
if errorWithCategory, ok := err.(validation.ErrorWithCategory); ok { | ||
return errorWithCategory.Category() != validation.BlockFutureTimestamp | ||
} |
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.
Check this.
now := uint64(time.Now().Unix()) | ||
if h.Timestamp > now+build.AllowableClockDrift { | ||
return xerrors.Errorf("block was from the future (now=%d, blk=%d): %w", now, h.Timestamp, ErrTemporal) | ||
maxTimeDrift := time.Now().Add(build.AllowableClockDrift) | ||
if h.Timestamp > uint64(maxTimeDrift.Unix()) { | ||
return validation.BlockFutureTimestamp.FromString(fmt.Sprintf("%s > %s", time.Unix(int64(h.Timestamp), 0).Format("%FT%T"), maxTimeDrift.Format("%FT%T"))) | ||
// FIXME: There surely is a simpler way to format these times. |
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.
Check this.
There are still more validations that need to be extracted but this branch moves too fast so I rather get this reviewed and merged now and continue the extraction in a follow-up PR. |
be61d7d
to
931a384
Compare
Might need a broader name later, naming it "security" seemed too much.
Encapsulate and extract validation errors (e.g., block, messages) for explicit testing later. One of the objectives is to distinguish between validation errors (e.g., invalid signature) exposed to the consumer and with potential security implications from internal errors (e.g., network timeout). This also allows us to have a central place to control validation checks.
This package should also extract validation logic as well as just errors, starting with the latter simplifies this PR to get something going. The downside is that this incorrect separation boundary causes many ugly
validation.*
imports. Ideally in the future all the validation code should be concentrated and encapsulated to minimize cross-over.