github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/consensus/dbft/backend.go (about) 1 package dbft 2 3 import ( 4 "math/big" 5 "time" 6 7 "github.com/quickchainproject/quickchain/common" 8 "github.com/quickchainproject/quickchain/event" 9 ) 10 11 // Backend provides application specific functions for BFT core 12 type Backend interface { 13 // Address returns the owner's address 14 Address() common.Address 15 16 // Validators returns the validator set 17 Validators(proposal Proposal) ValidatorSet 18 19 // EventMux returns the event mux in backend 20 EventMux() *event.TypeMux 21 22 // Broadcast sends a message to all validators (include self) 23 Broadcast(valSet ValidatorSet, payload []byte) error 24 25 // Gossip sends a message to all validators (exclude self) 26 Gossip(valSet ValidatorSet, payload []byte) error 27 28 // Commit delivers an approved proposal to backend. 29 // The delivered proposal will be put into blockchain. 30 Commit(proposal Proposal, seals [][]byte) error 31 32 // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, 33 // the time difference of the proposal and current time is also returned. 34 Verify(Proposal) (time.Duration, error) 35 36 // Sign signs input data with the backend's private key 37 Sign([]byte) ([]byte, error) 38 39 // CheckSignature verifies the signature by checking if it's signed by 40 // the given validator 41 CheckSignature(data []byte, addr common.Address, sig []byte) error 42 43 // LastProposal retrieves latest committed proposal and the address of proposer 44 LastProposal() (Proposal, common.Address) 45 46 // HasPropsal checks if the combination of the given hash and height matches any existing blocks 47 HasPropsal(hash common.Hash, number *big.Int) bool 48 49 // GetProposer returns the proposer of the given block height 50 GetProposer(number uint64) common.Address 51 52 // ParentValidators returns the validator set of the given proposal's parent block 53 ParentValidators(proposal Proposal) ValidatorSet 54 55 // HasBadBlock returns whether the block with the hash is a bad block 56 HasBadProposal(hash common.Hash) bool 57 }