network

package
v0.0.0-...-619e62a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CancelCommand is the name of the command to cancel a command if it is
	// still running. This is a special command because it is not executed
	// normally, instead the Operator executes it directly.
	CancelCommand = "cancel"
	// TestEndName is the name of the command to signal the end of a test. This
	// is a special command because it is not executed normally, instead the
	// Operator executes it directly.
	TestEndName = "test_end"
)
View Source
const (
	TopologyParam         = "topology"
	ConnectAllTopology    = "connect_all"
	ConnectRandomTopology = "connect_random"
	SeedTopology          = "seed"
	SeedGroupID           = "seeds"
)
View Source
const (
	UnboundedBlockSize = "unbounded"
	ConsistentFill     = "consistent-fill"
)
View Source
const (
	RunTxSimCommandID   = "run_txsim"
	RunSubmitRandomPFBs = "submit-random-pfbs"
)
View Source
const (
	TimeoutParam           = "timeout"
	ChainIDParam           = "chain_id"
	ValidatorsParam        = "validators"
	FullNodesParam         = "full_nodes"
	HaltHeightParam        = "halt_height"
	PexParam               = "pex"
	SeedNodeParam          = "seed_node"
	BlobSequencesParam     = "blob_sequences"
	BlobSizesParam         = "blob_sizes"
	BlobsPerSeqParam       = "blobs_per_sequence"
	TimeoutCommitParam     = "timeout_commit"
	TimeoutProposeParam    = "timeout_propose"
	InboundPeerCountParam  = "inbound_peer_count"
	OutboundPeerCountParam = "outbound_peer_count"
	GovMaxSquareSizeParam  = "gov_max_square_size"
	MaxBlockBytesParam     = "max_block_bytes"
	MempoolParam           = "mempool"
	BroadcastTxsParam      = "broadcast_txs"
	TracingTokenParam      = "tracing_token"
	TracingURLParam        = "tracing_url"
	TracingNodesParam      = "tracing_nodes"
	ExperimentParam        = "experiment"
)
View Source
const (
	TxSimAccountName     = "txsim"
	ValidatorGroupID     = "validators"
	LeaderGlobalSequence = 1
)
View Source
const FailedState = "failed"
View Source
const (
	FinishedConfigState = sync.State("finished-config")
)

Variables

View Source
var (
	// PeerPacketTopic is the topic that the peer packets are published to. This
	// is the first piece of information that is published.
	PeerPacketTopic = sync.NewTopic("peer_packet", PeerPacket{})
	// GenesisTopic is the topic that the genesis is published to.
	GenesisTopic = sync.NewTopic("genesis", GenesisWrapper{})
	// MetaConfigTopic is the topic where each node's app and tendermint configs
	// are puslished to. These are published before the any node starts.
	MetaConfigTopic = sync.NewTopic("meta_config", RoleConfig{})
	// CommandTopic is the topic that commands are published to. These commands
	// are published by the leader and subscribed to by all followers.
	CommandTopic = sync.NewTopic("command", Command{})
)

Functions

func DefaultCommandRegistry

func DefaultCommandRegistry() map[string]CommandHandler

func DefaultTopologies

func DefaultTopologies() []string

func DeserializeAccountPublicKey

func DeserializeAccountPublicKey(hexPubKey string) (cryptotypes.PubKey, error)

func DownloadGenesis

func DownloadGenesis(ctx context.Context, initCtx *run.InitContext) (json.RawMessage, error)

func DownloadSync

func DownloadSync[T any](ctx context.Context, initCtx *run.InitContext, topic *sync.Topic, _ T, count int) ([]T, error)

DownloadSync downloads the given topic from the sync service. It will download the given number of messages from the topic. If the topic is closed before the expected number of messages are received, an error is returned.

func EntryPoint

func EntryPoint(runenv *runtime.RunEnv, initCtx *run.InitContext) error

EntryPoint is the universal entry point for all role based tests.

func NodeID

func NodeID(globalSeq int64) string

func PublishGenesis

func PublishGenesis(ctx context.Context, initCtx *run.InitContext, gen *coretypes.GenesisDoc) error

PublishGenesis publishes the genesis to the sync service. It splits the genesis into 10 parts and publishes each part separately. This gets around the 32Kb limit the underlying websocket has

func PublishNodeConfigs

func PublishNodeConfigs(ctx context.Context, initCtx *run.InitContext, nodes []RoleConfig) error

func SerializePublicKey

func SerializePublicKey(pubKey cryptotypes.PubKey) string

func StandardAppConfig

func StandardAppConfig(_ *Params) *srvconfig.Config

func StandardCometConfig

func StandardCometConfig(params *Params) *tmconfig.Config

func TestgroundConsensusParams

func TestgroundConsensusParams(params *Params) *tmproto.ConsensusParams

Types

type Command

type Command struct {
	ID          string          `json:"id"`
	Name        string          `json:"name"`
	Args        json.RawMessage `json:"args"`
	Timeout     time.Duration   `json:"timeout"`
	TargetGroup string          `json:"target_group"`
}

