core, consensus: nanoseconds-precision timestamp
Keep timestamp of consensus messages in nanoseconds-precision state
This commit is contained in:
parent
aa554f0a9a
commit
0de5cb1bde
9 changed files with 22 additions and 9 deletions
2
go.mod
2
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
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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{},
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue