backend

package
v0.3.0-doc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2019 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolName protocol name
	ProtocolName = "dpor"

	// ProtocolVersion protocol version
	ProtocolVersion = 65

	// ProtocolLength protocol length, max msg code
	ProtocolLength = 100
)
View Source
const (
	// PbftMsgOutset is not a msg code, just used for msg code comparing
	PbftMsgOutset = 0x42

	// NewSignerMsg is a msg code used for network building
	NewSignerMsg = 0x42

	// those are messages for normal block verification
	PreprepareBlockMsg = 0x43
	PrepareHeaderMsg   = 0x44
	CommitHeaderMsg    = 0x45
	ValidateBlockMsg   = 0x46

	// those are messages for abnormal(impeachment) block verification
	PreprepareImpeachBlockMsg = 0x47
	PrepareImpeachHeaderMsg   = 0x48
	CommitImpeachHeaderMsg    = 0x49
	ValidateImpeachBlockMsg   = 0x50
)

Protocol messages belonging to cpc/01

View Source
const (
	// ErrMsgTooLarge is returned if msg if too large
	ErrMsgTooLarge = iota

	// ErrDecode is returned if decode failed
	ErrDecode

	// ErrInvalidMsgCode is returned if msg code is invalid
	ErrInvalidMsgCode

	// ErrProtocolVersionMismatch is returned if protocol version is not matched when handshaking
	ErrProtocolVersionMismatch

	// ErrNetworkIDMismatch is returned if networkid is not matched when handshaking
	ErrNetworkIDMismatch

	// ErrGenesisBlockMismatch is returned if genesis block is different from remote signer
	ErrGenesisBlockMismatch

	// ErrNoStatusMsg is returned if failed when reading status msg
	ErrNoStatusMsg

	// ErrExtraStatusMsg is returned if failed when extracting status msg
	ErrExtraStatusMsg

	// ErrSuspendedPeer is returned if remote signer is dead
	ErrSuspendedPeer
)
View Source
const ProtocolMaxMsgSize = 10 * 1024 * 1024

ProtocolMaxMsgSize Maximum cap on the size of a protocol message

Variables

View Source
var (
	// ErrUnknownHandlerMode is returned if in an unknown mode
	ErrUnknownHandlerMode = errors.New("unknown dpor handler mode")

	// ErrFailToAddPendingBlock is returned if failed to add block to pending
	ErrFailToAddPendingBlock = errors.New("fail to add pending block")

	// ErrNotSigner is returned if i am not a signer when handshaking
	// with remote signer
	ErrNotSigner = errors.New("local peer is not in the PV committees")
)
View Source
var (
	ErrBlockAlreadyInChain = errors.New("the block is already in local chain")
	ErrMsgTooOld           = errors.New("the msg is outdated")
	ErrInvalidBlockFormat  = errors.New("the block format is invalid")
	ErrInvalidHeaderFormat = errors.New("the header format is invalid")
)

errors returned by fsm

Functions

func Handshake

func Handshake(p *p2p.Peer, rw p2p.MsgReadWriter, mac string, sig []byte, term uint64, futureTerm uint64) (address common.Address, err error)

Handshake tries to handshake with remote validator

func IsCheckPoint added in v0.3.1

func IsCheckPoint(number uint64, termLen uint64, viewLen uint64) bool

IsCheckPoint returns if a given block number is in a checkpoint with given termLen and viewLen

func IsDefaultValidator added in v0.3.1

func IsDefaultValidator(nodeID string, defaultValidators []string) bool

IsDefaultValidator checks if a validator is a default validator

func IsDporMsg

func IsDporMsg(msg p2p.Msg) bool

IsDporMsg checks if msg is a dpor related msg

func IsSyncMsg

func IsSyncMsg(msg p2p.Msg) bool

IsSyncMsg checks if msg is a sync msg

func ReadSignerStatus added in v0.3.1

func ReadSignerStatus(msg p2p.Msg, signerStatusData *SignerStatusData) (address common.Address, err error)

ReadSignerStatus reads status of remote validator

func RecoverBlockFromMsg

func RecoverBlockFromMsg(msg p2p.Msg, p interface{}) (*types.Block, error)

RecoverBlockFromMsg recovers a block from a p2p msg

func RecoverHeaderFromMsg

func RecoverHeaderFromMsg(msg p2p.Msg, p interface{}) (*types.Header, error)

RecoverHeaderFromMsg recovers a header from a p2p msg

func TermOf added in v0.3.1

func TermOf(blockNum uint64) uint64

TermOf returns the term index of given block number

func ValidMacSig

func ValidMacSig(mac string, sig []byte) (valid bool, signer common.Address, err error)

ValidMacSig recovers an address from a signed mac

Types

type Action

type Action uint8

Action is type enumerator for FSM action

const (
	NoAction Action = iota
	BroadcastMsgAction
	BroadcastAndInsertBlockAction
)

Those actions are the result after handleMsg returned

type BlockIdentifier added in v0.3.1

type BlockIdentifier struct {
	// contains filtered or unexported fields
}

BlockIdentifier is the identifier to a block

func NewBlockIdentifier added in v0.3.1

func NewBlockIdentifier(number uint64, hash common.Hash) BlockIdentifier

NewBlockIdentifier creates a block identifier with given block number and hash

type BlockOrHeader added in v0.3.1

type BlockOrHeader struct {
	// contains filtered or unexported fields
}

BlockOrHeader represents a block or a header

func NewBOHFromBlock added in v0.3.1

func NewBOHFromBlock(block *types.Block) *BlockOrHeader

NewBOHFromBlock creates a new BlockOrHeader from a block

func NewBOHFromHeader added in v0.3.1

func NewBOHFromHeader(header *types.Header) *BlockOrHeader

NewBOHFromHeader creates a new BlockOrHeader from a header

func (*BlockOrHeader) Hash added in v0.3.1

func (bh *BlockOrHeader) Hash() common.Hash

Hash returns hash of the boh

func (*BlockOrHeader) IsBlock added in v0.3.1

func (bh *BlockOrHeader) IsBlock() bool

IsBlock checks if the boh is a block

func (*BlockOrHeader) IsHeader added in v0.3.1

func (bh *BlockOrHeader) IsHeader() bool

IsHeader checks if the boh is a header

func (*BlockOrHeader) Number added in v0.3.1

func (bh *BlockOrHeader) Number() uint64

Number returns number of the boh

type ChainBackend

type ChainBackend interface {
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
}

ChainBackend is the chain client operation interface

type ClientBackend

type ClientBackend interface {
	ChainBackend
	ContractBackend
}

ClientBackend is the client operation interface

type ConsensusStateMachine added in v0.3.1

type ConsensusStateMachine interface {
	Status() DSMStatus
	Faulty() uint64
	FSM(input *BlockOrHeader, msgCode MsgCode) ([]*BlockOrHeader, Action, MsgCode, error)
}

ConsensusStateMachine is a state machine used for consensus protocol for validators msg processing

type ContractBackend

type ContractBackend interface {
	bind.ContractBackend
}

ContractBackend is the contract client operation interface

type ContractCaller

type ContractCaller struct {
	Key    *keystore.Key
	Client ClientBackend

	GasLimit uint64
}

ContractCaller is used to call the contract with given key and client. TODO: remove this later

func NewContractCaller

func NewContractCaller(key *keystore.Key, client ClientBackend, gasLimit uint64) (*ContractCaller, error)

NewContractCaller returns a ContractCaller.

type DSMStatus added in v0.3.1

type DSMStatus struct {
	Number uint64
	// TODO: i need hash here
	State consensus.State
}

DSMStatus represents a Dpor State Machine Status

type Dialer

type Dialer struct {
	// contains filtered or unexported fields
}

Dialer dials a remote peer

func NewDialer

func NewDialer() *Dialer

NewDialer creates a new dialer to dial remote peers

func (*Dialer) AddPeer

func (d *Dialer) AddPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter, mac string, sig []byte, term uint64, futureTerm uint64) (string, bool, bool, error)

AddPeer adds a peer to local dpor peer set: remote proposers or remote validators

func (*Dialer) AllUselessProposers added in v0.3.1

func (d *Dialer) AllUselessProposers() map[common.Address]*RemoteProposer

AllUselessProposers returns all useless proposers

func (*Dialer) EnoughImpeachValidatorsOfTerm added in v0.3.1

func (d *Dialer) EnoughImpeachValidatorsOfTerm(term uint64) (validators map[common.Address]*RemoteValidator, enough bool)

