downloader

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	Og01 = 01
	Og02 = 02
)

Variables

View Source
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

	MaxForkAncestry = 3 * uint64(3000) // Number of blocks to retrieve fully even in fast sync
)

Functions

func InitLoggers

func InitLoggers(logger *logrus.Logger, logdir string)

Types

type Downloader

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

func New

func New(mode SyncMode, dag IDag, dropPeer peerDropFn, insertTxs insertTxsFn) *Downloader

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

func (*Downloader) Cancel

func (d *Downloader) Cancel()

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

func (*Downloader) DeliverBodies

func (d *Downloader) DeliverBodies(id string, transactions []types.Txis, sequencers []*types.Sequencer) (err error)

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

func (*Downloader) DeliverHeaders

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

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

func (*Downloader) DeliverNodeData

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) RegisterPeer

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) Start added in v0.0.2

func (d *Downloader) Start()

func (*Downloader) Synchronise

func (d *Downloader) Synchronise(id string, head types2.Hash, seqId uint64, 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

func (d *Downloader) Synchronising() bool

Synchronising returns whether the downloader is currently retrieving blocks.

func (*Downloader) Terminate

func (d *Downloader) Terminate()

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

func (*Downloader) UnregisterPeer

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 IDag

type IDag interface {
	LatestSequencer() *types.Sequencer
	GetSequencer(hash types2.Hash, id uint64) *types.Sequencer
}

type Peer

type Peer interface {
	Head() (types.Hash, uint64)
	RequestHeadersByHash(origin types.Hash, amount int, skip int, reverse bool) error
	RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool) error
	//RequestSequencerByHash(common.Hash, int, int, bool) error
	//RequestSequencerByNumber(uint64, int, int, bool) error
	//RequestTxs(common.Hashes) error
	RequestBodies(seqHashs types.Hashes) error
	//RequestTxsByHash(hash common.Hash, id uint64) error
	RequestNodeData(types.Hashes) error
}

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

type SyncMode

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

func (mode SyncMode) IsValid() bool

func (SyncMode) MarshalText

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

func (SyncMode) String

func (mode SyncMode) String() string

String implements the stringer interface.

func (*SyncMode) UnmarshalText

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

Jump to

Keyboard shortcuts

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