github.com/electroneum/electroneum-sc@v0.0.0-20230105223411-3bc1d078281e/consensus/istanbul/backend.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 "math/big" 21 "time" 22 23 "github.com/electroneum/electroneum-sc/common" 24 "github.com/electroneum/electroneum-sc/event" 25 ) 26 27 // Backend provides application specific functions for Istanbul core 28 type Backend interface { 29 // Address returns the owner's address 30 Address() common.Address 31 32 // Validators returns the validator set 33 Validators(proposal Proposal) ValidatorSet 34 35 // EventMux returns the event mux in backend 36 EventMux() *event.TypeMux 37 38 // Broadcast sends a message to all validators (include self) 39 Broadcast(valSet ValidatorSet, code uint64, payload []byte) error 40 41 // Gossip sends a message to all validators (exclude self) 42 Gossip(valSet ValidatorSet, code uint64, payload []byte) error 43 44 // Commit delivers an approved proposal to backend. 45 // The delivered proposal will be put into blockchain. 46 Commit(proposal Proposal, seals [][]byte, round *big.Int) error 47 48 // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, 49 // the time difference of the proposal and current time is also returned. 50 Verify(Proposal) (time.Duration, error) 51 52 // Sign signs input data with the backend's private key 53 Sign([]byte) ([]byte, error) 54 55 // SignWithoutHashing sign input data with the backend's private key without hashing the input data 56 SignWithoutHashing([]byte) ([]byte, error) 57 58 // CheckSignature verifies the signature by checking if it's signed by 59 // the given validator 60 CheckSignature(data []byte, addr common.Address, sig []byte) error 61 62 // LastProposal retrieves latest committed proposal and the address of proposer 63 LastProposal() (Proposal, common.Address) 64 65 // HasPropsal checks if the combination of the given hash and height matches any existing blocks 66 HasPropsal(hash common.Hash, number *big.Int) bool 67 68 // GetProposer returns the proposer of the given block height 69 GetProposer(number uint64) common.Address 70 71 // ParentValidators returns the validator set of the given proposal's parent block 72 ParentValidators(proposal Proposal) ValidatorSet 73 74 // HasBadProposal returns whether the block with the hash is a bad block 75 HasBadProposal(hash common.Hash) bool 76 77 Close() error 78 79 // StartQBFTConsensus stops existing legacy ibft consensus and starts the new qbft consensus 80 StartQBFTConsensus() error 81 }