go-ethereum: github.com/ethereum/go-ethereum/eth/downloader Index | Files

package downloader

import "github.com/ethereum/go-ethereum/eth/downloader"

Package downloader contains the manual full chain synchronisation.

Index

Package Files

api.go downloader.go events.go fakepeer.go metrics.go modes.go peer.go queue.go statesync.go types.go

Variables

var (
    MaxHashFetch    = 512 // Amount of hashes to be fetched per retrieval request
    MaxBlockFetch   = 128 // Amount of blocks to be fetched per retrieval request
    MaxHeaderFetch  = 192 // Amount of block headers to be fetched per retrieval request
    MaxSkeletonSize = 128 // Number of header fetches to need for a skeleton assembly
    MaxBodyFetch    = 128 // Amount of block bodies to be fetched per retrieval request
    MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request
    MaxStateFetch   = 384 // Amount of node state values to allow fetching per request

)

type BlockChain Uses

type BlockChain interface {
    LightChain

    // HasBlock verifies a block's presence in the local chain.
    HasBlock(common.Hash, uint64) bool

    // HasFastBlock verifies a fast block's presence in the local chain.
    HasFastBlock(common.Hash, uint64) bool

    // GetBlockByHash retrieves a block from the local chain.
    GetBlockByHash(common.Hash) *types.Block

    // CurrentBlock retrieves the head block from the local chain.
    CurrentBlock() *types.Block

    // CurrentFastBlock retrieves the head fast block from the local chain.
    CurrentFastBlock() *types.Block

    // FastSyncCommitHead directly commits the head block to a certain entity.
    FastSyncCommitHead(common.Hash) error

    // InsertChain inserts a batch of blocks into the local chain.
    InsertChain(types.Blocks) (int, error)

    // InsertReceiptChain inserts a batch of receipts into the local chain.
    InsertReceiptChain(types.Blocks, []types.Receipts, uint64) (int, error)
}

BlockChain encapsulates functions required to sync a (full or fast) blockchain.

type DoneEvent Uses

type DoneEvent struct {
    Latest *types.Header
}

type Downloader Uses

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

func New Uses

func New(checkpoint uint64, stateDb ethdb.Database, stateBloom *trie.SyncBloom, mux *event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer peerDropFn) *Downloader

New creates a new downloader to fetch hashes and blocks from remote peers.

func (*Downloader) Cancel Uses

func (d *Downloader) Cancel()

Cancel aborts all of the operations and waits for all download goroutines to finish before returning.

func (*Downloader) DeliverBodies Uses

func (d *Downloader) DeliverBodies(id string, transactions [][]*types.Transaction, uncles [][]*types.Header) (err error)

DeliverBodies injects a new batch of block bodies received from a remote node.

func (*Downloader) DeliverHeaders Uses

func (d *Downloader) DeliverHeaders(id string, headers []*types.Header) (err error)

DeliverHeaders injects a new batch of block headers received from a remote node into the download schedule.

func (*Downloader) DeliverNodeData Uses

func (d *Downloader) DeliverNodeData(id string, data [][]byte) (err error)

DeliverNodeData injects a new batch of node state data received from a remote node.

func (*Downloader) DeliverReceipts Uses

func (d *Downloader) DeliverReceipts(id string, receipts [][]*types.Receipt) (err error)

DeliverReceipts injects a new batch of receipts received from a remote node.

func (*Downloader) Progress Uses

func (d *Downloader) Progress() ethereum.SyncProgress

Progress retrieves the synchronisation boundaries, specifically the origin block where synchronisation started at (may have failed/suspended); the block or header sync is currently at; and the latest known block which the sync targets.

In addition, during the state download phase of fast synchronisation the number of processed and the total number of known states are also returned. Otherwise these are zero.

func (*Downloader) RegisterLightPeer Uses

func (d *Downloader) RegisterLightPeer(id string, version int, peer LightPeer) error

RegisterLightPeer injects a light client peer, wrapping it so it appears as a regular peer.

func (*Downloader) RegisterPeer Uses

func (d *Downloader) RegisterPeer(id string, version int, peer Peer) error

RegisterPeer injects a new download peer into the set of block source to be used for fetching hashes and blocks from.

func (*Downloader) Synchronise Uses

func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode SyncMode) error

Synchronise tries to sync up our local block chain with a remote peer, both adding various sanity checks as well as wrapping it with various log entries.

func (*Downloader) Synchronising Uses

func (d *Downloader) Synchronising() bool

Synchronising returns whether the downloader is currently retrieving blocks.

func (*Downloader) Terminate Uses

func (d *Downloader) Terminate()

Terminate interrupts the downloader, canceling all pending operations. The downloader cannot be reused after calling Terminate.

func (*Downloader) UnregisterPeer Uses

func (d *Downloader) UnregisterPeer(id string) error

UnregisterPeer remove a peer from the known list, preventing any action from the specified peer. An effort is also made to return any pending fetches into the queue.

type FailedEvent Uses

type FailedEvent struct{ Err error }

type FakePeer Uses

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

FakePeer is a mock downloader peer that operates on a local database instance instead of being an actual live node. It's useful for testing and to implement sync commands from an existing local database.

func NewFakePeer Uses

