istanbul

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: GPL-3.0, GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorizedAddress is returned when given address cannot be found in
	// current validator set.
	ErrUnauthorizedAddress = errors.New("unauthorized address")
	// ErrStoppedEngine is returned if the engine is stopped
	ErrStoppedEngine = errors.New("stopped engine")
	// ErrStartedEngine is returned if the engine is already started
	ErrStartedEngine = errors.New("started engine")
)
View Source
var DefaultConfig = &Config{
	RequestTimeout: 10000,
	BlockPeriod:    1,
	ProposerPolicy: RoundRobin,
	Epoch:          30000,
	Deployer:       common.HexToAddress("0x1336000000000000000000000000000000000000"),
	Bytecode:       "608060405234801561001057600080fd5b506040516107843803806107848339810180604052610032919081019061012c565b60005b8151811015610093576000828281518110151561004e57fe5b6020908102919091018101518254600180820185556000948552929093209092018054600160a060020a031916600160a060020a039093169290921790915501610035565b50506101ba565b60006100a682516101ae565b9392505050565b6000601f820183136100be57600080fd5b81516100d16100cc8261018e565b610168565b915081818352602084019350602081019050838560208402820111156100f657600080fd5b60005b83811015610122578161010c888261009a565b84525060209283019291909101906001016100f9565b5050505092915050565b60006020828403121561013e57600080fd5b81516001604060020a0381111561015457600080fd5b610160848285016100ad565b949350505050565b6040518181016001604060020a038111828210171561018657600080fd5b604052919050565b60006001604060020a038211156101a457600080fd5b5060209081020190565b600160a060020a031690565b6105bb806101c96000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631af60f72811461006657806335aa2e44146100885780636a7a7b9e146100be578063b7ab4db5146100de575b600080fd5b34801561007257600080fd5b5061008661008136600461045c565b610100565b005b34801561009457600080fd5b506100a86100a3366004610482565b61027e565b6040516100b59190610536565b60405180910390f35b3480156100ca57600080fd5b506100866100d936600461045c565b6102a6565b3480156100ea57600080fd5b506100f3610393565b6040516100b5919061054a565b60003381805b6000548110156101555782600160a060020a031660008281548110151561012957fe5b600091825260209091200154600160a060020a0316141561014d5760019150610155565b600101610106565b811515610197576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161018e9061055b565b60405180910390fd5b6000546001106101a657600080fd5b600093505b6000548410156102775784600160a060020a03166000858154811015156101ce57fe5b600091825260209091200154600160a060020a0316141561026c576000805460001981019081106101fb57fe5b60009182526020822001548154600160a060020a0390911691908690811061021f57fe5b60009182526020822001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0393909316929092179091558054906102669060001983016103f6565b50610277565b6001909301926101ab565b5050505050565b600080548290811061028c57fe5b600091825260209091200154600160a060020a0316905081565b336000805b6000548110156102fa5782600160a060020a03166000828154811015156102ce57fe5b600091825260209091200154600160a060020a031614156102f257600191506102fa565b6001016102ab565b811515610333576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161018e9061055b565b5050600080546001810182559080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03939093169290921790915550565b606060008054806020026020016040519081016040528092919081815260200182805480156103eb57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116103cd575b505050505090505b90565b81548183558181111561041a5760008381526020902061041a91810190830161041f565b505050565b6103f391905b808211156104395760008155600101610425565b5090565b60006104498235610575565b9392505050565b600061044982356103f3565b60006020828403121561046e57600080fd5b600061047a848461043d565b949350505050565b60006020828403121561049457600080fd5b600061047a8484610450565b6104a981610575565b82525050565b60006104ba82610571565b8084526020840193506104cc8361056b565b60005b828110156104fc576104e28683516104a0565b6104eb8261056b565b6020969096019591506001016104cf565b5093949350505050565b601881527f566f746572206973206e6f7420612076616c696461746f720000000000000000602082015260400190565b6020810161054482846104a0565b92915050565b6020808252810161044981846104af565b6020808252810161054481610506565b60200190565b5190565b600160a060020a0316905600a265627a7a723058205f81cd52dd12f18b7f19e75d72d9de5854ba26340f120c54ee2982235f7b56826c6578706572696d656e74616cf50037",
	ABI:            `[{"constant":false,"inputs":[{"name":"_validator","type":"address"}],"name":"RemoveValidator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"validators","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_validator","type":"address"}],"name":"AddValidator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getValidators","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_validators","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]`,
}

Functions

func CheckValidatorSignature

func CheckValidatorSignature(valSet ValidatorSet, data []byte, sig []byte) (common.Address, error)

Types

type Backend

type Backend interface {
	// Address returns the owner's address
	Address() common.Address

	// Validators returns the validator set
	Validators(number uint64) ValidatorSet

	// EventMux returns the event mux in backend
	EventMux() *event.TypeMux

	// Broadcast sends a message to all validators (include self)
	Broadcast(valSet ValidatorSet, payload []byte) error

	// Gossip sends a message to all validators (exclude self)
	Gossip(valSet ValidatorSet, payload []byte) error

	// Commit delivers an approved proposal to backend.
	// The delivered proposal will be put into blockchain.
	Commit(proposal Proposal, seals [][]byte) error

	// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
	// the time difference of the proposal and current time is also returned.
	Verify(Proposal) (time.Duration, error)

	// Sign signs input data with the backend's private key
	Sign([]byte) ([]byte, error)

	// CheckSignature verifies the signature by checking if it's signed by
	// the given validator
	CheckSignature(data []byte, addr common.Address, sig []byte) error

	// LastProposal retrieves latest committed proposal and the address of proposer
	LastProposal() (Proposal, common.Address)

	// HasPropsal checks if the combination of the given hash and height matches any existing blocks
	HasPropsal(hash common.Hash, number *big.Int) bool

	// GetProposer returns the proposer of the given block height
	GetProposer(number uint64) common.Address

	// HasBadBlock returns whether the block with the hash is a bad block
	HasBadProposal(hash common.Hash) bool

	// Setter for proposed block hash
	SetProposedBlockHash(hash common.Hash)
}

Backend provides application specific functions for Istanbul core

type Config

type Config struct {
	RequestTimeout uint64         `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
	BlockPeriod    uint64         `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
	ProposerPolicy ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
	Epoch          uint64         `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
	Deployer       common.Address `toml:",omitempty"` // Address of the validator who deploys contract stored in bytecode
	Bytecode       string         `toml:",omitempty"` // Bytecode of validators contract // would like this type to be []byte but the unmarshalling is not working
	ABI            string         `toml:",omitempty"` // Json ABI of the contract

	sync.RWMutex
}

func (*Config) GetProposerPolicy

func (cfg *Config) GetProposerPolicy() ProposerPolicy

func (*Config) SetProposerPolicy

func (cfg *Config) SetProposerPolicy(p ProposerPolicy)

type FinalCommittedEvent

type FinalCommittedEvent struct {
}

FinalCommittedEvent is posted when a proposal is committed

type MessageEvent

type MessageEvent struct {
	Payload []byte
}

MessageEvent is posted for Istanbul engine communication

type Preprepare

type Preprepare struct {
	View     *View
	Proposal Proposal
}

func (*Preprepare) DecodeRLP

func (b *Preprepare) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Preprepare) EncodeRLP

func (b *Preprepare) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

type Proposal

type Proposal interface {
	// Number retrieves the sequence number of this proposal.
	Number() *big.Int

	// Hash retrieves the hash of this proposal.
	Hash() common.Hash

	EncodeRLP(w io.Writer) error

	DecodeRLP(s *rlp.Stream) error
}

ProposalBlock supports retrieving height and serialized block to be used during Istanbul consensus.

type ProposalSelector

type ProposalSelector func(ValidatorSet, common.Address, uint64) Validator

type ProposerPolicy

type ProposerPolicy uint64
const (
	RoundRobin ProposerPolicy = iota
	Sticky
)

type Request

type Request struct {
	Proposal Proposal
}

type RequestEvent

type RequestEvent struct {
	Proposal Proposal
}

RequestEvent is posted to propose a proposal

type Subject

type Subject struct {
	View   *View
	Digest common.Hash
}

func (*Subject) DecodeRLP

func (b *Subject) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Subject) EncodeRLP

func (b *Subject) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*Subject) String

func (b *Subject) String() string

type Validator

type Validator interface {
	// Address returns address
	Address() common.Address

	// String representation of Validator
	String() string
}

type ValidatorSet

type ValidatorSet interface {
	// Calculate the proposer
	CalcProposer(lastProposer common.Address, round uint64)
	// Return the validator size
	Size() int
	// Return the validator array
	List() []Validator
	// Get validator by index
	GetByIndex(i uint64) Validator
	// Get validator by given address
	GetByAddress(addr common.Address) (int, Validator)
	// Get current proposer
	GetProposer() Validator
	// Check whether the validator with given address is a proposer
	IsProposer(address common.Address) bool
	// Add validator
	AddValidator(address common.Address) bool
	// Remove validator
	RemoveValidator(address common.Address) bool
	// Copy validator set
	Copy() ValidatorSet
	// Get the maximum number of faulty nodes
	F() int
	// Get proposer policy
	Policy() ProposerPolicy
}

type Validators

type Validators []Validator

func (Validators) Len

func (slice Validators) Len() int

func (Validators) Less

func (slice Validators) Less(i, j int) bool

func (Validators) Swap

func (slice Validators) Swap(i, j int)

type View

type View struct {
	Round    *big.Int
	Sequence *big.Int
}

View includes a round number and a sequence number. Sequence is the block number we'd like to commit. Each round has a number and is composed by 3 steps: preprepare, prepare and commit.

If the given block is not accepted by validators, a round change will occur and the validators start a new round with round+1.

func (*View) Cmp

func (v *View) Cmp(y *View) int

Cmp compares v and y and returns:

-1 if v <  y
 0 if v == y
+1 if v >  y

func (*View) DecodeRLP

func (v *View) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*View) EncodeRLP

func (v *View) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*View) String

func (v *View) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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