parachain

package
v0.0.0-...-2eef473 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: LGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const FinalizationTimeout = 4

The process for finalizing a backed parachain header times out after these many blocks:

Variables

This section is empty.

Functions

func ExtractCommitmentFromDigest

func ExtractCommitmentFromDigest(digest types.Digest) (*types.H256, error)

func Hex

func Hex(b []byte) string

Types

type BeefyListener

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

func NewBeefyListener

func NewBeefyListener(
	config *SourceConfig,
	ethereumConn *ethereum.Connection,
	relaychainConn *relaychain.Connection,
	parachainConnection *parachain.Connection,
	tasks chan<- *Task,
) *BeefyListener

func (*BeefyListener) Start

func (li *BeefyListener) Start(ctx context.Context, eg *errgroup.Group) error

type ByParaID

type ByParaID []relaychain.ParaHead

ByLeafIndex implements sort.Interface based on the LeafIndex field.

func (ByParaID) Len

func (b ByParaID) Len() int

func (ByParaID) Less

func (b ByParaID) Less(i, j int) bool

func (ByParaID) Swap

func (b ByParaID) Swap(i, j int)

type ChannelID

type ChannelID [32]byte

type Config

type Config struct {
	Source SourceConfig `mapstructure:"source"`
	Sink   SinkConfig   `mapstructure:"sink"`
}

type EthereumWriter

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

func NewEthereumWriter

func NewEthereumWriter(
	config *SinkConfig,
	conn *ethereum.Connection,
	tasks <-chan *Task,
) (*EthereumWriter, error)

func (*EthereumWriter) Start

func (wr *EthereumWriter) Start(ctx context.Context, eg *errgroup.Group) error

func (*EthereumWriter) WriteChannel

func (wr *EthereumWriter) WriteChannel(
	ctx context.Context,
	options *bind.TransactOpts,
	commitmentProof *MessageProof,
	proof *ProofOutput,
) error

Submit sends a SCALE-encoded message to an application deployed on the Ethereum network

func (*EthereumWriter) WriteChannels

func (wr *EthereumWriter) WriteChannels(
	ctx context.Context,
	options *bind.TransactOpts,
	task *Task,
) error

type HexBytes

type HexBytes []byte

func (HexBytes) Hex

func (h HexBytes) Hex() string

func (HexBytes) MarshalJSON

func (h HexBytes) MarshalJSON() ([]byte, error)

func (HexBytes) String

func (h HexBytes) String() string

type MerkleProof

type MerkleProof struct {
	Root        types.H256
	InnerHashes [][32]byte
}

func NewMerkleProof

func NewMerkleProof(rawProof RawMerkleProof) (MerkleProof, error)

type MerkleProofData

type MerkleProofData struct {
	PreLeaves       PreLeaves `json:"preLeaves"`
	NumberOfLeaves  int       `json:"numberOfLeaves"`
	ProvenPreLeaf   HexBytes  `json:"provenPreLeaf"`
	ProvenLeaf      HexBytes  `json:"provenLeaf"`
	ProvenLeafIndex int64     `json:"provenLeafIndex"`
	Root            HexBytes  `json:"root"`
	Proof           Proof     `json:"proof"`
}

func CreateParachainMerkleProof

func CreateParachainMerkleProof(heads []relaychain.ParaHead, paraID uint32) (MerkleProofData, error)

func (MerkleProofData) String

func (d MerkleProofData) String() string

type MessageProof

type MessageProof struct {
	Message OutboundQueueMessage
	Proof   MerkleProof
}

type OptionRawMerkleProof

type OptionRawMerkleProof struct {
	HasValue bool
	Value    RawMerkleProof
}

func (*OptionRawMerkleProof) Decode

func (o *OptionRawMerkleProof) Decode(decoder scale.Decoder) error

func (OptionRawMerkleProof) Encode

func (o OptionRawMerkleProof) Encode(encoder scale.Encoder) error

type OutboundQueueMessage

