network

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 50 Imported by: 0

README

Gossamer network Package

This package implements the peer-to-peer networking capabilities provided by the Substrate framework for blockchain development. It is built on the extensible libp2p networking stack. libp2p provides implementations of a number of battle-tested peer-to-peer (P2P) networking protocols (e.g. Noise for key exchange, and Yamux for stream multiplexing), and also makes it possible to implement the blockchain-specific protocols defined by Substrate (e.g. syncing and finalising blocks, and maintaining the transaction pool). The purpose of this document is to provide the information that is needed to understand the P2P networking capabilities that are implemented by Gossamer - this includes an introduction to P2P networks and libp2p, as well as detailed descriptions of the Gossamer P2P networking protocols.

Peer-to-Peer Networking & libp2p

Peer-to-peer networking has been a dynamic field of research for over two decades, and P2P protocols are at the heart of blockchain networks. P2P networks can be contrasted with traditional client-server networks where there is a clear separation of authority and privilege between the maintainers of the network and its users - in a P2P network, each participant possesses equal authority and equal privilege. libp2p is a framework for implementing P2P networks that was modularized out of IPFS; there are implementations in many languages including Go (used by this project), Rust, Javascript, C++, and more. In addition to the standard library of protocols in a libp2p implementation, there is a rich ecosystem of P2P networking packages that work with the pluggable architecture of libp2p. In some cases, Gossamer uses the libp2p networking primitives to implement custom protocols for blockchain-specific use cases. What follows is an exploration into three concepts that underpin P2P networks: identity & key management, peer discovery & management, and stream multiplexing.

Identity & Key Management

Many peer-to-peer networks, including those built with Gossamer, use public-key cryptography (also known as asymmetric cryptography) to allow network participants to securely identify themselves and interact with one another. The term "asymmetric" refers to the fact that in a public-key cryptography system, each participant's identity is associated with a set of two keys, each of which serve a distinct ("asymmetric") purpose. One of the keys in an asymmetric key pair is private and is used by the network participant to "sign" messages in order to cryptographically prove that the message originated from the private key's owner; the other key is public, this is the key that the participant uses to identify themselves - it is distributed to network peers to allow for the verification of messages signed by the corresponding private key. It may be constructive to think about a public key as a username and private key as a password, such as for a banking or social media website. Participants in P2P networks that use asymmetric cryptography must protect their private keys, as well as keep track of the public keys that belong to the other participants in the network. Gossamer provides a keystore for securely storing one's private keys. There are a number of Gossamer processes that manage the public keys of network peers - some of these, such as peer discovery and management, are described in this document, but there are other packages (most notably peerset) that also interact with the public keys of network peers. One of the most critical details in a network that uses asymmetric cryptography is the key distribution mechanism, which is the process that the nodes in the network use to securely exchange public keys - libp2p supports Noise, a key distribution framework that is based on Diffie-Hellman key exchange.

Peer Discovery & Management

In a peer-to-peer network, "discovery" is the term that is used to describe the mechanism that peers use to find one another - this is an important topic since there is not a privileged authority that can maintain an index of known/trusted network participants. The discovery mechanisms that peer-to-peer networks use have evolved over time - Napster relied on a central database, Gnutella used a brute-force technique called "flooding", BitTorrent takes a performance-preserving approach that relies on a distributed hash table (DHT). Gossamer uses a libp2p-based implementation of the Kademlia DHT for peer discovery.

Stream Multiplexing

Multiplexing allows multiple independent logical streams to share a common underlying transport medium, which amortizes the overhead of establishing new connections with peers in a P2P network. In particular, libp2p relies on "stream multiplexing", which uses logically distinct "paths" to route requests to the proper handlers. A familiar example of stream multiplexing exists in the TCP/IP stack, where unique port numbers are used to distinguish logically independent streams that share a common physical transport medium. Gossamer uses Yamux for stream multiplexing.

Gossamer Network Protocols

The types of network protocols that Gossamer uses can be separated into "core" peer-to-peer protocols, which are often maintained alongside libp2p, and blockchain network protocols, which Substrate implements on top of the libp2p stack.

Peer-to-Peer Protocols

These are the "core" peer-to-peer network protocols that are used by Gossamer.

ping

This is a simple liveness check protocol that peers can use to quickly see if another peer is online - it is included with the official Go implementation of libp2p.

identify

The identify protocol allows peers to exchange information about each other, most notably their public keys and known network addresses; like ping, it is included with go-libp2p.

Noise

Noise provides libp2p with its key distribution capabilities. The Noise protocol is well documented and the Go implementation is maintained under the official libp2p GitHub organization. Noise defines a handshake that participants in a peer-to-peer network can use to establish message-passing channels with one another.

Yamux

Yamux (Yet another Multiplexer) is a Golang library for stream-oriented multiplexing that is maintained by HashiCorp - it implements a well defined specification. Gossamer uses the official libp2p adapter for Yamux.

Kademlia

Kademlia is a battle-tested distributed hash table (DHT) that defines methods for managing a dynamic list of peers that is constantly updated in order to make a P2P network more resilient and resistant to attacks. Network peers use the DHT to advertise their presence, and also to discover each other by "walking" the DHT. Kademlia calculates a logical "distance" between any two nodes in the network by applying the xor operation to the IDs of those two peers. Although this "distance" is not correlated to the physical distance between the peers, it adheres to three properties that are crucial to the analysis of Kademlia as a protocol - in particular, these three properties are:

  • the "distance" between a peer and itself is zero
  • the "distance" between two peers is the same regardless of the order in which the peers are considered (it is symmetric)
  • the shortest "distance" between two peers does not include any intermediate peers (it follows the triangle inequality)

Gossamer uses the official libp2p implementation of Kademlia for Go.

Blockchain Network Protocols

The libp2p stack is used to implement the blockchain-specific protocols that are used to participate in "Substrate-like" networks - these protocols are divided into two types, notification and request/response. The two types of protocols are described in greater details below, along with the specific protocols for each type.

Notification Protocols

Notification protocols allow peers to unidirectionally "push" information to other peers in the network. When a notification stream is open, the peers exchange a handshake, after which the incoming side of the stream is closed for writing & the outgoing side of the stream is closed for reading. Notification streams may be left open indefinitely.

Transactions

This protocol is used to notify network peers of transactions that have been locally received and validated. Transactions are used to access the public APIs of blockchain runtimes.

Block Announces

The block announce protocol is used to notify network peers of the creation of a new block. The message for this protocol contains a block header and associated data, such as the BABE pre-runtime digest.

GRANDPA

Finality protocols ("gadgets") such as GRANDPA are often described in terms of "games" that are played by the participants in a network. In GRANDPA, this game relates to voting on what blocks should be part of the canonical chain. This notification protocol is used by peers to cast votes for participation in the GRANDPA game.

Request/Response Protocols

These protocols allow peers to request specific information from one another. The requesting peer sends a protocol-specific message that describes the request and the peer to which the request was sent replies with a message. When a peer opens a request/response stream by requesting data from another peer, they may only request data on that stream & the other peer may only respond to requests on that stream.

Sync

The sync protocol allows peers to request more information about a block that may have been discovered through the block announce notification protocol. The BlockRequest and BlockResponse messages for this protocol are defined in the api.v1.proto file that ships with Substrate.

Light

Light clients, like Substrate Connect, increase the decentralization of blockchain networks by allowing users to interact with the network directly through client applications, as opposed to using a client application to send a request to an intermediary node in the network. This protocol allows light clients to request information about the state of the network. The Request and Response messages for this protocol are defined in the light.v1.proto that ships with Substrate.

Documentation

Index

Constants

