message

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

README

P-Chain warp message payloads

This package defines parsing and serialization for the payloads of unsigned warp messages on the P-Chain.

These payloads are specified in LP-77, and are expected as part of the payload field of an AddressedCall message, with an empty source address.

Documentation

Index

Constants

View Source
const CodecVersion = 0

Variables

View Source
var (
	ErrInvalidChainID = errors.New("invalid chain ID")
	ErrInvalidWeight  = errors.New("invalid weight")
	ErrInvalidNodeID  = errors.New("invalid node ID")
	ErrInvalidOwner   = errors.New("invalid owner")
)
View Source
var ErrNonceReservedForRemoval = errors.New("maxUint64 nonce is reserved for removal")
View Source
var ErrWrongType = errors.New("wrong payload type")

Functions

func ChainToL1ConversionID

func ChainToL1ConversionID(c Codec, data ChainToL1ConversionData) (ids.ID, error)

ChainToL1ConversionID creates a chain conversion ID from the provided chain conversion data using the supplied Codec.

func Initialize

func Initialize(c Codec, p Payload) error

Initialize marshals p through the supplied Codec and stores the wire representation on p via its private initialize() method.

func RegisterTypes added in v1.2.0

func RegisterTypes(r Registry) error

RegisterTypes registers the warp-message wire payload types onto the supplied registry. Callers wire this through the registry they hand to their Codec implementation before invoking any Parse*.

Types

type ChainToL1Conversion

type ChainToL1Conversion struct {

	// ID of the chain conversion. It is typically generated by calling
	// ChainToL1ConversionID.
	ID ids.ID `serialize:"true" json:"id"`
	// contains filtered or unexported fields
}

ChainToL1Conversion reports the summary of the chain conversion that occurred on the P-chain.

func NewChainToL1Conversion

func NewChainToL1Conversion(c Codec, id ids.ID) (*ChainToL1Conversion, error)

NewChainToL1Conversion creates a new initialized ChainToL1Conversion using the supplied Codec.

func ParseChainToL1Conversion

func ParseChainToL1Conversion(c Codec, b []byte) (*ChainToL1Conversion, error)

ParseChainToL1Conversion parses bytes into an initialized ChainToL1Conversion using the supplied Codec.

func (ChainToL1Conversion) Bytes

func (p ChainToL1Conversion) Bytes() []byte

type ChainToL1ConversionData

type ChainToL1ConversionData struct {
	ChainID        ids.ID                             `serialize:"true" json:"chainID"`
	ManagerChainID ids.ID                             `serialize:"true" json:"managerChainID"`
	ManagerAddress types.JSONByteSlice                `serialize:"true" json:"managerAddress"`
	Validators     []ChainToL1ConversionValidatorData `serialize:"true" json:"validators"`
}

type ChainToL1ConversionValidatorData

type ChainToL1ConversionValidatorData struct {
	NodeID       types.JSONByteSlice    `serialize:"true" json:"nodeID"`
	BLSPublicKey [bls.PublicKeyLen]byte `serialize:"true" json:"blsPublicKey"`
	Weight       uint64                 `serialize:"true" json:"weight"`
}

type Codec

type Codec interface {
	Marshal(version uint16, source interface{}) ([]byte, error)
	Unmarshal(bytes []byte, dest interface{}) (uint16, error)
	Size(version uint16, value interface{}) (int, error)
}

Codec is the proto/p/warp/message-local wire codec interface. It is structurally identical to the legacy codec.Manager surface that lived in `github.com/luxfi/codec`, but defined locally so proto/p carries no import of that package. Any concrete codec (linearcodec via codec.Manager) satisfies this interface by shape, and callers from outside proto/p inject the implementation at parser construction time (see proto/internal/pcodectest).

