les

package
v0.0.0-...-92cc422 Latest Latest
Warning

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

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

Documentation

Overview

包les实现轻以太坊子协议。

package light实现可按需检索的状态和链对象 对于以太坊Light客户端。

包les实现轻以太坊子协议。

包les实现轻以太坊子协议。

包les实现轻以太坊子协议。

package light实现可按需检索的状态和链对象 对于以太坊Light客户端。

包les实现轻以太坊子协议。

包les实现轻以太坊子协议。

包les实现轻以太坊子协议。

package light实现可按需检索的状态和链对象 对于以太坊Light客户端。

包les实现轻以太坊子协议。

包les实现轻以太坊子协议。

Index

Constants

View Source
const (
	MaxHeaderFetch           = 192 //每个检索请求要获取的块头的数量
	MaxBodyFetch             = 32  //每个检索请求要获取的块体数量
	MaxReceiptFetch          = 128 //允许每个请求提取的事务处理收据的数量
	MaxCodeFetch             = 64  //允许按请求提取的合同代码量
	MaxProofsFetch           = 64  //每个检索请求要获取的Merkle证明的数量
	MaxHelperTrieProofsFetch = 64  //每个检索请求要获取的Merkle证明的数量
	MaxTxSend                = 64  //每个请求发送的事务量
	MaxTxStatus              = 256 //每个请求要查询的事务量

)
View Source
const (
	MsgBlockBodies = iota
	MsgCode
	MsgReceipts
	MsgProofsV1
	MsgProofsV2
	MsgHeaderProofs
	MsgHelperTrieProofs
)
View Source
const (
	NetworkId          = 1
	ProtocolMaxMsgSize = 10 * 1024 * 1024 //协议消息大小的最大上限
)
View Source
const (
	//属于lpv1的协议消息
	StatusMsg          = 0x00
	AnnounceMsg        = 0x01
	GetBlockHeadersMsg = 0x02
	BlockHeadersMsg    = 0x03
	GetBlockBodiesMsg  = 0x04
	BlockBodiesMsg     = 0x05
	GetReceiptsMsg     = 0x06
	ReceiptsMsg        = 0x07
	GetProofsV1Msg     = 0x08
	ProofsV1Msg        = 0x09
	GetCodeMsg         = 0x0a
	CodeMsg            = 0x0b
	SendTxMsg          = 0x0c
	GetHeaderProofsMsg = 0x0d
	HeaderProofsMsg    = 0x0e
	//属于lpv2的协议消息
	GetProofsV2Msg         = 0x0f
	ProofsV2Msg            = 0x10
	GetHelperTrieProofsMsg = 0x11
	HelperTrieProofsMsg    = 0x12
	SendTxV2Msg            = 0x13
	GetTxStatusMsg         = 0x14
	TxStatusMsg            = 0x15
)

LES协议消息代码

View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIdMismatch
	ErrGenesisBlockMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
	ErrUselessPeer
	ErrRequestRejected
	ErrUnexpectedResponse
	ErrInvalidResponse
	ErrTooManyTimeouts
	ErrMissingKey
)

Variables

View Source
var (
	ClientProtocolVersions    = []uint{lpv2, lpv1}
	ServerProtocolVersions    = []uint{lpv2, lpv1}
	AdvertiseProtocolVersions = []uint{lpv2} //客户端正在搜索列表中的第一个公告协议
)

支持的LES协议版本(第一个是主协议)

View Source
var ProtocolLengths = map[uint]uint64{/* contains filtered or unexported fields */}

对应于不同协议版本的已实现消息数。

Functions

This section is empty.

Types

type BlockChain

type BlockChain interface {
	Config() *params.ChainConfig
	HasHeader(hash common.Hash, number uint64) bool
	GetHeader(hash common.Hash, number uint64) *types.Header
	GetHeaderByHash(hash common.Hash) *types.Header
	CurrentHeader() *types.Header
	GetTd(hash common.Hash, number uint64) *big.Int
	State() (*state.StateDB, error)
	InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error)
	Rollback(chain []common.Hash)
	GetHeaderByNumber(number uint64) *types.Header
	GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
	Genesis() *types.Block
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
}

type BlockRequest

type BlockRequest light.BlockRequest

BlockRequest是块体的ODR请求类型

func (*BlockRequest) CanSend

func (r *BlockRequest) CanSend(peer *peer) bool

cansend告诉某个对等机是否适合服务于给定的请求

func (*BlockRequest) GetCost

func (r *BlockRequest) GetCost(peer *peer) uint64

getcost根据服务返回给定ODR请求的成本 同行成本表(lesodrequest的实现)

func (*BlockRequest) Request

func (r *BlockRequest) Request(reqID uint64, peer *peer) error

请求向LES网络发送一个ODR请求(LESODRREQUEST的实现)