View Source
const (
	// DefaultKeyFile the default value for KeyFile
	DefaultKeyFile = "node.key"

	// DefaultBasePath the default value for Config.BasePath
	DefaultBasePath = "~/.gossamer/gssmr"

	// DefaultPort the default value for Config.Port
	DefaultPort = uint16(7000)

	// DefaultRandSeed the default value for Config.RandSeed (0 = non-deterministic)
	DefaultRandSeed = int64(0)

	// DefaultProtocolID the default value for Config.ProtocolID
	DefaultProtocolID = "/gossamer/gssmr/0"

	// DefaultRoles the default value for Config.Roles (0 = no network, 1 = full node)
	DefaultRoles = common.FullNodeRole

	// DefaultMinPeerCount is the default minimum peer count
	DefaultMinPeerCount = 5

	// DefaultMaxPeerCount is the default maximum peer count
	DefaultMaxPeerCount = 50

	// DefaultDiscoveryInterval is the default interval for searching for DHT peers
	DefaultDiscoveryInterval = time.Minute * 5
)
View Source
const (
	RequestedDataHeader        = byte(1)
	RequestedDataBody          = byte(2)
	RequestedDataReceipt       = byte(4)
	RequestedDataMessageQueue  = byte(8)
	RequestedDataJustification = byte(16)
)
View Source
const (
	ConsensusMsgType byte = 5
)

Message types for notifications protocol messages. Used internally to map message to protocol.

View Source
const MDNSPeriod = time.Minute

MDNSPeriod is 1 minute

View Source
const (

	// MaxGrandpaNotificationSize is maximum size for a grandpa notification message.
	MaxGrandpaNotificationSize uint64 = 1024 * 1024 // 1mb

)
View Source
const (
	// NetworkStateTimeout is the set time interval that we update network state
	NetworkStateTimeout = time.Minute
)

Variables

View Source
var DefaultBootnodes = []string(nil)

DefaultBootnodes the default value for Config.Bootnodes

Functions

This section is empty.

Types

type BlockAnnounceHandshake added in v0.2.0

type BlockAnnounceHandshake struct {
	Roles           common.Roles
	BestBlockNumber uint32
	BestBlockHash   common.Hash
	GenesisHash     common.Hash
}

BlockAnnounceHandshake is exchanged by nodes that are beginning the BlockAnnounce protocol

func (*BlockAnnounceHandshake) Decode added in v0.2.0

func (hs *BlockAnnounceHandshake) Decode(in []byte) error

Decode the message into a BlockAnnounceHandshake

func (*BlockAnnounceHandshake) Encode added in v0.2.0

func (hs *BlockAnnounceHandshake) Encode() ([]byte, error)

Encode encodes a BlockAnnounceHandshake message using SCALE

func (*BlockAnnounceHandshake) IsValid added in v0.7.0

func (hs *BlockAnnounceHandshake) IsValid() bool

IsValid returns true if handshakes's role is valid.

func (*BlockAnnounceHandshake) String added in v0.2.0

func (hs *BlockAnnounceHandshake) String() string

String formats a BlockAnnounceHandshake as a string

type BlockAnnounceMessage

type BlockAnnounceMessage struct {
	ParentHash     common.Hash
	Number         uint
	StateRoot      common.Hash
	ExtrinsicsRoot common.Hash
	Digest         scale.VaryingDataTypeSlice
	BestBlock      bool
}

BlockAnnounceMessage is a state block header

func (*BlockAnnounceMessage) Decode

func (bm *BlockAnnounceMessage) Decode(in []byte) error

Decode the message into a BlockAnnounceMessage

func (*BlockAnnounceMessage) Encode

func (bm *BlockAnnounceMessage) Encode() ([]byte, error)

Encode a BlockAnnounce Msg Type containing the BlockAnnounceMessage using scale.Encode

func (*BlockAnnounceMessage) Hash added in v0.3.0

func (bm *BlockAnnounceMessage) Hash() (common.Hash, error)

Hash returns the hash of the BlockAnnounceMessage

func (*BlockAnnounceMessage) String

func (bm *BlockAnnounceMessage) String() string

string formats a BlockAnnounceMessage as a string

func (*BlockAnnounceMessage) Type added in v0.2.0

func (*BlockAnnounceMessage) Type() byte

Type returns blockAnnounceMsgType

type BlockRequestMessage

