Merge pull request #1172 from nspcc-dev/update-dbft-timestamps-and-cv-reasons

Update dbft, add 64-bit timestamps and cv reasons
This commit is contained in:
Roman Khimov 2020-07-13 09:14:54 +03:00 committed by GitHub
commit d1b92f1767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 79 additions and 57 deletions

2
go.mod
View file

@ -9,7 +9,7 @@ require (
github.com/go-yaml/yaml v2.1.0+incompatible github.com/go-yaml/yaml v2.1.0+incompatible
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/mr-tron/base58 v1.1.2 github.com/mr-tron/base58 v1.1.2
github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e github.com/nspcc-dev/dbft v0.0.0-20200711144034-c526ccc6f570
github.com/nspcc-dev/rfc6979 v0.2.0 github.com/nspcc-dev/rfc6979 v0.2.0
github.com/pierrec/lz4 v2.5.2+incompatible github.com/pierrec/lz4 v2.5.2+incompatible
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1

4
go.sum
View file

@ -137,8 +137,8 @@ github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a h1:ajvxgEe9qY4vvoSm
github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk= github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk=
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1 h1:yEx9WznS+rjE0jl0dLujCxuZSIb+UTjF+005TJu/nNI= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1 h1:yEx9WznS+rjE0jl0dLujCxuZSIb+UTjF+005TJu/nNI=
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ=
github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e h1:QOT9slflIkEKb5wY0ZUC0dCmCgoqGlhOAh9+xWMIxfg= github.com/nspcc-dev/dbft v0.0.0-20200711144034-c526ccc6f570 h1:EHBwlOyd2m06C3dnxhpPokpYqlNg7u5ZX/uPBhjYuZ4=
github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E= github.com/nspcc-dev/dbft v0.0.0-20200711144034-c526ccc6f570/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neofs-crypto v0.2.0 h1:ftN+59WqxSWz/RCgXYOfhmltOOqU+udsNQSvN6wkFck= github.com/nspcc-dev/neofs-crypto v0.2.0 h1:ftN+59WqxSWz/RCgXYOfhmltOOqU+udsNQSvN6wkFck=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=

View file

@ -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 }

View file

@ -8,19 +8,22 @@ import (
// changeView represents dBFT ChangeView message. // changeView represents dBFT ChangeView message.
type changeView struct { type changeView struct {
newViewNumber byte newViewNumber byte
timestamp uint32 timestamp uint64
reason payload.ChangeViewReason
} }
var _ payload.ChangeView = (*changeView)(nil) var _ payload.ChangeView = (*changeView)(nil)
// EncodeBinary implements io.Serializable interface. // EncodeBinary implements io.Serializable interface.
func (c *changeView) EncodeBinary(w *io.BinWriter) { func (c *changeView) EncodeBinary(w *io.BinWriter) {
w.WriteU32LE(c.timestamp) w.WriteU64LE(c.timestamp)
w.WriteB(byte(c.reason))
} }
// DecodeBinary implements io.Serializable interface. // DecodeBinary implements io.Serializable interface.
func (c *changeView) DecodeBinary(r *io.BinReader) { func (c *changeView) DecodeBinary(r *io.BinReader) {
c.timestamp = r.ReadU32LE() c.timestamp = r.ReadU64LE()
c.reason = payload.ChangeViewReason(r.ReadB())
} }
// NewViewNumber implements payload.ChangeView interface. // NewViewNumber implements payload.ChangeView interface.
@ -30,7 +33,13 @@ 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() uint32 { return c.timestamp } func (c changeView) Timestamp() uint64 { return c.timestamp * nsInMs }
// SetTimestamp implements payload.ChangeView interface. // SetTimestamp implements payload.ChangeView interface.
func (c *changeView) SetTimestamp(ts uint32) { c.timestamp = ts } func (c *changeView) SetTimestamp(ts uint64) { c.timestamp = ts / nsInMs }
// Reason implements payload.ChangeView interface.
func (c changeView) Reason() payload.ChangeViewReason { return c.reason }
// SetReason implements payload.ChangeView interface.
func (c *changeView) SetReason(reason payload.ChangeViewReason) { c.reason = reason }

View file

@ -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) c.SetTimestamp(123 * nsInMs)
require.EqualValues(t, 123, 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())

