-
Notifications
You must be signed in to change notification settings - Fork 10
Move future block check into validateHeader #204
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
Conversation
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.
I'm still bothered by the fact that this isn't technically a consensus rule. It can't be a consensus rule, because the network does not reach consensus on the current time! The network only reaches consensus on "history" -- the list of parent blocks. (This is also why SufficientlyHeavierThan
is not a consensus rule: it depends on information other than the history.)
Splitting the checks out like this does make the consensus
package slightly harder to use correctly. But I think I'm okay with that. consensus
is a low-level package whose only "real" consumer is coreutils/chain
, so it can have some sharp edges. In theory, someone else could write their own implementation of chain.Manager
with a different ErrFutureBlock
threshold, and it would still be 100% compliant with Sia consensus.
func validateHeader(s State, parentID types.BlockID, timestamp time.Time, nonce uint64, id types.BlockID) error { | ||
if parentID != s.Index.ID { | ||
return errors.New("wrong parent ID") | ||
} else if timestamp.After(s.MaxFutureTimestamp(time.Now())) { |
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.
this makes the function impure -- calling it at different times gives you different results. The current time should be passed in as an argument instead.
This seems accurate, but with a big caveat. |
The ambiguity of this, combined with the annoyance of having to thread a new argument through a bunch of functions, is pushing me towards a No on this. It's true that, if a significant fraction of nodes fail to implement this rule properly, it could cause a netsplit. But that's true of many other pieces of logic in the system as well -- particularly the Syncer and the TxPool. In my head, the distinction looks like this:
In other words, you need both, but |
I think I agree even if it's not ideal. Threading the new argument is indeed really, really, annoying. |
No description provided.