type BlockRequestMessage struct {
	RequestedData byte
	StartingBlock variadic.Uint32OrHash // first byte 0 = block hash (32 byte), first byte 1 = block number (uint32)
	EndBlockHash  *common.Hash
	Direction     SyncDirection // 0 = ascending, 1 = descending
	Max           *uint32
}

BlockRequestMessage is sent to request some blocks from a peer

func (*BlockRequestMessage) Decode

func (bm *BlockRequestMessage) Decode(in []byte) error

Decode decodes the protobuf encoded input to a BlockRequestMessage

func (*BlockRequestMessage) Encode

func (bm *BlockRequestMessage) Encode() ([]byte, error)

Encode returns the protobuf encoded BlockRequestMessage

func (*BlockRequestMessage) String

func (bm *BlockRequestMessage) String() string

String formats a BlockRequestMessage as a string

type BlockResponseMessage

type BlockResponseMessage struct {
	BlockData []*types.BlockData
}

BlockResponseMessage is sent in response to a BlockRequestMessage

func (*BlockResponseMessage) Decode

func (bm *BlockResponseMessage) Decode(in []byte) (err error)

Decode decodes the protobuf encoded input to a BlockResponseMessage

func (*BlockResponseMessage) Encode

func (bm *BlockResponseMessage) Encode() ([]byte, error)

Encode returns the protobuf encoded BlockResponseMessage

func (*BlockResponseMessage) String

func (bm *BlockResponseMessage) String() string

String formats a BlockResponseMessage as a string

type BlockState

type BlockState interface {
	BestBlockHeader() (*types.Header, error)
	BestBlockNumber() (blockNumber uint, err error)
	GenesisHash() common.Hash
	HasBlockBody(common.Hash) (bool, error)
	GetHighestFinalisedHeader() (*types.Header, error)
	GetHashByNumber(num uint) (common.Hash, error)
}

BlockState interface for block state methods

type Config

type Config struct {
	LogLvl log.Level

	ErrChan chan<- error

	// BasePath the data directory for the node
	BasePath string
	// Roles a bitmap value that represents the different roles for the sender node (see Table D.2)
	Roles common.Roles

	// Service interfaces
	BlockState         BlockState
	Syncer             Syncer
	TransactionHandler TransactionHandler

	// Used to specify the address broadcasted to other peers, and avoids using pubip.Get
	PublicIP string
	// Used to specify the dns broadcasted to other peers, and avoids using pubip.Get.
	// Only PublicIP or PublicDNS will be used
	PublicDNS string
	// Port the network port used for listening
	Port uint16
	// RandSeed the seed used to generate the network p2p identity (0 = non-deterministic random seed)
	RandSeed int64
	// Bootnodes the peer addresses used for bootstrapping
	Bootnodes []string
	// ProtocolID the protocol ID for network messages
	ProtocolID string
	// NoBootstrap disables bootstrapping
	NoBootstrap bool
	// NoMDNS disables MDNS discovery
	NoMDNS bool

	MinPeers int
	MaxPeers int

	DiscoveryInterval time.Duration

	// PersistentPeers is a list of multiaddrs which the node should remain connected to
	PersistentPeers []string

	// SlotDuration is the slot duration to produce a block
	SlotDuration time.Duration

	Telemetry telemetry.Client
	Metrics   metrics.IntervalConfig
	// contains filtered or unexported fields
}

Config is used to configure a network service

type ConnManager

type ConnManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConnManager implements connmgr.ConnManager

func (*ConnManager) Close

func (*ConnManager) Close() error

Close is unimplemented

func (*ConnManager) Connected

func (cm *ConnManager) Connected(n network.Network, c network.Conn)

Connected is called when a connection opened

func (*ConnManager) Disconnected

func (cm *ConnManager) Disconnected(_ network.Network, c network.Conn)

Disconnected is called when a connection closed

func (*ConnManager) GetTagInfo

func (*ConnManager) GetTagInfo(peer.ID) *connmgr.TagInfo

GetTagInfo is unimplemented

func (*ConnManager) IsProtected added in v0.2.0

func (cm *ConnManager) IsProtected(id peer.ID, _ string) (protected bool)

