stateexport

package
v1.0.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package stateexport provides state export implementations for snapshot-based genesis.

Index

Constants

View Source
const (
	// DefaultGenesisCacheExpiration matches snapshot cache expiration.
	// This ensures genesis export cache expires at the same time as the snapshot it came from.
	DefaultGenesisCacheExpiration = 30 * time.Minute
)

Variables

This section is empty.

Functions

func ClearGenesisCache

func ClearGenesisCache(homeDir, cacheKey string) error

ClearGenesisCache removes the cached genesis for a cache key.

func DetectSnapshotFormat

func DetectSnapshotFormat(path string) pkgNetwork.SnapshotFormat

DetectSnapshotFormat detects the snapshot format from URL or file path.

func GenesisCacheDir

func GenesisCacheDir(homeDir, cacheKey string) string

GenesisCacheDir returns the cache directory for genesis (same as snapshot cache).

func GenesisCacheExists

func GenesisCacheExists(homeDir, cacheKey string) bool

GenesisCacheExists returns true if a valid genesis cache exists for the cache key.

func GenesisCachePath

func GenesisCachePath(homeDir, cacheKey string) string

GenesisCachePath returns the path where the cached genesis should be stored.

func GenesisMetadataPath

func GenesisMetadataPath(homeDir, cacheKey string) string

GenesisMetadataPath returns the path to the genesis cache metadata file.

func GetChainIDFromGenesis

func GetChainIDFromGenesis(genesis []byte) (string, error)

GetChainIDFromGenesis extracts the chain_id from genesis bytes.

func SaveGenesisToCacheWithSnapshot

func SaveGenesisToCacheWithSnapshot(homeDir, cacheKey, snapshotURL string, genesis []byte) error

SaveGenesisToCacheWithSnapshot saves exported genesis to cache. This should be called after successfully exporting genesis from a snapshot. The snapshotURL is used to associate this genesis with the snapshot it came from. cacheKey format: "plugin-network" (e.g., "stable-mainnet", "ault-testnet")

Types

type Adapter

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

Adapter implements ports.StateExportService. It orchestrates the full export flow: prepare, export, validate.

func NewAdapter

func NewAdapter(homeDir string, logger *output.Logger) *Adapter

NewAdapter creates a new StateExportAdapter.

func (*Adapter) DefaultExportOptions

func (a *Adapter) DefaultExportOptions() *ports.ExportOptions

DefaultExportOptions returns the default export options for devnet.

func (*Adapter) ExportFromSnapshot

func (a *Adapter) ExportFromSnapshot(ctx context.Context, opts ports.StateExportOptions) ([]byte, error)

ExportFromSnapshot exports genesis from a snapshot's application state. This method supports caching: if the snapshot was loaded from cache AND a valid genesis cache exists for the same network, the cached genesis is returned immediately.

func (*Adapter) PrepareForExport

func (a *Adapter) PrepareForExport(ctx context.Context, homeDir string, rpcGenesis []byte) error

PrepareForExport prepares the node home directory for export.

func (*Adapter) ValidateExportedGenesis

func (a *Adapter) ValidateExportedGenesis(genesis []byte) error

ValidateExportedGenesis validates the exported genesis.

func (*Adapter) WithDefaultCommand

func (a *Adapter) WithDefaultCommand(cmdBuilder func(homeDir string) []string) *Adapter

WithDefaultCommand sets the default export command builder.

func (*Adapter) WithStateExporter

func (a *Adapter) WithStateExporter(exporter pkgNetwork.StateExporter) *Adapter

WithStateExporter sets a network-specific state exporter from the plugin.

type GenesisCache

type GenesisCache struct {
	// Identification
	CacheKey string `json:"cache_key"` // "plugin-network" format (e.g., "stable-mainnet", "ault-testnet")

	// Genesis Data
	FilePath  string `json:"file_path"`  // Path to cached genesis.json
	SizeBytes int64  `json:"size_bytes"` // Size of genesis file
	ChainID   string `json:"chain_id"`   // Chain ID from genesis

	// Source
	SnapshotURL string `json:"snapshot_url"` // URL of the snapshot this genesis was exported from

	// Timestamps
	ExportedAt time.Time `json:"exported_at"`
	ExpiresAt  time.Time `json:"expires_at"`
}

GenesisCache represents a cached exported genesis. This cache stores the raw genesis exported from a snapshot, BEFORE any plugin modifications.

func GetValidGenesisCache

func GetValidGenesisCache(homeDir, cacheKey string) (*GenesisCache, error)

GetValidGenesisCache returns a valid genesis cache entry if one exists, nil otherwise.

func LoadGenesisCache

func LoadGenesisCache(homeDir, cacheKey string) (*GenesisCache, error)

LoadGenesisCache loads genesis cache metadata from disk.

func NewGenesisCache

func NewGenesisCache(cacheKey, filePath, snapshotURL, chainID string, sizeBytes int64) *GenesisCache

NewGenesisCache creates a new GenesisCache entry with default expiration.

func NewGenesisCacheWithExpiration

func NewGenesisCacheWithExpiration(cacheKey, filePath, snapshotURL, chainID string, sizeBytes int64, expiration time.Duration) *GenesisCache

NewGenesisCacheWithExpiration creates a new GenesisCache entry with custom expiration.

func (*GenesisCache) IsExpired

func (g *GenesisCache) IsExpired() bool

IsExpired returns true if the cache entry has expired.

func (*GenesisCache) IsValid

func (g *GenesisCache) IsValid() bool

IsValid checks if the cache entry is valid and the file exists.

func (*GenesisCache) Save

func (g *GenesisCache) Save(homeDir string) error

Save persists the genesis cache metadata to disk.

func (*GenesisCache) TimeUntilExpiry

func (g *GenesisCache) TimeUntilExpiry() time.Duration

TimeUntilExpiry returns the duration until the cache expires.

type StateExportError

type StateExportError struct {
	Operation string
	Message   string
}

StateExportError represents an error during state export.

func (*StateExportError) Error

func (e *StateExportError) Error() string

Jump to

Keyboard shortcuts

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