diff --git a/go.mod b/go.mod index 06bce704d..636d7071e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-redis/redis v6.10.2+incompatible github.com/go-yaml/yaml v2.1.0+incompatible github.com/mr-tron/base58 v1.1.2 - github.com/nspcc-dev/dbft v0.0.0-20200427132226-660464796c11 + github.com/nspcc-dev/dbft v0.0.0-20200427132226-15a7927772a4 github.com/nspcc-dev/rfc6979 v0.2.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.2.1 diff --git a/go.sum b/go.sum index 003de7aad..7f8283738 100644 --- a/go.sum +++ b/go.sum @@ -131,6 +131,8 @@ github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1 h1:yEx9WznS+rjE0jl0 github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ= github.com/nspcc-dev/dbft v0.0.0-20200303183127-36d3da79c682 h1:63OWUolW4GcjJR7cThq8hLnMLTwL+sjO3Qf4fo4sx8w= github.com/nspcc-dev/dbft v0.0.0-20200303183127-36d3da79c682/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E= +github.com/nspcc-dev/dbft v0.0.0-20200427132226-15a7927772a4 h1:3cFSp4v2u9+S7K1GdLUOP1680EiGEHSBvSI6G2n8XzY= +github.com/nspcc-dev/dbft v0.0.0-20200427132226-15a7927772a4/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E= github.com/nspcc-dev/dbft v0.0.0-20200427132226-660464796c11 h1:sledsmRo0wzgWNCZir5/CeM0PjhHVP8khnGtOfBCFWk= github.com/nspcc-dev/dbft v0.0.0-20200427132226-660464796c11/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= diff --git a/pkg/consensus/block.go b/pkg/consensus/block.go index e907813af..845e6a2d7 100644 --- a/pkg/consensus/block.go +++ b/pkg/consensus/block.go @@ -74,10 +74,10 @@ func (n *neoBlock) MerkleRoot() util.Uint256 { return n.Block.MerkleRoot } func (n *neoBlock) SetMerkleRoot(r util.Uint256) { n.Block.MerkleRoot = r } // Timestamp implements block.Block interface. -func (n *neoBlock) Timestamp() uint64 { return n.Block.Timestamp } +func (n *neoBlock) Timestamp() uint64 { return n.Block.Timestamp * 1000000 } // SetTimestamp implements block.Block interface. -func (n *neoBlock) SetTimestamp(ts uint64) { n.Block.Timestamp = ts } +func (n *neoBlock) SetTimestamp(ts uint64) { n.Block.Timestamp = ts / 1000000 } // Index implements block.Block interface. func (n *neoBlock) Index() uint32 { return n.Block.Index } diff --git a/pkg/consensus/block_test.go b/pkg/consensus/block_test.go index 0e9edf915..b95072601 100644 --- a/pkg/consensus/block_test.go +++ b/pkg/consensus/block_test.go @@ -29,7 +29,12 @@ func TestNeoBlock_Setters(t *testing.T) { require.EqualValues(t, 12, b.Index()) b.SetTimestamp(777) - require.EqualValues(t, 777, b.Timestamp()) + // 777ns -> 0ms -> 0ns + require.EqualValues(t, 0, b.Timestamp()) + + b.SetTimestamp(7777777) + // 7777777ns -> 7ms -> 7000000ns + require.EqualValues(t, 7000000, b.Timestamp()) b.SetConsensusData(456) require.EqualValues(t, 456, b.ConsensusData()) diff --git a/pkg/consensus/prepare_request.go b/pkg/consensus/prepare_request.go index bcb5a5e42..b9b5ec76d 100644 --- a/pkg/consensus/prepare_request.go +++ b/pkg/consensus/prepare_request.go @@ -37,10 +37,10 @@ func (p *prepareRequest) DecodeBinary(r *io.BinReader) { } // Timestamp implements payload.PrepareRequest interface. -func (p *prepareRequest) Timestamp() uint64 { return p.timestamp } +func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * 1000000 } // SetTimestamp implements payload.PrepareRequest interface. -func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts } +func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / 1000000 } // Nonce implements payload.PrepareRequest interface. func (p *prepareRequest) Nonce() uint64 { return p.nonce } diff --git a/pkg/consensus/prepare_request_test.go b/pkg/consensus/prepare_request_test.go index d7a3473b9..4b91e6cfb 100644 --- a/pkg/consensus/prepare_request_test.go +++ b/pkg/consensus/prepare_request_test.go @@ -12,7 +12,12 @@ func TestPrepareRequest_Setters(t *testing.T) { var p prepareRequest p.SetTimestamp(123) - require.EqualValues(t, 123, p.Timestamp()) + // 123ns -> 0ms -> 0ns + require.EqualValues(t, 0, p.Timestamp()) + + p.SetTimestamp(1230000) + // 1230000ns -> 1ms -> 1000000ns + require.EqualValues(t, 1000000, p.Timestamp()) p.SetNextConsensus(util.Uint160{5, 6, 7}) require.Equal(t, util.Uint160{5, 6, 7}, p.NextConsensus()) diff --git a/pkg/core/block/block_base.go b/pkg/core/block/block_base.go index e1e142062..f32e17b05 100644 --- a/pkg/core/block/block_base.go +++ b/pkg/core/block/block_base.go @@ -20,6 +20,7 @@ type Base struct { // Root hash of a transaction list. MerkleRoot util.Uint256 `json:"merkleroot"` + // Timestamp is a millisecond-precision timestamp. // The time stamp of each block must be later than previous block's time stamp. // Generally the difference of two block's time stamp is about 15 seconds and imprecision is allowed. // The height of the block must be exactly equal to the height of the previous block plus 1. diff --git a/pkg/core/block/header_test.go b/pkg/core/block/header_test.go index f0820f120..35f669917 100644 --- a/pkg/core/block/header_test.go +++ b/pkg/core/block/header_test.go @@ -16,7 +16,7 @@ func TestHeaderEncodeDecode(t *testing.T) { Version: 0, PrevHash: hash.Sha256([]byte("prevhash")), MerkleRoot: hash.Sha256([]byte("merkleroot")), - Timestamp: uint64(time.Now().UTC().Unix()), + Timestamp: uint64(time.Now().UTC().Unix() * 1000), Index: 3445, ConsensusData: 394949, NextConsensus: util.Uint160{}, diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 733190075..ed5e4b9f5 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -1049,7 +1049,7 @@ func newBlock(t *testing.T, bc blockchainer.Blockchainer, index uint32, txs ...* b := &block.Block{ Base: block.Base{ PrevHash: hdr.Hash(), - Timestamp: uint64(time.Now().UTC().Unix()) + uint64(hdr.Index), + Timestamp: (uint64(time.Now().UTC().Unix()) + uint64(hdr.Index)) * 1000, Index: hdr.Index + index, ConsensusData: 1111, NextConsensus: witness.ScriptHash(),