eth

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 License: GPL-3.0 Imports: 47 Imported by: 0

Documentation

Overview

Package eth implements the Ethereum protocol.

Package eth implements the Ethereum protocol.

Index

Constants

View Source
const (
	NetworkId          = 1
	ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message
)
View Source
const (
	// Protocol messages belonging to eth/62
	StatusMsg          = 0x00
	NewBlockHashesMsg  = 0x01
	TxMsg              = 0x02
	GetBlockHeadersMsg = 0x03
	BlockHeadersMsg    = 0x04
	GetBlockBodiesMsg  = 0x05
	BlockBodiesMsg     = 0x06
	NewBlockMsg        = 0x07

	// Protocol messages belonging to eth/63
	GetNodeDataMsg = 0x0d
	NodeDataMsg    = 0x0e
	GetReceiptsMsg = 0x0f
	ReceiptsMsg    = 0x10
)

eth protocol message codes

View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIdMismatch
	ErrGenesisBlockMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
)

Variables

View Source
var EnableBadBlockReporting = false
View Source
var ProtocolLengths = []uint64{17, 8}

Number of implemented message corresponding to different protocol versions.

View Source
var ProtocolName = "eth"

Official short name of the protocol used during capability negotiation.

View Source
var ProtocolVersions = []uint{eth63, eth62}

Supported versions of the eth protocol (first is primary).

Functions

func CreatePoW added in v1.0.2

func CreatePoW(config *Config) (*ethash.Ethash, error)

CreatePoW creates the required type of PoW instance for an Ethereum service

func SetupGenesisBlock added in v1.0.2

func SetupGenesisBlock(chainDb *ethdb.Database, config *Config) error

SetupGenesisBlock initializes the genesis block for an Ethereum service

Types

type BlockTraceResult added in v1.0.2

type BlockTraceResult struct {
	Validated  bool                  `json:"validated"`
	StructLogs []ethapi.StructLogRes `json:"structLogs"`
	Error      string                `json:"error"`
}

BlockTraceResult is the returned value when replaying a block to check for consensus results and full VM trace logs for all included transactions.

type Config

type Config struct {
	ChainConfig *core.ChainConfig // chain configuration

	NetworkId            int    // Network ID to use for selecting peers to connect to
	Genesis              string // Genesis JSON to seed the chain database with
	SingleBlockMaker     bool   // Assume this node is the only node on the network allowed to create blocks
	EnableNodePermission bool   //Used for enabling / disabling node permissioning

	SkipBcVersionCheck bool // e.g. blockchain export
	DatabaseCache      int
	DatabaseHandles    int

	NatSpec   bool
	DocRoot   string
	AutoDAG   bool
	PowTest   bool
	PowShared bool
	ExtraData []byte

	Etherbase    common.Address
	MinerThreads int
	SolcPath     string

	EnableJit bool
	ForceJit  bool

	TestGenesisBlock *types.Block   // Genesis block to seed the chain database with (testing only!)
	TestGenesisState ethdb.Database // Genesis state to seed the database with (testing only!)

	VoteMinBlockTime uint
	VoteMaxBlockTime uint

	RaftMode bool
}

type ContractBackend added in v1.0.2

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

ContractBackend implements bind.ContractBackend with direct calls to Ethereum internals to support operating on contracts within subprotocols like eth and swarm.

Internally this backend uses the already exposed API endpoints of the Ethereum object. These should be rewritten to internal Go method calls when the Go API is refactored to support a clean library use.

func NewContractBackend added in v1.0.2

func NewContractBackend(eth *Ethereum) *ContractBackend

NewContractBackend creates a new native contract backend using an existing Etheruem object.

func (*ContractBackend) CallContract added in v1.0.2

func (b *ContractBackend) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNum *big.Int) ([]byte, error)

ContractCall implements bind.ContractCaller executing an Ethereum contract call with the specified data as the input. The pending flag requests execution against the pending block, not the stable head of the chain.

func (*ContractBackend) CodeAt added in v1.0.2

func (b *ContractBackend) CodeAt(ctx context.Context, contract common.Address, blockNum *big.Int) ([]byte, error)

CodeAt retrieves any code associated with the contract from the local API.

func (*ContractBackend) EstimateGas added in v1.0.2

func (b *ContractBackend) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (*big.Int, error)

EstimateGasLimit implements bind.ContractTransactor triing to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

func (*ContractBackend) PendingCallContract added in v1.0.2

func (b *ContractBackend) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

ContractCall implements bind.ContractCaller executing an Ethereum contract call with the specified data as the input. The pending flag requests execution against the pending block, not the stable head of the chain.

func (*ContractBackend) PendingCodeAt added in v1.0.2

func (b *ContractBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)

CodeAt retrieves any code associated with the contract from the local API.

func (*ContractBackend) PendingNonceAt added in v1.0.2