View file

@ -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.
@ -446,12 +449,16 @@ func (s *service) getVerifiedTx() []block.Transaction {
return res return res
} }
func (s *service) getValidators(_ ...block.Transaction) []crypto.PublicKey { func (s *service) getValidators(txes ...block.Transaction) []crypto.PublicKey {
var ( var (
pKeys []*keys.PublicKey pKeys []*keys.PublicKey
err error err error
) )
pKeys, err = s.Chain.GetValidators() if txes == nil {
pKeys, err = s.Chain.GetNextBlockValidators()
} else {
pKeys, err = s.Chain.GetValidators()
}
if err != nil { if err != nil {
s.log.Error("error while trying to get validators", zap.Error(err)) s.log.Error("error while trying to get validators", zap.Error(err))
} }
@ -464,15 +471,8 @@ func (s *service) getValidators(_ ...block.Transaction) []crypto.PublicKey {
return pubs return pubs
} }
func (s *service) getConsensusAddress(validators ...crypto.PublicKey) (h util.Uint160) { func (s *service) getConsensusAddress(validators ...crypto.PublicKey) util.Uint160 {
pubs := convertKeys(validators) return util.Uint160{}
script, err := smartcontract.CreateMultiSigRedeemScript(s.dbft.M(), pubs)
if err != nil {
return
}
return crypto.Hash160(script)
} }
func convertKeys(validators []crypto.PublicKey) (pubs []*keys.PublicKey) { func convertKeys(validators []crypto.PublicKey) (pubs []*keys.PublicKey) {
@ -491,9 +491,18 @@ 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
block.Block.NextConsensus = ctx.NextConsensus
validators, err := s.Chain.GetValidators()
if err != nil {
return nil
}
script, err := smartcontract.CreateMultiSigRedeemScript(len(validators)-(len(validators)-1)/3, validators)
if err != nil {
return nil
}
block.Block.NextConsensus = crypto.Hash160(script)
block.Block.PrevHash = ctx.PrevHash block.Block.PrevHash = ctx.PrevHash
block.Block.Version = ctx.Version block.Block.Version = ctx.Version
block.Block.ConsensusData.Nonce = ctx.Nonce block.Block.ConsensusData.Nonce = ctx.Nonce

View file

@ -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: uint32(time.Now().Unix())}) 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))

View file

