core

package
v0.0.0-...-1c163f6 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

go/src/core/blockchain.go

go/src/core/global.go

go/src/core/helper.go

go/src/core/params.go

go/src/core/types.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultMempoolConfig

func GetDefaultMempoolConfig() *pool.MempoolConfig

GetDefaultMempoolConfig returns the default mempool configuration

func GetMempoolConfigFromChainParams

func GetMempoolConfigFromChainParams(chainParams *SphinxChainParameters) *pool.MempoolConfig

GetMempoolConfigFromChainParams extracts mempool config from chain params

func NewBlockHelper

func NewBlockHelper(block *types.Block) consensus.Block

NewBlockAdapter creates a new adapter for types.Block

func ValidateChainParams

func ValidateChainParams(params *SphinxChainParameters) error

ValidateChainParams validates the chain parameters

Types

type BlockHelper

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

BlockAdapter wraps types.Block to implement consensus.Block interface

func (*BlockHelper) GetDifficulty

func (a *BlockHelper) GetDifficulty() *big.Int

GetDifficulty returns the block difficulty

func (*BlockHelper) GetHash

func (a *BlockHelper) GetHash() string

GetHash returns the block hash

func (*BlockHelper) GetHeight

func (a *BlockHelper) GetHeight() uint64

GetHeight returns the block height

func (*BlockHelper) GetPrevHash

func (a *BlockHelper) GetPrevHash() string

GetPrevHash returns the previous block hash

func (*BlockHelper) GetTimestamp

func (a *BlockHelper) GetTimestamp() int64

GetTimestamp returns the block timestamp

func (*BlockHelper) GetUnderlyingBlock

func (a *BlockHelper) GetUnderlyingBlock() *types.Block

GetUnderlyingBlock returns the underlying types.Block

func (*BlockHelper) Validate

func (a *BlockHelper) Validate() error

Validate validates the block

type BlockImportResult

type BlockImportResult int

BlockImportResult represents the outcome of importing a new block

const (
	ImportedBest BlockImportResult = iota
	ImportedSide
	ImportedExisting
	ImportInvalid
	ImportError
)

type Blockchain

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

Blockchain manages the chain of blocks with state machine replication

func NewBlockchain

func NewBlockchain(dataDir string, nodeID string, validators []string, networkType string) (*Blockchain, error)

NewBlockchain creates a blockchain with state machine replication

func (*Blockchain) AddTransaction

func (bc *Blockchain) AddTransaction(tx *types.Transaction) error

AddTransaction now uses the comprehensive mempool

func (*Blockchain) CacheTypeString

func (bc *Blockchain) CacheTypeString(cacheType CacheType) string

CacheTypeString returns a human-readable string for CacheType

func (*Blockchain) CalculateBlockSize

func (bc *Blockchain) CalculateBlockSize(block *types.Block) uint64

CalculateBlockSize calculates the approximate size of a block in bytes

func (*Blockchain) ChainLength

func (bc *Blockchain) ChainLength() int

ChainLength returns the current length of the in-memory chain

func (*Blockchain) ClearAllCaches

func (bc *Blockchain) ClearAllCaches() error

ClearAllCaches clears all caches to free maximum memory

func (*Blockchain) ClearCache

func (bc *Blockchain) ClearCache(cacheType CacheType) error

ClearCache clears specific caches to free memory

func (*Blockchain) Close

func (bc *Blockchain) Close() error

Close cleans up resources

func (*Blockchain) CommitBlock

func (bc *Blockchain) CommitBlock(block consensus.Block) error

CommitBlock commits a block through state machine replication

func (*Blockchain) ConvertDenomination

func (bc *Blockchain) ConvertDenomination(amount *big.Int, fromDenom, toDenom string) (*big.Int, error)

ConvertDenomination converts between SPX denominations

func (*Blockchain) CreateBlock

func (bc *Blockchain) CreateBlock() (*types.Block, error)

CreateBlock creates a new block with transactions from mempool

func (*Blockchain) DebugStorage