EnoughImpeachValidatorsOfTerm returns validator of given term and whether it is enough for impeach

func (*Dialer) EnoughValidatorsOfTerm added in v0.3.1

func (d *Dialer) EnoughValidatorsOfTerm(term uint64) (validators map[common.Address]*RemoteValidator, enough bool)

EnoughValidatorsOfTerm returns validator of given term and whether it is enough

func (*Dialer) KeepConnection added in v0.3.1

func (d *Dialer) KeepConnection()

KeepConnection tries to dial remote validators if local node is a current or future proposer and disconnect remote validators if it is not

func (*Dialer) ProposersOfTerm

func (d *Dialer) ProposersOfTerm(term uint64) map[common.Address]*RemoteProposer

ProposersOfTerm returns all proposers of given term

func (*Dialer) SetDporService

func (d *Dialer) SetDporService(dpor DporService)

SetDporService sets dpor service to dialer

func (*Dialer) SetServer

func (d *Dialer) SetServer(server *p2p.Server)

SetServer sets dialer.server

func (*Dialer) Stop added in v0.3.1

func (d *Dialer) Stop()

func (*Dialer) UpdateRemoteProposers

func (d *Dialer) UpdateRemoteProposers(term uint64, proposers []common.Address) error

UpdateRemoteProposers updates dialer.remoteProposers.

func (*Dialer) ValidatorsOfTerm

func (d *Dialer) ValidatorsOfTerm(term uint64) map[common.Address]*RemoteValidator

ValidatorsOfTerm returns all validators of given term

type DporService

type DporService interface {

	// Coinbase returns current coinbase
	Coinbase() common.Address

	// TermLength returns term length
	TermLength() uint64

	// Faulty returns the number of faulty nodes
	Faulty() uint64

	// ViewLength returns view length
	ViewLength() uint64

	// ValidatorsNum returns number of validators
	ValidatorsNum() uint64

	// Period returns period of block generation
	Period() time.Duration

	// BlockDelay returns max delay of preprepare block propagation
	BlockDelay() time.Duration

	// TermOf returns the term number of given block number
	TermOf(number uint64) uint64

	// FutureTermOf returns the future term number of given block number
	FutureTermOf(number uint64) uint64

	// VerifyProposerOf verifies if an address is a proposer of given term
	VerifyProposerOf(signer common.Address, term uint64) (bool, error)

	// VerifyValidatorOf verifies if an address is a validator of given term
	VerifyValidatorOf(signer common.Address, term uint64) (bool, error)

	// ValidatorsOf returns the list of validators in committee for the specified block number
	ValidatorsOf(number uint64) ([]common.Address, error)

	// ProposersOf returns the list of proposers in committee for the specified block number
	ProposersOf(number uint64) ([]common.Address, error)

	// ProposerOf returns the proposer of the specified block number by rpt and election calculation
	ProposerOf(number uint64) (common.Address, error)

	// ValidatorsOfTerm returns the list of validators in committee for the specified term
	ValidatorsOfTerm(term uint64) ([]common.Address, error)

	// ProposersOfTerm returns the list of proposers in committee for the specified term
	ProposersOfTerm(term uint64) ([]common.Address, error)

	// VerifyHeaderWithState verifies the given header
	// if in preprepared state, verify basic fields
	// if in prepared state, verify if enough prepare sigs
	// if in committed state, verify if enough commit sigs
	VerifyHeaderWithState(header *types.Header, state consensus.State) error

	// ValidateBlock verifies a block
	ValidateBlock(block *types.Block, verifySigs bool, verifyProposers bool) error

	// SignHeader signs the block if not signed it yet
	SignHeader(header *types.Header, state consensus.State) error

	// BroadcastBlock broadcasts a block to normal peers(not pbft replicas)
	BroadcastBlock(block *types.Block, prop bool)

	// InsertChain inserts a block to chain
	InsertChain(block *types.Block) error

	// Status returns a pbft replica's status
	Status() *consensus.PbftStatus

	// StatusUpdate updates status of dpor
	StatusUpdate() error

	// CreateImpeachBlock returns an impeachment block
	CreateImpeachBlock() (*types.Block, error)

	// CreateFailbackImpeachBlocks creates impeachment blocks with failback timestamps
	CreateFailbackImpeachBlocks() (firstImpeachment *types.Block, secondImpeachment *types.Block, err error)

	// GetCurrentBlock returns current block
	GetCurrentBlock() *types.Block

	// HasBlockInChain returns if a block is in local chain
	HasBlockInChain(hash common.Hash, number uint64) bool

	// GetBlockFromChain returns a block from local chain with given hash and number
	GetBlockFromChain(hash common.Hash, number uint64) *types.Block

	// ImpeachTimeout returns the timeout for impeachment
	ImpeachTimeout() time.Duration

	// ECRecoverProposer recovers proposer's address from a seal of a header
	ECRecoverProposer(header *types.Header) (common.Address, error)

	// ECRecoverSigs recovers signer address and corresponding signature, it ignores empty signature and return empty
	// addresses if one of the sigs are illegal
	ECRecoverSigs(header *types.Header, state consensus.State) ([]common.Address, []types.DporSignature, error)

	// Update the signature to prepare signature cache(two kinds of sigs, one for prepared, another for final)
	UpdatePrepareSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature)

	// Update the signature to final signature cache(two kinds of sigs, one for prepared, another for final)
	UpdateFinalSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature)

	// GetMac signs a Mac
	GetMac() (string, []byte, error)

	// SyncFrom tries to sync block from given peer
	SyncFrom(p *p2p.Peer)

	// Synchronize tries to sync block from best peer
	Synchronize()
}

