Documentation
¶
Index ¶
- Variables
- func BodyKey(number uint64, hash common.Hash) []byte
- func CalculateGenesisHash(cfg GenesisConfig) common.Hash
- func CalculateStateRoot(accounts map[common.Address]*big.Int) common.Hash
- func CanonicalKey(number uint64) []byte
- func ComputeBlockHash(block *TestBlock) common.Hash
- func CreateMultiChainGenesis(cfg MultiChainGenesisConfig) (*genesis.UnparsedConfig, error)
- func CreatePersistentTestDatabase(path string) (database.Database, error)
- func CreateTestDatabase(path string) database.Database
- func HeaderKey(number uint64, hash common.Hash) []byte
- func IsHeaderKey(key []byte) bool
- func OpenTestDatabase(path string) database.Database
- func ParseHeaderKey(key []byte) (bool, uint64, common.Hash)
- func WriteTestBlocks(db database.Database, count int)
- type AllocationConfig
- type BlockImporter
- func (i *BlockImporter) Close() error
- func (i *BlockImporter) GetBlock(number uint64) (*TestBlock, error)
- func (i *BlockImporter) GetBlockHash(number uint64) (common.Hash, error)
- func (i *BlockImporter) GetCanonicalHash(number uint64) (common.Hash, error)
- func (i *BlockImporter) ImportBlock(block *TestBlock) error
- func (i *BlockImporter) ImportBlockWithVerification(block *TestBlock) error
- type GenesisBlock
- type GenesisConfig
- type MigrationStats
- type MultiChainGenesisConfig
- type ProgressCallback
- type StateMigrator
- func (m *StateMigrator) Close() error
- func (m *StateMigrator) Migrate(ctx context.Context) (*MigrationStats, error)
- func (m *StateMigrator) SetNamespace(namespace []byte)
- func (m *StateMigrator) SetProgressCallback(cb ProgressCallback)
- func (m *StateMigrator) SetStartFrom(blockNum uint64)
- func (m *StateMigrator) SetStopAfter(count uint64)
- type TestBlock
- type TestChainConfig
- type TestGenesis
- type TestGenesisAccount
- type ValidatorConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrBlockNotFound = errors.New("block not found") ErrHashVerificationFailed = errors.New("hash verification failed") ErrInvalidBlockSequence = errors.New("invalid block sequence") )
var ( ErrInvalidNetworkID = errors.New("invalid network ID: cannot be 0") ErrNoValidators = errors.New("at least one validator is required") )
var ( ErrMigrationCancelled = errors.New("migration cancelled") ErrInvalidCheckpoint = errors.New("invalid checkpoint") )
Functions ¶
func CalculateGenesisHash ¶
func CalculateGenesisHash(cfg GenesisConfig) common.Hash
CalculateGenesisHash computes the genesis block hash
func CalculateStateRoot ¶
CalculateStateRoot computes a deterministic state root from accounts
func CanonicalKey ¶
CanonicalKey constructs a canonical hash key from block number
func ComputeBlockHash ¶
ComputeBlockHash computes a deterministic hash for a test block
func CreateMultiChainGenesis ¶
func CreateMultiChainGenesis(cfg MultiChainGenesisConfig) (*genesis.UnparsedConfig, error)
CreateMultiChainGenesis creates a full network genesis with P, X, and C chains
func CreatePersistentTestDatabase ¶
CreatePersistentTestDatabase creates a test database that persists to disk This is useful for integration tests that need to verify data across restarts
func CreateTestDatabase ¶
CreateTestDatabase creates a new test database For unit tests, we use an in-memory database for speed
func OpenTestDatabase ¶
OpenTestDatabase opens an existing test database For unit tests, we return a new memory database In integration tests, this would open the actual database
func ParseHeaderKey ¶
ParseHeaderKey parses a header key and returns block number and hash
func WriteTestBlocks ¶
WriteTestBlocks writes test blocks to a database
Types ¶
type AllocationConfig ¶
AllocationConfig defines an allocation in genesis
type BlockImporter ¶
type BlockImporter struct {
// contains filtered or unexported fields
}
BlockImporter handles importing blocks into a database
func NewBlockImporter ¶
func NewBlockImporter(path string) *BlockImporter
NewBlockImporter creates a new block importer
func (*BlockImporter) GetBlock ¶
func (i *BlockImporter) GetBlock(number uint64) (*TestBlock, error)
GetBlock retrieves a block by number
func (*BlockImporter) GetBlockHash ¶
func (i *BlockImporter) GetBlockHash(number uint64) (common.Hash, error)
GetBlockHash retrieves the hash for a block number
func (*BlockImporter) GetCanonicalHash ¶
func (i *BlockImporter) GetCanonicalHash(number uint64) (common.Hash, error)
GetCanonicalHash retrieves the canonical hash for a block number
func (*BlockImporter) ImportBlock ¶
func (i *BlockImporter) ImportBlock(block *TestBlock) error
ImportBlock imports a block into the database
func (*BlockImporter) ImportBlockWithVerification ¶
func (i *BlockImporter) ImportBlockWithVerification(block *TestBlock) error
ImportBlockWithVerification imports a block and verifies its hash
type GenesisBlock ¶
type GenesisBlock struct {
Number uint64
Hash common.Hash
ParentHash common.Hash
StateRoot common.Hash
Timestamp uint64
GasLimit uint64
BaseFee *big.Int
Header []byte
Transactions []byte
}
GenesisBlock represents a genesis block with essential fields
func CreateGenesisBlock ¶
func CreateGenesisBlock(cfg GenesisConfig) (*GenesisBlock, error)
CreateGenesisBlock creates a genesis block from configuration
type GenesisConfig ¶
type GenesisConfig struct {
NetworkID uint32
ChainID *big.Int
Timestamp uint64
GasLimit uint64
BaseFee *big.Int
PreFundedAccounts map[common.Address]*big.Int
Validators []ValidatorConfig
}
GenesisConfig defines configuration for creating a genesis block
func DefaultGenesisConfig ¶
func DefaultGenesisConfig() GenesisConfig
DefaultGenesisConfig returns a default genesis configuration for testing
type MigrationStats ¶
type MigrationStats struct {
KeysMigrated uint64
BlocksMigrated uint64
BytesMigrated uint64
LastProcessedBlock uint64
Errors []error
}
MigrationStats contains statistics about a migration
type MultiChainGenesisConfig ¶
type MultiChainGenesisConfig struct {
NetworkID uint32
Timestamp uint64
Validators []ValidatorConfig
Allocations []AllocationConfig
}
MultiChainGenesisConfig defines configuration for multi-chain genesis
type ProgressCallback ¶
type ProgressCallback func(current, total uint64)
ProgressCallback is called during migration to report progress
type StateMigrator ¶
type StateMigrator struct {
// contains filtered or unexported fields
}
StateMigrator handles migrating state between databases
func NewStateMigrator ¶
func NewStateMigrator(srcPath, dstPath string) *StateMigrator
NewStateMigrator creates a new state migrator
func NewStateMigratorWithDatabases ¶
func NewStateMigratorWithDatabases(srcDB, dstDB database.Database) *StateMigrator
NewStateMigratorWithDatabases creates a state migrator with injected databases for testing
func (*StateMigrator) Close ¶
func (m *StateMigrator) Close() error
Close closes the migrator and its databases
func (*StateMigrator) Migrate ¶
func (m *StateMigrator) Migrate(ctx context.Context) (*MigrationStats, error)
Migrate performs the state migration
func (*StateMigrator) SetNamespace ¶
func (m *StateMigrator) SetNamespace(namespace []byte)
SetNamespace sets the namespace to strip from source keys
func (*StateMigrator) SetProgressCallback ¶
func (m *StateMigrator) SetProgressCallback(cb ProgressCallback)
SetProgressCallback sets the progress callback
func (*StateMigrator) SetStartFrom ¶
func (m *StateMigrator) SetStartFrom(blockNum uint64)
SetStartFrom sets the block number to start migration from
func (*StateMigrator) SetStopAfter ¶
func (m *StateMigrator) SetStopAfter(count uint64)
SetStopAfter sets the number of blocks to migrate before stopping
type TestBlock ¶
type TestBlock struct {
Number uint64
Hash common.Hash
ParentHash common.Hash
StateRoot common.Hash
Timestamp uint64
GasLimit uint64
GasUsed uint64
BaseFee *big.Int
Header *types.Header
Transactions []*types.Transaction
Body []byte
}
TestBlock represents a simplified block for testing
type TestChainConfig ¶
TestChainConfig represents a minimal chain config for testing
type TestGenesis ¶
type TestGenesis struct {
Config *TestChainConfig `json:"config"`
Timestamp uint64 `json:"timestamp,omitempty"`
GasLimit uint64 `json:"gasLimit"`
Difficulty *big.Int `json:"difficulty"`
Alloc map[common.Address]TestGenesisAccount `json:"alloc"`
}
TestGenesis represents a minimal genesis for testing
func CreateTestGenesis ¶
CreateTestGenesis creates a test genesis with the given configuration
type TestGenesisAccount ¶
TestGenesisAccount represents a genesis account for testing
type ValidatorConfig ¶
ValidatorConfig defines a validator for genesis