func (*BlockRequest) Validate

func (r *BlockRequest) Validate(db ethdb.Database, msg *Msg) error

有效处理来自LES网络的ODR请求回复消息 如果消息是有效的答复,则返回true并将结果存储在内存中 到请求(lesodrequest的实现)

type BloomReq

type BloomReq struct {
	BloomTrieNum, BitIdx, SectionIdx, FromLevel uint64
}

type BloomRequest

type BloomRequest light.BloomRequest

用于通过规范哈希检索请求头的ODR请求类型,请参见leSodrRequest接口

func (*BloomRequest) CanSend

func (r *BloomRequest) CanSend(peer *peer) bool

cansend告诉某个对等机是否适合服务于给定的请求

func (*BloomRequest) GetCost

func (r *BloomRequest) GetCost(peer *peer) uint64

getcost根据服务返回给定ODR请求的成本 同行成本表(lesodrequest的实现)

func (*BloomRequest) Request

func (r *BloomRequest) Request(reqID uint64, peer *peer) error

请求向LES网络发送一个ODR请求(LESODRREQUEST的实现)

func (*BloomRequest) Validate

func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error

有效处理来自LES网络的ODR请求回复消息 如果消息是有效的答复,则返回true并将结果存储在内存中 到请求(lesodrequest的实现)

type ChtReq

type ChtReq struct {
	ChtNum, BlockNum uint64
	FromLevel        uint
}

遗产LES / 1

type ChtRequest

type ChtRequest light.ChtRequest

用于通过规范哈希检索请求头的ODR请求类型,请参见leSodrRequest接口

func (*ChtRequest) CanSend

func (r *ChtRequest) CanSend(peer *peer) bool

cansend告诉某个对等机是否适合服务于给定的请求

func (*ChtRequest) GetCost

func (r *ChtRequest) GetCost(peer *peer) uint64

getcost根据服务返回给定ODR请求的成本 同行成本表(lesodrequest的实现)

func (*ChtRequest) Request

func (r *ChtRequest) Request(reqID uint64, peer *peer) error

请求向LES网络发送一个ODR请求(LESODRREQUEST的实现)

func (*ChtRequest) Validate

func (r *ChtRequest) Validate(db ethdb.Database, msg *Msg) error

有效处理来自LES网络的ODR请求回复消息 如果消息是有效的答复,则返回true并将结果存储在内存中 到请求(lesodrequest的实现)

type ChtResp

type ChtResp struct {
	Header *types.Header
	Proof  []rlp.RawValue
}

遗产LES / 1

type CodeData

type CodeData []struct {
	Value []byte
}

codedata是用于节点数据检索的网络响应包。

type CodeReq

type CodeReq struct {
	BHash  common.Hash
	AccKey []byte
}

type CodeRequest

type CodeRequest light.CodeRequest

节点数据的ODR请求类型(用于检索合同代码),请参见LESODRREQUEST接口

func (*CodeRequest) CanSend

func (r *CodeRequest) CanSend(peer *peer) bool

cansend告诉某个对等机是否适合服务于给定的请求

func (*CodeRequest) GetCost

func (r *CodeRequest) GetCost(peer *peer) uint64

getcost根据服务返回给定ODR请求的成本 同行成本表(lesodrequest的实现)

func (*CodeRequest) Request

func (r *CodeRequest) Request(reqID uint64, peer *peer) error

请求向LES网络发送一个ODR请求(LESODRREQUEST的实现)

func (*CodeRequest) Validate

func (r *CodeRequest) Validate(db ethdb.Database, msg *Msg) error

有效处理来自LES网络的ODR请求回复消息 如果消息是有效的答复,则返回true并将结果存储在内存中 到请求(lesodrequest的实现)

type HelperTrieReq

type HelperTrieReq struct {
	Type              uint
	TrieIdx           uint64
	Key               []byte
	FromLevel, AuxReq uint
}

type HelperTrieResps

type HelperTrieResps struct {
	Proofs  light.NodeList
	AuxData [][]byte
}

type LesApiBackend

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

func (*LesApiBackend) AccountManager

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

func (*LesApiBackend) BlockByNumber

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

func (*LesApiBackend) BloomStatus

func (b *LesApiBackend) BloomStatus() (uint64, uint64)

func (*LesApiBackend) ChainConfig

func (b *LesApiBackend) ChainConfig() *params.ChainConfig

func (*LesApiBackend) ChainDb

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

func (*LesApiBackend) CurrentBlock

func (b *LesApiBackend) CurrentBlock() *types.Block

func (*LesApiBackend) Downloader

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

func (*LesApiBackend) EventMux

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

func (*LesApiBackend) GetBlock

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

func (*LesApiBackend) GetEVM

func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error)

func (*LesApiBackend) GetLogs

func (b *LesApiBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error)