func NewFakePeer(id string, db ethdb.Database, hc *core.HeaderChain, dl *Downloader) *FakePeer

NewFakePeer creates a new mock downloader peer with the given data sources.

func (*FakePeer) Head Uses

func (p *FakePeer) Head() (common.Hash, *big.Int)

Head implements downloader.Peer, returning the current head hash and number of the best known header.

func (*FakePeer) RequestBodies Uses

func (p *FakePeer) RequestBodies(hashes []common.Hash) error

RequestBodies implements downloader.Peer, returning a batch of block bodies corresponding to the specified block hashes.

func (*FakePeer) RequestHeadersByHash Uses

func (p *FakePeer) RequestHeadersByHash(hash common.Hash, amount int, skip int, reverse bool) error

RequestHeadersByHash implements downloader.Peer, returning a batch of headers defined by the origin hash and the associated query parameters.

func (*FakePeer) RequestHeadersByNumber Uses

func (p *FakePeer) RequestHeadersByNumber(number uint64, amount int, skip int, reverse bool) error

RequestHeadersByNumber implements downloader.Peer, returning a batch of headers defined by the origin number and the associated query parameters.

func (*FakePeer) RequestNodeData Uses

func (p *FakePeer) RequestNodeData(hashes []common.Hash) error

RequestNodeData implements downloader.Peer, returning a batch of state trie nodes corresponding to the specified trie hashes.

func (*FakePeer) RequestReceipts Uses

func (p *FakePeer) RequestReceipts(hashes []common.Hash) error

RequestReceipts implements downloader.Peer, returning a batch of transaction receipts corresponding to the specified block hashes.

type LightChain Uses

type LightChain interface {
    // HasHeader verifies a header's presence in the local chain.
    HasHeader(common.Hash, uint64) bool

    // GetHeaderByHash retrieves a header from the local chain.
    GetHeaderByHash(common.Hash) *types.Header

    // CurrentHeader retrieves the head header from the local chain.
    CurrentHeader() *types.Header

    // GetTd returns the total difficulty of a local block.
    GetTd(common.Hash, uint64) *big.Int

    // InsertHeaderChain inserts a batch of headers into the local chain.
    InsertHeaderChain([]*types.Header, int) (int, error)

    // Rollback removes a few recently added elements from the local chain.
    Rollback([]common.Hash)
}

LightChain encapsulates functions required to synchronise a light chain.

type LightPeer Uses

type LightPeer interface {
    Head() (common.Hash, *big.Int)
    RequestHeadersByHash(common.Hash, int, int, bool) error
    RequestHeadersByNumber(uint64, int, int, bool) error
}

LightPeer encapsulates the methods required to synchronise with a remote light peer.

type Peer Uses

type Peer interface {
    LightPeer
    RequestBodies([]common.Hash) error
    RequestReceipts([]common.Hash) error
    RequestNodeData([]common.Hash) error
}

Peer encapsulates the methods required to synchronise with a remote full peer.

type PublicDownloaderAPI Uses

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

PublicDownloaderAPI provides an API which gives information about the current synchronisation status. It offers only methods that operates on data that can be available to anyone without security risks.

func NewPublicDownloaderAPI Uses

func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI

NewPublicDownloaderAPI create a new PublicDownloaderAPI. The API has an internal event loop that listens for events from the downloader through the global event mux. In case it receives one of these events it broadcasts it to all syncing subscriptions that are installed through the installSyncSubscription channel.

func (*PublicDownloaderAPI) SubscribeSyncStatus Uses

func (api *PublicDownloaderAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription

SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates. The given channel must receive interface values, the result can either

func (*PublicDownloaderAPI) Syncing Uses

func (api *PublicDownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error)

Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.

type StartEvent Uses

type StartEvent struct{}

type SyncMode Uses

type SyncMode int

SyncMode represents the synchronisation mode of the downloader.

const (
    FullSync  SyncMode = iota // Synchronise the entire blockchain history from full blocks
    FastSync                  // Quickly download the headers, full sync only at the chain head
    LightSync                 // Download only the headers and terminate afterwards
)

func (SyncMode) IsValid Uses

func (mode SyncMode) IsValid() bool

func (SyncMode) MarshalText Uses

func (mode SyncMode) MarshalText() ([]byte, error)

func (SyncMode) String Uses

func (mode SyncMode) String() string

String implements the stringer interface.

func (*SyncMode) UnmarshalText Uses

func (mode *SyncMode) UnmarshalText(text []byte) error

type SyncStatusSubscription Uses

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

SyncStatusSubscription represents a syncing subscription.

func (*SyncStatusSubscription) Unsubscribe Uses

func (s *SyncStatusSubscription) Unsubscribe()

Unsubscribe uninstalls the subscription from the DownloadAPI event loop. The status channel that was passed to subscribeSyncStatus isn't used anymore after this method returns.

type SyncingResult Uses

type SyncingResult struct {
    Syncing bool                  `json:"syncing"`
    Status  ethereum.SyncProgress `json:"status"`
}

SyncingResult provides information about the current synchronisation status for this node.

Package downloader imports 25 packages (graph) and is imported by 694 packages. Updated 2019-10-29. Refresh now. Tools for package owners.