DporService provides functions used by dpor handler

type HandleGeneratedImpeachBlock added in v0.3.1

type HandleGeneratedImpeachBlock func(block *types.Block) error

HandleGeneratedImpeachBlock handles generated impeach block

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler implements PbftHandler

func NewHandler

func NewHandler(config *configs.DporConfig, coinbase common.Address, db database.Database) *Handler

NewHandler creates a new Handler

func (*Handler) AddPeer

func (h *Handler) AddPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) (string, bool, bool, error)

AddPeer adds a p2p peer to local peer set

func (*Handler) Available

func (h *Handler) Available() bool

Available returns if handler is available

func (*Handler) BroadcastCommitHeader

func (h *Handler) BroadcastCommitHeader(header *types.Header)

BroadcastCommitHeader broadcasts signed commit header to remote validators

func (*Handler) BroadcastCommitImpeachHeader

func (h *Handler) BroadcastCommitImpeachHeader(header *types.Header)

BroadcastCommitImpeachHeader broadcasts signed impeach commit header to remote validators

func (*Handler) BroadcastPrepareHeader

func (h *Handler) BroadcastPrepareHeader(header *types.Header)

BroadcastPrepareHeader broadcasts signed prepare header to remote validators

func (*Handler) BroadcastPrepareImpeachHeader

func (h *Handler) BroadcastPrepareImpeachHeader(header *types.Header)

BroadcastPrepareImpeachHeader broadcasts signed impeach prepare header to remote validators

func (*Handler) BroadcastPreprepareBlock

func (h *Handler) BroadcastPreprepareBlock(block *types.Block)

BroadcastPreprepareBlock broadcasts generated block to validators

func (*Handler) BroadcastPreprepareImpeachBlock

func (h *Handler) BroadcastPreprepareImpeachBlock(block *types.Block)

BroadcastPreprepareImpeachBlock broadcasts generated impeach block to validators

func (*Handler) BroadcastValidateBlock added in v0.3.1

func (h *Handler) BroadcastValidateBlock(block *types.Block)

BroadcastValidateBlock broadcasts validate block to validators

func (*Handler) BroadcastValidateImpeachBlock added in v0.3.1

func (h *Handler) BroadcastValidateImpeachBlock(block *types.Block)

BroadcastValidateImpeachBlock broadcasts validate impeach block to validators

func (*Handler) Coinbase

func (h *Handler) Coinbase() common.Address

Coinbase returns handler.signer

func (*Handler) GetProtocol

func (h *Handler) GetProtocol() consensus.Protocol

GetProtocol returns handler protocol

func (*Handler) HandleMsg

func (h *Handler) HandleMsg(addr string, version int, p *p2p.Peer, rw p2p.MsgReadWriter, msg p2p.Msg) (string, error)

HandleMsg handles a msg of peer with id "addr"

func (*Handler) Length

