github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/consensus/pbft/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 pbft 18 19 import ( 20 "math/big" 21 "time" 22 23 "github.com/bigzoro/my_simplechain/common" 24 "github.com/bigzoro/my_simplechain/consensus" 25 "github.com/bigzoro/my_simplechain/core/types" 26 "github.com/bigzoro/my_simplechain/event" 27 ) 28 29 // Backend provides application specific functions for Istanbul core 30 type Backend interface { 31 // Address returns the owner's address 32 Address() common.Address 33 34 // Validators returns the validator set 35 Validators(conclusion Conclusion) ValidatorSet 36 37 // EventMux returns the event mux in backend 38 EventMux() *event.TypeMux 39 40 // Post post a message 41 Post(payload []byte) 42 43 // Broadcast sends a message to other validators by router 44 Broadcast(valSet ValidatorSet, sender common.Address, payload []byte) error 45 46 // BroadcastMsg sends a message to specific validators 47 BroadcastMsg(ps map[common.Address]consensus.Peer, hash common.Hash, payload []byte) error 48 49 // Send a message to the specific validators 50 SendMsg(val Validators, payload []byte) error 51 52 // Guidance sends a message to other validators by router 53 Guidance(valSet ValidatorSet, sender common.Address, payload []byte) 54 55 // Gossip sends a message to all validators (exclude self) 56 Gossip(valSet ValidatorSet, payload []byte) 57 58 // GetForwardNodes returns peers of validators, and forward node addresses 59 GetForwardNodes(Validators) (map[common.Address]consensus.Peer, []common.Address) 60 61 // Commit delivers an approved proposal to backend. 62 // The delivered proposal will be put into blockchain. 63 Commit(proposal Conclusion, commitSeals [][]byte) error 64 65 // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, 66 // the time difference of the proposal and current time is also returned. 67 Verify(proposal Proposal, checkHeader, checkBody bool) (time.Duration, error) 68 69 // Execute a proposal by sealer 70 Execute(Proposal) (Conclusion, error) 71 72 // OnTimeout notify the sealer pbft on timeout event 73 OnTimeout() 74 75 // Fill a light proposal, return whether it is filled and missed transactions 76 FillLightProposal(proposal LightProposal) (bool, []types.MissedTx, error) 77 78 // MarkTransactionKnownBy mark transactions are known by validators, do not broadcast again 79 MarkTransactionKnownBy(val Validator, txs types.Transactions) 80 81 // Sign signs input data with the backend's private key 82 Sign([]byte) ([]byte, error) 83 84 // CheckSignature verifies the signature by checking if it's signed by 85 // the given validator 86 CheckSignature(data []byte, addr common.Address, sig []byte) error 87 88 // LastProposal retrieves latest committed proposal and the address of proposer 89 LastProposal() (Proposal, Conclusion, common.Address) 90 91 // HasProposal checks if the combination of the given hash and height matches any existing blocks 92 HasProposal(hash common.Hash, number *big.Int) (common.Hash, bool) 93 94 AnnounceCommittedProposal(hash common.Hash, number *big.Int, to Validator) 95 96 // GetProposer returns the proposer of the given block height 97 GetProposer(number uint64) common.Address 98 99 // ParentValidators returns the validator set of the given proposal's parent block 100 ParentValidators(proposal Proposal) ValidatorSet 101 102 // HasBadBlock returns whether the block with the hash is a bad block 103 HasBadProposal(hash common.Hash) bool 104 105 Close() error 106 }