func (bc *Blockchain) DebugStorage() error

DebugStorage tests storage functionality

func (*Blockchain) EstimateFee

func (bc *Blockchain) EstimateFee(blocks int) map[string]interface{}

EstimateFee estimates transaction fee (placeholder implementation)

func (*Blockchain) GenerateLedgerHeaders

func (bc *Blockchain) GenerateLedgerHeaders(operation string, amount float64, address string, memo string) string

GenerateLedgerHeaders generates headers specifically formatted for Ledger hardware

func (*Blockchain) GenerateNetworkInfo

func (bc *Blockchain) GenerateNetworkInfo() string

GenerateNetworkInfo returns network information for peer discovery

func (*Blockchain) GenerateTransactionProof

func (bc *Blockchain) GenerateTransactionProof(tx *types.Transaction, blockHash string) ([][]byte, error)

GenerateTransactionProof generates a Merkle proof for a transaction

func (*Blockchain) GetBestBlockHash

func (bc *Blockchain) GetBestBlockHash() []byte

GetBestBlockHash returns the hash of the active chain's tip

func (*Blockchain) GetBlockByHash

func (bc *Blockchain) GetBlockByHash(hash string) consensus.Block

GetBlockByHash returns a block by its hash with adapter

func (*Blockchain) GetBlockByNumber

func (bc *Blockchain) GetBlockByNumber(height uint64) *types.Block

GetBlockByNumber returns a block by its height/number

func (*Blockchain) GetBlockCount

func (bc *Blockchain) GetBlockCount() uint64

GetBlockCount returns the height of the active chain

func (*Blockchain) GetBlockHash

func (bc *Blockchain) GetBlockHash(height uint64) string

GetBlockHash returns the block hash for a given height

func (*Blockchain) GetBlockSizeStats

func (bc *Blockchain) GetBlockSizeStats() map[string]interface{}

GetBlockSizeStats returns block size statistics

func (*Blockchain) GetBlockWithMerkleInfo

func (bc *Blockchain) GetBlockWithMerkleInfo(blockHash string) (map[string]interface{}, error)

GetBlockWithMerkleInfo returns detailed block information including Merkle root

func (*Blockchain) GetBlocks

func (bc *Blockchain) GetBlocks() []*types.Block

GetBlocks returns the current in-memory blockchain (limited)

func (*Blockchain) GetBlocksizeInfo

func (bc *Blockchain) GetBlocksizeInfo() map[string]interface{}

GetBlocksizeInfo returns detailed blocksize information for RPC/API

func (*Blockchain) GetChainInfo

func (bc *Blockchain) GetChainInfo() map[string]interface{}

GetChainInfo returns formatted chain information with actual genesis hash

func (*Blockchain) GetChainParams

func (bc *Blockchain) GetChainParams() *SphinxChainParameters

GetChainParams returns the Sphinx blockchain parameters for external recognition

func (*Blockchain) GetChainTip

func (bc *Blockchain) GetChainTip() map[string]interface{}

GetChainTip returns information about the current chain tip

func (*Blockchain) GetCurrentMerkleRoot

func (bc *Blockchain) GetCurrentMerkleRoot() (string, error)

GetCurrentMerkleRoot returns the Merkle root of the latest block

func (*Blockchain) GetCurrentState

func (bc *Blockchain) GetCurrentState() *storage.StateSnapshot

GetCurrentState returns the current state snapshot

func (*Blockchain) GetDifficulty

func (bc *Blockchain) GetDifficulty() *big.Int

GetDifficulty returns the current network difficulty

func (*Blockchain) GetGenesisHashFromIndex

func (bc *Blockchain) GetGenesisHashFromIndex() (string, error)

GetGenesisHashFromIndex reads the actual genesis hash from block_index.json

func (*Blockchain) GetLatestBlock

func (bc *Blockchain) GetLatestBlock() consensus.Block

GetLatestBlock returns the head of the chain with adapter

func (*Blockchain) GetMemPoolInfo

