Documentation ¶
Index ¶
- Variables
- func Subnet(addr, mask string) string
- type ChainManager
- type Option
- func WithBanDuration(d time.Duration) Option
- func WithConnectTimeout(d time.Duration) Option
- func WithLogger(l *zap.Logger) Option
- func WithMaxInboundPeers(n int) Option
- func WithMaxInflightRPCs(n int) Option
- func WithMaxOutboundPeers(n int) Option
- func WithMaxSendBlocks(n uint64) Option
- func WithPeerDiscoveryInterval(d time.Duration) Option
- func WithRelayBlockOutlineTimeout(d time.Duration) Option
- func WithRelayHeaderTimeout(d time.Duration) Option
- func WithRelayTransactionSetTimeout(d time.Duration) Option
- func WithSendBlockTimeout(d time.Duration) Option
- func WithSendBlocksTimeout(d time.Duration) Option
- func WithSendTransactionsTimeout(d time.Duration) Option
- func WithShareNodesTimeout(d time.Duration) Option
- func WithSyncInterval(d time.Duration) Option
- type Peer
- func (p *Peer) Addr() string
- func (p *Peer) Close() error
- func (p *Peer) DiscoverIP(timeout time.Duration) (string, error)
- func (p *Peer) Err() error
- func (p *Peer) RelayHeader(h types.BlockHeader, timeout time.Duration) error
- func (p *Peer) RelayTransactionSet(txns []types.Transaction, timeout time.Duration) error
- func (p *Peer) RelayV2BlockOutline(b gateway.V2BlockOutline, timeout time.Duration) error
- func (p *Peer) RelayV2Header(bh types.BlockHeader, timeout time.Duration) error
- func (p *Peer) RelayV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction, timeout time.Duration) error
- func (p *Peer) SendBlock(id types.BlockID, timeout time.Duration) (types.Block, error)
- func (p *Peer) SendBlocks(history [32]types.BlockID, timeout time.Duration, fn func([]types.Block) error) error
- func (p *Peer) SendCheckpoint(index types.ChainIndex, timeout time.Duration) (types.Block, consensus.State, error)
- func (p *Peer) SendTransactions(index types.ChainIndex, txnHashes []types.Hash256, timeout time.Duration) ([]types.Transaction, []types.V2Transaction, error)
- func (p *Peer) SendV2Blocks(history []types.BlockID, maxBlocks uint64, timeout time.Duration) ([]types.Block, uint64, error)
- func (p *Peer) ShareNodes(timeout time.Duration) ([]string, error)
- func (p *Peer) String() string
- func (p *Peer) Synced() bool
- func (p *Peer) UniqueID() gateway.UniqueID
- func (p *Peer) Version() string
- type PeerInfo
- type PeerStore
- type Syncer
- func (s *Syncer) Addr() string
- func (s *Syncer) BroadcastHeader(bh types.BlockHeader)
- func (s *Syncer) BroadcastTransactionSet(txns []types.Transaction)
- func (s *Syncer) BroadcastV2BlockOutline(b gateway.V2BlockOutline)
- func (s *Syncer) BroadcastV2Header(bh types.BlockHeader)
- func (s *Syncer) BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction)
- func (s *Syncer) Close() error
- func (s *Syncer) Connect(ctx context.Context, addr string) (*Peer, error)
- func (s *Syncer) PeerInfo(addr string) (PeerInfo, error)
- func (s *Syncer) Peers() []*Peer
- func (s *Syncer) Run(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var ( // AnagamiBootstrapPeers is a list of peers for the Anagami network. AnagamiBootstrapPeers = []string{ "15.204.160.10:9781", "141.95.66.81:9781", "51.81.242.140:9781", "15.204.101.216:9781", "40.160.12.62:9781", } // MainnetBootstrapPeers is a list of peers for the Mainnet network. MainnetBootstrapPeers = []string{ "40.160.12.62:9881", "108.227.62.195:9981", "139.162.81.190:9991", "144.217.7.188:9981", "147.182.196.252:9981", "15.235.85.30:9981", "167.235.234.84:9981", "173.235.144.230:9981", "198.98.53.144:7791", "199.27.255.169:9981", "2.136.192.200:9981", "213.159.50.43:9981", "24.253.116.61:9981", "46.249.226.103:9981", "5.165.236.113:9981", "5.252.226.131:9981", "54.38.120.222:9981", "62.210.136.25:9981", "63.135.62.123:9981", "65.21.93.245:9981", "75.165.149.114:9981", "77.51.200.125:9981", "81.6.58.121:9981", "83.194.193.156:9981", "84.39.246.63:9981", "87.99.166.34:9981", "91.214.242.11:9981", "93.105.88.181:9981", "93.180.191.86:9981", "94.130.220.162:9981", } // ZenBootstrapPeers is a list of peers for the Zen network. ZenBootstrapPeers = []string{ "40.160.12.62:9881", "141.94.161.198:9881", "15.204.141.235:9881", "51.79.16.87:9881", "141.94.161.198:9881", "31.208.123.47:9881", "62.30.63.90:9881", "162.19.232.38:9881", "15.204.160.10:10881", "51.81.56.133:9881", } )
var ( // ErrPeerBanned is returned when a peer is banned. ErrPeerBanned = errors.New("peer is banned") // ErrPeerNotFound is returned when the peer is not found. ErrPeerNotFound = errors.New("peer not found") )
Functions ¶
Types ¶
type ChainManager ¶
type ChainManager interface { History() ([32]types.BlockID, error) BlocksForHistory(history []types.BlockID, max uint64) ([]types.Block, uint64, error) Block(id types.BlockID) (types.Block, bool) State(id types.BlockID) (consensus.State, bool) AddBlocks(blocks []types.Block) error Tip() types.ChainIndex TipState() consensus.State PoolTransaction(txid types.TransactionID) (types.Transaction, bool) AddPoolTransactions(txns []types.Transaction) (bool, error) V2PoolTransaction(txid types.TransactionID) (types.V2Transaction, bool) AddV2PoolTransactions(basis types.ChainIndex, txns []types.V2Transaction) (bool, error) TransactionsForPartialBlock(missing []types.Hash256) ([]types.Transaction, []types.V2Transaction) }
A ChainManager manages blockchain state.
type Option ¶
type Option func(*config)
An Option modifies a Syncer's configuration.
func WithBanDuration ¶
WithBanDuration sets the duration for which a peer is banned when misbehaving.
func WithConnectTimeout ¶
WithConnectTimeout sets the timeout when connecting to a peer. The default is 5 seconds.
func WithLogger ¶
WithLogger sets the logger used by a Syncer. The default is a logger that outputs to io.Discard.
func WithMaxInboundPeers ¶
WithMaxInboundPeers sets the maximum number of inbound connections. The default is 8.
func WithMaxInflightRPCs ¶
WithMaxInflightRPCs sets the maximum number of concurrent RPCs per peer. The default is 3.
func WithMaxOutboundPeers ¶
WithMaxOutboundPeers sets the maximum number of outbound connections. The default is 8.
func WithMaxSendBlocks ¶
WithMaxSendBlocks sets the maximum number of blocks requested per SendBlocks RPC. The default is 10.
func WithPeerDiscoveryInterval ¶
WithPeerDiscoveryInterval sets the frequency at which the syncer attempts to discover and connect to new peers. The default is 5 seconds.
func WithRelayBlockOutlineTimeout ¶
WithRelayBlockOutlineTimeout sets the timeout for the RelayV2BlockOutline RPC. The default is 60 seconds.
func WithRelayHeaderTimeout ¶
WithRelayHeaderTimeout sets the timeout for the RelayHeader and RelayV2Header RPCs. The default is 5 seconds.
func WithRelayTransactionSetTimeout ¶
WithRelayTransactionSetTimeout sets the timeout for the RelayTransactionSet RPC. The default is 60 seconds.
func WithSendBlockTimeout ¶
WithSendBlockTimeout sets the timeout for the SendBlock RPC. The default is 60 seconds.
func WithSendBlocksTimeout ¶
WithSendBlocksTimeout sets the timeout for the SendBlocks RPC. The default is 120 seconds.
func WithSendTransactionsTimeout ¶
WithSendTransactionsTimeout sets the timeout for the SendTransactions RPC. The default is 60 seconds.
func WithShareNodesTimeout ¶
WithShareNodesTimeout sets the timeout for the ShareNodes RPC. The default is 5 seconds.
func WithSyncInterval ¶
WithSyncInterval sets the frequency at which the syncer attempts to sync with peers. The default is 5 seconds.
type Peer ¶
A Peer is a connected gateway peer.
func (*Peer) DiscoverIP ¶
DiscoverIP requests our external IP as seen by the peer.
func (*Peer) RelayHeader ¶
RelayHeader relays a header to the peer.
func (*Peer) RelayTransactionSet ¶
RelayTransactionSet relays a transaction set to the peer.
func (*Peer) RelayV2BlockOutline ¶
RelayV2BlockOutline relays a v2 block outline to the peer.
func (*Peer) RelayV2Header ¶
RelayV2Header relays a v2 block header to the peer.
func (*Peer) RelayV2TransactionSet ¶
func (p *Peer) RelayV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction, timeout time.Duration) error
RelayV2TransactionSet relays a v2 transaction set to the peer.
func (*Peer) SendBlocks ¶
func (p *Peer) SendBlocks(history [32]types.BlockID, timeout time.Duration, fn func([]types.Block) error) error
SendBlocks downloads blocks from p, starting from the most recent element of history known to p. The blocks are sent in batches, and fn is called on each batch.
func (*Peer) SendCheckpoint ¶
func (p *Peer) SendCheckpoint(index types.ChainIndex, timeout time.Duration) (types.Block, consensus.State, error)
SendCheckpoint requests a checkpoint from the peer. The checkpoint is validated.
func (*Peer) SendTransactions ¶
func (p *Peer) SendTransactions(index types.ChainIndex, txnHashes []types.Hash256, timeout time.Duration) ([]types.Transaction, []types.V2Transaction, error)
SendTransactions requests a subset of a block's transactions from the peer.
func (*Peer) SendV2Blocks ¶
func (p *Peer) SendV2Blocks(history []types.BlockID, maxBlocks uint64, timeout time.Duration) ([]types.Block, uint64, error)
SendV2Blocks requests up to n blocks from p, starting from the most recent element of history known to p. The peer also returns the number of remaining blocks left to sync.
func (*Peer) ShareNodes ¶
ShareNodes requests a list of potential peers from the peer.
type PeerInfo ¶
type PeerInfo struct { Address string `json:"address"` FirstSeen time.Time `json:"firstSeen"` LastConnect time.Time `json:"lastConnect,omitempty"` SyncedBlocks uint64 `json:"syncedBlocks,omitempty"` SyncDuration time.Duration `json:"syncDuration,omitempty"` }
PeerInfo contains metadata about a peer.
type PeerStore ¶
type PeerStore interface { // AddPeer adds a peer to the store. If the peer already exists, nil should // be returned. AddPeer(addr string) error // Peers returns the set of known peers. Peers() ([]PeerInfo, error) // PeerInfo returns the metadata for the specified peer or ErrPeerNotFound // if the peer wasn't found in the store. PeerInfo(addr string) (PeerInfo, error) // UpdatePeerInfo updates the metadata for the specified peer. If the peer // is not found, the error should be ErrPeerNotFound. UpdatePeerInfo(addr string, fn func(*PeerInfo)) error // Ban temporarily bans one or more IPs. The addr should either be a single // IP with port (e.g. 1.2.3.4:5678) or a CIDR subnet (e.g. 1.2.3.4/16). Ban(addr string, duration time.Duration, reason string) error // Banned returns true, nil if the peer is banned. Banned(addr string) (bool, error) }
A PeerStore stores peers and bans.
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
A Syncer synchronizes blockchain data with peers.
func New ¶
func New(l net.Listener, cm ChainManager, pm PeerStore, header gateway.Header, opts ...Option) *Syncer
New returns a new Syncer.
func (*Syncer) BroadcastHeader ¶
func (s *Syncer) BroadcastHeader(bh types.BlockHeader)
BroadcastHeader broadcasts a header to all peers.
func (*Syncer) BroadcastTransactionSet ¶
func (s *Syncer) BroadcastTransactionSet(txns []types.Transaction)
BroadcastTransactionSet broadcasts a transaction set to all peers.
func (*Syncer) BroadcastV2BlockOutline ¶
func (s *Syncer) BroadcastV2BlockOutline(b gateway.V2BlockOutline)
BroadcastV2BlockOutline broadcasts a v2 block outline to all peers.
func (*Syncer) BroadcastV2Header ¶
func (s *Syncer) BroadcastV2Header(bh types.BlockHeader)
BroadcastV2Header broadcasts a v2 header to all peers.
func (*Syncer) BroadcastV2TransactionSet ¶
func (s *Syncer) BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction)
BroadcastV2TransactionSet broadcasts a v2 transaction set to all peers.
func (*Syncer) PeerInfo ¶ added in v0.0.4
PeerInfo returns the metadata for the specified peer or ErrPeerNotFound if the peer wasn't found in the store.