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

New validation package #1494

Closed
wants to merge 1 commit into from
Closed

Conversation

schomatis
Copy link
Contributor

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.

@schomatis schomatis self-assigned this Apr 2, 2020
chain/sync.go Outdated Show resolved Hide resolved
chain/sync.go Outdated Show resolved Hide resolved
@schomatis schomatis force-pushed the feat/add-validation-package branch 3 times, most recently from 161ce6b to be61d7d Compare April 13, 2020 01:41
Comment on lines +447 to +449
if errorWithCategory, ok := err.(validation.ErrorWithCategory); ok {
return errorWithCategory.Category() != validation.BlockFutureTimestamp
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this.

Comment on lines -523 to +533
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this.

@schomatis
Copy link
Contributor Author

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.

@schomatis schomatis marked this pull request as ready for review April 13, 2020 01:46
@Kubuxu Kubuxu changed the base branch from testnet/3 to master May 13, 2020 01:47
@Kubuxu Kubuxu changed the base branch from master to testnet/3 May 28, 2020 22:09
@Kubuxu Kubuxu closed this May 28, 2020
@Kubuxu Kubuxu deleted the feat/add-validation-package branch May 28, 2020 22:13
@Kubuxu
Copy link
Contributor

Kubuxu commented May 28, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants