Documentation
¶
Index ¶
- Constants
- Variables
- func NewLibP2PValidatorNetwork(ctx context.Context, node node, opts ValidatorNetworkOptions, ...) (*validatorNetwork, error)
- func NodeIDFromPublicKeyBytes(pubKey []byte) (peer.ID, error)
- type BootstrapConnectRetry
- type LibP2PNetwork
- type MsgQueue
- type Observability
- type Peer
- func (p *Peer) Advertise(ctx context.Context, topic string) error
- func (p *Peer) BootstrapConnect(ctx context.Context, log *slog.Logger) error
- func (p *Peer) Close() error
- func (p *Peer) Configuration() *PeerConfiguration
- func (p *Peer) CreateStream(ctx context.Context, peerID peer.ID, protocolID string) (network.Stream, error)
- func (p *Peer) Discover(ctx context.Context, topic string) (<-chan peer.AddrInfo, error)
- func (p *Peer) ID() peer.ID
- func (p *Peer) MultiAddresses() []ma.Multiaddr
- func (p *Peer) Network() network.Network
- func (p *Peer) RegisterProtocolHandler(protocolID string, handler network.StreamHandler)
- func (p *Peer) RemoveProtocolHandler(protocolID string)
- func (p *Peer) String() string
- type PeerConfiguration
- type PeerKeyPair
- type TxProcessor
- type TxReceiver
- type ValidatorNetworkOptions
Constants ¶
const ( ProtocolHandshake = "/ab/handshake/0.0.1" ProtocolBlockCertification = "/ab/block-certification/0.0.1" ProtocolUnicityCertificates = "/ab/certificates/0.0.1" )
const ( ProtocolRootIrChangeReq = "/ab/root-change-req/0.0.1" ProtocolRootProposal = "/ab/root-proposal/0.0.1" ProtocolRootVote = "/ab/root-vote/0.0.1" ProtocolRootTimeout = "/ab/root-timeout/0.0.1" ProtocolRootStateReq = "/ab/root-state-req/0.0.1" ProtocolRootStateResp = "/ab/root-state-resp/0.0.1" )
const ( ProtocolInputForward = "/ab/input-forward/0.0.1" ProtocolBlockProposal = "/ab/block-proposal/0.0.1" ProtocolLedgerReplicationReq = "/ab/replication-req/0.0.1" ProtocolLedgerReplicationResp = "/ab/replication-resp/0.0.1" TopicPrefixBlock = "/ab/block/0.0.1/" )
Variables ¶
var DefaultValidatorNetworkOptions = ValidatorNetworkOptions{ ReceivedChannelCapacity: 1000, TxBufferSize: 1000, TxBufferHashAlgorithm: crypto.SHA256, BlockCertificationTimeout: 300 * time.Millisecond, BlockProposalTimeout: 300 * time.Millisecond, LedgerReplicationRequestTimeout: 300 * time.Millisecond, LedgerReplicationResponseTimeout: 300 * time.Millisecond, HandshakeTimeout: 300 * time.Millisecond, }
var (
ErrPeerConfigurationIsNil = errors.New("peer configuration is nil")
)
Functions ¶
func NewLibP2PValidatorNetwork ¶
func NewLibP2PValidatorNetwork(ctx context.Context, node node, opts ValidatorNetworkOptions, obs Observability) (*validatorNetwork, error)
NewLibP2PValidatorNetwork creates a new LibP2PNetwork based validator network.
Logger (log) is assumed to already have node_id attribute added, won't be added by NW component!
Types ¶
type BootstrapConnectRetry ¶
type BootstrapConnectRetry struct {
Count int // number of times to retry connecting to bootstrap peers
Delay int // delay in seconds
}
BootstrapConnectRetry contains the number of times to retry connecting to bootstrap peers and the delay between retries.
type LibP2PNetwork ¶
type LibP2PNetwork struct {
// contains filtered or unexported fields
}
LibP2PNetwork implements "unicity network" using libp2p.
Zero value is not useable, use one of the constructors to create network!
func NewLibP2PRootChainNetwork ¶
func NewLibP2PRootChainNetwork(self *Peer, capacity uint, sendCertificateTimeout time.Duration, obs Observability) (*LibP2PNetwork, error)
Logger (log) is assumed to already have node_id attribute added, won't be added by NW component!
func NewLibP2RootConsensusNetwork ¶
func NewLibP2RootConsensusNetwork(self *Peer, capacity uint, sendTimeout time.Duration, obs Observability) (*LibP2PNetwork, error)
func (*LibP2PNetwork) ReceivedChannel ¶
func (n *LibP2PNetwork) ReceivedChannel() <-chan any
func (*LibP2PNetwork) SendMsgs ¶
func (n *LibP2PNetwork) SendMsgs(ctx context.Context, messages MsgQueue, receiver peer.ID) (resErr error)
SendMsgs - synchronously send a collection of the same type messages to peer (method can block) Returns successfully when all bytes have been written to the output buffer If during writing, the other side closes or resets the stream, an error will be returned However, this does not mean application level synchronization; messages can still be lost without the sender knowing
type Observability ¶
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer represents a single node in p2p network. It is a wrapper around the libp2p host.Host.
func NewPeer ¶
func NewPeer(ctx context.Context, conf *PeerConfiguration, log *slog.Logger, prom prometheus.Registerer) (*Peer, error)
NewPeer constructs a new peer node with given configuration. If no peer key is provided, it generates a random Secp256k1 key-pair and derives a new identity from it. If no transport and listen addresses are provided, the node listens to the multiaddresses "/ip4/0.0.0.0/tcp/0".
func (*Peer) BootstrapConnect ¶
This code is borrowed from the go-ipfs bootstrap process
func (*Peer) Configuration ¶
func (p *Peer) Configuration() *PeerConfiguration
Configuration returns peer configuration
func (*Peer) CreateStream ¶
func (p *Peer) CreateStream(ctx context.Context, peerID peer.ID, protocolID string) (network.Stream, error)
CreateStream opens a new stream to given peer p, and writes a libp2p protocol header with given ProtocolID.
func (*Peer) MultiAddresses ¶
MultiAddresses the address associated with this Peer.
func (*Peer) RegisterProtocolHandler ¶
func (p *Peer) RegisterProtocolHandler(protocolID string, handler network.StreamHandler)
RegisterProtocolHandler sets the protocol stream handler for given protocol.
func (*Peer) RemoveProtocolHandler ¶
RemoveProtocolHandler removes the given protocol handler.
type PeerConfiguration ¶
type PeerConfiguration struct {
ID peer.ID // peer identifier derived from the KeyPair.PublicKey.
Address string // address to listen for incoming connections. Uses libp2p multiaddress format.
AnnounceAddrs []ma.Multiaddr // callback addresses to announce to other peers, if specified then overwrites any and all default listen addresses
KeyPair *PeerKeyPair // keypair for the peer.
BootstrapPeers []peer.AddrInfo // a list of seed peers to connect to.
BootstrapConnectRetry *BootstrapConnectRetry
}
PeerConfiguration includes single peer configuration values.
func NewPeerConfiguration ¶
func NewPeerConfiguration( addr string, announceAddrs []string, keyPair *PeerKeyPair, bootstrapPeers []peer.AddrInfo, bootstrapConnectRetry *BootstrapConnectRetry, ) (*PeerConfiguration, error)
type PeerKeyPair ¶
PeerKeyPair contains node's public and private key.
type TxProcessor ¶
type TxProcessor func(ctx context.Context, tx *types.TransactionOrder) error
type TxReceiver ¶
type ValidatorNetworkOptions ¶
type ValidatorNetworkOptions struct {
// How many messages will be buffered (ReceivedChannel) in case of slow consumer.
// Once buffer is full messages will be dropped (ie not processed)
// until consumer catches up.
ReceivedChannelCapacity uint
TxBufferSize uint
TxBufferHashAlgorithm crypto.Hash
BlockCertificationTimeout time.Duration
BlockProposalTimeout time.Duration
LedgerReplicationRequestTimeout time.Duration
LedgerReplicationResponseTimeout time.Duration
HandshakeTimeout time.Duration
}