mirror of
https://github.com/luxfi/migrate.git
synced 2026-10-30 15:25:11 +00:00
The Exporter/Importer interfaces declared methods the concrete VM types did not all implement, breaking `go build ./...`. Remove-vs-implement decision (driven by real call sites): - ExportStateTrie / ImportStateTrie: REMOVED from the Exporter/Importer interfaces. These were aspirational — no code anywhere invokes them on an interface value (the only references were the interface decls plus RPCImporter.ImportStateTrie, which just returns ErrStateImportNotSupported). Removing them unblocks the build without inventing per-chain state-trie migration logic. RPCImporter.ImportStateTrie is kept as a harmless extra method; the TrieNode/TrieImportResult types remain (still referenced). - ExportBlocksWithState: KEPT in the Exporter interface — it has a real caller (cmd/export/main.go). Implemented on the four chains that lacked it (xchain, pchain, qchain, zool2) by delegating to ExportBlocks, mirroring the existing cchain.ExportBlocksWithState (these chains carry state in blocks / rebuild via replay, so the two are equivalent — same pattern cchain already documents). Also repaired the pre-existing (independent) build breakage in cmd/export-genesis (luxfi/geth v1.16.39 API drift): pebbleDB now implements ethdb.KeyValueStore (Stat()/SyncKeyValue/DeleteRange; dropped removed NewSnapshot) and is wrapped with rawdb.NewDatabase for the ancient-aware readers; trie.NewDatabase -> triedb.NewDatabase; StateAccount.CodeHash ([]byte) handled via common.BytesToHash; pebble NewIter's (iter, error) return handled. Fixed a go vet finding in cmd/key-sniff (redundant Println newline). go build ./... + go vet ./... + go test ./... all pass. Co-authored-by: Hanzo Dev <[email protected]>
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
package migrate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/luxfi/geth/common"
|
|
)
|
|
|
|
// Exporter defines the interface for exporting blockchain data from any VM
|
|
type Exporter interface {
|
|
// Init initializes the exporter with source database/RPC
|
|
Init(config ExporterConfig) error
|
|
|
|
// GetInfo returns metadata about the source chain
|
|
GetInfo() (*Info, error)
|
|
|
|
// ExportBlocks exports blocks in a range (inclusive)
|
|
// Returns channels for streaming blocks and any errors
|
|
ExportBlocks(ctx context.Context, start, end uint64) (<-chan *BlockData, <-chan error)
|
|
|
|
// ExportBlocksWithState exports blocks with full state attached to genesis block
|
|
// This is required for importing state that allows balance queries
|
|
ExportBlocksWithState(ctx context.Context, start, end uint64) (<-chan *BlockData, <-chan error)
|
|
|
|
// ExportState exports state at a specific block height
|
|
// Returns channels for streaming accounts and any errors
|
|
ExportState(ctx context.Context, blockNumber uint64) (<-chan *Account, <-chan error)
|
|
|
|
// ExportAccount exports a specific account's state
|
|
ExportAccount(ctx context.Context, address common.Address, blockNumber uint64) (*Account, error)
|
|
|
|
// ExportConfig exports chain configuration (genesis, network ID, etc.)
|
|
ExportConfig() (*Config, error)
|
|
|
|
// VerifyExport verifies export integrity at a block height
|
|
VerifyExport(blockNumber uint64) error
|
|
|
|
// Close closes the exporter and releases resources
|
|
Close() error
|
|
}
|
|
|
|
// ExporterFactory creates exporters for specific VM types
|
|
type ExporterFactory interface {
|
|
// Create creates an exporter for the given VM type
|
|
Create(vmType VMType) (Exporter, error)
|
|
|
|
// Supports returns true if this factory supports the VM type
|
|
Supports(vmType VMType) bool
|
|
}
|
|
|
|
// NewExporter creates an exporter for the given configuration
|
|
func NewExporter(config ExporterConfig) (Exporter, error) {
|
|
switch config.VMType {
|
|
case VMTypeSubnetEVM:
|
|
return NewSubnetEVMExporter(config)
|
|
case VMTypeCChain:
|
|
return NewCChainExporter(config)
|
|
case VMTypeZooL2:
|
|
return NewZooL2Exporter(config)
|
|
case VMTypePChain:
|
|
return NewPChainExporter(config)
|
|
case VMTypeXChain:
|
|
return NewXChainExporter(config)
|
|
case VMTypeQChain:
|
|
return NewQChainExporter(config)
|
|
default:
|
|
return nil, ErrUnsupportedVMType
|
|
}
|
|
}
|