p2p

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ProtocolPrefix                 = "/blobstream/0.1.0" // TODO "/blobstream/<version>" ?
	DataCommitmentConfirmNamespace = "dcc"
	ValsetConfirmNamespace         = "vc"
	LatestValsetNamespace          = "lv"
)

Variables

View Source
var (
	ErrPeersTimeout                    = errors.New("timeout while waiting for peers")
	ErrPeersThresholdCannotBeNegative  = errors.New("peers threshold cannot be negative")
	ErrNilPrivateKey                   = errors.New("private key cannot be nil")
	ErrNotEnoughValsetConfirms         = errors.New("couldn't find enough valset confirms")
	ErrNotEnoughDataCommitmentConfirms = errors.New("couldn't find enough data commitment confirms")
	ErrInvalidConfirmNamespace         = errors.New("invalid confirm namespace")
	ErrInvalidEVMAddress               = errors.New("invalid evm address")
	ErrNotTheSameEVMAddress            = errors.New("not the same evm address")
	ErrInvalidConfirmKey               = errors.New("invalid confirm key")
	ErrNoValues                        = errors.New("can't select from no values")
	ErrNoValidValueFound               = errors.New("no valid dht confirm value found")
	ErrEmptyNamespace                  = errors.New("empty namespace")
	ErrEmptyEVMAddr                    = errors.New("empty evm address")
	ErrEmptyDigest                     = errors.New("empty digest")
	ErrEmptyValset                     = errors.New("empty valset")
	ErrInvalidLatestValsetKey          = errors.New("invalid latest valset key")
)

Functions

func CreateHost

func CreateHost(listenMultiAddr string, privateKey crypto.PrivKey, registerer prometheus.Registerer) (host.Host, error)

CreateHost Creates a LibP2P host using a listen address and a private key. The listen address is a MultiAddress of the format: /ip4/0.0.0.0/tcp/0 Using port 0 means that it will use a random open port. The private key shouldn't be nil.

func GetDataCommitmentConfirmKey

func GetDataCommitmentConfirmKey(nonce uint64, evmAddr string, dataRootTupleRoot string) string

GetDataCommitmentConfirmKey creates a data commitment confirm in the format: "/<DataCommitmentConfirmNamespace>/<nonce>:<evm_account>:<data_root_tuple_root>": - nonce: in hex format - evm address: the 0x prefixed orchestrator EVM address in hex format - data root tuple root: is the digest, in a 0x prefixed hex format, that is signed over for a data commitment and whose signature is relayed to the Blobstream smart contract. Expects the EVM address to be a correct address.

func GetLatestValsetKey

func GetLatestValsetKey() string

GetLatestValsetKey creates the latest valset key.

func GetValsetConfirmKey

func GetValsetConfirmKey(nonce uint64, evmAddr string, signBytes string) string

GetValsetConfirmKey creates a valset confirm in the format: "/<ValsetNamespace>/<nonce>:<evm_account>:<sign_bytes>": - nonce: in hex format - evm address: the orchestrator EVM address in hex format - sign bytes: is the digest, in a 0x prefixed hex format, that is signed over for a valset and whose signature is relayed to the Blobstream smart contract. Expects the EVM address to be a correct address.

func ParseKey

func ParseKey(key string) (namespace string, nonce uint64, evmAddr string, digest string, err error)

ParseKey parses a key and returns its fields. Will return an error if the key is missing some fields, some fields are empty, or otherwise invalid.

Types

type BlobstreamDHT

type BlobstreamDHT struct {
	*dht.IpfsDHT
	// contains filtered or unexported fields
}

BlobstreamDHT wrapper around the `IpfsDHT` implementation. Used to add helper methods to easily handle the DHT.

func NewBlobstreamDHT

func NewBlobstreamDHT(ctx context.Context, h host.Host, store ds.Batching, bootstrappers []peer.AddrInfo, logger tmlog.Logger) (*BlobstreamDHT, error)

NewBlobstreamDHT create a new IPFS DHT using a suitable configuration for the Blobstream. If nil is passed for bootstrappers, the DHT will not try to connect to any existing peer.

