core: implement (*Blockchain).GetStandByCommitee()

This commit is contained in:
Evgenii Stratonikov 2020-08-05 11:30:14 +03:00
parent 05c24d9401
commit 27169d140f
4 changed files with 22 additions and 5 deletions

View file

@ -119,7 +119,7 @@ type Blockchain struct {
// cache for block verification keys. // cache for block verification keys.
keyCache map[util.Uint160]map[string]*keys.PublicKey keyCache map[util.Uint160]map[string]*keys.PublicKey
sbValidators keys.PublicKeys sbCommittee keys.PublicKeys
log *zap.Logger log *zap.Logger
@ -156,7 +156,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
cfg.MemPoolSize = defaultMemPoolSize cfg.MemPoolSize = defaultMemPoolSize
log.Info("mempool size is not set or wrong, setting default value", zap.Int("MemPoolSize", cfg.MemPoolSize)) 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 { if err != nil {
return nil, err return nil, err
} }
@ -169,7 +169,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
runToExitCh: make(chan struct{}), runToExitCh: make(chan struct{}),
memPool: mempool.NewMemPool(cfg.MemPoolSize), memPool: mempool.NewMemPool(cfg.MemPoolSize),
keyCache: make(map[util.Uint160]map[string]*keys.PublicKey), keyCache: make(map[util.Uint160]map[string]*keys.PublicKey),
sbValidators: validators, sbCommittee: committee,
log: log, log: log,
events: make(chan bcEvent), events: make(chan bcEvent),
subCh: make(chan interface{}), subCh: make(chan interface{}),
@ -1393,7 +1393,12 @@ func (bc *Blockchain) PoolTx(t *transaction.Transaction) error {
//GetStandByValidators returns validators from the configuration. //GetStandByValidators returns validators from the configuration.
func (bc *Blockchain) GetStandByValidators() keys.PublicKeys { 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. // GetValidators returns current validators.

View file

@ -42,6 +42,7 @@ type Blockchainer interface {
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)
GetStandByCommittee() keys.PublicKeys
GetStandByValidators() keys.PublicKeys GetStandByValidators() keys.PublicKeys
GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error)
GetStateRoot(height uint32) (*state.MPTRootState, error) GetStateRoot(height uint32) (*state.MPTRootState, error)

View file

@ -95,10 +95,18 @@ func deployNativeContracts(magic netmode.Magic) *transaction.Transaction {
} }
func validatorsFromConfig(cfg config.ProtocolConfiguration) ([]*keys.PublicKey, error) { 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 { if len(cfg.StandbyCommittee) < cfg.ValidatorsCount {
return nil, errors.New("validators count can be less than the size of StandbyCommittee") 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 { for i := range validators {
pubKey, err := keys.NewPublicKeyFromString(cfg.StandbyCommittee[i]) pubKey, err := keys.NewPublicKeyFromString(cfg.StandbyCommittee[i])
if err != nil { if err != nil {

View file

@ -103,6 +103,9 @@ func (chain testChain) GetNEP5Balances(util.Uint160) *state.NEP5Balances {
func (chain testChain) GetValidators() ([]*keys.PublicKey, error) { func (chain testChain) GetValidators() ([]*keys.PublicKey, error) {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetStandByCommittee() keys.PublicKeys {
panic("TODO")
}
func (chain testChain) GetStandByValidators() keys.PublicKeys { func (chain testChain) GetStandByValidators() keys.PublicKeys {
panic("TODO") panic("TODO")
} }