mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 14:22:16 +00:00
* validate reactor messages Refs #2683 * validate blockchain messages Refs #2683 * validate evidence messages Refs #2683 * todo * check ProposalPOL and signature sizes * add a changelog entry * check addr is valid when we add it to the addrbook * validate incoming netAddr (not just nil check!) * fixes after Bucky's review * check timestamps * beef up block#ValidateBasic * move some checks into bcBlockResponseMessage * update Gopkg.lock Fix ``` grouped write of manifest, lock and vendor: failed to export github.com/tendermint/go-amino: fatal: failed to unpack tree object 6dcc6ddc143e116455c94b25c1004c99e0d0ca12 ``` by running `dep ensure -update` * bump year since now we check it * generate test/p2p/data on the fly using tendermint testnet * allow sync chains older than 1 year * use full path when creating a testnet * move testnet gen to test/docker/Dockerfile * relax LastCommitRound check Refs #2737 * fix conflicts after merge * add small comment * some ValidateBasic updates * fixes * AppHash length is not fixed
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
)
|
|
|
|
// ValidateTime does a basic time validation ensuring time does not drift too
|
|
// much: +/- one year.
|
|
// TODO: reduce this to eg 1 day
|
|
// NOTE: DO NOT USE in ValidateBasic methods in this package. This function
|
|
// can only be used for real time validation, like on proposals and votes
|
|
// in the consensus. If consensus is stuck, and rounds increase for more than a day,
|
|
// having only a 1-day band here could break things...
|
|
// Can't use for validating blocks because we may be syncing years worth of history.
|
|
func ValidateTime(t time.Time) error {
|
|
var (
|
|
now = tmtime.Now()
|
|
oneYear = 8766 * time.Hour
|
|
)
|
|
if t.Before(now.Add(-oneYear)) || t.After(now.Add(oneYear)) {
|
|
return fmt.Errorf("Time drifted too much. Expected: -1 < %v < 1 year", now)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateHash returns an error if the hash is not empty, but its
|
|
// size != tmhash.Size.
|
|
func ValidateHash(h []byte) error {
|
|
if len(h) > 0 && len(h) != tmhash.Size {
|
|
return fmt.Errorf("Expected size to be %d bytes, got %d bytes",
|
|
tmhash.Size,
|
|
len(h),
|
|
)
|
|
}
|
|
return nil
|
|
}
|