From a58edeb96fa136cea3dd06d2e0341fd5d3d5b375 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 3 Aug 2020 18:39:27 +0200 Subject: [PATCH] Tighten up timestamp check Signed-off-by: Jakub Sztandera --- chain/sync.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 474701d64..163e1a59f 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -674,6 +674,10 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er //nulls := h.Height - (baseTs.Height() + 1) // fast checks first + nulls := h.Height - (baseTs.Height() + 1) + if tgtTs := baseTs.MinTimestamp() + build.BlockDelaySecs*uint64(nulls+1); h.Timestamp != tgtTs { + return xerrors.Errorf("block has wrong timestamp: %d != %d", h.Timestamp, tgtTs) + } now := uint64(build.Clock.Now().Unix()) if h.Timestamp > now+build.AllowableClockDriftSecs { @@ -683,13 +687,6 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er log.Warn("Got block from the future, but within threshold", h.Timestamp, build.Clock.Now().Unix()) } - if h.Timestamp < baseTs.MinTimestamp()+(build.BlockDelaySecs*uint64(h.Height-baseTs.Height())) { - log.Warn("timestamp funtimes: ", h.Timestamp, baseTs.MinTimestamp(), h.Height, baseTs.Height()) - diff := (baseTs.MinTimestamp() + (build.BlockDelaySecs * uint64(h.Height-baseTs.Height()))) - h.Timestamp - - return xerrors.Errorf("block was generated too soon (h.ts:%d < base.mints:%d + BLOCK_DELAY:%d * deltaH:%d; diff %d)", h.Timestamp, baseTs.MinTimestamp(), build.BlockDelaySecs, h.Height-baseTs.Height(), diff) - } - msgsCheck := async.Err(func() error { if err := syncer.checkBlockMessages(ctx, b, baseTs); err != nil { return xerrors.Errorf("block had invalid messages: %w", err)