bootstrap

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

README

Sequencer Bootstrap Helper

Utility to quickly wire a sequencer with:

  • Base 2PC coordinator (x/consensus)
  • SBCP sequencer coordinator (x/superblock/sequencer)
  • Transport client to the Shared Publisher (SP)
  • P2P TCP server and peer clients for CIRC messaging

Import

import (
"context"
"github.com/rs/zerolog"
pb "github.com/compose-network/publisher/proto/rollup/v1"
"github.com/compose-network/publisher/x/superblock/sequencer/bootstrap"
)

Quick Start

ctx := context.Background()
log := zerolog.Nop() // or your configured logger

rt, err := bootstrap.Setup(ctx, bootstrap.Config{
ChainID: []byte{0xD9, 0x03}, // example chain-id bytes (55555)
SPAddr:  "sp-host:8080",
PeerAddrs: map[string]string{
"11111":  "peer-a:9000", // decimal OK
"0x1a2b": "peer-b:9001", // hex OK
},
Log: log,
})
if err != nil { panic(err) }

if err := rt.Start(ctx); err != nil { panic(err) }
defer rt.Stop(ctx)

// Send a CIRC to a peer (destination chain determines the peer)
_ = rt.SendCIRC(ctx, &pb.CIRCMessage{
SourceChain:      []byte{0xD9, 0x03},
DestinationChain: []byte{0x01, 0x04, 0x6A},
XtId:             &pb.XtID{Hash: make([]byte, 32)},
Label:            "mailbox_write",
Data:             [][]byte{[]byte("payload")},
})

Config

  • ChainID []byte: raw chain-id bytes for this sequencer (must match XTRequest.Transactions[i].ChainId).
  • SPAddr string: address of the Shared Publisher (e.g., host:8080).
  • PeerAddrs map[string]string: other sequencers by chain-id → host:port. Keys may be decimal (e.g., "11111") or hex (e.g., "0x1a2b" or "1a2b"). Internally normalized to the canonical consensus key.
  • Log zerolog.Logger: optional; defaults to a no-op logger when zero.
  • BaseConsensus consensus.Coordinator: optional; provide your own 2PC coordinator if needed.
  • SPClientConfig *tcp.ClientConfig: optional; override TCP client options to SP.
  • P2PServerConfig *transport.Config: optional; override TCP server options for P2P.
  • P2PListenAddr string: optional; overrides server ListenAddr.
  • SlotDuration time.Duration: optional; defaults to 12s.
  • SlotSealCutover float64: optional; defaults to 2/3.

Lifecycle

  • Setup(ctx, Config) (*Runtime, error): builds coordinator, transports and peers; does not start them.
  • (*Runtime) Start(ctx) error: starts coordinator, P2P server, connects SP and peers.
  • (*Runtime) Stop(ctx) error: stops transports and coordinator.
  • (*Runtime) SendCIRC(ctx, *pb.CIRCMessage) error: sends to the peer selected by DestinationChain.

Notes

  • Chain ID normalization: peers and consume keys are aligned with x/consensus via hex-encoded keys derived from the raw bytes. Use consensus.ChainKeyBytes([]byte) when you need the same key.
  • StartSC: the sequencer coordinator initializes local 2PC state on StartSC, so CIRC recording/consumption works immediately.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ChainID is the ID of the chain the sequencer is running for.
	ChainID []byte
	// SPAddr is the address of the shared publisher in host:port format.
	SPAddr string
	// PeerAddrs is a map of chainID to host:port for other sequencers.
	// The chainID can be in decimal or hex format and will be normalized.
	PeerAddrs map[string]string

	// Log is the logger to use. If not provided, a no-op logger is used.
	Log zerolog.Logger

	// BaseConsensus is an optional existing 2PC coordinator. If nil, a default follower is created.
	BaseConsensus consensus.Coordinator

	// SPClientConfig is an optional override for the shared publisher client config.
	SPClientConfig *tcp.ClientConfig
	// P2PServerConfig is an optional override for the P2P server config.
	// If nil, tcp.DefaultServerConfig() is used.
	P2PServerConfig *transport.Config

	// P2PListenAddr is an optional P2P listen address, overriding P2PServerConfig.ListenAddr.
	P2PListenAddr string

	// SlotDuration is the duration of a slot. Defaults to 12 s.
	SlotDuration time.Duration
	// SlotSealCutover is the fraction of the slot after which it should be sealed. Defaults to 2/3.
	SlotSealCutover float64
}

Config holds inputs to wire a sequencer with SBCP and P2P CIRC.

type Runtime

type Runtime struct {
	// Coordinator is the sequencer coordinator.
	Coordinator sequencer.Coordinator
	// SPClient is the client for the shared publisher.
	SPClient transport.Client
	// P2PServer is the P2P server for CIRC.
	P2PServer transport.Server
	// Peers is a map of hex chainID key to peer client.
	Peers map[string]transport.Client
	// contains filtered or unexported fields
}

Runtime exposes the wired components and lifecycle.

func Setup

func Setup(ctx context.Context, cfg Config) (*Runtime, error)

Setup wires a sequencer coordinator, SP client, P2P server, and peer clients.

func (*Runtime) SendCIRC

func (r *Runtime) SendCIRC(ctx context.Context, circ *pb.CIRCMessage) error

SendCIRC sends a CIRC message to the peer indicated by DestinationChain.

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context) error

Start brings up coordinator, connects to SP, starts P2P, and dials peers.

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context) error

Stop stops coordinator and transports.

Jump to

Keyboard shortcuts

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