func (b *ContractBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingAccountNonce implements bind.ContractTransactor retrieving the current pending nonce associated with an account.

func (*ContractBackend) SendTransaction added in v1.0.2

func (b *ContractBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction implements bind.ContractTransactor injects the transaction into the pending pool for execution.

func (*ContractBackend) SuggestGasPrice added in v1.0.2

func (b *ContractBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice implements bind.ContractTransactor retrieving the currently suggested gas price to allow a timely execution of a transaction.

type EthApiBackend added in v1.0.2

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

EthApiBackend implements ethapi.Backend for full nodes

func (*EthApiBackend) AccountManager added in v1.0.2

func (b *EthApiBackend) AccountManager() *accounts.Manager

func (*EthApiBackend) BlockByNumber added in v1.0.2

func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)

func (*EthApiBackend) ChainDb added in v1.0.2

func (b *EthApiBackend) ChainDb() ethdb.Database

func (*EthApiBackend) Downloader added in v1.0.2

func (b *EthApiBackend) Downloader() *downloader.Downloader

func (*EthApiBackend) EventMux added in v1.0.2

func (b *EthApiBackend) EventMux() *event.TypeMux

func (*EthApiBackend) GetBlock added in v1.0.2

func (b *EthApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)

func (*EthApiBackend) GetPoolNonce added in v1.0.2

func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)

func (*EthApiBackend) GetPoolTransaction added in v1.0.2

func (b *EthApiBackend) GetPoolTransaction(hash common.Hash) *types.Transaction

func (*EthApiBackend) GetPoolTransactions added in v1.0.2

func (b *EthApiBackend) GetPoolTransactions() types.Transactions

func (*EthApiBackend) GetReceipts added in v1.0.2

func (b *EthApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)

func (*EthApiBackend) GetTd added in v1.0.2

func (b *EthApiBackend) GetTd(blockHash common.Hash) *big.Int

func (*EthApiBackend) GetVMEnv added in v1.0.2

func (b *EthApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header) (vm.Environment, func() error, error)

func (*EthApiBackend) HeaderByNumber added in v1.0.2

func (b *EthApiBackend) HeaderByNumber(blockNr rpc.BlockNumber) *types.Header

func (*EthApiBackend) ProtocolVersion added in v1.0.2

func (b *EthApiBackend) ProtocolVersion() int

func (*EthApiBackend) RemoveTx added in v1.0.2

func (b *EthApiBackend) RemoveTx(txHash common.Hash)

func (*EthApiBackend) SendTx added in v1.0.2

func (b *EthApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error

func (*EthApiBackend) SetHead added in v1.0.2

func (b *EthApiBackend) SetHead(number uint64)

func (*EthApiBackend) StateAndHeaderByNumber added in v1.0.2

func (b *EthApiBackend) StateAndHeaderByNumber(blockNr rpc.BlockNumber) (ethapi.State, *types.Header, error)

func (*EthApiBackend) Stats added in v1.0.2

func (b *EthApiBackend) Stats() (pending int, queued int)

func (*EthApiBackend) SuggestPrice added in v1.0.2

func (b *EthApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error)

func (*EthApiBackend) TxPoolContent added in v1.0.2

type EthApiState added in v1.0.2

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

func (EthApiState) GetBalance added in v1.0.2

func (s EthApiState) GetBalance(ctx context.Context, addr common.Address) (*big.Int, error)

func (EthApiState) GetCode added in v1.0.2

func (s EthApiState) GetCode(ctx context.Context, addr common.Address) ([]byte, error)

func (EthApiState) GetNonce added in v1.0.2

func (s EthApiState) GetNonce(ctx context.Context, addr common.Address) (uint64, error)

func (EthApiState) GetState added in v1.0.2

func (s EthApiState) GetState(ctx context.Context, a common.Address, b common.Hash) (common.Hash, error)

type EthNodeInfo added in v1.0.2

type EthNodeInfo struct {
	Network    int         `json:"network"`    // Ethereum network ID (0=Olympic, 1=Frontier, 2=Morden)
	Difficulty *big.Int    `json:"difficulty"` // Total difficulty of the host's blockchain
	Genesis    common.Hash `json:"genesis"`    // SHA3 hash of the host's genesis block
	Head       common.Hash `json:"head"`       // SHA3 hash of the host's best owned block
}

EthNodeInfo represents a short summary of the Ethereum sub-protocol metadata known about the host peer.

type Ethereum

type Ethereum struct {
	AutoDAG bool

	NatSpec bool
	PowTest bool
	// contains filtered or unexported fields
}

Ethereum implements the Ethereum full node service.

func New

func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error)

New creates a new Ethereum object (including the initialisation of the common Ethereum object)

func (*Ethereum) APIs added in v1.0.2

func (s *Ethereum) APIs() []rpc.API

APIs returns the collection of RPC services the ethereum package offers. NOTE, some of these services probably need to be moved to somewhere else.

func (*Ethereum) AccountManager added in v0.9.20

func (s *Ethereum) AccountManager() *accounts.Manager

func (*Ethereum) BlockChain added in v1.0.2

func (s *Ethereum) BlockChain() *core.BlockChain

func (*Ethereum) ChainDb added in v1.0.2

func (s *Ethereum) ChainDb() ethdb.Database

func (*Ethereum) Downloader added in v0.9.20

func (s *Ethereum) Downloader() *downloader.Downloader

func (*Ethereum) EthVersion added in v0.9.20

func (s *Ethereum) EthVersion() int

func (*Ethereum) Etherbase added in v0.9.20

func (s *Ethereum) Etherbase() (eb common.Address, err error)

func (*Ethereum) EventMux

func (s *Ethereum) EventMux() *event.TypeMux

func (*Ethereum) HTTPClient added in v1.0.2

func (self *Ethereum) HTTPClient() *httpclient.HTTPClient

HTTPClient returns the light http client used for fetching offchain docs (natspec, source for verification)

func (*Ethereum) IsListening

func (s *Ethereum) IsListening() bool

func (*Ethereum) NetVersion added in v0.9.20

func (s *Ethereum) NetVersion() int

func (*Ethereum) Pow added in v1.0.2

func (s *Ethereum) Pow() *ethash.Ethash

func (*Ethereum) Protocols added in v1.0.2

func (s *Ethereum) Protocols() []p2p.Protocol

Protocols implements node.Service, returning all the currently configured network protocols to start.

func (*Ethereum) ResetWithGenesisBlock added in v0.9.20

func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block)

