From 27169d140f498329a06bc19af14e8e036df3a336 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 5 Aug 2020 11:30:14 +0300 Subject: [PATCH] core: implement (*Blockchain).GetStandByCommitee() --- pkg/core/blockchain.go | 13 +++++++++---- pkg/core/blockchainer/blockchainer.go | 1 + pkg/core/util.go | 10 +++++++++- pkg/network/helper_test.go | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 5e648c965..3758d88f5 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -119,7 +119,7 @@ type Blockchain struct { // cache for block verification keys. keyCache map[util.Uint160]map[string]*keys.PublicKey - sbValidators keys.PublicKeys + sbCommittee keys.PublicKeys log *zap.Logger @@ -156,7 +156,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L cfg.MemPoolSize = defaultMemPoolSize log.Info("mempool size is not set or wrong, setting default value", zap.Int("MemPoolSize", cfg.MemPoolSize)) } - validators, err := validatorsFromConfig(cfg) + committee, err := committeeFromConfig(cfg) if err != nil { return nil, err } @@ -169,7 +169,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L runToExitCh: make(chan struct{}), memPool: mempool.NewMemPool(cfg.MemPoolSize), keyCache: make(map[util.Uint160]map[string]*keys.PublicKey), - sbValidators: validators, + sbCommittee: committee, log: log, events: make(chan bcEvent), subCh: make(chan interface{}), @@ -1393,7 +1393,12 @@ func (bc *Blockchain) PoolTx(t *transaction.Transaction) error { //GetStandByValidators returns validators from the configuration. func (bc *Blockchain) GetStandByValidators() keys.PublicKeys { - return bc.sbValidators.Copy() + return bc.sbCommittee[:bc.config.ValidatorsCount].Copy() +} + +// GetStandByCommittee returns standby commitee from the configuration. +func (bc *Blockchain) GetStandByCommittee() keys.PublicKeys { + return bc.sbCommittee.Copy() } // GetValidators returns current validators. diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index b1ff94f12..ffa98c3c0 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -42,6 +42,7 @@ type Blockchainer interface { GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog GetNEP5Balances(util.Uint160) *state.NEP5Balances GetValidators() ([]*keys.PublicKey, error) + GetStandByCommittee() keys.PublicKeys GetStandByValidators() keys.PublicKeys GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) GetStateRoot(height uint32) (*state.MPTRootState, error) diff --git a/pkg/core/util.go b/pkg/core/util.go index 72f555523..7f8d4eb20 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -95,10 +95,18 @@ func deployNativeContracts(magic netmode.Magic) *transaction.Transaction { } func validatorsFromConfig(cfg config.ProtocolConfiguration) ([]*keys.PublicKey, error) { + vs, err := committeeFromConfig(cfg) + if err != nil { + return nil, err + } + return vs[:cfg.ValidatorsCount], nil +} + +func committeeFromConfig(cfg config.ProtocolConfiguration) ([]*keys.PublicKey, error) { if len(cfg.StandbyCommittee) < cfg.ValidatorsCount { return nil, errors.New("validators count can be less than the size of StandbyCommittee") } - validators := make([]*keys.PublicKey, cfg.ValidatorsCount) + validators := make([]*keys.PublicKey, len(cfg.StandbyCommittee)) for i := range validators { pubKey, err := keys.NewPublicKeyFromString(cfg.StandbyCommittee[i]) if err != nil { diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index 45ccc3615..a06b12704 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -103,6 +103,9 @@ func (chain testChain) GetNEP5Balances(util.Uint160) *state.NEP5Balances { func (chain testChain) GetValidators() ([]*keys.PublicKey, error) { panic("TODO") } +func (chain testChain) GetStandByCommittee() keys.PublicKeys { + panic("TODO") +} func (chain testChain) GetStandByValidators() keys.PublicKeys { panic("TODO") }