diff --git a/pkg/consensus/block.go b/pkg/consensus/block.go index cc4a77f99..390846fc6 100644 --- a/pkg/consensus/block.go +++ b/pkg/consensus/block.go @@ -65,7 +65,7 @@ func (n *neoBlock) PrevHash() util.Uint256 { return n.Block.PrevHash } func (n *neoBlock) MerkleRoot() util.Uint256 { return n.Block.MerkleRoot } // Timestamp implements block.Block interface. -func (n *neoBlock) Timestamp() uint64 { return n.Block.Timestamp * 1000000 } +func (n *neoBlock) Timestamp() uint64 { return n.Block.Timestamp * nsInMs } // Index implements block.Block interface. func (n *neoBlock) Index() uint32 { return n.Block.Index } diff --git a/pkg/consensus/change_view.go b/pkg/consensus/change_view.go index a292619e9..fedc72c8e 100644 --- a/pkg/consensus/change_view.go +++ b/pkg/consensus/change_view.go @@ -33,10 +33,10 @@ func (c changeView) NewViewNumber() byte { return c.newViewNumber } func (c *changeView) SetNewViewNumber(view byte) { c.newViewNumber = view } // Timestamp implements payload.ChangeView interface. -func (c changeView) Timestamp() uint64 { return c.timestamp * 1000000 } +func (c changeView) Timestamp() uint64 { return c.timestamp * nsInMs } // SetTimestamp implements payload.ChangeView interface. -func (c *changeView) SetTimestamp(ts uint64) { c.timestamp = ts / 1000000 } +func (c *changeView) SetTimestamp(ts uint64) { c.timestamp = ts / nsInMs } // Reason implements payload.ChangeView interface. func (c changeView) Reason() payload.ChangeViewReason { return c.reason } diff --git a/pkg/consensus/change_view_test.go b/pkg/consensus/change_view_test.go index 70fd117ec..eaad6b2db 100644 --- a/pkg/consensus/change_view_test.go +++ b/pkg/consensus/change_view_test.go @@ -9,8 +9,8 @@ import ( func TestChangeView_Setters(t *testing.T) { var c changeView - c.SetTimestamp(123 * 1000000) - require.EqualValues(t, 123*1000000, c.Timestamp()) + c.SetTimestamp(123 * nsInMs) + require.EqualValues(t, 123*nsInMs, c.Timestamp()) c.SetNewViewNumber(2) require.EqualValues(t, 2, c.NewViewNumber()) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index be9545cff..921da8659 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -32,6 +32,9 @@ const cacheMaxCapacity = 100 // defaultTimePerBlock is a period between blocks which is used in NEO. const defaultTimePerBlock = 15 * time.Second +// Number of nanoseconds in millisecond. +const nsInMs = 1000000 + // Service represents consensus instance. type Service interface { // Start initializes dBFT and starts event loop for consensus service. @@ -488,7 +491,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block { } block.Block.Network = s.network - block.Block.Timestamp = ctx.Timestamp / 1000000 + block.Block.Timestamp = ctx.Timestamp / nsInMs block.Block.Index = ctx.BlockIndex validators, err := s.Chain.GetValidators() diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index f6221894c..569c1acac 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -63,7 +63,7 @@ func TestService_GetVerified(t *testing.T) { p.SetPayload(&prepareRequest{transactionHashes: hashes}) } else { p.SetType(payload.ChangeViewType) - p.SetPayload(&changeView{newViewNumber: 1, timestamp: uint64(time.Now().UnixNano() / 1000000)}) + p.SetPayload(&changeView{newViewNumber: 1, timestamp: uint64(time.Now().UnixNano() / nsInMs)}) } p.SetHeight(1) p.SetValidatorIndex(uint16(i)) diff --git a/pkg/consensus/prepare_request.go b/pkg/consensus/prepare_request.go index 26be085ad..cded41ed2 100644 --- a/pkg/consensus/prepare_request.go +++ b/pkg/consensus/prepare_request.go @@ -30,10 +30,10 @@ func (p *prepareRequest) DecodeBinary(r *io.BinReader) { } // Timestamp implements payload.PrepareRequest interface. -func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * 1000000 } +func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * nsInMs } // SetTimestamp implements payload.PrepareRequest interface. -func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / 1000000 } +func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / nsInMs } // Nonce implements payload.PrepareRequest interface. func (p *prepareRequest) Nonce() uint64 { return p.nonce } diff --git a/pkg/consensus/recovery_message.go b/pkg/consensus/recovery_message.go index a9ce3f569..817e241e8 100644 --- a/pkg/consensus/recovery_message.go +++ b/pkg/consensus/recovery_message.go @@ -164,7 +164,7 @@ func (m *recoveryMessage) AddPayload(p payload.ConsensusPayload) { m.changeViewPayloads = append(m.changeViewPayloads, &changeViewCompact{ ValidatorIndex: p.ValidatorIndex(), OriginalViewNumber: p.ViewNumber(), - Timestamp: p.GetChangeView().Timestamp() / 1000000, + Timestamp: p.GetChangeView().Timestamp() / nsInMs, InvocationScript: p.(*Payload).Witness.InvocationScript, }) case payload.CommitType: diff --git a/pkg/consensus/recovery_request.go b/pkg/consensus/recovery_request.go index 630775b86..52e0fb269 100644 --- a/pkg/consensus/recovery_request.go +++ b/pkg/consensus/recovery_request.go @@ -23,7 +23,7 @@ func (m *recoveryRequest) EncodeBinary(w *io.BinWriter) { } // Timestamp implements payload.RecoveryRequest interface. -func (m *recoveryRequest) Timestamp() uint64 { return m.timestamp * 1000000 } +func (m *recoveryRequest) Timestamp() uint64 { return m.timestamp * nsInMs } // SetTimestamp implements payload.RecoveryRequest interface. -func (m *recoveryRequest) SetTimestamp(ts uint64) { m.timestamp = ts / 1000000 } +func (m *recoveryRequest) SetTimestamp(ts uint64) { m.timestamp = ts / nsInMs } diff --git a/pkg/consensus/recovery_request_test.go b/pkg/consensus/recovery_request_test.go index 8bae99aa6..adfc57c51 100644 --- a/pkg/consensus/recovery_request_test.go +++ b/pkg/consensus/recovery_request_test.go @@ -9,6 +9,6 @@ import ( func TestRecoveryRequest_Setters(t *testing.T) { var r recoveryRequest - r.SetTimestamp(123 * 1000000) - require.EqualValues(t, 123*1000000, r.Timestamp()) + r.SetTimestamp(123 * nsInMs) + require.EqualValues(t, 123*nsInMs, r.Timestamp()) }