From 53a88af6bdfaffa9493220b1b366326408ccf7c4 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 17 Sep 2024 07:43:16 -0700 Subject: [PATCH 1/2] consensus: move future block check into validateHeader --- consensus/validation.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/consensus/validation.go b/consensus/validation.go index 8519e963..ea284b40 100644 --- a/consensus/validation.go +++ b/consensus/validation.go @@ -11,9 +11,16 @@ import ( "go.sia.tech/core/types" ) +var ( + // ErrFutureBlock is returned when a block's timestamp is too far in the future. + ErrFutureBlock = errors.New("block's timestamp is too far in the future") +) + 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())) { + return ErrFutureBlock } else if timestamp.Before(s.medianTimestamp()) { return errors.New("timestamp is too far in the past") } else if nonce%s.NonceFactor() != 0 { From a6c30a3afa09ced6dd93d80301969b122612805f Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 17 Sep 2024 07:47:01 -0700 Subject: [PATCH 2/2] consensus: fix lint --- consensus/validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/validation.go b/consensus/validation.go index ea284b40..f757721a 100644 --- a/consensus/validation.go +++ b/consensus/validation.go @@ -20,7 +20,7 @@ func validateHeader(s State, parentID types.BlockID, timestamp time.Time, nonce if parentID != s.Index.ID { return errors.New("wrong parent ID") } else if timestamp.After(s.MaxFutureTimestamp(time.Now())) { - return ErrFutureBlock + return ErrFutureBlock } else if timestamp.Before(s.medianTimestamp()) { return errors.New("timestamp is too far in the past") } else if nonce%s.NonceFactor() != 0 {