IsProtected returns whether the given peer is protected from pruning or not.

func (*ConnManager) Listen

func (cm *ConnManager) Listen(n network.Network, addr ma.Multiaddr)

Listen is called when network starts listening on an address

func (*ConnManager) ListenClose

func (cm *ConnManager) ListenClose(n network.Network, addr ma.Multiaddr)

ListenClose is called when network stops listening on an address

func (*ConnManager) Notifee

func (cm *ConnManager) Notifee() network.Notifiee

Notifee is used to monitor changes to a connection

func (*ConnManager) Protect

func (cm *ConnManager) Protect(id peer.ID, _ string)

Protect peer will add the given peer to the protectedPeerMap which will protect the peer from pruning.

func (*ConnManager) TagPeer

func (*ConnManager) TagPeer(peer.ID, string, int)

TagPeer is unimplemented

func (*ConnManager) TrimOpenConns

func (*ConnManager) TrimOpenConns(context.Context)

TrimOpenConns is unimplemented

func (*ConnManager) Unprotect

func (cm *ConnManager) Unprotect(id peer.ID, _ string) bool

Unprotect peer will remove the given peer from prune protection. returns true if we have successfully removed the peer from the protectedPeerMap. False otherwise.

func (*ConnManager) UntagPeer

func (*ConnManager) UntagPeer(peer.ID, string)

UntagPeer is unimplemented

func (*ConnManager) UpsertTag

func (*ConnManager) UpsertTag(peer.ID, string, func(int) int)

UpsertTag is unimplemented

type ConsensusMessage

type ConsensusMessage struct {
	Data []byte
}

ConsensusMessage is mostly opaque to us

func (*ConsensusMessage) Decode

func (cm *ConsensusMessage) Decode(in []byte) error

Decode the message into a ConsensusMessage

func (*ConsensusMessage) Encode

func (cm *ConsensusMessage) Encode() ([]byte, error)

Encode encodes a block response message using SCALE

func (*ConsensusMessage) Hash added in v0.3.0

func (cm *ConsensusMessage) Hash() (common.Hash, error)

Hash returns the Hash of ConsensusMessage

func (*ConsensusMessage) String

func (cm *ConsensusMessage) String() string

String is the string

func (*ConsensusMessage) Type added in v0.2.0

func (cm *ConsensusMessage) Type() byte

Type returns ConsensusMsgType

type Handshake added in v0.3.0

type Handshake interface {
	Message
	IsValid() bool
}

Handshake is the interface all handshakes for notifications protocols must implement

type HandshakeDecoder added in v0.3.0

type HandshakeDecoder = func([]byte) (Handshake, error)

HandshakeDecoder is a custom decoder for a handshake

type HandshakeGetter added in v0.3.0

type HandshakeGetter = func() (Handshake, error)

HandshakeGetter is a function that returns a custom handshake

type HandshakeValidator added in v0.3.0

type HandshakeValidator = func(peer.ID, Handshake) error

HandshakeValidator validates a handshake. It returns an error if it is invalid

type LightRequest added in v0.3.0

LightRequest is all possible light client related requests.

func NewLightRequest added in v0.3.0

func NewLightRequest() *LightRequest

NewLightRequest returns a new LightRequest

func (*LightRequest) Decode added in v0.3.0

func (l *LightRequest) Decode(in []byte) error

Decode the message into a LightRequest, it assumes the type byte has been removed

func (*LightRequest) Encode added in v0.3.0

func (l *LightRequest) Encode() ([]byte, error)

Encode encodes a LightRequest message using SCALE and appends the type byte to the start

func (LightRequest) String added in v0.3.0

func (l LightRequest) String() string

String formats a LightRequest as a string

type LightResponse added in v0.3.0

LightResponse is all possible light client response messages.

func NewLightResponse added in v0.3.0

func NewLightResponse() *LightResponse

NewLightResponse returns a new LightResponse

func (*LightResponse) Decode added in v0.3.0

func (l *LightResponse) Decode(in []byte) error

