github.com/zjj1991/quorum@v0.0.0-20190524123704-ae4b0a1e1a19/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/ethereum/go-ethereum/common"
    24  	"github.com/ethereum/go-ethereum/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, payload []byte) error
    40  
    41  	// Gossip sends a message to all validators (exclude self)
    42  	Gossip(valSet ValidatorSet, 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) 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  	// CheckSignature verifies the signature by checking if it's signed by
    56  	// the given validator
    57  	CheckSignature(data []byte, addr common.Address, sig []byte) error
    58  
    59  	// LastProposal retrieves latest committed proposal and the address of proposer
    60  	LastProposal() (Proposal, common.Address)
    61  
    62  	// HasPropsal checks if the combination of the given hash and height matches any existing blocks
    63  	HasPropsal(hash common.Hash, number *big.Int) bool
    64  
    65  	// GetProposer returns the proposer of the given block height
    66  	GetProposer(number uint64) common.Address
    67  
    68  	// ParentValidators returns the validator set of the given proposal's parent block
    69  	ParentValidators(proposal Proposal) ValidatorSet
    70  
    71  	// HasBadBlock returns whether the block with the hash is a bad block
    72  	HasBadProposal(hash common.Hash) bool
    73  
    74  	Close() error
    75  }