github.com/Blockdaemon/celo-blockchain@v0.0.0-20200129231733-e667f6b08419/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  	blscrypto "github.com/ethereum/go-ethereum/crypto/bls"
    21  	"math/big"
    22  	"time"
    23  
    24  	"github.com/ethereum/go-ethereum/accounts"
    25  	"github.com/ethereum/go-ethereum/common"
    26  	"github.com/ethereum/go-ethereum/core/types"
    27  	"github.com/ethereum/go-ethereum/event"
    28  )
    29  
    30  // SignerFn is a signer callback function to request a hash to be signed by a
    31  // backing account.
    32  type SignerFn func(accounts.Account, []byte) ([]byte, error)
    33  
    34  // BLSSignerFn is a signer callback function to request a hash to be signed by a
    35  // backing account using BLS.
    36  type BLSSignerFn func(accounts.Account, []byte) (blscrypto.SerializedSignature, error)
    37  
    38  // MessageSignerFn is a signer callback function to request a raw message to
    39  // be signed by a backing account.
    40  type MessageSignerFn func(accounts.Account, []byte, []byte) (blscrypto.SerializedSignature, error)
    41  
    42  // Backend provides application specific functions for Istanbul core
    43  type Backend interface {
    44  	// Address returns the owner's address
    45  	Address() common.Address
    46  
    47  	// Validators returns the validator set
    48  	Validators(proposal Proposal) ValidatorSet
    49  	NextBlockValidators(proposal Proposal) (ValidatorSet, error)
    50  
    51  	// EventMux returns the event mux in backend
    52  	EventMux() *event.TypeMux
    53  
    54  	// BroadcastConsensusMsg sends a message to all validators (include self)
    55  	BroadcastConsensusMsg(validators []common.Address, payload []byte) error
    56  
    57  	// Gossip sends a message to all validators (exclude self)
    58  	Gossip(validators []common.Address, payload []byte, ethMsgCode uint64, ignoreCache bool) error
    59  
    60  	// Commit delivers an approved proposal to backend.
    61  	// The delivered proposal will be put into blockchain.
    62  	Commit(proposal Proposal, aggregatedSeal types.IstanbulAggregatedSeal, aggregatedEpochValidatorSetSeal types.IstanbulEpochValidatorSetSeal) error
    63  
    64  	// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
    65  	// the time difference of the proposal and current time is also returned.
    66  	Verify(Proposal) (time.Duration, error)
    67  
    68  	// Sign signs input data with the backend's private key
    69  	Sign([]byte) ([]byte, error)
    70  	SignBlockHeader([]byte) (blscrypto.SerializedSignature, error)
    71  	SignBLSWithCompositeHash([]byte) (blscrypto.SerializedSignature, error)
    72  
    73  	// CheckSignature verifies the signature by checking if it's signed by
    74  	// the given validator
    75  	CheckSignature(data []byte, addr common.Address, sig []byte) error
    76  
    77  	// GetCurrentHeadBlock retrieves the last block
    78  	GetCurrentHeadBlock() Proposal
    79  
    80  	// GetCurrentHeadBlockAndAuthor retrieves the last block alongside the author for that block
    81  	GetCurrentHeadBlockAndAuthor() (Proposal, common.Address)
    82  
    83  	// LastSubject retrieves latest committed subject (view and digest)
    84  	LastSubject() (Subject, error)
    85  
    86  	// HasBlock checks if the combination of the given hash and height matches any existing blocks
    87  	HasBlock(hash common.Hash, number *big.Int) bool
    88  
    89  	// AuthorForBlock returns the proposer of the given block height
    90  	AuthorForBlock(number uint64) common.Address
    91  
    92  	// ParentBlockValidators returns the validator set of the given proposal's parent block
    93  	ParentBlockValidators(proposal Proposal) ValidatorSet
    94  
    95  	// RefreshValPeers will connect with all the validators in the valset and disconnect validator peers that are not in the set
    96  	RefreshValPeers(valset ValidatorSet)
    97  
    98  	// Authorize injects a private key into the consensus engine.
    99  	Authorize(address common.Address, signFn SignerFn, signHashBLSFn BLSSignerFn, signMessageBLSFn MessageSignerFn)
   100  }