mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-01 23:45:50 +00:00
consensus: replace magic 1000000 with something more meaningful
This commit is contained in:
parent
579630a3fa
commit
a43e374ac6
9 changed files with 17 additions and 14 deletions
|
@ -65,7 +65,7 @@ func (n *neoBlock) PrevHash() util.Uint256 { return n.Block.PrevHash }
|
||||||
func (n *neoBlock) MerkleRoot() util.Uint256 { return n.Block.MerkleRoot }
|
func (n *neoBlock) MerkleRoot() util.Uint256 { return n.Block.MerkleRoot }
|
||||||
|
|
||||||
// Timestamp implements block.Block interface.
|
// 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.
|
// Index implements block.Block interface.
|
||||||
func (n *neoBlock) Index() uint32 { return n.Block.Index }
|
func (n *neoBlock) Index() uint32 { return n.Block.Index }
|
||||||
|
|
|
@ -33,10 +33,10 @@ func (c changeView) NewViewNumber() byte { return c.newViewNumber }
|
||||||
func (c *changeView) SetNewViewNumber(view byte) { c.newViewNumber = view }
|
func (c *changeView) SetNewViewNumber(view byte) { c.newViewNumber = view }
|
||||||
|
|
||||||
// Timestamp implements payload.ChangeView interface.
|
// 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.
|
// 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.
|
// Reason implements payload.ChangeView interface.
|
||||||
func (c changeView) Reason() payload.ChangeViewReason { return c.reason }
|
func (c changeView) Reason() payload.ChangeViewReason { return c.reason }
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
func TestChangeView_Setters(t *testing.T) {
|
func TestChangeView_Setters(t *testing.T) {
|
||||||
var c changeView
|
var c changeView
|
||||||
|
|
||||||
c.SetTimestamp(123 * 1000000)
|
c.SetTimestamp(123 * nsInMs)
|
||||||
require.EqualValues(t, 123*1000000, c.Timestamp())
|
require.EqualValues(t, 123*nsInMs, c.Timestamp())
|
||||||
|
|
||||||
c.SetNewViewNumber(2)
|
c.SetNewViewNumber(2)
|
||||||
require.EqualValues(t, 2, c.NewViewNumber())
|
require.EqualValues(t, 2, c.NewViewNumber())
|
||||||
|
|
|
@ -32,6 +32,9 @@ const cacheMaxCapacity = 100
|
||||||
// defaultTimePerBlock is a period between blocks which is used in NEO.
|
// defaultTimePerBlock is a period between blocks which is used in NEO.
|
||||||
const defaultTimePerBlock = 15 * time.Second
|
const defaultTimePerBlock = 15 * time.Second
|
||||||
|
|
||||||
|
// Number of nanoseconds in millisecond.
|
||||||
|
const nsInMs = 1000000
|
||||||
|
|
||||||
// Service represents consensus instance.
|
// Service represents consensus instance.
|
||||||
type Service interface {
|
type Service interface {
|
||||||
// Start initializes dBFT and starts event loop for consensus service.
|
// 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.Network = s.network
|
||||||
block.Block.Timestamp = ctx.Timestamp / 1000000
|
block.Block.Timestamp = ctx.Timestamp / nsInMs
|
||||||
block.Block.Index = ctx.BlockIndex
|
block.Block.Index = ctx.BlockIndex
|
||||||
|
|
||||||
validators, err := s.Chain.GetValidators()
|
validators, err := s.Chain.GetValidators()
|
||||||
|
|
|
@ -63,7 +63,7 @@ func TestService_GetVerified(t *testing.T) {
|
||||||
p.SetPayload(&prepareRequest{transactionHashes: hashes})
|
p.SetPayload(&prepareRequest{transactionHashes: hashes})
|
||||||
} else {
|
} else {
|
||||||
p.SetType(payload.ChangeViewType)
|
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.SetHeight(1)
|
||||||
p.SetValidatorIndex(uint16(i))
|
p.SetValidatorIndex(uint16(i))
|
||||||
|
|
|
@ -30,10 +30,10 @@ func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timestamp implements payload.PrepareRequest interface.
|
// 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.
|
// 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.
|
// Nonce implements payload.PrepareRequest interface.
|
||||||
func (p *prepareRequest) Nonce() uint64 { return p.nonce }
|
func (p *prepareRequest) Nonce() uint64 { return p.nonce }
|
||||||
|
|
|
@ -164,7 +164,7 @@ func (m *recoveryMessage) AddPayload(p payload.ConsensusPayload) {
|
||||||
m.changeViewPayloads = append(m.changeViewPayloads, &changeViewCompact{
|
m.changeViewPayloads = append(m.changeViewPayloads, &changeViewCompact{
|
||||||
ValidatorIndex: p.ValidatorIndex(),
|
ValidatorIndex: p.ValidatorIndex(),
|
||||||
OriginalViewNumber: p.ViewNumber(),
|
OriginalViewNumber: p.ViewNumber(),
|
||||||
Timestamp: p.GetChangeView().Timestamp() / 1000000,
|
Timestamp: p.GetChangeView().Timestamp() / nsInMs,
|
||||||
InvocationScript: p.(*Payload).Witness.InvocationScript,
|
InvocationScript: p.(*Payload).Witness.InvocationScript,
|
||||||
})
|
})
|
||||||
case payload.CommitType:
|
case payload.CommitType:
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (m *recoveryRequest) EncodeBinary(w *io.BinWriter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timestamp implements payload.RecoveryRequest interface.
|
// 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.
|
// 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 }
|
||||||
|
|
|
@ -9,6 +9,6 @@ import (
|
||||||
func TestRecoveryRequest_Setters(t *testing.T) {
|
func TestRecoveryRequest_Setters(t *testing.T) {
|
||||||
var r recoveryRequest
|
var r recoveryRequest
|
||||||
|
|
||||||
r.SetTimestamp(123 * 1000000)
|
r.SetTimestamp(123 * nsInMs)
|
||||||
require.EqualValues(t, 123*1000000, r.Timestamp())
|
require.EqualValues(t, 123*nsInMs, r.Timestamp())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue