Documentation
¶
Overview ¶
Package stateexport provides state export implementations for snapshot-based genesis.
Index ¶
- Constants
- func ClearGenesisCache(homeDir, cacheKey string) error
- func DetectSnapshotFormat(path string) pkgNetwork.SnapshotFormat
- func GenesisCacheDir(homeDir, cacheKey string) string
- func GenesisCacheExists(homeDir, cacheKey string) bool
- func GenesisCachePath(homeDir, cacheKey string) string
- func GenesisMetadataPath(homeDir, cacheKey string) string
- func GetChainIDFromGenesis(genesis []byte) (string, error)
- func SaveGenesisToCacheWithSnapshot(homeDir, cacheKey, snapshotURL string, genesis []byte) error
- type Adapter
- func (a *Adapter) DefaultExportOptions() *ports.ExportOptions
- func (a *Adapter) ExportFromSnapshot(ctx context.Context, opts ports.StateExportOptions) ([]byte, error)
- func (a *Adapter) PrepareForExport(ctx context.Context, homeDir string, rpcGenesis []byte) error
- func (a *Adapter) ValidateExportedGenesis(genesis []byte) error
- func (a *Adapter) WithDefaultCommand(cmdBuilder func(homeDir string) []string) *Adapter
- func (a *Adapter) WithStateExporter(exporter pkgNetwork.StateExporter) *Adapter
- type GenesisCache
- func GetValidGenesisCache(homeDir, cacheKey string) (*GenesisCache, error)
- func LoadGenesisCache(homeDir, cacheKey string) (*GenesisCache, error)
- func NewGenesisCache(cacheKey, filePath, snapshotURL, chainID string, sizeBytes int64) *GenesisCache
- func NewGenesisCacheWithExpiration(cacheKey, filePath, snapshotURL, chainID string, sizeBytes int64, ...) *GenesisCache
- type StateExportError
Constants ¶
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 ¶
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 ¶
GenesisCacheDir returns the cache directory for genesis (same as snapshot cache).
func GenesisCacheExists ¶
GenesisCacheExists returns true if a valid genesis cache exists for the cache key.
func GenesisCachePath ¶
GenesisCachePath returns the path where the cached genesis should be stored.
func GenesisMetadataPath ¶
GenesisMetadataPath returns the path to the genesis cache metadata file.
func GetChainIDFromGenesis ¶
GetChainIDFromGenesis extracts the chain_id from genesis bytes.
func SaveGenesisToCacheWithSnapshot ¶
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 ¶
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 ¶
PrepareForExport prepares the node home directory for export.
func (*Adapter) ValidateExportedGenesis ¶
ValidateExportedGenesis validates the exported genesis.
func (*Adapter) WithDefaultCommand ¶
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 ¶
StateExportError represents an error during state export.
func (*StateExportError) Error ¶
func (e *StateExportError) Error() string