Limit generated timestamps to one second precision.
This commit changes all cases which generate default timestamps to time.Now to limit the timestamp to one second precision. The code which serializes and deserializes timestamps already does this, but it is useful to make sure defaults don't exceed the precision of the protocol either. With this change there is less chance that developers using defaults will end up with structures that have a higher time precision than what will ultimately be sent across the wire.
This commit is contained in:
parent
f6b03bf8a8
commit
13e0b0e7b9
3 changed files with 7 additions and 3 deletions
|
@ -89,11 +89,13 @@ func (h *BlockHeader) Serialize(w io.Writer) error {
|
|||
func NewBlockHeader(prevHash *ShaHash, merkleRootHash *ShaHash, bits uint32,
|
||||
nonce uint32) *BlockHeader {
|
||||
|
||||
// Limit the timestamp to one second precision since the protocol
|
||||
// doesn't support better.
|
||||
return &BlockHeader{
|
||||
Version: BlockVersion,
|
||||
PrevBlock: *prevHash,
|
||||
MerkleRoot: *merkleRootHash,
|
||||
Timestamp: time.Now(),
|
||||
Timestamp: time.Unix(time.Now().Unix(), 0),
|
||||
Bits: bits,
|
||||
Nonce: nonce,
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32 {
|
|||
func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64,
|
||||
userAgent string, lastBlock int32) *MsgVersion {
|
||||
|
||||
// Limit the Timestamp to millisecond precision since the protocol
|
||||
// Limit the timestamp to one second precision since the protocol
|
||||
// doesn't support better.
|
||||
return &MsgVersion{
|
||||
ProtocolVersion: int32(ProtocolVersion),
|
||||
|
|
|
@ -75,8 +75,10 @@ func (na *NetAddress) SetAddress(ip net.IP, port uint16) {
|
|||
// NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and
|
||||
// supported services with defaults for the remaining fields.
|
||||
func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress {
|
||||
// Limit the timestamp to one second precision since the protocol
|
||||
// doesn't support better.
|
||||
na := NetAddress{
|
||||
Timestamp: time.Now(),
|
||||
Timestamp: time.Unix(time.Now().Unix(), 0),
|
||||
Services: services,
|
||||
IP: ip,
|
||||
Port: port,
|
||||
|
|
Loading…
Reference in a new issue