func (bc *Blockchain) GetMemPoolInfo() map[string]interface{}

GetMemPoolInfo returns mempool information

func (*Blockchain) GetMempool

func (bc *Blockchain) GetMempool() *pool.Mempool

GetMempool returns the mempool instance

func (*Blockchain) GetMerkleRoot

func (bc *Blockchain) GetMerkleRoot(blockHash string) (string, error)

GetMerkleRoot returns the Merkle root of transactions for a specific block

func (*Blockchain) GetMiningInfo

func (bc *Blockchain) GetMiningInfo() map[string]interface{}

GetMiningInfo returns mining-related information

func (*Blockchain) GetNetworkInfo

func (bc *Blockchain) GetNetworkInfo() map[string]interface{}

GetNetworkInfo returns network information

func (*Blockchain) GetRawTransaction

func (bc *Blockchain) GetRawTransaction(txID string, verbose bool) interface{}

GetRawTransaction returns raw transaction data

func (*Blockchain) GetStats

func (bc *Blockchain) GetStats() map[string]interface{}

GetStats returns blockchain statistics for monitoring

func (*Blockchain) GetStatus

func (bc *Blockchain) GetStatus() BlockchainStatus

GetStatus returns the current blockchain status

func (*Blockchain) GetStorage

func (bc *Blockchain) GetStorage() *storage.Storage

GetStorage returns the storage instance for external access

func (*Blockchain) GetSyncMode

func (bc *Blockchain) GetSyncMode() SyncMode

GetSyncMode returns the current synchronization mode

func (*Blockchain) GetTransactionByID

func (bc *Blockchain) GetTransactionByID(txID []byte) (*types.Transaction, error)

GetTransactionByID retrieves a transaction by its ID

func (*Blockchain) GetTransactionByIDString

func (bc *Blockchain) GetTransactionByIDString(txIDStr string) (*types.Transaction, error)

GetTransactionByIDString retrieves a transaction by its ID (string version)

func (*Blockchain) GetWalletDerivationPaths

func (bc *Blockchain) GetWalletDerivationPaths() map[string]string

GetWalletDerivationPaths returns standard derivation paths for wallets

func (*Blockchain) HasPendingTx

func (bc *Blockchain) HasPendingTx(hash string) bool

HasPendingTx checks if a transaction is in the mempool

func (*Blockchain) ImportBlock

func (bc *Blockchain) ImportBlock(block *types.Block) BlockImportResult

ImportBlock imports a new block into the blockchain with result tracking

func (*Blockchain) ImportResultString

func (bc *Blockchain) ImportResultString(result BlockImportResult) string

ImportResultString returns a human-readable string for BlockImportResult

func (*Blockchain) IsSphinxChain

func (bc *Blockchain) IsSphinxChain() bool

IsSphinxChain validates if this blockchain follows Sphinx protocol using actual genesis hash

func (*Blockchain) IsValidChain

func (bc *Blockchain) IsValidChain() error

IsValidChain checks the integrity of the full chain

func (*Blockchain) PrintBlockIndex

func (bc *Blockchain) PrintBlockIndex()

PrintBlockIndex prints the current block_index.json contents

func (*Blockchain) SaveBasicChainState

func (bc *Blockchain) SaveBasicChainState() error

SaveBasicChainState saves a basic chain state

func (*Blockchain) SetConsensus

func (bc *Blockchain) SetConsensus(consensus *consensus.Consensus)

SetConsensus sets the consensus module for the state machine

func (*Blockchain) SetConsensusEngine

func (bc *Blockchain) SetConsensusEngine(engine *consensus.Consensus)

SetConsensusEngine sets the consensus engine

func (*Blockchain) SetStatus

func (bc *Blockchain) SetStatus(status BlockchainStatus)

SetStatus updates the blockchain status

func (*Blockchain) SetSyncMode

func (bc *Blockchain) SetSyncMode(mode SyncMode)

SetSyncMode updates the synchronization mode

func (*Blockchain) StartLeaderLoop