func (*Ethereum) SetEtherbase added in v0.9.36

func (self *Ethereum) SetEtherbase(etherbase common.Address)

set in js console via admin interface or wrapper from cli flags

func (*Ethereum) Start

func (s *Ethereum) Start(srvr *p2p.Server) error

Start implements node.Service, starting all internal goroutines needed by the Ethereum protocol implementation.

func (*Ethereum) StartAutoDAG added in v0.9.23

func (self *Ethereum) StartAutoDAG()

StartAutoDAG() spawns a go routine that checks the DAG every autoDAGcheckInterval by default that is 10 times per epoch in epoch n, if we past autoDAGepochHeight within-epoch blocks, it calls ethash.MakeDAG to pregenerate the DAG for the next epoch n+1 if it does not exist yet as well as remove the DAG for epoch n-1 the loop quits if autodagquit channel is closed, it can safely restart and stop any number of times. For any more sophisticated pattern of DAG generation, use CLI subcommand makedag

func (*Ethereum) StartBlockVoting added in v1.0.2

func (s *Ethereum) StartBlockVoting(client *rpc.Client, voteKey, blockMakerKey *ecdsa.PrivateKey) error

func (*Ethereum) Stop

func (s *Ethereum) Stop() error

Stop implements node.Service, terminating all internal goroutines used by the Ethereum protocol.

func (*Ethereum) StopAutoDAG added in v0.9.23

func (self *Ethereum) StopAutoDAG()

stopAutoDAG stops automatic DAG pregeneration by quitting the loop

func (*Ethereum) TxPool

func (s *Ethereum) TxPool() *core.TxPool

func (*Ethereum) WaitForShutdown

func (s *Ethereum) WaitForShutdown()

This function will wait for a shutdown and resumes main thread execution

type PeerInfo added in v0.9.20

type PeerInfo struct {
	Version    int      `json:"version"`    // Ethereum protocol version negotiated
	Difficulty *big.Int `json:"difficulty"` // Total difficulty of the peer's blockchain
	Head       string   `json:"head"`       // SHA3 hash of the peer's best owned block
}

PeerInfo represents a short summary of the Ethereum sub-protocol metadata known about a connected peer.

type PrivateAdminAPI added in v1.0.2

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

PrivateAdminAPI is the collection of Etheruem full node-related APIs exposed over the private admin endpoint.

func NewPrivateAdminAPI added in v1.0.2

func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI

NewPrivateAdminAPI creates a new API definition for the full node private admin methods of the Ethereum service.

func (*PrivateAdminAPI) ExportChain added in v1.0.2

func (api *PrivateAdminAPI) ExportChain(file string) (bool, error)

ExportChain exports the current blockchain into a local file.

func (*PrivateAdminAPI) ImportChain added in v1.0.2

func (api *PrivateAdminAPI) ImportChain(file string) (bool, error)

ImportChain imports a blockchain from a local file.

type PrivateDebugAPI added in v1.0.2

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

PrivateDebugAPI is the collection of Etheruem full node APIs exposed over the private debugging endpoint.