func (*LesApiBackend) GetPoolNonce

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

func (*LesApiBackend) GetPoolTransaction

func (b *LesApiBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction

func (*LesApiBackend) GetPoolTransactions

func (b *LesApiBackend) GetPoolTransactions() (types.Transactions, error)

func (*LesApiBackend) GetReceipts

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

func (*LesApiBackend) GetTd

func (b *LesApiBackend) GetTd(hash common.Hash) *big.Int

func (*LesApiBackend) HeaderByHash

func (b *LesApiBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

func (*LesApiBackend) HeaderByNumber

func (b *LesApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)

func (*LesApiBackend) ProtocolVersion

func (b *LesApiBackend) ProtocolVersion() int

func (*LesApiBackend) RemoveTx

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

func (*LesApiBackend) SendTx

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

func (*LesApiBackend) ServiceFilter

func (b *LesApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

func (*LesApiBackend) SetHead

func (b *LesApiBackend) SetHead(number uint64)

func (*LesApiBackend) StateAndHeaderByNumber

func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)

func (*LesApiBackend) Stats

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

func (*LesApiBackend) SubscribeChainEvent

func (b *LesApiBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription

func (*LesApiBackend) SubscribeChainHeadEvent

func (b *LesApiBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription

func (*LesApiBackend) SubscribeChainSideEvent

func (b *LesApiBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription

func (*LesApiBackend) SubscribeLogsEvent

func (b *LesApiBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription

func (*LesApiBackend) SubscribeNewTxsEvent

func (b *LesApiBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription

func (*LesApiBackend) SubscribeRemovedLogsEvent

func (b *LesApiBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription

func (*LesApiBackend) SuggestPrice

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

func (*LesApiBackend) TxPoolContent

type LesOdr

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

lesodr实现light.odrbackend

func NewLesOdr

func NewLesOdr(db ethdb.Database, retriever *retrieveManager) *LesOdr

func (*LesOdr) BloomIndexer

func (odr *LesOdr) BloomIndexer() *core.ChainIndexer

BloomIndexer返回BloomBits链索引器

func (*LesOdr) BloomTrieIndexer

func (odr *LesOdr) BloomTrieIndexer() *core.ChainIndexer

BloomTrieIndexer返回BloomTrie链索引器

func (*LesOdr) ChtIndexer

func (odr *LesOdr) ChtIndexer() *core.ChainIndexer

返回CHT链索引器

func (*LesOdr) Database

func (odr *LesOdr) Database() ethdb.Database

数据库返回后备数据库

func (*LesOdr) Retrieve

func (odr *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err error)

retrieve尝试从les网络获取对象。 如果网络检索成功,它将对象存储在本地数据库中。

func (*LesOdr) SetIndexers

func (odr *LesOdr) SetIndexers(chtIndexer, bloomTrieIndexer, bloomIndexer *core.ChainIndexer)

setindexers将必要的链索引器添加到ODR后端

func (*LesOdr) Stop

func (odr *LesOdr) Stop()

停止取消所有挂起的检索

type LesOdrRequest

type LesOdrRequest interface {
	GetCost(*peer) uint64
	CanSend(*peer) bool
	Request(uint64, *peer) error
	Validate(ethdb.Database, *Msg) error
}

func LesRequest

func LesRequest(req light.OdrRequest) LesOdrRequest

type LesServer

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

func NewLesServer

func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error)

func (*LesServer) Protocols

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

func (*LesServer) SetBloomBitsIndexer

func (s *LesServer) SetBloomBitsIndexer(bloomIndexer *core.ChainIndexer)

func (*LesServer) Start

func (s *LesServer) Start(srvr *p2p.Server)

启动启动LES服务器

func (*LesServer) Stop

func (s *LesServer) Stop()

停止停止LES服务

type LesTxRelay

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

func NewLesTxRelay

func NewLesTxRelay(ps *peerSet, reqDist *requestDistributor) *LesTxRelay

func (*LesTxRelay) Discard

func (self *LesTxRelay) Discard(hashes []common.Hash)

func (*LesTxRelay) NewHead

func (self *LesTxRelay) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash)

func (*LesTxRelay) Send

func (self *LesTxRelay) Send(txs types.Transactions)

type LightDummyAPI

type LightDummyAPI struct{}

func (*LightDummyAPI) Coinbase

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

CoinBase是采矿奖励将发送到的地址

func (*LightDummyAPI) Hashrate

func (s *LightDummyAPI) Hashrate() hexutil.Uint

hashRate返回pow hashRate

func (*LightDummyAPI) Mining

func (s *LightDummyAPI) Mining() bool

挖掘返回当前是否正在挖掘此节点的指示。

type LightEthereum

type LightEthereum struct {
	ApiBackend *LesApiBackend
	// contains filtered or unexported fields
}

func New

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

func (*LightEthereum) APIs

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

API返回以太坊包提供的RPC服务集合。 注意,其中一些服务可能需要转移到其他地方。

func (*LightEthereum) BlockChain

func (s *LightEthereum) BlockChain() *light.LightChain

func (*LightEthereum) Downloader

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

func (*LightEthereum) Engine

func (s *LightEthereum) Engine() consensus.Engine

func (*LightEthereum) EventMux

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

func (*LightEthereum) LesVersion

func (s *LightEthereum) LesVersion() int

func (*LightEthereum) Protocols

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

协议实现node.service,返回所有当前配置的 要启动的网络协议。

func (*LightEthereum) ResetWithGenesisBlock

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

func (*LightEthereum) Start

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

start实现node.service,启动 以太坊协议实现。

func (*LightEthereum) Stop

func (s *LightEthereum) Stop() error

停止实现node.service,终止由 以太坊协议。

func (*LightEthereum) TxPool

func (s *LightEthereum) TxPool() *light.TxPool

type Msg

type Msg struct {
	MsgType int
	ReqID   uint64
	Obj     interface{}
}

msg对为请求传递答复数据的les消息进行编码

type NodeInfo

type NodeInfo struct {
	Network    uint64                  `json:"network"`    //以太坊网络ID(1=前沿,2=现代,Ropsten=3,Rinkeby=4)
	Difficulty *big.Int                `json:"difficulty"` //主机区块链的总难度
	Genesis    common.Hash             `json:"genesis"`    //寄主创世纪区块的沙3哈希
	Config     *params.ChainConfig     `json:"config"`     //分叉规则的链配置
	Head       common.Hash             `json:"head"`       //主机最好拥有的块的sha3哈希
	CHT        light.TrustedCheckpoint `json:"cht"`        //桁架式CHT检查站,快速接球
}

nodeinfo表示以太坊子协议元数据的简短摘要 了解主机对等机。

type ProofReq

type ProofReq struct {
	BHash       common.Hash
	AccKey, Key []byte
	FromLevel   uint
}

type ProtocolManager

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

func NewProtocolManager

func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, networkId uint64, mux *event.TypeMux, engine consensus.Engine, peers *peerSet, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, txrelay *LesTxRelay, serverPool *serverPool, quitSync chan struct{}, wg *sync.WaitGroup) (*ProtocolManager, error)

NewProtocolManager返回新的以太坊子协议管理器。以太坊子协议管理对等端 使用以太坊网络。

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start(maxPeers int)

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

type ReceiptsRequest

type ReceiptsRequest light.ReceiptsRequest

ReceiptsRequest是按块哈希列出的块接收的ODR请求类型

func (*ReceiptsRequest) CanSend

func (r *ReceiptsRequest) CanSend(peer *peer) bool

cansend告诉某个对等机是否适合服务于给定的请求

func (*ReceiptsRequest) GetCost

func (r *ReceiptsRequest) GetCost(peer *peer) uint64

getcost根据服务返回给定ODR请求的成本 同行成本表(lesodrequest的实现)

func (*ReceiptsRequest) Request

func (r *ReceiptsRequest) Request(reqID uint64, peer *peer) error

请求向LES网络发送一个ODR请求(LESODRREQUEST的实现)

func (*ReceiptsRequest) Validate

func (r *ReceiptsRequest) Validate(db ethdb.Database, msg *Msg) error

有效处理来自LES网络的ODR请求回复消息 如果消息是有效的答复,则返回true并将结果存储在内存中 到请求(lesodrequest的实现)

type RequestCostList

type RequestCostList []struct {
	MsgCode, BaseCost, ReqCost uint64
}

type TrieRequest

type TrieRequest light.TrieRequest

状态/存储trie项的ODR请求类型,请参见leSodrRequest接口

func (*TrieRequest) CanSend

func (r *TrieRequest) CanSend(peer *peer) bool

cansend告诉某个对等机是否适合服务于给定的请求

func (*TrieRequest) GetCost

func (r *TrieRequest) GetCost(peer *peer) uint64

getcost根据服务返回给定ODR请求的成本 同行成本表(lesodrequest的实现)

func (*TrieRequest) Request

func (r *TrieRequest) Request(reqID uint64, peer *peer) error

请求向LES网络发送一个ODR请求(LESODRREQUEST的实现)

func (*TrieRequest) Validate

func (r *TrieRequest) Validate(db ethdb.Database, msg *Msg) error

有效处理来自LES网络的ODR请求回复消息 如果消息是有效的答复,则返回true并将结果存储在内存中 到请求(lesodrequest的实现)

Directories

Path Synopsis
包流控制实现客户端流控制机制 包流控制实现客户端流控制机制
包流控制实现客户端流控制机制 包流控制实现客户端流控制机制

Jump to

Keyboard shortcuts

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