protocol

package
v1.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: LGPL-3.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Handshake         = 0x01
	ProposeBlock      = 0x02
	ProposeProof      = 0x03
	Vote              = 0x04
	NewTx             = 0x05
	GetBlockByHash    = 0x06
	GetBlocksRange    = 0x07
	BlocksRange       = 0x08
	FlipBody          = 0x09
	FlipKey           = 0x0A
	SnapshotManifest  = 0x0B
	GetForkBlockRange = 0x0C
	FlipKeysPackage   = 0x0D
	Push              = 0x0E
	Pull              = 0x0F
	Block             = 0x10
	UpdateShardId     = 0x11
	BatchPush         = 0x12
	BatchFlipKey      = 0x13
	Disconnect        = 0x14
)
View Source
const (
	DecodeErr                  = 1
	ValidationErr              = 2
	MaxTimestampLagSeconds     = 15
	MaxBannedPeers             = 500000
	IdenaProtocolWeight        = 25
	ReconnectAfterDiscTimeout  = time.Minute * 1
	ReconnectAfterResetTimeout = time.Minute * 3
)
View Source
const Batches = PeerFeature("batches")
View Source
const FastSyncBatchSize = 1000
View Source
const FullSyncBatchSize = 200
View Source
const (
	MaxAttemptsCountPerBatch = 10
)
View Source
const MempoolSyncDelay = time.Second * 5

Variables

View Source
var (
	BanReasonTimeout = errors.New("timeout")
)
View Source
var (
	BlockCertIsMissing = errors.New("block cert is missing")
)
View Source
var FailedToDialPeer = errors.New("failed to select peer")
View Source
var IdenaProtocol = core.ProtocolID(IdenaProtocolPath + "/1.1.0")
View Source
var IdenaProtocolPath = "/idena/gossip"
View Source
var NoPeersToDial = errors.New("no peers to dial")

Functions

func Decode added in v0.21.0

func Decode(src []byte) ([]byte, error)

func Encode added in v0.21.0

func Encode(msgcode uint64, src []byte) []byte

func NewFastSync

func NewFastSync(pm *IdenaGossipHandler, log log.Logger,
	chain *blockchain.Blockchain,
	ipfs ipfs.Proxy,
	appState *appstate.AppState,
	potentialForkedPeers mapset.Set,
	manifest *snapshot.Manifest, sm *state.SnapshotManager, bus eventbus.Bus, coinbase common.Address, keyStore *keystore.KeyStore,
	subManager *subscriptions.Manager, upgrader *upgrade.Upgrader) *fastSync

func NewFullSync

func NewFullSync(
	pm *IdenaGossipHandler,
	log log.Logger,
	chain *blockchain.Blockchain,
	ipfs ipfs.Proxy,
	appState *appstate.AppState,
	potentialForkedPeers mapset.Set,
	targetHeight uint64,
	statsCollector collector.StatsCollector,
) *fullSync

func SetSupportedFeatures added in v0.27.3

func SetSupportedFeatures(peer *protoPeer)

func SntpDrift

func SntpDrift(measurements int) (time.Duration, error)

SntpDrift does a naive time resolution against an NTP server and returns the measured drift. This method uses the simple version of NTP. It's not precise but should be fine for these purposes.

Note, it executes two extra measurements compared to the number of requested ones to be able to discard the two extremes as outliers.

Types

type BlockSeeker

type BlockSeeker interface {
	SeekBlocks(fromBlock, toBlock uint64, peers []peer.ID) chan *types.BlockBundle
}

type CeremonyChecker added in v0.21.5

type CeremonyChecker interface {
	IsRunning() bool
}

type ConnManager

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

func NewConnManager

func NewConnManager(host core.Host, cfg config.P2P) *ConnManager

func (*ConnManager) AddConnection

func (m *ConnManager) AddConnection(conn network.Conn)

func (*ConnManager) BanPeer

func (m *ConnManager) BanPeer(id peer.ID)

func (*ConnManager) CanAcceptStream

func (m *ConnManager) CanAcceptStream() bool

func (*ConnManager) CanConnect

func (m *ConnManager) CanConnect(id peer.ID) bool

func (*ConnManager) CanDial

func (m *ConnManager) CanDial() bool

func (*ConnManager) Connected

func (m *ConnManager) Connected(id peer.ID, inbound bool, shardId common.ShardId)

