ethereum

package
v0.0.0-...-2662d33 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

Initial code taken from Armiarma by Migalabs

Index

Constants

View Source
const EPOCH_DURATION = 12 * 32 * time.Second

Variables

View Source
var (
	EnrValidationError   error = errors.New("error validating ENR")
	Eth2DataParsingError error = errors.New("error parsing eth2 data")
)
View Source
var (
	EnrHostInfoAttribute   string = "enr-info"
	EnrAttnetsAttribute    string = "enr-attnets"
	EnrAttnetsNumAttribute string = "enr-att-num"
)

Functions

func ConvertECDSAPubkeyToSecp2561k

func ConvertECDSAPubkeyToSecp2561k(pubkey *ecdsa.PublicKey) (crypto.PubKey, error)

func CountBits

func CountBits(byteArr []byte) int

func MaddrFrom

func MaddrFrom(ip string, port uint) (ma.Multiaddr, error)

MaddrFrom takes in an ip address string and port to produce a go multiaddr format.

Types

type Attnets

type Attnets struct {
	Raw       utils.AttnetsENREntry
	NetNumber int
}

func ParseAttnets

func ParseAttnets(node enode.Node) (attnets *Attnets, exists bool, err error)

ParseAttnets returns always an initialized Attnet object If the Ethereum Node doesn't have the Attnets key-value NetNumber will be -1

type ConnectionState

type ConnectionState int

ConnectionState signals the capacity for a connection with a given node. It is used to signal to services and other peers whether a node is reachable.

const (
	// NotConnected means no connection to peer, and no extra information (default)
	NotConnected ConnectionState = iota

	// Connecting means we are in the process of connecting to this peer
	Connecting
)

type ContextStreamHandler

type ContextStreamHandler func(context.Context, network.Stream) error

type DiscoveryV5

type DiscoveryV5 struct {
	Dv5Listener  *discover.UDPv5
	FilterDigest string
	// contains filtered or unexported fields
}

func NewDiscoveryV5

func NewDiscoveryV5(pk *ecdsa.PrivateKey, discConfig *config.DiscConfig) (*DiscoveryV5, error)

func (*DiscoveryV5) Serve

func (d *DiscoveryV5) Serve(ctx context.Context) error

type EnrNode

type EnrNode struct {
	Timestamp time.Time
	ID        enode.ID
	IP        net.IP
	Seq       uint64
	UDP       int
	TCP       int
	Pubkey    *ecdsa.PublicKey
	Eth2Data  *common.Eth2Data
	Attnets   *Attnets
}

func NewEnrNode

func NewEnrNode(nodeID enode.ID) *EnrNode

func ParseEnr

func ParseEnr(node *enode.Node) (*EnrNode, error)

define the Handler for when we discover a new ENR

func (*EnrNode) GetAttnetsString

func (enr *EnrNode) GetAttnetsString() string

func (*EnrNode) GetPeerID

func (enr *EnrNode) GetPeerID() (peer.ID, error)

func (*EnrNode) GetPubkeyString

func (enr *EnrNode) GetPubkeyString() string

type HostInfo

type HostInfo struct {
	sync.RWMutex

	// AddrInfo
	ID     peer.ID
	IP     string
	Port   int
	MAddrs []ma.Multiaddr

	Attr map[string]interface{}
}

func NewHostInfo

func NewHostInfo(peerID peer.ID, opts ...RemoteHostOptions) *HostInfo

NewHostInfo returns a new structure of the PeerInfo field for the specific network passed as argk

func (*HostInfo) AddAtt

func (h *HostInfo) AddAtt(key string, attr interface{})

type Node

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

Node represents a node in the network with a host and configuration.

func NewNode

func NewNode(cfg *config.NodeConfig) (*Node, error)

NewNode initializes a new Node using the provided configuration and options.

func (*Node) CanSubscribe

func (n *Node) CanSubscribe(topic string) bool

func (*Node) Connected

func (n *Node) Connected(net network.Network, c network.Conn)

func (*Node) Disconnected

func (n *Node) Disconnected(net network.Network, c network.Conn)

func (*Node) FilterIncomingSubscriptions

func (n *Node) FilterIncomingSubscriptions(pid peer.ID, opts []*pb.RPC_SubOpts) ([]*pb.RPC_SubOpts, error)

func (*Node) Listen

func (n *Node) Listen(net network.Network, maddr ma.Multiaddr)

func (*Node) ListenClose

func (n *Node) ListenClose(net network.Network, maddr ma.Multiaddr)

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start runs the operational routines of the node, such as network services and handling connections.

type NodeInfo

type NodeInfo struct {
	Node enode.Node
	Flag bool
}

type PeerBackoff

type PeerBackoff struct {
	LastSeen       time.Time
	BackoffCounter int
	AddrInfo       peer.AddrInfo
}

type PeerDialer

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

PeerDialer is a suture service that reads peers from the peerChan (which is filled by the [Discovery] service until that peerChan channel is closed. When PeerDialer sees a new peer, it does a few sanity checks and tries to establish a connection.

func (*PeerDialer) Serve

func (p *PeerDialer) Serve(ctx context.Context) error

type PeerInfo

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

PeerInfo contains information about a peer

func (*PeerInfo) IntoMetadataEvent

func (p *PeerInfo) IntoMetadataEvent() *types.MetadataReceivedEvent

type PeerMetadata

type PeerMetadata struct {
	LastSeen time.Time
	Metadata *eth.MetaDataV1
}

type Peerstore

type Peerstore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewPeerstore

func NewPeerstore(defaultBackoff time.Duration) *Peerstore

NewPeerstore creates a new peerstore

func (*Peerstore) AddSubscribedSubnets

func (p *Peerstore) AddSubscribedSubnets(id peer.ID, subnet ...int64)

func (*Peerstore) Get

func (p *Peerstore) Get(id peer.ID) *PeerInfo

func (*Peerstore) Insert

func (p *Peerstore) Insert(id peer.ID, addr multiaddr.Multiaddr, enode enode.Node)

Insert inserts a peer into the peerstore in the `NotConnected` state.

func (*Peerstore) IsBackedOff

func (p *Peerstore) IsBackedOff(id peer.ID) bool

func (*Peerstore) LastErr

func (p *Peerstore) LastErr(id peer.ID) error

func (*Peerstore) PeersToReconnect

func (p *Peerstore) PeersToReconnect() []peer.AddrInfo

PeersToReconnect returns the peers that we need to reconnect to. This includes the not connected peers that have an expired backoff, but also the succesfully connected peers that have not been seen for 1 epoch.

func (*Peerstore) Reset

func (p *Peerstore) Reset(id peer.ID)

Reset MUST be called every time we've had a succesful handshake & metadata exchange with a peer. It will reset the backoff counter and the last error, and remove the last status & metadata

func (*Peerstore) SetBackoff

func (p *Peerstore) SetBackoff(id peer.ID, err error) uint32

SetBackoff marks the peer as backed off, increments the backoff counter and records the last error. This should only be used on outbound connections.

func (*Peerstore) SetClientVersion

func (p *Peerstore) SetClientVersion(id peer.ID, version string)

func (*Peerstore) SetMetadata

func (p *Peerstore) SetMetadata(id peer.ID, metadata *eth.MetaDataV1)

func (*Peerstore) SetState

func (p *Peerstore) SetState(id peer.ID, state ConnectionState)

func (*Peerstore) SetStatus

func (p *Peerstore) SetStatus(id peer.ID, status *eth.Status)

func (*Peerstore) Size

func (p *Peerstore) Size() int

func (*Peerstore) State

func (p *Peerstore) State(id peer.ID) ConnectionState

func (*Peerstore) Status

func (p *Peerstore) Status(id peer.ID) *eth.Status

type RemoteHostOptions

type RemoteHostOptions func(*HostInfo) error

func WithIPAndPorts

func WithIPAndPorts(ip string, port int) RemoteHostOptions

type ReqResp

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

ReqResp handles request-response operations for the node.

func NewReqResp

func NewReqResp(h host.Host, peerstore *Peerstore, cfg *ReqRespConfig) (*ReqResp, error)

func (*ReqResp) Goodbye

func (r *ReqResp) Goodbye(ctx context.Context, pid peer.ID, code uint64) error

Goodbye sends a goodbye request to the given peer.

func (*ReqResp) MetaData

func (r *ReqResp) MetaData(ctx context.Context, pid peer.ID) (resp *pb.MetaDataV1, err error)

MetaData sends a metadata request to the given peer.

func (*ReqResp) Ping

func (r *ReqResp) Ping(ctx context.Context, pid peer.ID) error

Ping sends a ping request to the given peer.

func (*ReqResp) RegisterHandlers

func (r *ReqResp) RegisterHandlers(ctx context.Context) error

RegisterHandlers registers all RPC handlers. It verifies that initial status and metadata are valid.

func (*ReqResp) SetStatus

func (r *ReqResp) SetStatus(status *pb.Status)

func (*ReqResp) Status

func (r *ReqResp) Status(ctx context.Context, pid peer.ID) (status *pb.Status, err error)

Status sends a status request to the given peer.

type ReqRespConfig

type ReqRespConfig struct {
	ForkDigest [4]byte
	Encoder    encoder.NetworkEncoding

	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Jump to

Keyboard shortcuts

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