func (BlobstreamDHT) GetDataCommitmentConfirm

func (q BlobstreamDHT) GetDataCommitmentConfirm(ctx context.Context, key string) (types.DataCommitmentConfirm, error)

GetDataCommitmentConfirm looks for a data commitment confirm referenced by its key in the DHT. The key can be generated using the `GetDataCommitmentConfirmKey` method. Returns an error if it fails to get the confirm.

func (BlobstreamDHT) GetLatestValset

func (q BlobstreamDHT) GetLatestValset(ctx context.Context) (types.LatestValset, error)

GetLatestValset looks for the latest valset in the DHT. The key will be returned by the `GetValsetKey` method. Returns an error if it fails.

func (BlobstreamDHT) GetValsetConfirm

func (q BlobstreamDHT) GetValsetConfirm(ctx context.Context, key string) (types.ValsetConfirm, error)

GetValsetConfirm looks for a valset confirm referenced by its key in the DHT. The key can be generated using the `GetValsetConfirmKey` method. Returns an error if it fails to get the confirm.

func (BlobstreamDHT) PutDataCommitmentConfirm

func (q BlobstreamDHT) PutDataCommitmentConfirm(ctx context.Context, key string, dcc types.DataCommitmentConfirm) error

PutDataCommitmentConfirm encodes a data commitment confirm then puts its value to the DHT. The key can be generated using the `GetDataCommitmentConfirmKey` method. Returns an error if it fails to do so.

func (BlobstreamDHT) PutLatestValset

func (q BlobstreamDHT) PutLatestValset(ctx context.Context, v types.LatestValset) error

PutLatestValset encodes a valset then puts its value to the DHT. The key will be returned by the `GetValsetKey` method. If the valset is not the latest, it will fail. Returns an error if it fails.

func (BlobstreamDHT) PutValsetConfirm

func (q BlobstreamDHT) PutValsetConfirm(ctx context.Context, key string, vc types.ValsetConfirm) error

PutValsetConfirm encodes a valset confirm then puts its value to the DHT. The key can be generated using the `GetValsetConfirmKey` method. Returns an error if it fails to do so.

func (BlobstreamDHT) WaitForPeers

func (q BlobstreamDHT) WaitForPeers(ctx context.Context, timeout time.Duration, rate time.Duration, peersThreshold int) error

WaitForPeers waits for peers to be connected to the DHT. Returns nil if the context is done or the peers list has more peers than the specified peersThreshold. Returns error if it times out.

type DataCommitmentConfirmValidator

type DataCommitmentConfirmValidator struct{}

DataCommitmentConfirmValidator runs stateless checks on data commitment confirms when submitting to the DHT.

func (DataCommitmentConfirmValidator) Select

func (dcv DataCommitmentConfirmValidator) Select(key string, values [][]byte) (int, error)

Select selects a valid dht confirm value from multiple ones. returns an error of no valid value is found.

func (DataCommitmentConfirmValidator) Validate

func (dcv DataCommitmentConfirmValidator) Validate(key string, value []byte) error

Validate runs stateless checks on the provided confirm key and value.

type LatestValsetValidator

type LatestValsetValidator struct{}

LatestValsetValidator runs stateless checks on the latest valset when submitting it to the DHT.

func (LatestValsetValidator) Select

func (lcv LatestValsetValidator) Select(key string, values [][]byte) (int, error)

Select selects a valid dht valset value from multiple ones. returns the latest one ordered by nonces. returns an error of no valid value is found.

func (LatestValsetValidator) Validate

func (lcv LatestValsetValidator) Validate(key string, value []byte) error

Validate runs stateless checks on the provided valset key and value.

type Querier

type Querier struct {
	BlobstreamDHT *BlobstreamDHT
	// contains filtered or unexported fields
}

Querier used to query the DHT for confirms.

func NewQuerier

func NewQuerier(blobStreamDht *BlobstreamDHT, logger tmlog.Logger) *Querier

func (Querier) QueryDataCommitmentConfirmByEVMAddress

func (q Querier) QueryDataCommitmentConfirmByEVMAddress(ctx context.Context, nonce uint64, address string, dataRootTupleRoot string) (*types.DataCommitmentConfirm, error)

