Documentation ¶
Index ¶
- Constants
- Variables
- func AvailablePeerScoreParams() []string
- func AvailableTopicScoreParams() []string
- func BlockSigningHash(cfg *rollup.Config, payloadBytes []byte) (common.Hash, error)
- func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRuntimeConfig) pubsub.ValidatorEx
- func BuildGlobalGossipParams(cfg *rollup.Config) pubsub.GossipSubParams
- func BuildMsgIdFn(cfg *rollup.Config) pubsub.MsgIdFunction
- func BuildSubscriptionFilter(cfg *rollup.Config) pubsub.SubscriptionFilter
- func ConfigurePeerScoring(gossipConf GossipSetupConfigurables, scorer Scorer, log log.Logger) []pubsub.Option
- func DefaultConnManager(conf *Config) (connmgr.ConnManager, error)
- func FilterEnodes(log log.Logger, cfg *rollup.Config) func(node *enode.Node) bool
- func FindActiveTCPPort(h host.Host) (uint16, error)
- func GetPeerScoreParams(name string, blockTime uint64) (pubsub.PeerScoreParams, error)
- func GetTopicScoreParams(name string, blockTime uint64) (pubsub.TopicScoreParams, error)
- func LogTopicEvents(ctx context.Context, log log.Logger, evHandler *pubsub.TopicEventHandler)
- func MakeStreamHandler(resourcesCtx context.Context, log log.Logger, fn requestHandlerFn) network.StreamHandler
- func MplexC() libp2p.Option
- func NewGossipSub(p2pCtx context.Context, h host.Host, cfg *rollup.Config, ...) (*pubsub.PubSub, error)
- func NewNetworkNotifier(log log.Logger, m metrics.Metricer) network.Notifiee
- func NewPeerScoreThresholds() pubsub.PeerScoreThresholds
- func NoiseC() libp2p.Option
- func PayloadByNumberProtocolID(l2ChainID *big.Int) protocol.ID
- func ScoreDecay(duration time.Duration, slot time.Duration) float64
- func SigningHash(domain [32]byte, chainID *big.Int, payloadBytes []byte) (common.Hash, error)
- func TlsC() libp2p.Option
- func YamuxC() libp2p.Option
- type API
- type APIBackend
- func (s *APIBackend) BlockAddr(_ context.Context, ip net.IP) error
- func (s *APIBackend) BlockPeer(_ context.Context, p peer.ID) error
- func (s *APIBackend) BlockSubnet(_ context.Context, ipnet *net.IPNet) error
- func (s *APIBackend) ConnectPeer(ctx context.Context, addr string) error
- func (s *APIBackend) DisconnectPeer(_ context.Context, id peer.ID) error
- func (s *APIBackend) DiscoveryTable(_ context.Context) ([]*enode.Node, error)
- func (s *APIBackend) ListBlockedAddrs(_ context.Context) ([]net.IP, error)
- func (s *APIBackend) ListBlockedPeers(_ context.Context) ([]peer.ID, error)
- func (s *APIBackend) ListBlockedSubnets(_ context.Context) ([]*net.IPNet, error)
- func (s *APIBackend) PeerStats(_ context.Context) (*PeerStats, error)
- func (s *APIBackend) Peers(ctx context.Context, connected bool) (*PeerDump, error)
- func (s *APIBackend) ProtectPeer(_ context.Context, p peer.ID) error
- func (s *APIBackend) Self(ctx context.Context) (*PeerInfo, error)
- func (s *APIBackend) UnblockAddr(_ context.Context, ip net.IP) error
- func (s *APIBackend) UnblockPeer(_ context.Context, p peer.ID) error
- func (s *APIBackend) UnblockSubnet(_ context.Context, ipnet *net.IPNet) error
- func (s *APIBackend) UnprotectPeer(_ context.Context, p peer.ID) error
- type BandScoreThresholds
- type Client
- func (c *Client) BlockAddr(ctx context.Context, ip net.IP) error
- func (c *Client) BlockPeer(ctx context.Context, p peer.ID) error
- func (c *Client) BlockSubnet(ctx context.Context, ipnet *net.IPNet) error
- func (c *Client) ConnectPeer(ctx context.Context, addr string) error
- func (c *Client) DisconnectPeer(ctx context.Context, id peer.ID) error
- func (c *Client) DiscoveryTable(ctx context.Context) ([]*enode.Node, error)
- func (c *Client) ListBlockedAddrs(ctx context.Context) ([]net.IP, error)
- func (c *Client) ListBlockedPeers(ctx context.Context) ([]peer.ID, error)
- func (c *Client) ListBlockedSubnets(ctx context.Context) ([]*net.IPNet, error)
- func (c *Client) PeerStats(ctx context.Context) (*PeerStats, error)
- func (c *Client) Peers(ctx context.Context, connected bool) (*PeerDump, error)
- func (c *Client) ProtectPeer(ctx context.Context, p peer.ID) error
- func (c *Client) Self(ctx context.Context) (*PeerInfo, error)
- func (c *Client) UnblockAddr(ctx context.Context, ip net.IP) error
- func (c *Client) UnblockPeer(ctx context.Context, p peer.ID) error
- func (c *Client) UnblockSubnet(ctx context.Context, ipnet *net.IPNet) error
- func (c *Client) UnprotectPeer(ctx context.Context, p peer.ID) error
- type Config
- func (conf *Config) BanDuration() time.Duration
- func (conf *Config) BanPeers() bool
- func (conf *Config) BanThreshold() float64
- func (conf *Config) Check() error
- func (p *Config) ConfigureGossip(rollupCfg *rollup.Config) []pubsub.Option
- func (conf *Config) Disabled() bool
- func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort uint16) (*enode.LocalNode, *discover.UDPv5, error)
- func (conf *Config) Host(log log.Logger, reporter metrics.Reporter, metrics HostMetrics) (host.Host, error)
- func (conf *Config) PeerBandScorer() *BandScoreThresholds
- func (conf *Config) PeerScoringParams() *pubsub.PeerScoreParams
- func (conf *Config) ReqRespSyncEnabled() bool
- func (conf *Config) TargetPeers() uint
- func (conf *Config) TopicScoringParams() *pubsub.TopicScoreParams
- type ExtraHostFeatures
- type GossipIn
- type GossipMetricer
- type GossipOut
- type GossipRuntimeConfig
- type GossipSetupConfigurables
- type GossipTopicInfo
- type HostMetrics
- type L2Chain
- type LocalSigner
- type MessageHandler
- type Node
- type NodeP2P
- func (n *NodeP2P) AltSyncEnabled() bool
- func (n *NodeP2P) BanIP(ip net.IP, expiration time.Time) error
- func (n *NodeP2P) BanPeer(id peer.ID, expiration time.Time) error
- func (n *NodeP2P) Close() error
- func (n *NodeP2P) ConnectionGater() gating.BlockingConnectionGater
- func (n *NodeP2P) ConnectionManager() connmgr.ConnManager
- func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rollup.Config, connectGoal uint)
- func (n *NodeP2P) Dv5Local() *enode.LocalNode
- func (n *NodeP2P) Dv5Udp() *discover.UDPv5
- func (n *NodeP2P) GetPeerScore(id peer.ID) (float64, error)
- func (n *NodeP2P) GossipOut() GossipOut
- func (n *NodeP2P) GossipSub() *pubsub.PubSub
- func (n *NodeP2P) Host() host.Host
- func (n *NodeP2P) IsStatic(id peer.ID) bool
- func (n *NodeP2P) Peers() []peer.ID
- func (n *NodeP2P) RequestL2Range(ctx context.Context, start, end eth.L2BlockRef) error
- type NotificationsMetricer
- type PeerDump
- type PeerInfo
- type PeerStats
- type Peerstore
- type Prepared
- func (p *Prepared) BanDuration() time.Duration
- func (p *Prepared) BanPeers() bool
- func (p *Prepared) BanThreshold() float64
- func (p *Prepared) Check() error
- func (p *Prepared) ConfigureGossip(rollupCfg *rollup.Config) []pubsub.Option
- func (p *Prepared) Disabled() bool
- func (p *Prepared) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort uint16) (*enode.LocalNode, *discover.UDPv5, error)
- func (p *Prepared) Host(log log.Logger, reporter metrics.Reporter, metrics HostMetrics) (host.Host, error)
- func (p *Prepared) PeerBandScorer() *BandScoreThresholds
- func (p *Prepared) PeerScoringParams() *pubsub.PeerScoreParams
- func (p *Prepared) ReqRespSyncEnabled() bool
- func (p *Prepared) TargetPeers() uint
- func (p *Prepared) TopicScoringParams() *pubsub.TopicScoreParams
- type PreparedSigner
- type PtStackENRData
- type ReqRespServer
- type ReqRespServerMetrics
- type ScoreMetrics
- type Scorer
- type Secp256k1
- type SetupP2P
- type Signer
- type SignerSetup
- type StreamCtxFn
- type SyncClient
- type SyncClientMetrics
- type TopicSubscriber
Constants ¶
const ( DefaultMeshD = 8 // topic stable mesh target count DefaultMeshDlo = 6 // topic stable mesh low watermark DefaultMeshDhi = 12 // topic stable mesh high watermark DefaultMeshDlazy = 6 // gossip target )
const DecayEpoch = time.Duration(5)
DecayEpoch is the number of epochs to decay the score over.
const DecayToZero = 0.01
DecayToZero is the decay factor for a peer's score to zero.
const MaxInMeshScore = 10
MaxInMeshScore is the maximum score for being in the mesh.
const MeshWeight = -0.7
MeshWeight is the weight of the mesh delivery topic.
Variables ¶
var ( ErrDisabledDiscovery = errors.New("discovery disabled") ErrNoConnectionManager = errors.New("no connection manager") ErrNoConnectionGater = errors.New("no connection gater") )
var DefaultBootnodes = []*enode.Node{ enode.MustParse("enode://869d07b5932f17e8490990f75a3f94195e9504ddb6b85f7189e5a9c0a8fff8b00aecf6f3ac450ecba6cdabdb5858788a94bde2b613e0f2d82e9b395355f76d1a@34.65.67.101:0?discport=30305"), enode.MustParse("enode://2d4e7e9d48f4dd4efe9342706dd1b0024681bd4c3300d021f86fc75eab7865d4e0cbec6fbc883f011cfd6a57423e7e2f6e104baad2b744c3cafaec6bc7dc92c1@34.65.43.171:0?discport=30305"), enode.MustParse("enode://9d7a3efefe442351217e73b3a593bcb8efffb55b4807699972145324eab5e6b382152f8d24f6301baebbfb5ecd4127bd3faab2842c04cd432bdf50ba092f6645@34.65.109.126:0?discport=30305"), }
var DisabledPeerScoreParams = func(blockTime uint64) pubsub.PeerScoreParams { slot := time.Duration(blockTime) * time.Second if slot == 0 { slot = 2 * time.Second } epoch := 6 * slot tenEpochs := 10 * epoch oneHundredEpochs := 100 * epoch return pubsub.PeerScoreParams{ Topics: make(map[string]*pubsub.TopicScoreParams), TopicScoreCap: 0, AppSpecificScore: func(p peer.ID) float64 { return 0 }, AppSpecificWeight: 1, IPColocationFactorWeight: 0, IPColocationFactorWhitelist: nil, BehaviourPenaltyWeight: 0, BehaviourPenaltyDecay: ScoreDecay(tenEpochs, slot), DecayInterval: slot, DecayToZero: DecayToZero, RetainScore: oneHundredEpochs, } }
DisabledPeerScoreParams is an instantiation of pubsub.PeerScoreParams where all scoring is disabled. See PeerScoreParams for detailed documentation.
var DisabledTopicScoreParams = func(blockTime uint64) pubsub.TopicScoreParams { slot := time.Duration(blockTime) * time.Second if slot == 0 { slot = 2 * time.Second } epoch := 6 * slot invalidDecayPeriod := 50 * epoch return pubsub.TopicScoreParams{ TopicWeight: 0, TimeInMeshWeight: 0, TimeInMeshQuantum: slot, TimeInMeshCap: inMeshCap(slot), FirstMessageDeliveriesWeight: 0, FirstMessageDeliveriesDecay: ScoreDecay(20*epoch, slot), FirstMessageDeliveriesCap: 23, MeshMessageDeliveriesWeight: 0, MeshMessageDeliveriesDecay: ScoreDecay(DecayEpoch*epoch, slot), MeshMessageDeliveriesCap: float64(uint64(epoch/slot) * uint64(DecayEpoch)), MeshMessageDeliveriesThreshold: float64(uint64(epoch/slot) * uint64(DecayEpoch) / 10), MeshMessageDeliveriesWindow: 2 * time.Second, MeshMessageDeliveriesActivation: 4 * epoch, MeshFailurePenaltyWeight: 0, MeshFailurePenaltyDecay: ScoreDecay(DecayEpoch*epoch, slot), InvalidMessageDeliveriesWeight: 0, InvalidMessageDeliveriesDecay: ScoreDecay(invalidDecayPeriod, slot), } }
DisabledTopicScoreParams is an instantiation of pubsub.TopicScoreParams where all scoring is disabled. See TopicScoreParams for detailed documentation.
var LightPeerScoreParams = func(blockTime uint64) pubsub.PeerScoreParams { slot := time.Duration(blockTime) * time.Second if slot == 0 { slot = 2 * time.Second } epoch := 6 * slot tenEpochs := 10 * epoch oneHundredEpochs := 100 * epoch return pubsub.PeerScoreParams{ Topics: make(map[string]*pubsub.TopicScoreParams), TopicScoreCap: 34, AppSpecificScore: func(p peer.ID) float64 { return 0 }, AppSpecificWeight: 1, IPColocationFactorWeight: -35, IPColocationFactorThreshold: 10, IPColocationFactorWhitelist: nil, BehaviourPenaltyWeight: -16, BehaviourPenaltyThreshold: 6, BehaviourPenaltyDecay: ScoreDecay(tenEpochs, slot), DecayInterval: slot, DecayToZero: DecayToZero, RetainScore: oneHundredEpochs, } }
LightPeerScoreParams is an instantiation of pubsub.PeerScoreParams with light penalties. See PeerScoreParams for detailed documentation.
var LightTopicScoreParams = func(blockTime uint64) pubsub.TopicScoreParams { slot := time.Duration(blockTime) * time.Second if slot == 0 { slot = 2 * time.Second } epoch := 6 * slot invalidDecayPeriod := 50 * epoch return pubsub.TopicScoreParams{ TopicWeight: 0.8, TimeInMeshWeight: MaxInMeshScore / inMeshCap(slot), TimeInMeshQuantum: slot, TimeInMeshCap: inMeshCap(slot), FirstMessageDeliveriesWeight: 1, FirstMessageDeliveriesDecay: ScoreDecay(20*epoch, slot), FirstMessageDeliveriesCap: 23, MeshMessageDeliveriesWeight: MeshWeight, MeshMessageDeliveriesDecay: ScoreDecay(DecayEpoch*epoch, slot), MeshMessageDeliveriesCap: float64(uint64(epoch/slot) * uint64(DecayEpoch)), MeshMessageDeliveriesThreshold: float64(uint64(epoch/slot) * uint64(DecayEpoch) / 10), MeshMessageDeliveriesWindow: 2 * time.Second, MeshMessageDeliveriesActivation: 4 * epoch, MeshFailurePenaltyWeight: MeshWeight, MeshFailurePenaltyDecay: ScoreDecay(DecayEpoch*epoch, slot), InvalidMessageDeliveriesWeight: -140.4475, InvalidMessageDeliveriesDecay: ScoreDecay(invalidDecayPeriod, slot), } }
LightTopicScoreParams is a default instantiation of pubsub.TopicScoreParams. See TopicScoreParams for detailed documentation.
var MessageDomainInvalidSnappy = [4]byte{0, 0, 0, 0}
var MessageDomainValidSnappy = [4]byte{1, 0, 0, 0}
var NamespaceRPC = "opp2p"
var PeerScoreParamsByName = map[string](func(blockTime uint64) pubsub.PeerScoreParams){ "light": LightPeerScoreParams, "none": DisabledPeerScoreParams, }
PeerScoreParamsByName is a map of name to function that returns a pubsub.PeerScoreParams based on the provided rollup.Config.
var SigningDomainBlocksV1 = [32]byte{}
var TopicScoreParamsByName = map[string](func(blockTime uint64) pubsub.TopicScoreParams){ "light": LightTopicScoreParams, "none": DisabledTopicScoreParams, }
TopicScoreParamsByName is a map of name to pubsub.TopicScoreParams.
Functions ¶
func AvailablePeerScoreParams ¶
func AvailablePeerScoreParams() []string
AvailablePeerScoreParams returns a list of available peer score params. These can be used as an input to GetPeerScoreParams which returns the corresponding pubsub.PeerScoreParams.
func AvailableTopicScoreParams ¶
func AvailableTopicScoreParams() []string
AvailableTopicScoreParams returns a list of available topic score params. These can be used as an input to GetTopicScoreParams which returns the corresponding pubsub.TopicScoreParams.
func BlockSigningHash ¶
func BuildBlocksValidator ¶
func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRuntimeConfig) pubsub.ValidatorEx
func BuildGlobalGossipParams ¶
func BuildGlobalGossipParams(cfg *rollup.Config) pubsub.GossipSubParams
func BuildMsgIdFn ¶
func BuildMsgIdFn(cfg *rollup.Config) pubsub.MsgIdFunction
BuildMsgIdFn builds a generic message ID function for gossipsub that can handle compressed payloads, mirroring the eth2 p2p gossip spec.
func BuildSubscriptionFilter ¶
func BuildSubscriptionFilter(cfg *rollup.Config) pubsub.SubscriptionFilter
BuildSubscriptionFilter builds a simple subscription filter, to help protect against peers spamming useless subscriptions.
func ConfigurePeerScoring ¶
func ConfigurePeerScoring(gossipConf GossipSetupConfigurables, scorer Scorer, log log.Logger) []pubsub.Option
ConfigurePeerScoring configures the peer scoring parameters for the pubsub
func DefaultConnManager ¶
func DefaultConnManager(conf *Config) (connmgr.ConnManager, error)
func FilterEnodes ¶
func GetPeerScoreParams ¶
func GetPeerScoreParams(name string, blockTime uint64) (pubsub.PeerScoreParams, error)
GetPeerScoreParams returns the pubsub.PeerScoreParams for the given name.
func GetTopicScoreParams ¶
func GetTopicScoreParams(name string, blockTime uint64) (pubsub.TopicScoreParams, error)
GetTopicScoreParams returns the pubsub.TopicScoreParams for the given name.
func LogTopicEvents ¶
func MakeStreamHandler ¶
func NewGossipSub ¶
func NewGossipSub(p2pCtx context.Context, h host.Host, cfg *rollup.Config, gossipConf GossipSetupConfigurables, scorer Scorer, m GossipMetricer, log log.Logger) (*pubsub.PubSub, error)
NewGossipSub configures a new pubsub instance with the specified parameters. PubSub uses a GossipSubRouter as it's router under the hood.
func NewNetworkNotifier ¶
func NewPeerScoreThresholds ¶
func NewPeerScoreThresholds() pubsub.PeerScoreThresholds
NewPeerScoreThresholds returns a default pubsub.PeerScoreThresholds. See PeerScoreThresholds for detailed documentation.
func ScoreDecay ¶
ScoreDecay returns the decay factor for a given duration.
func SigningHash ¶
Types ¶
type API ¶
type API interface { Self(ctx context.Context) (*PeerInfo, error) Peers(ctx context.Context, connected bool) (*PeerDump, error) PeerStats(ctx context.Context) (*PeerStats, error) DiscoveryTable(ctx context.Context) ([]*enode.Node, error) BlockPeer(ctx context.Context, p peer.ID) error UnblockPeer(ctx context.Context, p peer.ID) error ListBlockedPeers(ctx context.Context) ([]peer.ID, error) BlockAddr(ctx context.Context, ip net.IP) error UnblockAddr(ctx context.Context, ip net.IP) error ListBlockedAddrs(ctx context.Context) ([]net.IP, error) BlockSubnet(ctx context.Context, ipnet *net.IPNet) error UnblockSubnet(ctx context.Context, ipnet *net.IPNet) error ListBlockedSubnets(ctx context.Context) ([]*net.IPNet, error) ProtectPeer(ctx context.Context, p peer.ID) error UnprotectPeer(ctx context.Context, p peer.ID) error ConnectPeer(ctx context.Context, addr string) error DisconnectPeer(ctx context.Context, id peer.ID) error }
type APIBackend ¶
type APIBackend struct {
// contains filtered or unexported fields
}
func NewP2PAPIBackend ¶
func (*APIBackend) BlockAddr ¶
BlockAddr adds an IP address to the set of blocked addresses. Note: active connections to the IP address are not automatically closed.
func (*APIBackend) BlockSubnet ¶
BlockSubnet adds an IP subnet to the set of blocked addresses. Note: active connections to the IP subnet are not automatically closed.
func (*APIBackend) ConnectPeer ¶
func (s *APIBackend) ConnectPeer(ctx context.Context, addr string) error
ConnectPeer connects to a given peer address, and wait for protocol negotiation & identification of the peer
func (*APIBackend) DisconnectPeer ¶
func (*APIBackend) DiscoveryTable ¶
func (*APIBackend) ListBlockedAddrs ¶
func (*APIBackend) ListBlockedPeers ¶
func (*APIBackend) ListBlockedSubnets ¶
func (*APIBackend) PeerStats ¶
func (s *APIBackend) PeerStats(_ context.Context) (*PeerStats, error)
func (*APIBackend) Peers ¶
Peers lists information of peers. Optionally filter to only retrieve connected peers.
func (*APIBackend) ProtectPeer ¶
func (*APIBackend) UnblockAddr ¶
func (*APIBackend) UnblockPeer ¶
func (*APIBackend) UnblockSubnet ¶
func (*APIBackend) UnprotectPeer ¶
type BandScoreThresholds ¶
type BandScoreThresholds struct {
// contains filtered or unexported fields
}
BandScoreThresholds holds the thresholds for classifying peers into different score bands.
func NewBandScorer ¶
func NewBandScorer(str string) (*BandScoreThresholds, error)
NewBandScorer constructs a new BandScoreThresholds instance.
func (*BandScoreThresholds) Bucket ¶
func (s *BandScoreThresholds) Bucket(score float64) string
Bucket returns the appropriate band for a given score.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) BlockSubnet ¶
func (*Client) DisconnectPeer ¶
func (*Client) DiscoveryTable ¶
func (*Client) ListBlockedAddrs ¶
func (*Client) ListBlockedPeers ¶
func (*Client) ListBlockedSubnets ¶
func (*Client) UnblockSubnet ¶
type Config ¶
type Config struct { Priv *crypto.Secp256k1PrivateKey DisableP2P bool NoDiscovery bool // Enable P2P-based alt-syncing method (req-resp protocol, not gossip) AltSync bool // Pubsub Scoring Parameters PeerScoring pubsub.PeerScoreParams TopicScoring pubsub.TopicScoreParams // Peer Score Band Thresholds BandScoreThresholds BandScoreThresholds // Whether to ban peers based on their [PeerScoring] score. Should be negative. BanningEnabled bool // Minimum score before peers are disconnected and banned BanningThreshold float64 BanningDuration time.Duration ListenIP net.IP ListenTCPPort uint16 // Port to bind discv5 to ListenUDPPort uint16 AdvertiseIP net.IP AdvertiseTCPPort uint16 AdvertiseUDPPort uint16 Bootnodes []*enode.Node DiscoveryDB *enode.DB StaticPeers []core.Multiaddr HostMux []libp2p.Option HostSecurity []libp2p.Option NoTransportSecurity bool PeersLo uint PeersHi uint PeersGrace time.Duration MeshD int // topic stable mesh target count MeshDLo int // topic stable mesh low watermark MeshDHi int // topic stable mesh high watermark MeshDLazy int // gossip target // FloodPublish publishes messages from ourselves to peers outside of the gossip topic mesh but supporting the same topic. FloodPublish bool // If true a NAT manager will host a NAT port mapping that is updated with PMP and UPNP by libp2p/go-nat NAT bool UserAgent string TimeoutNegotiation time.Duration TimeoutAccept time.Duration TimeoutDial time.Duration // Underlying store that hosts connection-gater and peerstore data. Store ds.Batching EnableReqRespSync bool }
Config sets up a p2p host and discv5 service from configuration. This implements SetupP2P.
func (*Config) BanDuration ¶
func (*Config) BanThreshold ¶
func (*Config) ConfigureGossip ¶
func (*Config) PeerBandScorer ¶
func (conf *Config) PeerBandScorer() *BandScoreThresholds
func (*Config) PeerScoringParams ¶
func (conf *Config) PeerScoringParams() *pubsub.PeerScoreParams
func (*Config) ReqRespSyncEnabled ¶
func (*Config) TargetPeers ¶
func (*Config) TopicScoringParams ¶
func (conf *Config) TopicScoringParams() *pubsub.TopicScoreParams
type ExtraHostFeatures ¶
type ExtraHostFeatures interface { host.Host ConnectionGater() gating.BlockingConnectionGater ConnectionManager() connmgr.ConnManager }
type GossipMetricer ¶
type GossipMetricer interface {
RecordGossipEvent(evType int32)
}
type GossipOut ¶
type GossipOut interface { GossipTopicInfo PublishL2Payload(ctx context.Context, msg *eth.ExecutionPayload, signer Signer) error Close() error }
type GossipRuntimeConfig ¶
type GossipSetupConfigurables ¶
type GossipSetupConfigurables interface { PeerScoringParams() *pubsub.PeerScoreParams TopicScoringParams() *pubsub.TopicScoreParams // ConfigureGossip creates configuration options to apply to the GossipSub setup ConfigureGossip(rollupCfg *rollup.Config) []pubsub.Option }
type GossipTopicInfo ¶
type HostMetrics ¶
type HostMetrics interface { gating.UnbanMetrics gating.ConnectionGaterMetrics }
type LocalSigner ¶
type LocalSigner struct {
// contains filtered or unexported fields
}
LocalSigner is suitable for testing
func NewLocalSigner ¶
func NewLocalSigner(priv *ecdsa.PrivateKey) *LocalSigner
func (*LocalSigner) Close ¶
func (s *LocalSigner) Close() error
type MessageHandler ¶
func BlocksHandler ¶
func BlocksHandler(onBlock func(ctx context.Context, from peer.ID, msg *eth.ExecutionPayload) error) MessageHandler
type Node ¶
type Node interface { // Host returns the libp2p host Host() host.Host // Dv5Local returns the control over the Discv5 data of the local node, nil if disabled Dv5Local() *enode.LocalNode // Dv5Udp returns the control over the Discv5 network, nil if disabled Dv5Udp() *discover.UDPv5 // GossipSub returns the gossip router GossipSub() *pubsub.PubSub // GossipOut returns the gossip output/info control GossipOut() GossipOut // ConnectionGater returns the connection gater, to ban/unban peers with, may be nil ConnectionGater() gating.BlockingConnectionGater // ConnectionManager returns the connection manager, to protect peers with, may be nil ConnectionManager() connmgr.ConnManager }
type NodeP2P ¶
type NodeP2P struct {
// contains filtered or unexported fields
}
NodeP2P is a p2p node, which can be used to gossip messages.
func NewNodeP2P ¶
func NewNodeP2P(resourcesCtx context.Context, rollupCfg *rollup.Config, log log.Logger, setup SetupP2P, gossipIn GossipIn, l2Chain L2Chain, runCfg GossipRuntimeConfig, metrics metrics.Metricer) (*NodeP2P, error)
NewNodeP2P creates a new p2p node, and returns a reference to it. If the p2p is disabled, it returns nil. If metrics are configured, a bandwidth monitor will be spawned in a goroutine.
func (*NodeP2P) AltSyncEnabled ¶
func (*NodeP2P) ConnectionGater ¶
func (n *NodeP2P) ConnectionGater() gating.BlockingConnectionGater
func (*NodeP2P) ConnectionManager ¶
func (n *NodeP2P) ConnectionManager() connmgr.ConnManager
func (*NodeP2P) DiscoveryProcess ¶
func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rollup.Config, connectGoal uint)
DiscoveryProcess runs a discovery process that randomly walks the DHT to fill the peerstore, and connects to nodes in the peerstore that we are not already connected to. Nodes from the peerstore will be shuffled, unsuccessful connection attempts will cause peers to be avoided, and only nodes with addresses (under TTL) will be connected to.
func (*NodeP2P) RequestL2Range ¶
type NotificationsMetricer ¶
type NotificationsMetricer interface { IncPeerCount() DecPeerCount() IncStreamCount() DecStreamCount() }
type PeerInfo ¶
type PeerInfo struct { PeerID peer.ID `json:"peerID"` NodeID enode.ID `json:"nodeID"` UserAgent string `json:"userAgent"` ProtocolVersion string `json:"protocolVersion"` ENR string `json:"ENR"` // might not always be known, e.g. if the peer connected us instead of us discovering them Addresses []string `json:"addresses"` // multi-addresses. may be mix of LAN / docker / external IPs. All of them are communicated. Protocols []string `json:"protocols"` // negotiated protocols list //GossipScore float64 //PeerScore float64 Connectedness network.Connectedness `json:"connectedness"` // "NotConnected", "Connected", "CanConnect" (gracefully disconnected), or "CannotConnect" (tried but failed) Direction network.Direction `json:"direction"` // "Unknown", "Inbound" (if the peer contacted us), "Outbound" (if we connected to them) Protected bool `json:"protected"` // Protected peers do not get ChainID uint64 `json:"chainID"` // some peers might try to connect, but we figure out they are on a different chain later. This may be 0 if the peer is not an patex node at all. Latency time.Duration `json:"latency"` GossipBlocks bool `json:"gossipBlocks"` // if the peer is in our gossip topic PeerScores store.PeerScores `json:"scores"` }
type Peerstore ¶
type Peerstore interface { // PeerInfo returns a peer.PeerInfo struct for given peer.ID. // This is a small slice of the information Peerstore has on // that peer, useful to other services. PeerInfo(peer.ID) peer.AddrInfo // Peers returns all of the peer IDs stored across all inner stores. Peers() peer.IDSlice SetScore(id peer.ID, diff store.ScoreDiff) error }
Peerstore is a subset of the libp2p peerstore.Peerstore interface.
type Prepared ¶
type Prepared struct { HostP2P host.Host LocalNode *enode.LocalNode UDPv5 *discover.UDPv5 EnableReqRespSync bool }
Prepared provides a p2p host and discv5 service that is already set up. This implements SetupP2P.
func (*Prepared) BanDuration ¶
func (*Prepared) BanThreshold ¶
func (*Prepared) ConfigureGossip ¶
func (*Prepared) Discovery ¶
func (p *Prepared) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort uint16) (*enode.LocalNode, *discover.UDPv5, error)
Discovery creates a disc-v5 service. Returns nil, nil, nil if discovery is disabled.
func (*Prepared) Host ¶
func (p *Prepared) Host(log log.Logger, reporter metrics.Reporter, metrics HostMetrics) (host.Host, error)
Host creates a libp2p host service. Returns nil, nil if p2p is disabled.
func (*Prepared) PeerBandScorer ¶
func (p *Prepared) PeerBandScorer() *BandScoreThresholds
func (*Prepared) PeerScoringParams ¶
func (p *Prepared) PeerScoringParams() *pubsub.PeerScoreParams
func (*Prepared) ReqRespSyncEnabled ¶
func (*Prepared) TargetPeers ¶
func (*Prepared) TopicScoringParams ¶
func (p *Prepared) TopicScoringParams() *pubsub.TopicScoreParams
type PreparedSigner ¶
type PreparedSigner struct {
Signer
}
func (*PreparedSigner) SetupSigner ¶
func (p *PreparedSigner) SetupSigner(ctx context.Context) (Signer, error)
type PtStackENRData ¶
type PtStackENRData struct {
// contains filtered or unexported fields
}
The discovery ENRs are just key-value lists, and we filter them by records tagged with the "ptstack" key, and then check the chain ID and version.
func (*PtStackENRData) ENRKey ¶
func (o *PtStackENRData) ENRKey() string
type ReqRespServer ¶
type ReqRespServer struct {
// contains filtered or unexported fields
}
func NewReqRespServer ¶
func NewReqRespServer(cfg *rollup.Config, l2 L2Chain, metrics ReqRespServerMetrics) *ReqRespServer
func (*ReqRespServer) HandleSyncRequest ¶
func (srv *ReqRespServer) HandleSyncRequest(ctx context.Context, log log.Logger, stream network.Stream)
HandleSyncRequest is a stream handler function to register the L2 unsafe payloads alt-sync protocol. See MakeStreamHandler to transform this into a LibP2P handler function.
Note that the same peer may open parallel streams.
The caller must Close the stream.
type ReqRespServerMetrics ¶
type ScoreMetrics ¶
type Scorer ¶
type Scorer interface { OnConnect(id peer.ID) OnDisconnect(id peer.ID) SnapshotHook() pubsub.ExtendedPeerScoreInspectFn }
Scorer is a peer scorer that scores peers based on application-specific metrics.
func NewScorer ¶
func NewScorer(cfg *rollup.Config, peerStore Peerstore, metricer ScoreMetrics, bandScoreThresholds *BandScoreThresholds, log log.Logger) Scorer
NewScorer returns a new peer scorer.
type Secp256k1 ¶
type Secp256k1 crypto.Secp256k1PublicKey
Secp256k1 is like the geth Secp256k1 enr entry type, but using the libp2p pubkey representation instead
type SetupP2P ¶
type SetupP2P interface { Check() error Disabled() bool // Host creates a libp2p host service. Returns nil, nil if p2p is disabled. Host(log log.Logger, reporter metrics.Reporter, metrics HostMetrics) (host.Host, error) // Discovery creates a disc-v5 service. Returns nil, nil, nil if discovery is disabled. Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort uint16) (*enode.LocalNode, *discover.UDPv5, error) TargetPeers() uint BanPeers() bool BanThreshold() float64 BanDuration() time.Duration PeerBandScorer() *BandScoreThresholds GossipSetupConfigurables ReqRespSyncEnabled() bool }
SetupP2P provides a host and discovery service for usage in the rollup node.
type StreamCtxFn ¶
StreamCtxFn provides a new context to use when handling stream requests
type SyncClient ¶
type SyncClient struct {
// contains filtered or unexported fields
}
SyncClient implements a reverse chain sync with a minimal interface: signal the desired range, and receive blocks within this range back. Through parent-hash verification, received blocks are all ensured to be part of the canonical chain at one point, but it is up to the user to organize and process the results further.
For the sync-client to retrieve any data, peers must be added with AddPeer(id), and removed upon disconnect with RemovePeer(id). The client is started with Start(), and may be started before or after changing any peers.
### Stages
The sync mechanism is implemented as following: - User sends range request: blocks on sync main loop (with ctx timeout) - Main loop processes range request (from high to low), dividing block requests by number between parallel peers.
- The high part of the range has a known block-hash, and is marked as trusted.
- Once there are no more peers available for buffering requests, we stop the range request processing.
- Every request buffered for a peer is tracked as in-flight, by block number.
- In-flight requests are not repeated
- Requests for data that's already in the quarantine are not repeated
- Data already in the quarantine that is trusted is attempted to be promoted.
- Peers each have their own routine for processing requests.
- They fetch the requested block by number, parse and validate it, and then send it back to the main loop
- If peers fail to fetch or process it, or fail to send it back to the main loop within timeout, then the doRequest returns an error. It then marks the in-flight request as completed.
- Main loop receives results synchronously with the range requests
- The result is removed from in-flight tracker
- The result is added to the quarantine
- If we trust the hash, we try to promote the result.
### Concepts
The main concepts are: - Quarantine: an LRU that stores the latest fetched block data, by hash as well as an extra index by number.
- Quarantine eviction: upon regular LRU eviction, or explicit removal (when we learn data is not canonical), the sync result is removed from quarantine without being forwarded to the receiver. The peer that provided the data may be down-scored for providing un-utilized data if the data is not trusted during eviction.
- Trusted data: data becomes trusted through 2 ways:
- The hash / parent-hash of the sync target is marked as trusted.
- The parent-hash of any promoted data is marked as trusted.
- The trusted-data is maintained in LRU: we only care about the recent accessed blocks.
- Result promotion: content from the quarantine is "promoted" when we find the blockhash is trusted. The data is removed from the quarantine, and forwarded to the receiver.
### Usage
The user is expected to request the range of blocks between its existing chain head, and a trusted future block-hash as reference to sync towards. Upon receiving results from the sync-client, the user should adjust down its sync-target based on the received results, to avoid duplicating work when req-requesting an updated range. Range requests should still be repeated eventually however, as the sync client will give up on syncing a large range when it's too busy syncing.
The rationale for this approach is that this sync mechanism is primarily intended for quickly filling gaps between an existing chain and a gossip chain, and not for very long block ranges. Syncing in the execution-layer (through snap-sync) is more appropriate for long ranges. If the user does sync a long range of blocks through this mechanism, it does end up traversing through the chain, but receives the blocks in reverse order. It is up to the user to persist the blocks for later processing, or drop & resync them if persistence is limited.
func NewSyncClient ¶
func NewSyncClient(log log.Logger, cfg *rollup.Config, newStream newStreamFn, rcv receivePayloadFn, metrics SyncClientMetrics) *SyncClient
func (*SyncClient) AddPeer ¶
func (s *SyncClient) AddPeer(id peer.ID)
func (*SyncClient) Close ¶
func (s *SyncClient) Close() error
Close will shut down the sync client and all attached work, and block until shutdown is complete. This will block if the Start() has not created the main background loop.
func (*SyncClient) RemovePeer ¶
func (s *SyncClient) RemovePeer(id peer.ID)
func (*SyncClient) RequestL2Range ¶
func (s *SyncClient) RequestL2Range(ctx context.Context, start, end eth.L2BlockRef) error
func (*SyncClient) Start ¶
func (s *SyncClient) Start()
type SyncClientMetrics ¶
type TopicSubscriber ¶
type TopicSubscriber func(ctx context.Context, sub *pubsub.Subscription)
func MakeSubscriber ¶
func MakeSubscriber(log log.Logger, msgHandler MessageHandler) TopicSubscriber