@ -224,7 +224,7 @@ func randomMessage(t *testing.T, mt messageType) io.Serializable {
switch mt { switch mt {
case changeViewType: case changeViewType:
return &changeView{ return &changeView{
timestamp: rand.Uint32(), timestamp: rand.Uint64(),
} }
case prepareRequestType: case prepareRequestType:
return randomPrepareRequest(t) return randomPrepareRequest(t)
@ -235,7 +235,7 @@ func randomMessage(t *testing.T, mt messageType) io.Serializable {
random.Fill(c.signature[:]) random.Fill(c.signature[:])
return &c return &c
case recoveryRequestType: case recoveryRequestType:
return &recoveryRequest{timestamp: rand.Uint32()} return &recoveryRequest{timestamp: rand.Uint64()}
case recoveryMessageType: case recoveryMessageType:
return randomRecoveryMessage(t) return randomRecoveryMessage(t)
default: default:
@ -256,7 +256,6 @@ func randomPrepareRequest(t *testing.T) *prepareRequest {
for i := 0; i < txCount; i++ { for i := 0; i < txCount; i++ {
req.transactionHashes[i] = random.Uint256() req.transactionHashes[i] = random.Uint256()
} }
req.nextConsensus = random.Uint160()
return req return req
} }
@ -289,7 +288,7 @@ func randomRecoveryMessage(t *testing.T) *recoveryMessage {
}, },
changeViewPayloads: []*changeViewCompact{ changeViewPayloads: []*changeViewCompact{
{ {
Timestamp: rand.Uint32(), Timestamp: rand.Uint64(),
ValidatorIndex: 3, ValidatorIndex: 3,
OriginalViewNumber: 3, OriginalViewNumber: 3,
InvocationScript: random.Bytes(4), InvocationScript: random.Bytes(4),

View file

@ -11,7 +11,6 @@ type prepareRequest struct {
timestamp uint64 timestamp uint64
nonce uint64 nonce uint64
transactionHashes []util.Uint256 transactionHashes []util.Uint256
nextConsensus util.Uint160
} }
var _ payload.PrepareRequest = (*prepareRequest)(nil) var _ payload.PrepareRequest = (*prepareRequest)(nil)
@ -20,7 +19,6 @@ var _ payload.PrepareRequest = (*prepareRequest)(nil)
func (p *prepareRequest) EncodeBinary(w *io.BinWriter) { func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
w.WriteU64LE(p.timestamp) w.WriteU64LE(p.timestamp)
w.WriteU64LE(p.nonce) w.WriteU64LE(p.nonce)
w.WriteBytes(p.nextConsensus[:])
w.WriteArray(p.transactionHashes) w.WriteArray(p.transactionHashes)
} }
@ -28,15 +26,14 @@ func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
func (p *prepareRequest) DecodeBinary(r *io.BinReader) { func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
p.timestamp = r.ReadU64LE() p.timestamp = r.ReadU64LE()
p.nonce = r.ReadU64LE() p.nonce = r.ReadU64LE()
r.ReadBytes(p.nextConsensus[:])
r.ReadArray(&p.transactionHashes) r.ReadArray(&p.transactionHashes)
} }
// 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 }
@ -51,7 +48,7 @@ func (p *prepareRequest) TransactionHashes() []util.Uint256 { return p.transacti
func (p *prepareRequest) SetTransactionHashes(hs []util.Uint256) { p.transactionHashes = hs } func (p *prepareRequest) SetTransactionHashes(hs []util.Uint256) { p.transactionHashes = hs }
// NextConsensus implements payload.PrepareRequest interface. // NextConsensus implements payload.PrepareRequest interface.
func (p *prepareRequest) NextConsensus() util.Uint160 { return p.nextConsensus } func (p *prepareRequest) NextConsensus() util.Uint160 { return util.Uint160{} }
// SetNextConsensus implements payload.PrepareRequest interface. // SetNextConsensus implements payload.PrepareRequest interface.
func (p *prepareRequest) SetNextConsensus(nc util.Uint160) { p.nextConsensus = nc } func (p *prepareRequest) SetNextConsensus(_ util.Uint160) {}

View file

@ -20,7 +20,7 @@ func TestPrepareRequest_Setters(t *testing.T) {
require.EqualValues(t, 1000000, p.Timestamp()) require.EqualValues(t, 1000000, p.Timestamp())
p.SetNextConsensus(util.Uint160{5, 6, 7}) p.SetNextConsensus(util.Uint160{5, 6, 7})
require.Equal(t, util.Uint160{5, 6, 7}, p.NextConsensus()) require.Equal(t, util.Uint160{}, p.NextConsensus())
p.SetNonce(8765) p.SetNonce(8765)
require.EqualValues(t, 8765, p.Nonce()) require.EqualValues(t, 8765, p.Nonce())

View file

@ -21,7 +21,7 @@ type (
changeViewCompact struct { changeViewCompact struct {
ValidatorIndex uint16 ValidatorIndex uint16
OriginalViewNumber byte OriginalViewNumber byte
Timestamp uint32 Timestamp uint64
InvocationScript []byte InvocationScript []byte
} }
@ -95,7 +95,7 @@ func (m *recoveryMessage) EncodeBinary(w *io.BinWriter) {
func (p *changeViewCompact) DecodeBinary(r *io.BinReader) { func (p *changeViewCompact) DecodeBinary(r *io.BinReader) {
p.ValidatorIndex = r.ReadU16LE() p.ValidatorIndex = r.ReadU16LE()
p.OriginalViewNumber = r.ReadB() p.OriginalViewNumber = r.ReadB()
p.Timestamp = r.ReadU32LE() p.Timestamp = r.ReadU64LE()
p.InvocationScript = r.ReadVarBytes(1024) p.InvocationScript = r.ReadVarBytes(1024)
} }
@ -103,7 +103,7 @@ func (p *changeViewCompact) DecodeBinary(r *io.BinReader) {
func (p *changeViewCompact) EncodeBinary(w *io.BinWriter) { func (p *changeViewCompact) EncodeBinary(w *io.BinWriter) {
w.WriteU16LE(p.ValidatorIndex) w.WriteU16LE(p.ValidatorIndex)
w.WriteB(p.OriginalViewNumber) w.WriteB(p.OriginalViewNumber)
w.WriteU32LE(p.Timestamp) w.WriteU64LE(p.Timestamp)
w.WriteVarBytes(p.InvocationScript) w.WriteVarBytes(p.InvocationScript)
} }
@ -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(), Timestamp: p.GetChangeView().Timestamp() / nsInMs,
InvocationScript: p.(*Payload).Witness.InvocationScript, InvocationScript: p.(*Payload).Witness.InvocationScript,
}) })
case payload.CommitType: case payload.CommitType:

View file

@ -31,7 +31,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
timestamp: 87, timestamp: 87,
nonce: 321, nonce: 321,
transactionHashes: []util.Uint256{{1}}, transactionHashes: []util.Uint256{{1}},
nextConsensus: util.Uint160{1, 2},
} }
p1 := new(Payload) p1 := new(Payload)
p1.message = &message{} p1.message = &message{}

View file

@ -7,23 +7,23 @@ import (
// recoveryRequest represents dBFT RecoveryRequest message. // recoveryRequest represents dBFT RecoveryRequest message.
type recoveryRequest struct { type recoveryRequest struct {
timestamp uint32 timestamp uint64
} }
var _ payload.RecoveryRequest = (*recoveryRequest)(nil) var _ payload.RecoveryRequest = (*recoveryRequest)(nil)
// DecodeBinary implements io.Serializable interface. // DecodeBinary implements io.Serializable interface.
func (m *recoveryRequest) DecodeBinary(r *io.BinReader) { func (m *recoveryRequest) DecodeBinary(r *io.BinReader) {
m.timestamp = r.ReadU32LE() m.timestamp = r.ReadU64LE()
} }
// EncodeBinary implements io.Serializable interface. // EncodeBinary implements io.Serializable interface.
func (m *recoveryRequest) EncodeBinary(w *io.BinWriter) { func (m *recoveryRequest) EncodeBinary(w *io.BinWriter) {
w.WriteU32LE(m.timestamp) w.WriteU64LE(m.timestamp)
} }
// Timestamp implements payload.RecoveryRequest interface. // Timestamp implements payload.RecoveryRequest interface.
func (m *recoveryRequest) Timestamp() uint32 { return m.timestamp } func (m *recoveryRequest) Timestamp() uint64 { return m.timestamp * nsInMs }
// SetTimestamp implements payload.RecoveryRequest interface. // SetTimestamp implements payload.RecoveryRequest interface.
func (m *recoveryRequest) SetTimestamp(ts uint32) { m.timestamp = ts } func (m *recoveryRequest) SetTimestamp(ts uint64) { m.timestamp = ts / nsInMs }

View file

@ -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) r.SetTimestamp(123 * nsInMs)
require.EqualValues(t, 123, r.Timestamp()) require.EqualValues(t, 123*nsInMs, r.Timestamp())
} }