func (*ConnManager) DialRandomPeer

func (m *ConnManager) DialRandomPeer() (network.Stream, error)

func (*ConnManager) Disconnected

func (m *ConnManager) Disconnected(id peer.ID, reason error)

func (*ConnManager) GetRandomPeer added in v0.27.0

func (m *ConnManager) GetRandomPeer(inbound bool) peer.ID

func (*ConnManager) IsFromOwnShards added in v0.27.0

func (m *ConnManager) IsFromOwnShards(id common.ShardId) bool

func (*ConnManager) MaxOutboundOwnPeers added in v0.27.0

func (m *ConnManager) MaxOutboundOwnPeers() int

func (*ConnManager) MaxOutboundPeers added in v0.23.2

func (m *ConnManager) MaxOutboundPeers() int

func (*ConnManager) NeedInboundOwnShardPeers added in v0.27.0

func (m *ConnManager) NeedInboundOwnShardPeers() bool

func (*ConnManager) NeedOutboundOwnShardPeers added in v0.27.0

func (m *ConnManager) NeedOutboundOwnShardPeers() bool

func (*ConnManager) NeedPeerFromShard added in v0.28.0

func (m *ConnManager) NeedPeerFromShard(inbound bool, shardId common.ShardId) (canConnect bool, shouldDisconnectAnotherPeer bool)

func (*ConnManager) NeedPeerFromSomeShard added in v0.27.0

func (m *ConnManager) NeedPeerFromSomeShard(shardsNum int) bool

func (*ConnManager) PeerForDisconnect added in v0.27.0

func (m *ConnManager) PeerForDisconnect(inbound bool, newPeerShardId common.ShardId) peer.ID

func (*ConnManager) PeersFromShard added in v0.27.0

func (m *ConnManager) PeersFromShard(shardId common.ShardId) int

func (*ConnManager) RemoveConnection

func (m *ConnManager) RemoveConnection(conn network.Conn)

func (*ConnManager) SetShardId added in v0.27.0

func (m *ConnManager) SetShardId(shard common.ShardId) (updated bool)

func (*ConnManager) UpdatePeerShardId added in v0.27.0

func (m *ConnManager) UpdatePeerShardId(id peer.ID, shardId common.ShardId)

type Downloader

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

func NewDownloader

func NewDownloader(
	pm *IdenaGossipHandler,
	cfg *config.Config,
	chain *blockchain.Blockchain,
	ipfs ipfs.Proxy,
	appState *appstate.AppState,
	sm *state.SnapshotManager,
	bus eventbus.Bus,
	secStore *secstore.SecStore,
	statsCollector collector.StatsCollector,
	subManager *subscriptions.Manager,
	keyStore *keystore.KeyStore,
	upgrader *upgrade.Upgrader,
) *Downloader

func (*Downloader) BanPeer

func (d *Downloader) BanPeer(peerId peer.ID, reason error)

func (*Downloader) ClearPotentialForks

func (d *Downloader) ClearPotentialForks()

func (*Downloader) GetForkedPeers

func (d *Downloader) GetForkedPeers() mapset.Set

func (*Downloader) HasPotentialFork

func (d *Downloader) HasPotentialFork() bool

func (*Downloader) IsSyncing

func (d *Downloader) IsSyncing() bool

func (*Downloader) Load

func (d *Downloader) Load()

func (*Downloader) SeekBlocks

func (d *Downloader) SeekBlocks(fromBlock, toBlock uint64, peers []peer.ID) chan *types.BlockBundle

func (*Downloader) SeekForkedBlocks

func (d *Downloader) SeekForkedBlocks(ownBlocks []common.Hash, peerId peer.ID) chan types.BlockBundle

func (*Downloader) SyncBlockchain

func (d *Downloader) SyncBlockchain(forkResolver ForkResolver) error

func (*Downloader) SyncProgress

func (d *Downloader) SyncProgress() (head uint64, top uint64)

type ForkResolver

type ForkResolver interface {
	HasLoadedFork() bool
}

type IdenaGossipHandler

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

func NewIdenaGossipHandler

func NewIdenaGossipHandler(host core.Host, pubsub *pubsub.PubSub, cfg config.P2P, chain *blockchain.Blockchain, proposals *pengings.Proposals, votes *pengings.Votes, txpool *mempool.TxPool, fp *flip.Flipper, bus eventbus.Bus, flipKeyPool *mempool.KeysPool, appVersion string, ceremonyChecker CeremonyChecker) *IdenaGossipHandler