func NewPrivateDebugAPI added in v1.0.2

func NewPrivateDebugAPI(config *core.ChainConfig, eth *Ethereum) *PrivateDebugAPI

NewPrivateDebugAPI creates a new API definition for the full node-related private debug methods of the Ethereum service.

func (*PrivateDebugAPI) TraceBlock added in v1.0.2

func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config *vm.LogConfig) BlockTraceResult

TraceBlock processes the given block's RLP but does not import the block in to the chain.

func (*PrivateDebugAPI) TraceBlockByHash added in v1.0.2

func (api *PrivateDebugAPI) TraceBlockByHash(hash common.Hash, config *vm.LogConfig) BlockTraceResult

TraceBlockByHash processes the block by hash.

func (*PrivateDebugAPI) TraceBlockByNumber added in v1.0.2

func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config *vm.LogConfig) BlockTraceResult

TraceBlockByNumber processes the block by canonical block number.

func (*PrivateDebugAPI) TraceBlockFromFile added in v1.0.2

func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config *vm.LogConfig) BlockTraceResult

TraceBlockFromFile loads the block's RLP from the given file name and attempts to process it but does not import the block in to the chain.

func (*PrivateDebugAPI) TraceTransaction added in v1.0.2

func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common.Hash, config *TraceArgs) (interface{}, error)

TraceTransaction returns the structured logs created during the execution of EVM and returns them as a JSON object.

type ProtocolManager added in v0.9.20

type ProtocolManager struct {
	SubProtocols []p2p.Protocol
	// contains filtered or unexported fields
}

func NewProtocolManager added in v0.9.20

func NewProtocolManager(config *core.ChainConfig, singleMiner bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database, raftMode bool) (*ProtocolManager, error)

NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable with the ethereum network.

func (*ProtocolManager) BroadcastBlock added in v0.9.20

func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool)

BroadcastBlock will either propagate a block to a subset of it's peers, or will only announce it's availability (depending what's requested).

func (*ProtocolManager) BroadcastTx added in v0.9.20

func (pm *ProtocolManager) BroadcastTx(hash common.Hash, tx *types.Transaction)

BroadcastTx will propagate a transaction to all peers which are not known to already have the given transaction.

func (*ProtocolManager) NodeInfo added in v1.0.2

func (self *ProtocolManager) NodeInfo() *EthNodeInfo

NodeInfo retrieves some protocol metadata about the running host node.

func (*ProtocolManager) Start added in v0.9.20

func (pm *ProtocolManager) Start()

func (*ProtocolManager) Stop added in v0.9.20

func (pm *ProtocolManager) Stop()

type PublicDebugAPI added in v1.0.2

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

PublicDebugAPI is the collection of Etheruem full node APIs exposed over the public debugging endpoint.

func NewPublicDebugAPI added in v1.0.2

func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI

NewPublicDebugAPI creates a new API definition for the full node- related public debug methods of the Ethereum service.

func (*PublicDebugAPI) DumpBlock added in v1.0.2

func (api *PublicDebugAPI) DumpBlock(number uint64, typ string) (state.Dump, error)

DumpBlock retrieves the entire state of the database at a given block.

type PublicEthereumAPI added in v1.0.2

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

PublicEthereumAPI provides an API to access Ethereum full node-related information.

func NewPublicEthereumAPI added in v1.0.2

func NewPublicEthereumAPI(e *Ethereum) *PublicEthereumAPI

NewPublicEthereumAPI creates a new Etheruem protocol API for full nodes.

func (*PublicEthereumAPI) Coinbase added in v1.0.2

func (s *PublicEthereumAPI) Coinbase() (common.Address, error)

Coinbase is the address that mining rewards will be send to (alias for Etherbase)

func (*PublicEthereumAPI) Etherbase added in v1.0.2

func (s *PublicEthereumAPI) Etherbase() (common.Address, error)

Etherbase is the address that mining rewards will be send to

func (*PublicEthereumAPI) StorageRoot added in v1.0.2

func (s *PublicEthereumAPI) StorageRoot(addr common.Address, blockNr *rpc.BlockNumber) (common.Hash, error)

StorageRoot returns the storage root of an account on the the given (optional) block height. If block number is not given the latest block is used.

type TraceArgs added in v1.0.2

type TraceArgs struct {
	*vm.LogConfig
	Tracer  *string
	Timeout *string
}

TraceArgs holds extra parameters to trace functions

Directories

Path Synopsis
Package downloader contains the manual full chain synchronisation.
Package downloader contains the manual full chain synchronisation.
Package fetcher contains the block announcement based synchronisation.
Package fetcher contains the block announcement based synchronisation.
Package filters implements an ethereum filtering system for block, transactions and log events.
Package filters implements an ethereum filtering system for block, transactions and log events.

Jump to

Keyboard shortcuts

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