View file

@ -1240,8 +1240,13 @@ func (bc *Blockchain) GetStandByValidators() keys.PublicKeys {
return bc.sbValidators.Copy() return bc.sbValidators.Copy()
} }
// GetValidators returns next block validators. // GetValidators returns current validators.
func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) { func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) {
return bc.contracts.NEO.GetValidatorsInternal(bc, bc.dao)
}
// GetNextBlockValidators returns next block validators.
func (bc *Blockchain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
return bc.contracts.NEO.GetNextBlockValidatorsInternal(bc, bc.dao) return bc.contracts.NEO.GetNextBlockValidatorsInternal(bc, bc.dao)
} }

View file

@ -36,6 +36,7 @@ type Blockchainer interface {
HasTransaction(util.Uint256) bool HasTransaction(util.Uint256) bool
GetAccountState(util.Uint160) *state.Account GetAccountState(util.Uint160) *state.Account
GetAppExecResult(util.Uint256) (*state.AppExecResult, error) GetAppExecResult(util.Uint256) (*state.AppExecResult, error)
GetNextBlockValidators() ([]*keys.PublicKey, error)
GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog
GetNEP5Balances(util.Uint160) *state.NEP5Balances GetNEP5Balances(util.Uint160) *state.NEP5Balances
GetValidators() ([]*keys.PublicKey, error) GetValidators() ([]*keys.PublicKey, error)

View file

@ -142,7 +142,7 @@ func (n *NEO) Initialize(ic *interop.Context) error {
// OnPersist implements Contract interface. // OnPersist implements Contract interface.
func (n *NEO) OnPersist(ic *interop.Context) error { func (n *NEO) OnPersist(ic *interop.Context) error {
pubs, err := n.getValidatorsInternal(ic.Chain, ic.DAO) pubs, err := n.GetValidatorsInternal(ic.Chain, ic.DAO)
if err != nil { if err != nil {
return err return err
} }
@ -385,16 +385,16 @@ func (n *NEO) getRegisteredValidatorsCall(ic *interop.Context, _ []stackitem.Ite
return stackitem.NewArray(arr) return stackitem.NewArray(arr)
} }
// getValidatorsInternal returns a list of current validators. // GetValidatorsInternal returns a list of current validators.
func (n *NEO) getValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
if vals := n.validators.Load().(keys.PublicKeys); vals != nil { if vals := n.validators.Load().(keys.PublicKeys); vals != nil {
return vals, nil return vals.Copy(), nil
} }
standByValidators := bc.GetStandByValidators() standByValidators := bc.GetStandByValidators()
si := d.GetStorageItem(n.ContractID, validatorsCountKey) si := d.GetStorageItem(n.ContractID, validatorsCountKey)
if si == nil { if si == nil {
n.validators.Store(standByValidators) n.validators.Store(standByValidators)
return standByValidators, nil return standByValidators.Copy(), nil
} }
validatorsCount, err := ValidatorsCountFromBytes(si.Value) validatorsCount, err := ValidatorsCountFromBytes(si.Value)
if err != nil { if err != nil {
@ -442,7 +442,7 @@ func (n *NEO) getValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (ke
} }
func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item { func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
result, err := n.getValidatorsInternal(ic.Chain, ic.DAO) result, err := n.GetValidatorsInternal(ic.Chain, ic.DAO)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -470,7 +470,7 @@ func (n *NEO) GetNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao
func (n *NEO) getNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { func (n *NEO) getNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
si := d.GetStorageItem(n.ContractID, nextValidatorsKey) si := d.GetStorageItem(n.ContractID, nextValidatorsKey)
if si == nil { if si == nil {
return n.getValidatorsInternal(bc, d) return n.GetValidatorsInternal(bc, d)
} }
pubs := keys.PublicKeys{} pubs := keys.PublicKeys{}
err := pubs.DecodeBytes(si.Value) err := pubs.DecodeBytes(si.Value)

View file

@ -77,6 +77,9 @@ func (chain testChain) GetHeader(hash util.Uint256) (*block.Header, error) {
func (chain testChain) GetAccountState(util.Uint160) *state.Account { func (chain testChain) GetAccountState(util.Uint160) *state.Account {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
panic("TODO")
}
func (chain testChain) GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog { func (chain testChain) GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog {
panic("TODO") panic("TODO")
} }