Command is a struct to represent commands from the leader. Each command has an associated handler that describes the execution logic for the command.

func EndTestCommand

func EndTestCommand() Command

func NewRunTxSimCommand

func NewRunTxSimCommand(id string, timeout time.Duration, args RunTxSimCommandArgs) Command

type CommandHandler

type CommandHandler func(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext, args json.RawMessage) error

CommandHandler type defines the signature for command handlers

type Configurator

type Configurator func(nodes []RoleConfig) ([]RoleConfig, error)

Configurator is a function that arbitrarily modifies the provided node configurations. It is used to generate the topology (which nodes are connected to which) of the network, along with making other arbitrary changes to the configs.

func ConnectRandom

func ConnectRandom(numPeers int) Configurator

func GetConfigurators

func GetConfigurators(runenv *runtime.RunEnv) ([]Configurator, error)

GetConfigurators

func TracingConfigurator

func TracingConfigurator(runenv *runtime.RunEnv, tparams TracingParams) Configurator

TracingConfigurator is a Configurator that configures tracing for the network. It will set the nodes to collect only the round state data, and will set the nodes specified in the TracingParams to collect all trace data.

type ConsensusNode

type ConsensusNode struct {
	Name string

	CmtConfig *tmconfig.Config
	AppConfig *srvconfig.Config

	// AppOptions are the application options of the test node.
	AppOptions *testnode.KVAppOptions
	// AppCreator is used to create the application for the testnode.
	AppCreator srvtypes.AppCreator
	// SuppressLogs in testnode. This should be set to true when running
	// testground tests unless debugging.
	SuppressLogs bool
	// contains filtered or unexported fields
}

ConsensusNode is the node type used by testground instances to run a celestia-app full node. It can optionally be configured to be a validator, and has methods to bootstrap a network, initialize itself, start, and stop.

func (*ConsensusNode) Bootstrap

func (cn *ConsensusNode) Bootstrap(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) ([]PeerPacket, error)

Bootstrap is the first function called in a test by each node. It is responsible for initializing the node and creating a gentx if this node is a validator.

func (*ConsensusNode) Init

func (cn *ConsensusNode) Init(baseDir string, genesis json.RawMessage, mcfg RoleConfig) error

Init creates the files required by tendermint and celestia-app using the data downloaded from the Leader node.

func (*ConsensusNode) StartNode

func (cn *ConsensusNode) StartNode(ctx context.Context, baseDir string) error

StartNode uses the testnode package to start a tendermint node with celestia-app and the provided configuration.

func (*ConsensusNode) Stop

func (cn *ConsensusNode) Stop() error

Stop stops the node and cleans up the data directory by calling the cleanup functions. It returns the last error that was not nil if any of the cleanup functions returned an error.

func (*ConsensusNode) UniversalTestingConfig

func (cn *ConsensusNode) UniversalTestingConfig() testnode.UniversalTestingConfig

UniversalTestingConfig returns the configuration used by the testnode package.

type Follower

type Follower struct {
	*ConsensusNode
	// contains filtered or unexported fields
}

Follower is the role for all nodes in a test except for the leader. It is responsible for downloading the genesis block and any other configuration data from the leader node.

func NewFollower

func NewFollower() *Follower

NewFollower creates a new follower role.

func (*Follower) Execute

