github.com/klaytn/klaytn@v1.10.2/consensus/istanbul/backend.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2017 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from quorum/consensus/istanbul/backend.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package istanbul 22 23 import ( 24 "math/big" 25 "time" 26 27 "github.com/klaytn/klaytn/common" 28 "github.com/klaytn/klaytn/event" 29 ) 30 31 // Backend provides application specific functions for Istanbul core 32 // 33 //go:generate mockgen -destination=consensus/istanbul/mocks/backend_mock.go github.com/klaytn/klaytn/consensus/istanbul Backend 34 type Backend interface { 35 // Address returns the owner's address 36 Address() common.Address 37 38 // Validators returns the validator set 39 Validators(proposal Proposal) ValidatorSet 40 41 // EventMux returns the event mux in backend 42 EventMux() *event.TypeMux 43 44 // Broadcast sends a message to all validators (include self) 45 Broadcast(prevHash common.Hash, valSet ValidatorSet, payload []byte) error 46 47 // Gossip sends a message to all validators (exclude self) 48 Gossip(valSet ValidatorSet, payload []byte) error 49 50 GossipSubPeer(prevHash common.Hash, valSet ValidatorSet, payload []byte) map[common.Address]bool 51 52 // Commit delivers an approved proposal to backend. 53 // The delivered proposal will be put into blockchain. 54 Commit(proposal Proposal, seals [][]byte) error 55 56 // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, 57 // the time difference of the proposal and current time is also returned. 58 Verify(Proposal) (time.Duration, error) 59 60 // Sign signs input data with the backend's private key 61 Sign([]byte) ([]byte, error) 62 63 // CheckSignature verifies the signature by checking if it's signed by 64 // the given validator 65 CheckSignature(data []byte, addr common.Address, sig []byte) error 66 67 // LastProposal retrieves latest committed proposal and the address of proposer 68 LastProposal() (Proposal, common.Address) 69 70 // HasPropsal checks if the combination of the given hash and height matches any existing blocks 71 HasPropsal(hash common.Hash, number *big.Int) bool 72 73 // GetProposer returns the proposer of the given block height 74 GetProposer(number uint64) common.Address 75 76 // ParentValidators returns the validator set of the given proposal's parent block 77 ParentValidators(proposal Proposal) ValidatorSet 78 79 // HasBadBlock returns whether the block with the hash is a bad block 80 HasBadProposal(hash common.Hash) bool 81 82 GetRewardBase() common.Address 83 84 SetCurrentView(view *View) 85 86 NodeType() common.ConnType 87 }