func (h *Handler) Length() uint64

Length returns protocol max msg code

func (*Handler) Name

func (h *Handler) Name() string

Name returns protocol name

func (*Handler) NodeInfo

func (h *Handler) NodeInfo() interface{}

NodeInfo returns node status

func (*Handler) PendingBlockBroadcastLoop

func (h *Handler) PendingBlockBroadcastLoop()

PendingBlockBroadcastLoop loops to broadcast blocks

func (*Handler) PendingImpeachBlockBroadcastLoop added in v0.3.1

func (h *Handler) PendingImpeachBlockBroadcastLoop()

PendingImpeachBlockBroadcastLoop loops to broadcasts pending impeachment block

func (*Handler) ProposerBroadcastPreprepareBlock added in v0.3.1

func (h *Handler) ProposerBroadcastPreprepareBlock(block *types.Block)

ProposerBroadcastPreprepareBlock broadcasts generated block to validators

func (*Handler) ReceiveImpeachPendingBlock

func (vh *Handler) ReceiveImpeachPendingBlock(block *types.Block) error

ReceiveImpeachPendingBlock receives a block to add to pending block channel

func (*Handler) ReceiveMinedPendingBlock

func (ph *Handler) ReceiveMinedPendingBlock(block *types.Block) error

ReceiveMinedPendingBlock receives a block to add to pending block channel

func (*Handler) RemovePeer

func (h *Handler) RemovePeer(addr string)

RemovePeer removes a p2p peer with its addr

func (*Handler) SetAvailable

func (h *Handler) SetAvailable()

SetAvailable sets available

func (*Handler) SetCoinbase

func (h *Handler) SetCoinbase(coinbase common.Address)

SetCoinbase sets coinbase of handler

func (*Handler) SetDporService

func (h *Handler) SetDporService(dpor DporService)

SetDporService sets dpor service to handler

func (*Handler) SetDporStateMachine

func (h *Handler) SetDporStateMachine(fsm ConsensusStateMachine)

SetDporStateMachine sets dpor state machine

func (*Handler) SetServer

func (h *Handler) SetServer(server *p2p.Server)

SetServer sets dialer.server

func (*Handler) Start

func (h *Handler) Start()

Start starts handler

func (*Handler) Stop

func (h *Handler) Stop()

Stop stops all

func (*Handler) Version

func (h *Handler) Version() uint

Version returns protocol version

type HandlerMode

type HandlerMode int

HandlerMode indicates the run mode of handler

const (
	LBFTMode HandlerMode = iota
	LBFT2Mode
)

Those are handler mode

type LBFT added in v0.3.1

type LBFT struct {
	// contains filtered or unexported fields
}

LBFT is the 1.0 version for lbft protocol within validator committee

func NewLBFT added in v0.3.1

func NewLBFT(handler *Handler) *LBFT

NewLBFT creates an LBFT instance

func (*LBFT) Handle added in v0.3.1

func (l *LBFT) Handle(msg p2p.Msg, p *RemoteSigner) error

Handle handles a msg from remote peer(proposer or validator)

type LBFT2 added in v0.3.1

type LBFT2 struct {
	// contains filtered or unexported fields
}

LBFT2 is a state machine used for consensus protocol for validators msg processing

func NewLBFT2 added in v0.3.1

func NewLBFT2(faulty uint64, dpor DporService, handleImpeachBlock HandleGeneratedImpeachBlock, db database.Database) *LBFT2

NewLBFT2 create an LBFT2 instance

func (*LBFT2) CommitHandler added in v0.3.1

func (p *LBFT2) CommitHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

CommitHandler is the handler for Commit state

func (*LBFT2) FSM added in v0.3.1

func (p *LBFT2) FSM(input *BlockOrHeader, msgCode MsgCode) ([]*BlockOrHeader, Action, MsgCode, error)

FSM implements ConsensusStateMachine.FSM

func (*LBFT2) Faulty added in v0.3.1

func (p *LBFT2) Faulty() uint64

Faulty returns the number of faulty nodes

func (*LBFT2) IdleHandler added in v0.3.1

func (p *LBFT2) IdleHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

IdleHandler is the handler for Idle state

func (*LBFT2) ImpeachCommitHandler added in v0.3.1

func (p *LBFT2) ImpeachCommitHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