QueryDataCommitmentConfirmByEVMAddress get the data commitment confirm having nonce `nonce` and signed by the orchestrator whose EVM address is `address`. Returns (nil, nil) if the confirm is not found

func (Querier) QueryDataCommitmentConfirms

func (q Querier) QueryDataCommitmentConfirms(ctx context.Context, valset celestiatypes.Valset, nonce uint64, dataRootTupleRoot string) ([]types.DataCommitmentConfirm, error)

QueryDataCommitmentConfirms get all the data commitment confirms in store for a certain nonce. It goes over the valset members and looks if they submitted any confirms.

func (Querier) QueryLatestValset

func (q Querier) QueryLatestValset(
	ctx context.Context,
) (*types.LatestValset, error)

QueryLatestValset get the latest valset from the p2p network.

func (Querier) QueryTwoThirdsDataCommitmentConfirms

func (q Querier) QueryTwoThirdsDataCommitmentConfirms(
	ctx context.Context,
	timeout time.Duration,
	rate time.Duration,
	previousValset celestiatypes.Valset,
	nonce uint64,
	dataRootTupleRoot string,
) ([]types.DataCommitmentConfirm, error)

QueryTwoThirdsDataCommitmentConfirms queries two thirds or more of data commitment confirms from the P2P network. The method will not return unless it finds more than two thirds, or it times out. No validation is required to be done at this level because the P2P validators defined at `p2p/validators.go` will make sure that the values queried from the DHT are valid. The `timeout` parameter represents the amount of time to wait for confirms before returning, if their number is less than 2/3rds. The `rate` parameter represents the rate at which the requests for confirms are sent to the P2P network. Should return an empty slice and no error if it couldn't find enough signatures.

func (Querier) QueryTwoThirdsValsetConfirms

func (q Querier) QueryTwoThirdsValsetConfirms(
	ctx context.Context,
	timeout time.Duration,
	rate time.Duration,
	valsetNonce uint64,
	previousValset celestiatypes.Valset,
	signBytes string,
) ([]types.ValsetConfirm, error)

QueryTwoThirdsValsetConfirms queries two thirds or more of valset confirms from the P2P network. The method will not return unless it finds more than two thirds, or it times out. No validation is required to be done at this level because the P2P validators defined at `p2p/validators.go` will make sure that the values queried from the DHT are valid. The `timeout` parameter represents the amount of time to wait for confirms before returning, if their number is less than 2/3rds. The `rate` parameter represents the rate at which the requests for confirms are sent to the P2P network. Should return an empty slice and no error if it couldn't find enough signatures. For valsets, generally the first valset, whose nonce is 1, is never signed by the network. Thus, the call to this method for the genesis valset will only time out.

func (Querier) QueryValsetConfirmByEVMAddress

func (q Querier) QueryValsetConfirmByEVMAddress(
	ctx context.Context,
	nonce uint64,
	address string,
	signBytes string,
) (*types.ValsetConfirm, error)

QueryValsetConfirmByEVMAddress get the valset confirm having nonce `nonce` and signed by the orchestrator whose EVM address is `address`. Returns (nil, nil) if the confirm is not found.

func (Querier) QueryValsetConfirms

func (q Querier) QueryValsetConfirms(ctx context.Context, nonce uint64, valset celestiatypes.Valset, signBytes string) ([]types.ValsetConfirm, error)

QueryValsetConfirms get all the valset confirms in store for a certain nonce. It goes over the specified valset members and looks if they submitted any confirms for the provided nonce.

type ValsetConfirmValidator

type ValsetConfirmValidator struct{}

ValsetConfirmValidator runs stateless checks on valset confirms when submitting them to the DHT.

func (ValsetConfirmValidator) Select

func (vcv ValsetConfirmValidator) Select(key string, values [][]byte) (int, error)

Select selects a valid dht confirm value from multiple ones. returns an error of no valid value is found.

func (ValsetConfirmValidator) Validate

func (vcv ValsetConfirmValidator) Validate(key string, value []byte) error

Validate runs stateless checks on the provided confirm key and value.

Jump to

Keyboard shortcuts

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