Decode the message into a LightResponse, it assumes the type byte has been removed

func (*LightResponse) Encode added in v0.3.0

func (l *LightResponse) Encode() ([]byte, error)

Encode encodes a LightResponse message using SCALE and appends the type byte to the start

func (LightResponse) String added in v0.3.0

func (l LightResponse) String() string

String formats a RemoteReadRequest as a string

type Message

type Message interface {
	Encode() ([]byte, error)
	Decode([]byte) error
	String() string
}

Message must be implemented by all network messages

type MessageDecoder added in v0.3.0

type MessageDecoder = func([]byte) (NotificationsMessage, error)

MessageDecoder is a custom decoder for a message

type Notifee

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

Notifee See https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#Notifee

func (Notifee) HandlePeerFound

func (n Notifee) HandlePeerFound(p peer.AddrInfo)

HandlePeerFound is event handler called when a peer is found

type NotificationsMessage added in v0.3.0

type NotificationsMessage interface {
	Message
	Type() byte
	Hash() (common.Hash, error)
}

NotificationsMessage must be implemented by all messages sent over a notifications protocol

type NotificationsMessageBatchHandler added in v0.7.0

type NotificationsMessageBatchHandler = func(peer peer.ID, msg NotificationsMessage)

NotificationsMessageBatchHandler is called when a (non-handshake) message is received over a notifications stream in batch processing mode.

type NotificationsMessageHandler added in v0.3.0

type NotificationsMessageHandler = func(peer peer.ID, msg NotificationsMessage) (propagate bool, err error)

NotificationsMessageHandler is called when a (non-handshake) message is received over a notifications stream.

type Pair added in v0.3.0

type Pair struct {
	First  []byte
	Second []byte
}

Pair is a pair of arbitrary bytes.

type Peer added in v0.7.0

type Peer interface {
	PeerReputation(peer.ID) (peerset.Reputation, error)
	SortedPeers(idx int) chan peer.IDSlice
	Messages() chan peerset.Message
}

Peer is the interface used by the PeerSetHandler to get the peer data from peerSet.

type PeerAdd added in v0.7.0

type PeerAdd interface {
	Incoming(int, ...peer.ID)
	AddReservedPeer(int, ...peer.ID)
	AddPeer(int, ...peer.ID)
	SetReservedPeer(int, ...peer.ID)
}

PeerAdd is the interface used by the PeerSetHandler to add peers in peerSet.

type PeerRemove added in v0.7.0

type PeerRemove interface {
	DisconnectPeer(int, ...peer.ID)
	RemoveReservedPeer(int, ...peer.ID)
	RemovePeer(int, ...peer.ID)
}

PeerRemove is the interface used by the PeerSetHandler to remove peers from peerSet.

type PeerSetHandler added in v0.7.0

type PeerSetHandler interface {
	Start(context.Context)
	ReportPeer(peerset.ReputationChange, ...peer.ID)
	PeerAdd
	PeerRemove
	Peer
}

PeerSetHandler is the interface used by the connection manager to handle peerset.

type RemoteCallRequest added in v0.3.0

type RemoteCallRequest struct {
	Block  []byte
	Method string
	Data   []byte
}

RemoteCallRequest ...

func (*RemoteCallRequest) String added in v0.3.0

func (rc *RemoteCallRequest) String() string

String formats a RemoteCallRequest as a string

type RemoteCallResponse added in v0.3.0

type RemoteCallResponse struct {
	Proof []byte
}

RemoteCallResponse ...

func (*RemoteCallResponse) String added in v0.3.0

func (rc *RemoteCallResponse) String() string

String formats a RemoteCallResponse as a string

type RemoteChangesRequest added in v0.3.0

type RemoteChangesRequest struct {
	FirstBlock *common.Hash
	LastBlock  *common.Hash
	Min        []byte
	Max        []byte
	StorageKey *[]byte
	// contains filtered or unexported fields
}

RemoteChangesRequest ...

func (*RemoteChangesRequest) String added in v0.3.0

func (rc *RemoteChangesRequest) String() string

String formats a RemoteChangesRequest as a string

