Documentation
¶
Overview ¶
Package cluster provides the cluster configuration API. It defines the `Definition` type that is the output of the Launchpad and `charon create dkg` commands. `Definition` is also the input to `charon dkg`. If defines the `Lock` type that is the output of the `charon dkg` and `charon create cluster` commands. `Lock` is also the input to `charon run` command.
launchpad.obol.net ─┐
├─► cluster-definition.json ──► charon dkg ─┐
charon create dkg ─┘ ├─► cluster-lock.json ──► charon run
charon create cluster ─┘
Index ¶
- func SupportedVersionsForT(*testing.T) []string
- func Threshold(nodes int) int
- type Definition
- func (d Definition) MarshalJSON() ([]byte, error)
- func (d Definition) NodeIdx(pID peer.ID) (NodeIdx, error)
- func (d Definition) PeerIDs() ([]peer.ID, error)
- func (d Definition) Peers() ([]p2p.Peer, error)
- func (d Definition) SetDefinitionHashes() (Definition, error)
- func (d *Definition) UnmarshalJSON(data []byte) error
- func (d Definition) VerifyHashes() error
- func (d Definition) VerifySignatures() error
- type DistValidator
- type Lock
- type NodeIdx
- type Operator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SupportedVersionsForT ¶ added in v0.10.0
SupportedVersionsForT returns the supported definition versions for testing purposes only.
func Threshold ¶ added in v0.10.0
Threshold returns minimum threshold required for a cluster with given nodes. This formula has been taken from: https://github.com/ObolNetwork/charon/blob/a8fc3185bdda154412fe034dcd07c95baf5c1aaf/core/qbft/qbft.go#L63
Types ¶
type Definition ¶ added in v0.4.0
type Definition struct {
// UUID is a human-readable random unique identifier. Max 64 chars.
UUID string `json:"uuid" ssz:"ByteList[64]" config_hash:"0" definition_hash:"0"`
// Name is a human-readable cosmetic identifier. Max 256 chars.
Name string `json:"name" ssz:"ByteList[256]" config_hash:"1" definition_hash:"1"`
// Version is the schema version of this definition. Max 16 chars.
Version string `json:"version" ssz:"ByteList[16]" config_hash:"2" definition_hash:"2"`
// Timestamp is the human-readable timestamp of this definition. Max 32 chars.
// Note that this was added in v1.1.0, so may be empty for older versions.
Timestamp string `json:"timestamp" ssz:"ByteList[32]" config_hash:"3" definition_hash:"3"`
// NumValidators is the number of DVs (n*32ETH) to be created in the cluster lock file.
NumValidators int `json:"num_validators" ssz:"uint64" config_hash:"4" definition_hash:"4"`
// Threshold required for signature reconstruction. Defaults to safe value for number of nodes/peers.
Threshold int `json:"threshold" ssz:"uint64" config_hash:"5" definition_hash:"5"`
// FeeRecipientAddress 20 byte Ethereum address.
FeeRecipientAddress string `json:"fee_recipient_address,0xhex" ssz:"Bytes20" config_hash:"6" definition_hash:"6"`
// WithdrawalAddress 20 byte Ethereum address.
WithdrawalAddress string `json:"withdrawal_address,0xhex" ssz:"Bytes20" config_hash:"7" definition_hash:"7"`
// DKGAlgorithm to use for key generation. Max 32 chars.
DKGAlgorithm string `json:"dkg_algorithm" ssz:"ByteList[32]" config_hash:"8" definition_hash:"8"`
// ForkVersion defines the cluster's 4 byte beacon chain fork version (network/chain identifier).
ForkVersion []byte `json:"fork_version,0xhex" ssz:"Bytes4" config_hash:"9" definition_hash:"9"`
// Operators define the charon nodes in the cluster and their operators. Max 256 operators.
Operators []Operator `json:"operators" ssz:"CompositeList[256]" config_hash:"10" definition_hash:"10"`
// ConfigHash uniquely identifies a cluster definition excluding operator ENRs and signatures.
ConfigHash []byte `json:"config_hash,0xhex" ssz:"Bytes32" config_hash:"-" definition_hash:"11"`
// DefinitionHash uniquely identifies a cluster definition including operator ENRs and signatures.
DefinitionHash []byte `json:"definition_hash,0xhex" ssz:"Bytes32" config_hash:"-" definition_hash:"-"`
}
Definition defines an intended charon cluster configuration excluding validators. Note the following struct tag meanings:
- json: json field name. Suffix 0xhex indicates bytes are formatted as 0x prefixed hex strings.
- ssz: ssz equivalent. Either uint64 for numbers, BytesN for fixed length bytes, ByteList[MaxN] for variable length strings, or CompositeList[MaxN] for nested object arrays.
- config_hash: field ordering when calculating config hash. Some fields are excluded indicated by `-`.
- definition_hash: field ordering when calculating definition hash. Some fields are excluded indicated by `-`.
func NewDefinition ¶ added in v0.4.0
func NewDefinition(name string, numVals int, threshold int, feeRecipientAddress string, withdrawalAddress string, forkVersionHex string, operators []Operator, random io.Reader, opts ...func(*Definition), ) (Definition, error)
NewDefinition returns a new definition populated with the latest version, timestamp and UUID. The hashes are also populated accordingly. Note that the hashes need to be recalculated when any field is modified.
func (Definition) MarshalJSON ¶ added in v0.4.0
func (d Definition) MarshalJSON() ([]byte, error)
func (Definition) NodeIdx ¶ added in v0.4.0
func (d Definition) NodeIdx(pID peer.ID) (NodeIdx, error)
NodeIdx returns the node index for the peer.
func (Definition) PeerIDs ¶ added in v0.5.0
func (d Definition) PeerIDs() ([]peer.ID, error)
PeerIDs is a convenience function that returns the operators p2p peer IDs.
func (Definition) Peers ¶ added in v0.4.0
func (d Definition) Peers() ([]p2p.Peer, error)
Peers returns the operators as a slice of p2p peers.
func (Definition) SetDefinitionHashes ¶ added in v0.10.1
func (d Definition) SetDefinitionHashes() (Definition, error)
SetDefinitionHashes returns a copy of the definition with the config hash and definition hash populated.
func (*Definition) UnmarshalJSON ¶ added in v0.4.0
func (d *Definition) UnmarshalJSON(data []byte) error
func (Definition) VerifyHashes ¶ added in v0.10.1
func (d Definition) VerifyHashes() error
VerifyHashes returns an error if hashes populated from json object doesn't matches actual hashes.
func (Definition) VerifySignatures ¶ added in v0.10.1
func (d Definition) VerifySignatures() error
type DistValidator ¶ added in v0.4.0
type DistValidator struct {
// PubKey is the distributed validator group public key.
PubKey []byte `json:"distributed_public_key" ssz:"Bytes48" lock_hash:"0"`
// It can be used to verify a partial signature created by any node in the cluster.
PubShares [][]byte `json:"public_shares,omitempty" ssz:"CompositeList[256],Bytes48" lock_hash:"1"`
// FeeRecipientAddress Ethereum address override for this validator, defaults to definition withdrawal address.
FeeRecipientAddress []byte `json:"fee_recipient_address,omitempty" ssz:"Bytes20" lock_hash:"2"`
}
DistValidator is a distributed validator (1x32ETH) managed by the cluster.
func (DistValidator) PublicKey ¶ added in v0.5.0
func (v DistValidator) PublicKey() (*bls_sig.PublicKey, error)
PublicKey returns the validator BLS group public key.
func (DistValidator) PublicKeyHex ¶ added in v0.10.1
func (v DistValidator) PublicKeyHex() string
PublicKeyHex returns the validator hex group public key.
func (DistValidator) PublicShare ¶ added in v0.5.0
func (v DistValidator) PublicShare(peerIdx int) (*bls_sig.PublicKey, error)
PublicShare returns a peer's threshold BLS public share.
type Lock ¶ added in v0.4.0
type Lock struct {
// Definition is embedded and extended by Lock.
Definition `json:"cluster_definition" ssz:"Composite" lock_hash:"0"`
// Validators are the distributed validators (n*32ETH) managed by the cluster.
Validators []DistValidator `json:"distributed_validators" ssz:"Composite[65536]" lock_hash:"1"`
// LockHash uniquely identifies a cluster lock.
LockHash []byte `json:"lock_hash" ssz:"Bytes32" lock_hash:"-"`
// SignatureAggregate is the bls aggregate signature of the lock hash signed by
// all the private key shares of all the distributed validators.
// It acts as an attestation by all the distributed validators
// of the charon cluster they are part of.
SignatureAggregate []byte `json:"signature_aggregate" ssz:"Bytes96" lock_hash:"-"`
}
Lock extends the cluster config Definition with bls threshold public keys and checksums.
func NewForT ¶ added in v0.1.1
func NewForT(t *testing.T, dv, k, n, seed int, opts ...func(*Definition)) (Lock, []*ecdsa.PrivateKey, [][]*bls_sig.SecretKeyShare)
NewForT returns a new cluster lock with dv number of distributed validators, k threshold and n peers. It also returns the peer p2p keys and BLS secret shares. If the seed is zero a random cluster on available loopback ports is generated, else a deterministic cluster is generated. Note this is not defined in testutil since it is tightly coupled with the cluster package.
func (Lock) MarshalJSON ¶ added in v0.4.0
func (Lock) SetLockHash ¶ added in v0.10.1
SetLockHash returns a copy of the lock with the lock hash populated.
func (*Lock) UnmarshalJSON ¶ added in v0.4.0
func (Lock) VerifyHashes ¶ added in v0.11.0
VerifyHashes returns an error if hashes populated from json object doesn't matches actual hashes.
func (Lock) VerifySignatures ¶ added in v0.10.1
VerifySignatures returns true if all config signatures are fully populated and valid. A verified lock is ready for use in charon run.
type NodeIdx ¶ added in v0.4.0
type NodeIdx struct {
// PeerIdx is the index of a peer in the peer list (it 0-indexed).
PeerIdx int
ShareIdx int
}
NodeIdx represents the index of a node/peer/share in the cluster as operator order in cluster definition.
type Operator ¶ added in v0.4.0
type Operator struct {
// The 20 byte Ethereum address of the operator
Address string `json:"address,0xhex" ssz:"Bytes20" config_hash:"0" definition_hash:"0"`
// ENR identifies the charon node. Max 1024 chars.
ENR string `json:"enr" ssz:"ByteList[1024]" config_hash:"-" definition_hash:"1"`
// ConfigSignature is an EIP712 signature of the config_hash using privkey corresponding to operator Ethereum Address.
ConfigSignature []byte `json:"config_signature,0xhex" ssz:"Bytes65" config_hash:"-" definition_hash:"2"`
// ENRSignature is a EIP712 signature of the ENR by the Address, authorising the charon node to act on behalf of the operator in the cluster.
ENRSignature []byte `json:"enr_signature,0xhex" ssz:"Bytes65" config_hash:"-" definition_hash:"3"`
}
Operator identifies the operator of a charon node and its ENR. Note the following struct tag meanings:
- json: json field name. Suffix 0xhex indicates bytes are formatted as 0x prefixed hex strings.
- ssz: ssz equivalent. Either uint64 for numbers, BytesN for fixed length bytes, ByteList[MaxN] for variable length strings, or CompositeList[MaxN] for nested object arrays.
- config_hash: field ordering when calculating config hash. Some fields are excluded indicated by `-`.
- definition_hash: field ordering when calculating definition hash. Some fields are excluded indicated by `-`.