func (bc *Blockchain) StartLeaderLoop(ctx context.Context)

Enhanced StartLeaderLoop with better leader coordination

func (*Blockchain) StatusString

func (bc *Blockchain) StatusString(status BlockchainStatus) string

StatusString returns a human-readable string for BlockchainStatus

func (*Blockchain) StoreChainState

func (bc *Blockchain) StoreChainState(nodes []*storage.NodeInfo) error

SaveChainState saves the chain state with the actual genesis hash SaveChainState saves the chain state with the actual genesis hash

func (*Blockchain) SyncModeString

func (bc *Blockchain) SyncModeString(mode SyncMode) string

SyncModeString returns a human-readable string for SyncMode

func (*Blockchain) ValidateAddress

func (bc *Blockchain) ValidateAddress(address string) bool

ValidateAddress validates if an address is properly formatted

func (*Blockchain) ValidateBlock

func (bc *Blockchain) ValidateBlock(block consensus.Block) error

ValidateBlock validates a block including TxsRoot = MerkleRoot verification

func (*Blockchain) ValidateBlockSize

func (bc *Blockchain) ValidateBlockSize(block *types.Block) error

ValidateBlockSize checks if a block exceeds size limits

func (*Blockchain) ValidateChainID

func (bc *Blockchain) ValidateChainID(chainID uint64) bool

ValidateChainID validates if this blockchain matches Sphinx network parameters

func (*Blockchain) VerifyMessage

func (bc *Blockchain) VerifyMessage(address, signature, message string) bool

VerifyMessage verifies a signed message (placeholder)

func (*Blockchain) VerifyState

func (bc *Blockchain) VerifyState() error

VerifyState verifies that chain_state.json has the correct genesis hash

func (*Blockchain) VerifyStateConsistency

func (bc *Blockchain) VerifyStateConsistency(otherState *storage.StateSnapshot) (bool, error)

VerifyStateConsistency verifies that this node's state matches other nodes

func (*Blockchain) VerifyTransactionInBlock

func (bc *Blockchain) VerifyTransactionInBlock(tx *types.Transaction, blockHash string) (bool, error)

VerifyTransactionInBlock verifies if a transaction is included in a block

type BlockchainStatus

type BlockchainStatus int

BlockchainStatus represents the current status of the blockchain

const (
	StatusInitializing BlockchainStatus = iota
	StatusSyncing
	StatusRunning
	StatusStopped
	StatusForked
)

Constants for blockchain status, sync modes, etc.

type CacheType

type CacheType int

CacheType represents different types of caches used in the blockchain

const (
	CacheTypeBlock CacheType = iota
	CacheTypeTransaction
	CacheTypeReceipt
	CacheTypeState
)

type ChainParamsProvider

type ChainParamsProvider interface {
	GetChainParams() *SphinxChainParameters
	GetWalletDerivationPaths() map[string]string
}

ChainParamsProvider defines an interface to get chain parameters without import cycle

type ConsensusConfig

type ConsensusConfig struct {
	BlockTime        time.Duration
	EpochLength      uint64
	ValidatorSetSize int
	MaxValidators    int
	MinStakeAmount   *big.Int
	UnbondingPeriod  time.Duration
	SlashingEnabled  bool
	DoubleSignSlash  *big.Int // Slashing amount for double signing
}

ConsensusConfig defines consensus-related parameters

func GetDefaultConsensusConfig

func GetDefaultConsensusConfig() *ConsensusConfig

GetDefaultConsensusConfig returns the default consensus configuration

type MockChainParamsProvider

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

Mock implementation for storage package to use

func (*MockChainParamsProvider) GetChainParams

func (m *MockChainParamsProvider) GetChainParams() *SphinxChainParameters

func (*MockChainParamsProvider) GetWalletDerivationPaths

func (m *MockChainParamsProvider) GetWalletDerivationPaths() map[string]string

type PerformanceConfig