Wave 2A of the codec rip (#101). The shape of this interface MUST stay byte-compatible with codec.Manager so existing wire bytes continue to roundtrip during the multi-wave migration.

type L1ValidatorRegistration

type L1ValidatorRegistration struct {
	ValidationID ids.ID `serialize:"true" json:"validationID"`
	// Registered being true means that validationID is currently a validator on
	// the P-chain.
	//
	// Registered being false means that validationID is not and can never
	// become a validator on the P-chain. It is possible that validationID was
	// previously a validator on the P-chain.
	Registered bool `serialize:"true" json:"registered"`
	// contains filtered or unexported fields
}

L1ValidatorRegistration reports if a validator is registered on the P-chain.

func NewL1ValidatorRegistration

func NewL1ValidatorRegistration(
	c Codec,
	validationID ids.ID,
	registered bool,
) (*L1ValidatorRegistration, error)

NewL1ValidatorRegistration creates a new initialized L1ValidatorRegistration using the supplied Codec.

func ParseL1ValidatorRegistration

func ParseL1ValidatorRegistration(c Codec, b []byte) (*L1ValidatorRegistration, error)

ParseL1ValidatorRegistration parses bytes into an initialized L1ValidatorRegistration using the supplied Codec.

func (L1ValidatorRegistration) Bytes

func (p L1ValidatorRegistration) Bytes() []byte

type L1ValidatorWeight

type L1ValidatorWeight struct {
	ValidationID ids.ID `serialize:"true" json:"validationID"`
	Nonce        uint64 `serialize:"true" json:"nonce"`
	Weight       uint64 `serialize:"true" json:"weight"`
	// contains filtered or unexported fields
}

L1ValidatorWeight is both received and sent by the P-chain.

If the P-chain is receiving this message, it is treated as a command to update the weight of the validator.

If the P-chain is sending this message, it is reporting the current nonce and weight of the validator.

func NewL1ValidatorWeight

func NewL1ValidatorWeight(
	c Codec,
	validationID ids.ID,
	nonce uint64,
	weight uint64,
) (*L1ValidatorWeight, error)

NewL1ValidatorWeight creates a new initialized L1ValidatorWeight using the supplied Codec.

func ParseL1ValidatorWeight

func ParseL1ValidatorWeight(c Codec, b []byte) (*L1ValidatorWeight, error)

ParseL1ValidatorWeight parses bytes into an initialized L1ValidatorWeight using the supplied Codec.

func (L1ValidatorWeight) Bytes

func (p L1ValidatorWeight) Bytes() []byte

func (*L1ValidatorWeight) Verify

func (s *L1ValidatorWeight) Verify() error

type PChainOwner

type PChainOwner struct {
	// The threshold number of `Addresses` that must provide a signature in
	// order for the `PChainOwner` to be considered valid.
	Threshold uint32 `serialize:"true" json:"threshold"`
	// The addresses that are allowed to sign to authenticate a `PChainOwner`.
	Addresses []ids.ShortID `serialize:"true" json:"addresses"`
}

type Payload

type Payload interface {
	// Bytes returns the binary representation of this payload.
	//
	// If the payload is not initialized, this method will return nil.
	Bytes() []byte
	// contains filtered or unexported methods
}

Payload provides a common interface for all payloads implemented by this package.

func Parse

func Parse(c Codec, bytes []byte) (Payload, error)

Parse decodes a payload from wire bytes using the supplied Codec.

type RegisterL1Validator

type RegisterL1Validator struct {
	ChainID               ids.ID                 `serialize:"true" json:"chainID"`
	NodeID                types.JSONByteSlice    `serialize:"true" json:"nodeID"`
	BLSPublicKey          [bls.PublicKeyLen]byte `serialize:"true" json:"blsPublicKey"`
	Expiry                uint64                 `serialize:"true" json:"expiry"`
	RemainingBalanceOwner PChainOwner            `serialize:"true" json:"remainingBalanceOwner"`
	DisableOwner          PChainOwner            `serialize:"true" json:"disableOwner"`
	Weight                uint64                 `serialize:"true" json:"weight"`
	// contains filtered or unexported fields
}

RegisterL1Validator adds a validator to the chain.

func NewRegisterL1Validator

func NewRegisterL1Validator(
	c Codec,
	chainID ids.ID,
	nodeID ids.NodeID,
	blsPublicKey [bls.PublicKeyLen]byte,
	expiry uint64,
	remainingBalanceOwner PChainOwner,
	disableOwner PChainOwner,
	weight uint64,
) (*RegisterL1Validator, error)

NewRegisterL1Validator creates a new initialized RegisterL1Validator using the supplied Codec.

func ParseRegisterL1Validator

func ParseRegisterL1Validator(c Codec, b []byte) (*RegisterL1Validator, error)

ParseRegisterL1Validator parses bytes into an initialized RegisterL1Validator using the supplied Codec.

func (RegisterL1Validator) Bytes

func (p RegisterL1Validator) Bytes() []byte

func (*RegisterL1Validator) ValidationID

func (r *RegisterL1Validator) ValidationID() ids.ID

func (*RegisterL1Validator) Verify

func (r *RegisterL1Validator) Verify() error

type Registry added in v1.2.0

type Registry interface {
	RegisterType(interface{}) error
}

Registry is the proto/p/warp/message-local type-registration surface. Same rationale as Codec — structurally mirrors codec.Registry.

Jump to

Keyboard shortcuts

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