type RemoteChangesResponse added in v0.3.0

type RemoteChangesResponse struct {
	Max        []byte
	Proof      [][]byte
	Roots      [][]Pair
	RootsProof []byte
}

RemoteChangesResponse ...

func (*RemoteChangesResponse) String added in v0.3.0

func (rc *RemoteChangesResponse) String() string

String formats a RemoteChangesResponse as a string

type RemoteHeaderRequest added in v0.3.0

type RemoteHeaderRequest struct {
	Block []byte
}

RemoteHeaderRequest ...

func (*RemoteHeaderRequest) String added in v0.3.0

func (rh *RemoteHeaderRequest) String() string

String formats a RemoteHeaderRequest as a string

type RemoteHeaderResponse added in v0.3.0

type RemoteHeaderResponse struct {
	Header []*types.Header
	// contains filtered or unexported fields
}

RemoteHeaderResponse ...

func (*RemoteHeaderResponse) String added in v0.3.0

func (rh *RemoteHeaderResponse) String() string

String formats a RemoteHeaderResponse as a string

type RemoteReadChildRequest added in v0.3.0

type RemoteReadChildRequest struct {
	Block      []byte
	StorageKey []byte
	Keys       [][]byte
}

RemoteReadChildRequest ...

func (*RemoteReadChildRequest) String added in v0.3.0

func (rr *RemoteReadChildRequest) String() string

String formats a RemoteReadChildRequest as a string

type RemoteReadRequest added in v0.3.0

type RemoteReadRequest struct {
	Block []byte
	Keys  [][]byte
}

RemoteReadRequest ...

func (*RemoteReadRequest) String added in v0.3.0

func (rr *RemoteReadRequest) String() string

String formats a RemoteReadRequest as a string

type RemoteReadResponse added in v0.3.0

type RemoteReadResponse struct {
	Proof []byte
}

RemoteReadResponse ...

func (*RemoteReadResponse) String added in v0.3.0

func (rr *RemoteReadResponse) String() string

String formats a RemoteReadResponse as a string

type Service

type Service struct {
	Metrics metrics.IntervalConfig
	// contains filtered or unexported fields
}

Service describes a network service

func NewService

func NewService(cfg *Config) (*Service, error)

NewService creates a new network service from the configuration and message channels

func (*Service) AddReservedPeers added in v0.7.0

func (s *Service) AddReservedPeers(addrs ...string) error

AddReservedPeers insert new peers to the peerstore with PermanentAddrTTL

func (*Service) DoBlockRequest added in v0.7.0

func (s *Service) DoBlockRequest(to peer.ID, req *BlockRequestMessage) (*BlockResponseMessage, error)

DoBlockRequest sends a request to the given peer. If a response is received within a certain time period, it is returned, otherwise an error is returned.

func (*Service) GossipMessage added in v0.7.0

func (s *Service) GossipMessage(msg NotificationsMessage)

GossipMessage gossips a notifications protocol message to our peers

func (*Service) Health

func (s *Service) Health() common.Health

Health returns information about host needed for the rpc server

func (*Service) HighestBlock added in v0.7.0

func (*Service) HighestBlock() int64

HighestBlock returns the highest known block number

func (*Service) IsStopped added in v0.2.0

func (s *Service) IsStopped() bool

IsStopped returns true if the service is stopped

func (*Service) IsSynced added in v0.7.0

func (s *Service) IsSynced() bool

IsSynced returns whether we are synced (no longer in bootstrap mode) or not

func (*Service) NetworkState

func (s *Service) NetworkState() common.NetworkState

NetworkState returns information about host needed for the rpc server and the runtime

func (*Service) NodeRoles

func (s *Service) NodeRoles() common.Roles

NodeRoles Returns the roles the node is running as.

func (*Service) Peers

func (s *Service) Peers() []common.PeerInfo

Peers returns information about connected peers needed for the rpc server

func (*Service) RegisterNotificationsProtocol added in v0.3.0