type PerformanceConfig struct {
	MaxConcurrentValidations int
	ValidationTimeout        time.Duration
	CacheSize                int
	PruningInterval          time.Duration
	MaxPeers                 int
	SyncBatchSize            int
}

PerformanceConfig defines performance-related parameters

func GetDefaultPerformanceConfig

func GetDefaultPerformanceConfig() *PerformanceConfig

GetDefaultPerformanceConfig returns the default performance configuration

type SphinxChainParameters

type SphinxChainParameters struct {
	// Network Identification
	ChainID       uint64
	ChainName     string
	Symbol        string
	GenesisTime   int64
	GenesisHash   string
	Version       string
	MagicNumber   uint32
	DefaultPort   int
	BIP44CoinType uint64
	LedgerName    string
	Denominations map[string]*big.Int

	// Block Configuration
	MaxBlockSize       uint64
	MaxTransactionSize uint64
	TargetBlockSize    uint64
	BlockGasLimit      *big.Int

	// Mempool Configuration
	MempoolConfig *pool.MempoolConfig

	// Consensus Configuration
	ConsensusConfig *ConsensusConfig

	// Performance Configuration
	PerformanceConfig *PerformanceConfig
}

SphinxChainParameters defines the complete blockchain parameters

func GetDevnetChainParams

func GetDevnetChainParams(genesisHash string) *SphinxChainParameters

GetDevnetChainParams returns development network parameters

func GetSphinxChainParams

func GetSphinxChainParams(genesisHash string) *SphinxChainParameters

GetSphinxChainParams returns the mainnet parameters

func GetTestnetChainParams

func GetTestnetChainParams(genesisHash string) *SphinxChainParameters

GetTestnetChainParams returns testnet parameters

func (*SphinxChainParameters) ConvertFromBaseUnits

func (p *SphinxChainParameters) ConvertFromBaseUnits(amount *big.Int, toDenom string) (*big.Int, error)

ConvertFromBaseUnits converts amount from base units to target denomination

func (*SphinxChainParameters) ConvertToBaseUnits

func (p *SphinxChainParameters) ConvertToBaseUnits(amount *big.Int, fromDenom string) (*big.Int, error)

ConvertToBaseUnits converts amount to base units (nSPX)

func (*SphinxChainParameters) GetNetworkName

func (p *SphinxChainParameters) GetNetworkName() string

GetNetworkName returns human-readable network name

func (*SphinxChainParameters) GetStakeDenomination

func (p *SphinxChainParameters) GetStakeDenomination() string

GetStakeDenomination returns the stake denomination

func (*SphinxChainParameters) IsDevnet

func (p *SphinxChainParameters) IsDevnet() bool

IsDevnet returns true if this is devnet configuration

func (*SphinxChainParameters) IsMainnet

func (p *SphinxChainParameters) IsMainnet() bool

IsMainnet returns true if this is mainnet configuration

func (*SphinxChainParameters) IsTestnet

func (p *SphinxChainParameters) IsTestnet() bool

IsTestnet returns true if this is testnet configuration

type SyncMode

type SyncMode int

SyncMode represents different synchronization modes for the blockchain

const (
	SyncModeFull SyncMode = iota
	SyncModeFast
	SyncModeLight
)

Directories

Path Synopsis
go/src/core/hashtree/hashtree.go
go/src/core/hashtree/hashtree.go
mps
sphincs
config
go/src/core/sphincs/config/params.go
go/src/core/sphincs/config/params.go
key command
key/backend
go/src/core/sphincs/key/backend/key.go
go/src/core/sphincs/key/backend/key.go
sign command
sign/backend
go/src/core/sphincs/sign/backend/serialize.go
go/src/core/sphincs/sign/backend/serialize.go
zk
go/src/core/stark/zk/air.go
go/src/core/stark/zk/air.go
svm
opcodes
go/src/core/svm/opcodes/arith_ops.go
go/src/core/svm/opcodes/arith_ops.go
go/src/core/transaction/bench.go
go/src/core/transaction/bench.go
address command

Jump to

Keyboard shortcuts

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