ImpeachCommitHandler is the handler for ImpeachCommit state

func (*LBFT2) ImpeachHandler added in v0.3.1

func (p *LBFT2) ImpeachHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

ImpeachHandler is the handler for all impeachment related msg

func (*LBFT2) ImpeachPrepareHandler added in v0.3.1

func (p *LBFT2) ImpeachPrepareHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

ImpeachPrepareHandler is the handler for ImpeachPrepare state

func (*LBFT2) Number added in v0.3.1

func (p *LBFT2) Number() uint64

Number returns current number

func (*LBFT2) PrepareHandler added in v0.3.1

func (p *LBFT2) PrepareHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

PrepareHandler is the handler for Prepare state

func (*LBFT2) SetNumber added in v0.3.1

func (p *LBFT2) SetNumber(number uint64)

SetNumber sets number of the state machine

func (*LBFT2) SetState added in v0.3.1

func (p *LBFT2) SetState(state consensus.State)

SetState sets state of the state machine

func (*LBFT2) State added in v0.3.1

func (p *LBFT2) State() consensus.State

State returns current state

func (*LBFT2) Status added in v0.3.1

func (p *LBFT2) Status() DSMStatus

Status returns current states

func (*LBFT2) ValidateHandler added in v0.3.1

func (p *LBFT2) ValidateHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)

ValidateHandler is the handler for bot Validate state and ImpeachValidate state

type MsgCode

type MsgCode uint8

MsgCode is type enumerator for FSM message type

const (
	NoMsgCode MsgCode = iota

	PreprepareMsgCode
	PrepareMsgCode
	CommitMsgCode
	PrepareAndCommitMsgCode
	ValidateMsgCode

	ImpeachPreprepareMsgCode
	ImpeachPrepareMsgCode
	ImpeachCommitMsgCode
	ImpeachPrepareAndCommitMsgCode
	ImpeachValidateMsgCode
)

Those are msg codes used in fsm

func (MsgCode) String added in v0.3.1

func (mc MsgCode) String() string

type RecentBlocks

type RecentBlocks struct {
	// contains filtered or unexported fields
}

RecentBlocks caches recent received blocks

func NewRecentBlocks added in v0.3.1

func NewRecentBlocks(db database.Database) *RecentBlocks

NewRecentBlocks creates a new block cache object

func (*RecentBlocks) AddBlock

func (rb *RecentBlocks) AddBlock(block *types.Block) error

AddBlock adds a block to caches

func (*RecentBlocks) GetBlock

func (rb *RecentBlocks) GetBlock(bi BlockIdentifier) (*types.Block, error)

GetBlock returns a block with given block identifier

func (*RecentBlocks) GetBlockIdentifiers added in v0.3.1

func (rb *RecentBlocks) GetBlockIdentifiers() []BlockIdentifier

GetBlockIdentifiers returns a slice of block identifiers in this cache

func (*RecentBlocks) RemoveBlock added in v0.3.1

func (rb *RecentBlocks) RemoveBlock(bi BlockIdentifier) error

RemoveBlock removes a block from caches

type RemoteProposer

type RemoteProposer struct {
	*RemoteSigner
}

RemoteProposer represents a remote proposer waiting to be connected.

func NewRemoteProposer

func NewRemoteProposer(address common.Address) *RemoteProposer

NewRemoteProposer creates a new remote proposer

type RemoteSigner

type RemoteSigner struct {
	*p2p.Peer
	// contains filtered or unexported fields
}

RemoteSigner represents a remote peer, ether proposer or validator

func NewRemoteSigner

func NewRemoteSigner(address common.Address) *RemoteSigner

NewRemoteSigner creates a new remote signer

func (*RemoteSigner) AddStatic

func (s *RemoteSigner) AddStatic(srv *p2p.Server) error

AddStatic adds remote validator as a static peer

func (*RemoteSigner) Coinbase

func (s *RemoteSigner) Coinbase() common.Address

Coinbase returns remote peer's addr

func (*RemoteSigner) EnodeID added in v0.3.1

func (s *RemoteSigner) EnodeID() string

EnodeID returns remote signer's enode id

func (*RemoteSigner) SetPeer

func (s *RemoteSigner) SetPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter)

SetPeer sets a p2p peer

type RemoteValidator