func (f *Follower) Execute(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error

func (*Follower) ListenForCommands

func (f *Follower) ListenForCommands(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error

func (*Follower) Plan

func (f *Follower) Plan(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error

Plan is the method that downloads the genesis, configurations, and keys for all of the other nodes in the network.

func (*Follower) Retro

func (f *Follower) Retro(ctx context.Context, runenv *runtime.RunEnv, _ *run.InitContext) error

Retro collects standard data from the follower node and saves it as a file. This data includes the block times, rounds required to reach consensus, and the block sizes.

func (*Follower) RunTxSim

func (f *Follower) RunTxSim(ctx context.Context, c RunTxSimCommandArgs) error

RunTxSim runs the txsim tool on the follower node.

type GenesisWrapper

type GenesisWrapper struct {
	// Part is the index of the part of the genesis file. This is used to bypass
	// testground's 32Kb limit on messages.
	Part    int    `json:"part"`
	Genesis string `json:"genesis"`
}

GenesisWrapper is a simple struct wrapper that makes it easier testground to properly serialize and distribute the genesis file.

type Leader

type Leader struct {
	*ConsensusNode
	// contains filtered or unexported fields
}

Leader is the role for the leader node in a test. It is responsible for creating the genesis block and distributing it to all nodes.

func (*Leader) Execute

func (l *Leader) Execute(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error

func (*Leader) GenesisEvent

func (l *Leader) GenesisEvent(params *Params, packets []PeerPacket) (*coretypes.GenesisDoc, error)

func (*Leader) Plan

func (l *Leader) Plan(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error

Plan is the method that creates and distributes the genesis, configurations, and keys for all of the other nodes in the network.

func (*Leader) Retro

func (l *Leader) Retro(ctx context.Context, runenv *runtime.RunEnv, _ *run.InitContext) error

Retro collects standard data from the leader node and saves it as a file. This data includes the block times, rounds required to reach consensus, and the block sizes.

type Operator

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

Operator is a struct to manage the execution of commands. This is used to orchestrate actions across a network. When a command is received, the Operator will spawn a new goroutine to execute the command. The Operator will also track the status of each job and cancel any jobs that are still running when the Operator is stopped.

func NewOperator

func NewOperator() *Operator

NewOperator initialize a new Operator struct.

func (*Operator) RegisterCommand

func (o *Operator) RegisterCommand(name string, handler CommandHandler)

func (*Operator) Run

func (o *Operator) Run(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext, cmds <-chan Command) error

Run starts the Operator and waits for commands to be received that target its group. The Operator will spawn a new goroutine for each command received. It will also cancel any running jobs when the context is canceled or an error is thrown.

func (*Operator) Stop

func (o *Operator) Stop()

Stop will stop the Operator and wait for all jobs to complete

func (*Operator) StopJob

func (o *Operator) StopJob(id string)

type Params

type Params struct {
	ChainID           string
	Validators        int
	FullNodes         int
	HaltHeight        int
	Timeout           time.Duration
	Pex               bool
	Configurators     []Configurator
	GenesisModifiers  []genesis.Modifier
	PerPeerBandwidth  int
	BlobsPerSeq       int
	BlobSequences     int
	BlobSizes         int
	InboundPeerCount  int
	OutboundPeerCount int
	GovMaxSquareSize  int
	MaxBlockBytes     int
	TimeoutCommit     time.Duration
	TimeoutPropose    time.Duration
	Mempool           string
	BroadcastTxs      bool
	TracingParams
	Experiment string
}

func ParseParams

func ParseParams(ecfg encoding.Config, runenv *runtime.RunEnv) (*Params, error)

func (*Params) NodeCount

func (p *Params) NodeCount() int

func (*Params) ValidateBasic

func (p *Params) ValidateBasic() error

type PeerPacket

type PeerPacket struct {
	PeerID          string          `json:"peer_id"`
	GroupID         string          `json:"group_id"`
	GlobalSequence  int64           `json:"global_sequence"`
	GenesisAccounts []string        `json:"genesis_accounts"`
	GenesisPubKeys  []string        `json:"pub_keys"`
	GenTx           json.RawMessage `json:"gen_tx"`
}

PeerPacket is the message that is sent to other nodes upon network initialization. It contains the necessary info from this node to start the network.

func (*PeerPacket) GetPubKeys

func (pp *PeerPacket) GetPubKeys() ([]cryptotypes.PubKey, error)

func (*PeerPacket) IsLeader

func (pp *PeerPacket) IsLeader() bool

func (*PeerPacket) IsValidator

func (pp *PeerPacket) IsValidator() bool

func (*PeerPacket) Name

func (pp *PeerPacket) Name() string

type Role

type Role interface {
	// Plan is the first function called in a test by each node. It is
	// responsible for creating the genesis block, configuring nodes, and
	// starting the network.
	Plan(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error
	// Execute is the second function called in a test by each node. It is
	// responsible for running any experiments. This is phase where commands are
	// sent and received.
	Execute(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error
	// Retro is the last function called in a test by each node. It is
	// responsible for collecting any data from the node and/or running any
	// retrospective tests or benchmarks.
	Retro(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) error
}

Role is the interface between a testground test entrypoint and the actual test logic. Testground creates many instances and passes each instance a configuration from the plan and manifest toml files. From those configurations a Role is created for each node, and the three methods below are ran in order.

func NewRole

func NewRole(runenv *runtime.RunEnv, initCtx *run.InitContext) (Role, error)

NewRole creates a new role based on the role name.

type RoleConfig

type RoleConfig struct {
	PeerID         string            `json:"peer_id"`
	GroupID        string            `json:"group_id"`
	GlobalSequence int64             `json:"global_sequence"`
	CmtConfig      *tmconfig.Config  `json:"cmt_config"`
	AppConfig      *srvconfig.Config `json:"app_config"`
}

func ConnectAll

func ConnectAll(nodes []RoleConfig) ([]RoleConfig, error)

ConnectAll is a Configurator that connects all nodes to each other via persistent peers.

func DownloadNodeConfigs

func DownloadNodeConfigs(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) ([]RoleConfig, error)

func NewConfigSet

func NewConfigSet(params *Params, pps []PeerPacket) []RoleConfig

type RunTxSimCommandArgs

type RunTxSimCommandArgs struct {
	// BlobSequences is the number of blob sequences to run
	BlobSequences int `json:"blob_sequences"`
	BlobSize      int `json:"blob_size"`
	BlobCount     int `json:"blob_count"`
}

func (*RunTxSimCommandArgs) Sequences

func (c *RunTxSimCommandArgs) Sequences() []txsim.Sequence

type TracingParams

type TracingParams struct {
	Nodes int
	URL   string
	Token string
}

func ParseTracingParams

func ParseTracingParams(runenv *runtime.RunEnv) TracingParams

Jump to

Keyboard shortcuts

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