wpoa

package
v0.0.0-...-ed2c97c Latest Latest
Warning

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

Go to latest
Published: May 18, 2019 License: GPL-3.0 Imports: 25 Imported by: 1

README

wpoa consensus for Ethereum

Introduction

The wpoa consensus is base on poa, and bcos add the manager control.

only the manager can change the signer, only manager can create contract.

Documentation

Overview

Package wpoa implements the proof-of-authority consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidTimestamp is returned if the timestamp of a block is lower than
	// the previous block's timestamp + the minimum block period.
	ErrInvalidTimestamp = errors.New("invalid timestamp")
)

Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.

Functions

func CalcDifficulty

func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.

Types

type API

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

API is a user facing RPC API to allow controlling the signer and voting mechanisms of the proof-of-authority scheme.

func (*API) GetManagers

func (api *API) GetManagers(number *rpc.BlockNumber) ([]common.Address, error)

GetSigners retrieves the list of authorized signers at the specified block.

func (*API) GetManagersAtHash

func (api *API) GetManagersAtHash(hash common.Hash) ([]common.Address, error)

GetSignersAtHash retrieves the list of authorized signers at the specified block.

func (*API) GetSigners

func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error)

GetSigners retrieves the list of authorized signers at the specified block.

func (*API) GetSignersAtHash

func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error)

GetSignersAtHash retrieves the list of authorized signers at the specified block.

func (*API) GetSnapshot

func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetSnapshotAtHash

func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)

GetSnapshotAtHash retrieves the state snapshot at a given block.

type SignerFn

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

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

type Snapshot

type Snapshot struct {
	Number   uint64                      `json:"number"`   // Block number where the snapshot was created
	Hash     common.Hash                 `json:"hash"`     // Block hash where the snapshot was created
	Managers map[common.Address]struct{} `json:"managers"` // set of authorized manager at this moment
	Signers  map[common.Address]struct{} `json:"signers"`  // Set of authorized signers at this moment
	Recents  map[uint64]common.Address   `json:"recents"`  // Set of recent signers for spam protections
	// contains filtered or unexported fields
}

Snapshot is the state of the authorization voting at a given point in time.

func (*Snapshot) String

func (s *Snapshot) String() string

debug

type WPoa

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

bcos is the proof-of-authority consensus engine

func New

func New(config *params.WPoaConfig, privateKey *ecdsa.PrivateKey, db ethdb.Database) *WPoa

New creates a bcos proof-of-authority consensus engine with the initial signers set to the ones provided by the user.

func (*WPoa) APIs

func (w *WPoa) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.

func (*WPoa) Author

func (w *WPoa) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.

func (*WPoa) CalcDifficulty

func (w *WPoa) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.

func (*WPoa) Close

func (w *WPoa) Close() error

Close implements consensus.Engine. It's a noop for wpoa as there is are no background threads.

func (*WPoa) Finalize

func (w *WPoa) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.

func (*WPoa) Prepare

func (w *WPoa) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.

func (*WPoa) Protocol

func (w *WPoa) Protocol() consensus.Protocol

Protocol implements consensus.Engine.Protocol

func (*WPoa) Seal

func (w *WPoa) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error

Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.

func (*WPoa) SealHash

func (w *WPoa) SealHash(header *types.Header) common.Hash

SealHash returns the hash of a block prior to it being sealed.

func (*WPoa) ValidateTransaction

func (w *WPoa) ValidateTransaction(chain consensus.ChainReader, block *types.Block, tx *types.Transaction) error

func (*WPoa) VerifyHeader

func (w *WPoa) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*WPoa) VerifyHeaders

func (w *WPoa) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).

func (*WPoa) VerifySeal

func (w *WPoa) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

func (*WPoa) VerifyUncles

func (w *WPoa) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.

Jump to

Keyboard shortcuts

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