type RemoteValidator struct {
	*RemoteSigner
	// contains filtered or unexported fields
}

RemoteValidator represents a remote signer waiting to be connected and communicate with.

func NewRemoteValidator

func NewRemoteValidator(address common.Address) *RemoteValidator

NewRemoteValidator creates a new NewRemoteValidator with given view idx and address.

func (*RemoteValidator) AsyncSendCommitHeader

func (s *RemoteValidator) AsyncSendCommitHeader(header *types.Header)

AsyncSendCommitHeader sends new signed block header.

func (*RemoteValidator) AsyncSendCommitImpeachHeader

func (s *RemoteValidator) AsyncSendCommitImpeachHeader(header *types.Header)

AsyncSendCommitImpeachHeader sends new signed block header.

func (*RemoteValidator) AsyncSendImpeachValidateBlock added in v0.3.1

func (s *RemoteValidator) AsyncSendImpeachValidateBlock(block *types.Block)

AsyncSendImpeachValidateBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*RemoteValidator) AsyncSendPrepareHeader

func (s *RemoteValidator) AsyncSendPrepareHeader(header *types.Header)

AsyncSendPrepareHeader adds a msg to broadcast channel

func (*RemoteValidator) AsyncSendPrepareImpeachHeader

func (s *RemoteValidator) AsyncSendPrepareImpeachHeader(header *types.Header)

AsyncSendPrepareImpeachHeader adds a msg to broadcast channel

func (*RemoteValidator) AsyncSendPreprepareBlock

func (s *RemoteValidator) AsyncSendPreprepareBlock(block *types.Block)

AsyncSendPreprepareBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*RemoteValidator) AsyncSendPreprepareImpeachBlock

func (s *RemoteValidator) AsyncSendPreprepareImpeachBlock(block *types.Block)

AsyncSendPreprepareImpeachBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*RemoteValidator) AsyncSendValidateBlock added in v0.3.1

func (s *RemoteValidator) AsyncSendValidateBlock(block *types.Block)

AsyncSendValidateBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*RemoteValidator) SendCommitHeader

func (s *RemoteValidator) SendCommitHeader(header *types.Header) error

SendCommitHeader sends new signed block header.

func (*RemoteValidator) SendCommitImpeachHeader

func (s *RemoteValidator) SendCommitImpeachHeader(header *types.Header) error

SendCommitImpeachHeader sends new signed block header.

func (*RemoteValidator) SendImpeachValidateBlock added in v0.3.1

func (s *RemoteValidator) SendImpeachValidateBlock(block *types.Block) error

SendImpeachValidateBlock propagates an entire block to a remote peer.

func (*RemoteValidator) SendNewSignerMsg

func (s *RemoteValidator) SendNewSignerMsg(eb common.Address) error

SendNewSignerMsg sends a

func (*RemoteValidator) SendPrepareHeader

func (s *RemoteValidator) SendPrepareHeader(header *types.Header) error

SendPrepareHeader sends new signed block header.

func (*RemoteValidator) SendPrepareImpeachHeader

func (s *RemoteValidator) SendPrepareImpeachHeader(header *types.Header) error

SendPrepareImpeachHeader sends new signed block header.

func (*RemoteValidator) SendPreprepareBlock

func (s *RemoteValidator) SendPreprepareBlock(block *types.Block) error

SendPreprepareBlock propagates an entire block to a remote peer.

func (*RemoteValidator) SendPreprepareImpeachBlock

func (s *RemoteValidator) SendPreprepareImpeachBlock(block *types.Block) error

SendPreprepareImpeachBlock propagates an entire block to a remote peer.

func (*RemoteValidator) SendValidateBlock added in v0.3.1

func (s *RemoteValidator) SendValidateBlock(block *types.Block) error

SendValidateBlock propagates an entire block to a remote peer.

type SignFn

type SignFn func(accounts.Account, []byte) ([]byte, error)

SignFn is a signer callback function to request a hash to be signed by a backing account.

type SignerStatusData

type SignerStatusData struct {
	ProtocolVersion uint32
	Mac             string
	Sig             []byte
}

SignerStatusData represents signer status when handshaking

type VerifyBlockFn added in v0.3.1

type VerifyBlockFn func(block *types.Block) error

VerifyBlockFn verifies basic fields of a block

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL