github.com/zjj1991/quorum@v0.0.0-20190524123704-ae4b0a1e1a19/consensus/istanbul/validator.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package istanbul 18 19 import ( 20 "strings" 21 22 "github.com/ethereum/go-ethereum/common" 23 ) 24 25 type Validator interface { 26 // Address returns address 27 Address() common.Address 28 29 // String representation of Validator 30 String() string 31 } 32 33 // ---------------------------------------------------------------------------- 34 35 type Validators []Validator 36 37 func (slice Validators) Len() int { 38 return len(slice) 39 } 40 41 func (slice Validators) Less(i, j int) bool { 42 return strings.Compare(slice[i].String(), slice[j].String()) < 0 43 } 44 45 func (slice Validators) Swap(i, j int) { 46 slice[i], slice[j] = slice[j], slice[i] 47 } 48 49 // ---------------------------------------------------------------------------- 50 51 type ValidatorSet interface { 52 // Calculate the proposer 53 CalcProposer(lastProposer common.Address, round uint64) 54 // Return the validator size 55 Size() int 56 // Return the validator array 57 List() []Validator 58 // Get validator by index 59 GetByIndex(i uint64) Validator 60 // Get validator by given address 61 GetByAddress(addr common.Address) (int, Validator) 62 // Get current proposer 63 GetProposer() Validator 64 // Check whether the validator with given address is a proposer 65 IsProposer(address common.Address) bool 66 // Add validator 67 AddValidator(address common.Address) bool 68 // Remove validator 69 RemoveValidator(address common.Address) bool 70 // Copy validator set 71 Copy() ValidatorSet 72 // Get the maximum number of faulty nodes 73 F() int 74 // Get proposer policy 75 Policy() ProposerPolicy 76 } 77 78 // ---------------------------------------------------------------------------- 79 80 type ProposalSelector func(ValidatorSet, common.Address, uint64) Validator