blockalloc

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTransactionCoinType

func GetTransactionCoinType(tx *dcrutil.Tx) cointype.CoinType

GetTransactionCoinType determines the primary coin type of a transaction based on the coin type of outputs. Since transactions cannot mix coin types (all outputs must have the same coin type), we return the coin type of the first non-null-data output.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type AllocationResult

type AllocationResult struct {
	Allocations     map[cointype.CoinType]*CoinTypeAllocation
	TotalAllocated  uint32
	TotalUsed       uint32
	OverflowHandled uint32
}

AllocationResult contains the complete block space allocation for all coin types.

func (*AllocationResult) GetAllocationForCoinType

func (result *AllocationResult) GetAllocationForCoinType(coinType cointype.CoinType) *CoinTypeAllocation

GetAllocationForCoinType returns the space allocation for a specific coin type.

func (*AllocationResult) GetUtilizationPercentage

func (result *AllocationResult) GetUtilizationPercentage() float64

GetUtilizationPercentage returns the overall block space utilization as a percentage.

type BlockSpaceAllocator

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

BlockSpaceAllocator manages the allocation of block space among different coin types following the 10% VAR / 90% SKA proportional distribution strategy.

func NewBlockSpaceAllocator

func NewBlockSpaceAllocator(maxBlockSize uint32, chainParams *chaincfg.Params) *BlockSpaceAllocator

NewBlockSpaceAllocator creates a new block space allocator with the standard 10% VAR / 90% SKA allocation strategy.

func (*BlockSpaceAllocator) AllocateBlockSpace

func (bsa *BlockSpaceAllocator) AllocateBlockSpace(pendingTxBytes map[cointype.CoinType]uint32) *AllocationResult

AllocateBlockSpace calculates the optimal block space allocation given pending transaction sizes for each coin type. Returns allocation details for all coin types.

Algorithm: 1. If no SKA has pending transactions, VAR gets 100% of block space (early exit) 2. Otherwise, initial 10% VAR / 90% SKA split among active SKA types 3. Redistribute unused space ONCE with 10%/90% proportional allocation 4. Any remaining unused space goes to VAR

type CoinTypeAllocation

type CoinTypeAllocation struct {
	CoinType        cointype.CoinType
	BaseAllocation  uint32 // Guaranteed space allocation
	FinalAllocation uint32 // Final space after overflow distribution
	PendingBytes    uint32 // Bytes of transactions pending for this coin type
	UsedBytes       uint32 // Bytes actually used by this coin type
}

CoinTypeAllocation represents the space allocation for a specific coin type.

type TransactionSizeTracker

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

TransactionSizeTracker tracks transaction sizes by coin type for block space allocation.

func NewTransactionSizeTracker

func NewTransactionSizeTracker(allocator *BlockSpaceAllocator) *TransactionSizeTracker

NewTransactionSizeTracker creates a new transaction size tracker.

func (*TransactionSizeTracker) AddTransaction

func (tst *TransactionSizeTracker) AddTransaction(tx *dcrutil.Tx)

AddTransaction adds a transaction to the size tracking.

func (*TransactionSizeTracker) CanAddTransaction

func (tst *TransactionSizeTracker) CanAddTransaction(tx *dcrutil.Tx) bool

CanAddTransaction checks if a transaction can be added without exceeding coin type allocation.

func (*TransactionSizeTracker) GetAllocation

func (tst *TransactionSizeTracker) GetAllocation() *AllocationResult

GetAllocation returns the current block space allocation based on tracked transaction sizes.

func (*TransactionSizeTracker) GetSizeForCoinType

func (tst *TransactionSizeTracker) GetSizeForCoinType(coinType cointype.CoinType) uint32

GetSizeForCoinType returns the current size tracked for a specific coin type.

func (*TransactionSizeTracker) Reset

func (tst *TransactionSizeTracker) Reset()

Reset clears all tracked transaction sizes.

Jump to

Keyboard shortcuts

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