func (*IdenaGossipHandler) AddPeer

func (h *IdenaGossipHandler) AddPeer(url string) error

func (*IdenaGossipHandler) BanPeer

func (h *IdenaGossipHandler) BanPeer(peerId peer.ID, reason error)

func (*IdenaGossipHandler) Endpoint

func (h *IdenaGossipHandler) Endpoint() string

func (*IdenaGossipHandler) GetBlocksRange

func (h *IdenaGossipHandler) GetBlocksRange(peerId peer.ID, from uint64, to uint64) (*batch, error)

func (*IdenaGossipHandler) GetForkBlockRange

func (h *IdenaGossipHandler) GetForkBlockRange(peerId peer.ID, ownBlocks []common.Hash) (*batch, error)

func (*IdenaGossipHandler) GetKnownHeights

func (h *IdenaGossipHandler) GetKnownHeights() map[peer.ID]uint64

func (*IdenaGossipHandler) GetKnownManifests

func (h *IdenaGossipHandler) GetKnownManifests() map[peer.ID]*snapshot.Manifest

func (*IdenaGossipHandler) HasPeers

func (h *IdenaGossipHandler) HasPeers() bool

func (*IdenaGossipHandler) IsConnected

func (h *IdenaGossipHandler) IsConnected(id peer.ID) bool

func (*IdenaGossipHandler) OwnPeeringShardId added in v0.27.0

func (h *IdenaGossipHandler) OwnPeeringShardId() common.ShardId

func (*IdenaGossipHandler) OwnShardPeersCount added in v0.27.0

func (h *IdenaGossipHandler) OwnShardPeersCount() int

func (*IdenaGossipHandler) PeerHeights

func (h *IdenaGossipHandler) PeerHeights() []uint64

func (*IdenaGossipHandler) Peers

func (h *IdenaGossipHandler) Peers() []*protoPeer

func (*IdenaGossipHandler) PeersCount

func (h *IdenaGossipHandler) PeersCount() int

func (*IdenaGossipHandler) PotentialForwardPeers

func (h *IdenaGossipHandler) PotentialForwardPeers(round uint64) []peer.ID

func (*IdenaGossipHandler) ProposeBlock

func (h *IdenaGossipHandler) ProposeBlock(block *types.BlockProposal)

func (*IdenaGossipHandler) ProposeProof

func (h *IdenaGossipHandler) ProposeProof(proposal *types.ProofProposal)

func (*IdenaGossipHandler) RequestBlockByHash

func (h *IdenaGossipHandler) RequestBlockByHash(hash common.Hash)

func (*IdenaGossipHandler) SendVote

func (h *IdenaGossipHandler) SendVote(vote *types.Vote)

func (*IdenaGossipHandler) Start

func (h *IdenaGossipHandler) Start()

func (*IdenaGossipHandler) WrongTime

func (h *IdenaGossipHandler) WrongTime() bool

type Msg

type Msg struct {
	Code    uint64
	ShardId common.ShardId
	Payload []byte
}

func (*Msg) FromBytes added in v0.21.0

func (msg *Msg) FromBytes(data []byte) error

func (*Msg) ToBytes added in v0.21.0

func (msg *Msg) ToBytes() ([]byte, error)

type PeerFeature added in v0.27.3

type PeerFeature = string

type PushPullManager

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

func NewPushPullManager

func NewPushPullManager() *PushPullManager

func (*PushPullManager) AddEntry

func (m *PushPullManager) AddEntry(key pushPullHash, entry interface{}, shardId common.ShardId, highPriority bool)

func (*PushPullManager) AddEntryHolder

func (m *PushPullManager) AddEntryHolder(pushId pushType, holder pushpull.Holder)

func (*PushPullManager) GetEntry

func (m *PushPullManager) GetEntry(hash pushPullHash) (interface{}, common.ShardId, bool, bool)

func (*PushPullManager) Requests

func (m *PushPullManager) Requests() chan pullRequest

func (*PushPullManager) Run added in v0.19.5

func (m *PushPullManager) Run()

type Syncer

type Syncer interface {
	IsSyncing() bool
}

Jump to

Keyboard shortcuts

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