type OutboundQueueMessage struct {
	ChannelID      types.H256
	Nonce          uint64
	Command        uint8
	Params         []byte
	MaxDispatchGas uint64
	MaxFeePerGas   types.U128
	Reward         types.U128
	ID             types.Bytes32
}

func (*OutboundQueueMessage) Decode

func (m *OutboundQueueMessage) Decode(decoder scale.Decoder) error

func (OutboundQueueMessage) Encode

func (m OutboundQueueMessage) Encode(encoder scale.Encoder) error

func (OutboundQueueMessage) IntoInboundMessage

func (m OutboundQueueMessage) IntoInboundMessage() contracts.InboundMessage

type PersistedValidationData

type PersistedValidationData struct {
	ParentHead             []byte
	RelayParentNumber      uint32
	RelayParentStorageRoot types.Hash
	MaxPOVSize             uint32
}

type PreLeaves

type PreLeaves [][]byte

func (PreLeaves) MarshalJSON

func (d PreLeaves) MarshalJSON() ([]byte, error)

type Proof

type Proof [][32]byte

func (Proof) MarshalJSON

func (d Proof) MarshalJSON() ([]byte, error)

type ProofInput

type ProofInput struct {
	// Parachain ID
	ParaID uint32
	// Relay chain block number in which our parachain head was included
	RelayBlockNumber uint64
	// All included paraheads in RelayBlockNumber
	ParaHeads []relaychain.ParaHead
}

A ProofInput is data needed to generate a proof of parachain header inclusion

type ProofOutput

type ProofOutput struct {
	MMRProof        merkle.SimplifiedMMRProof
	MMRRootHash     types.Hash
	Header          types.Header
	MerkleProofData MerkleProofData
}

A ProofOutput represents the generated header inclusion proof

type RawMerkleProof

type RawMerkleProof struct {
	Root           types.H256
	Proof          []types.H256
	NumberOfLeaves uint64
	LeafIndex      uint64
	Leaf           types.H256
}

type Relay

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

func NewRelay

func NewRelay(config *Config, keypair *secp256k1.Keypair) (*Relay, error)

func (*Relay) Start

func (relay *Relay) Start(ctx context.Context, eg *errgroup.Group) error

type Scanner

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

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context, beefyBlockNumber uint64) ([]*Task, error)

Scans for all parachain message commitments for the configured parachain channelID that need to be relayed and can be proven using the MMR root at the specified beefyBlockNumber of the relay chain.

The algorithm works roughly like this:

  1. Fetch channel nonce on both sides of the bridge and compare them
  2. If the nonce on the parachain side is larger that means messages need to be relayed. If not then exit early.
  3. Scan parachain blocks to figure out exactly which commitments need to be relayed.
  4. For all the parachain blocks with unsettled commitments, determine the relay chain block number in which the parachain block was included.

type SinkConfig

type SinkConfig struct {
	Ethereum  config.EthereumConfig `mapstructure:"ethereum"`
	Contracts SinkContractsConfig   `mapstructure:"contracts"`
}

type SinkContractsConfig

type SinkContractsConfig struct {
	Gateway string `mapstructure:"Gateway"`
}

type SourceConfig

type SourceConfig struct {
	Polkadot  config.PolkadotConfig  `mapstructure:"polkadot"`
	Parachain config.ParachainConfig `mapstructure:"parachain"`
	Ethereum  config.EthereumConfig  `mapstructure:"ethereum"`
	Contracts SourceContractsConfig  `mapstructure:"contracts"`
	ChannelID ChannelID              `mapstructure:"channel-id"`
}

type SourceContractsConfig

type SourceContractsConfig struct {
	BeefyClient string `mapstructure:"BeefyClient"`
	Gateway     string `mapstructure:"Gateway"`
}

type Task

type Task struct {
	// Parachain header
	Header *types.Header
	// Inputs for MMR proof generation
	ProofInput *ProofInput
	// Outputs of MMR proof generation
	ProofOutput *ProofOutput
	// Proofs for messages from outbound channel on Polkadot
	MessageProofs *[]MessageProof
}

A Task contains the working state for message commitments in a single parachain block

Jump to

Keyboard shortcuts

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