github.com/reapchain/go-reapchain@v0.2.15-0.20210609012950-9735c110c705/consensus/podc/validator.go (about) 1 // Copyright 2017 AMIS Technologies 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 podc 18 19 import ( 20 "strings" 21 "github.com/ethereum/go-ethereum/common" 22 ) 23 24 type Validator interface { 25 // Address returns address 26 Address() common.Address 27 28 // String representation of Validator 29 String() string 30 31 32 Tag() common.Tag 33 34 Qrnd() uint64 35 36 SetAddress(a common.Address) 37 38 SetTag(t common.Tag) 39 40 SetQrnd(q uint64) 41 //Tag() uint64 // Tag() is bug ,, just test by yichoi 42 // Tag define : Senator(상원), parliamentarian(하원), general(일반), candidate(운영위 후보) 43 44 // Qrnd() uint64 45 } 46 47 // ---------------------------------------------------------------------------- 48 49 //type Validators []validator.ValidatorElement // go 배열 표현 50 type Validators []Validator // go 배열 표현 51 /* 설명 : Validators = [ address, String, Tag ] [ ... ] [ ... ] ......... */ 52 /* Validator node 53 |-------------------------| 54 | enode address(20 byte) 55 |-------------------------| 56 String인데,,String()모르겠으나, 그냥 문자열, 57 Validator 를 나타내는 58 |-------------------------| 59 Tag를 새로 달았음. 60 |-------------------------| ............ N 개 Validators 61 62 63 64 */ 65 func (slice Validators) Len() int { 66 return len(slice) 67 } 68 69 func (slice Validators) Less(i, j int) bool { 70 return strings.Compare(slice[i].String(), slice[j].String()) < 0 71 } 72 73 func (slice Validators) Swap(i, j int) { 74 slice[i], slice[j] = slice[j], slice[i] 75 } 76 77 78 79 type ValidatorSet interface { 80 // Calculate the proposer 81 CalcProposer(lastProposer common.Address, round uint64 ) // 최초 Proposer 가 누군지 계산 ,, 82 83 // 코디 후보군 선정 ? 84 //RecvCordinator(lastProposer common.Address, round uint64) //yichoi 85 86 //Empty() string 87 88 // Return the validator size 89 Size() int 90 // Return the validator array 91 List() []Validator 92 // Get validator by index 93 GetByIndex(i uint64) Validator 94 // Get validator by given address 95 GetByAddress(addr common.Address) (int, Validator) 96 // Get current proposer 97 GetProposer() Validator 98 99 // 상임위, 운영위 확정 구성 위원회 정보 가져오기 , Steering committee ( 운영위원회 ) 100 //GetConfirmedCommittee() Validator //yichoi 101 102 // Check whether the validator with given address is a proposer 103 IsProposer(address common.Address) bool 104 // Is request a ExtraDATA to Qmanager 105 //IsRequestQman(address common.Address) bool //podc 106 107 // Add validator 108 AddValidator(address common.Address) bool 109 // Remove validator 110 RemoveValidator(address common.Address) bool 111 // Copy validator set 112 Copy() ValidatorSet 113 // Get the maximum number of faulty nodes 114 F() int 115 } 116 117 // ---------------------------------------------------------------------------- 118 119 type ProposalSelector func(ValidatorSet, common.Address, uint64 ) Validator 120 //type ProposalSelector func(ValidatorSet, common.Address, uint64) Validator 121 //func EmptyValSet() { 122 // valSet := validator.NewSet(validator.ExtractValidators([]byte{})) 123 // if valSet == nil { 124 // fmt.Errorf("validator set should not be nil") 125 // } 126 //}