func (s *Service) RegisterNotificationsProtocol(
	protocolID protocol.ID,
	messageID byte,
	handshakeGetter HandshakeGetter,
	handshakeDecoder HandshakeDecoder,
	handshakeValidator HandshakeValidator,
	messageDecoder MessageDecoder,
	messageHandler NotificationsMessageHandler,
	batchHandler NotificationsMessageBatchHandler,
	maxSize uint64,
) error

RegisterNotificationsProtocol registers a protocol with the network service with the given handler messageID is a user-defined message ID for the message passed over this protocol.

func (*Service) RemoveReservedPeers added in v0.7.0

func (s *Service) RemoveReservedPeers(addrs ...string) error

RemoveReservedPeers closes all connections with the target peers and remove it from the peerstore

func (*Service) ReportPeer added in v0.7.0

func (s *Service) ReportPeer(change peerset.ReputationChange, p peer.ID)

ReportPeer reports ReputationChange according to the peer behaviour.

func (*Service) SendMessage added in v0.2.0

func (s *Service) SendMessage(to peer.ID, msg NotificationsMessage) error

SendMessage sends a message to the given peer

func (*Service) SetSyncer added in v0.3.0

func (s *Service) SetSyncer(syncer Syncer)

SetSyncer sets the Syncer used by the network service

func (*Service) SetTransactionHandler added in v0.3.0

func (s *Service) SetTransactionHandler(handler TransactionHandler)

SetTransactionHandler sets the TransactionHandler used by the network service

func (*Service) Start

func (s *Service) Start() error

Start starts the network service

func (*Service) StartingBlock added in v0.7.0

func (*Service) StartingBlock() int64

StartingBlock return the starting block number that's currently being synced

func (*Service) Stop

func (s *Service) Stop() error

Stop closes running instances of the host and network services as well as the message channel from the network service to the core service (services that are dependent on the host instance should be closed first)

type SyncDirection added in v0.7.0

type SyncDirection byte

SyncDirection is the direction of data in a block response

const (
	// Ascending is used when block response data is in ascending order (ie parent to child)
	Ascending SyncDirection = iota

	// Descending is used when block response data is in descending order (ie child to parent)
	Descending
)

func (SyncDirection) String added in v0.7.0

func (sd SyncDirection) String() string

type Syncer added in v0.2.0

type Syncer interface {
	HandleBlockAnnounceHandshake(from peer.ID, msg *BlockAnnounceHandshake) error

	// HandleBlockAnnounce is called upon receipt of a BlockAnnounceMessage to process it.
	// If a request needs to be sent to the peer to retrieve the full block, this function will return it.
	HandleBlockAnnounce(from peer.ID, msg *BlockAnnounceMessage) error

	// IsSynced exposes the internal synced state
	IsSynced() bool

	// CreateBlockResponse is called upon receipt of a BlockRequestMessage to create the response
	CreateBlockResponse(*BlockRequestMessage) (*BlockResponseMessage, error)
}

Syncer is implemented by the syncing service

type TransactionHandler added in v0.3.0

type TransactionHandler interface {
	HandleTransactionMessage(peer.ID, *TransactionMessage) (bool, error)
	TransactionsCount() int
}

TransactionHandler is the interface used by the transactions sub-protocol

type TransactionMessage

type TransactionMessage struct {
	Extrinsics []types.Extrinsic
}

TransactionMessage is a network message that is sent to notify of new transactions entering the network

func (*TransactionMessage) Decode

func (tm *TransactionMessage) Decode(in []byte) error

Decode the message into a TransactionMessage

func (*TransactionMessage) Encode

func (tm *TransactionMessage) Encode() ([]byte, error)

Encode will encode TransactionMessage using scale.Encode

func (*TransactionMessage) Hash added in v0.3.0

func (tm *TransactionMessage) Hash() (common.Hash, error)

Hash returns the hash of the TransactionMessage

func (*TransactionMessage) String

func (tm *TransactionMessage) String() string

String returns the TransactionMessage extrinsics

func (*TransactionMessage) Type added in v0.2.0

func (*TransactionMessage) Type() byte

Type returns transactionMsgType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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