ledger

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockfetchEventType event.EventType = "blockfetch.event"
	ChainsyncEventType  event.EventType = "chainsync.event"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockfetchEvent

type BlockfetchEvent struct {
	ConnectionId ouroboros.ConnectionId // Connection ID associated with event
	Block        ledger.Block
	Point        ocommon.Point // Chain point for block
	Type         uint          // Block type ID
	BatchDone    bool          // Set to true for a BatchDone event
}

BlockfetchEvent represents either a Block or BatchDone blockfetch event. We use a single event type for both to make synchronization easier.

type BlockfetchRequestRangeFunc

type BlockfetchRequestRangeFunc func(ouroboros.ConnectionId, ocommon.Point, ocommon.Point) error

BlockfetchRequestRangeFunc describes a callback function used to start a blockfetch request for a range of blocks

type ChainsyncEvent

type ChainsyncEvent struct {
	ConnectionId ouroboros.ConnectionId // Connection ID associated with event
	BlockHeader  ledger.BlockHeader
	Point        ocommon.Point  // Chain point for roll forward/backward
	Tip          ochainsync.Tip // Upstream chain tip
	BlockNumber  uint64
	Type         uint // Block or header type ID
	Rollback     bool // Set to true for a Rollback event
}

ChainsyncEvent represents either a RollForward or RollBackward chainsync event. We use a single event type for both to make synchronization easier.

type ChainsyncState added in v0.12.0

type ChainsyncState string
const (
	InitChainsyncState     ChainsyncState = "init"
	RollbackChainsyncState ChainsyncState = "rollback"
	SyncingChainsyncState  ChainsyncState = "syncing"
)

type LedgerDelta added in v0.7.0

type LedgerDelta struct {
	Point        ocommon.Point
	BlockEraId   uint
	Transactions []TransactionRecord
	// contains filtered or unexported fields
}

func NewLedgerDelta added in v0.18.0

func NewLedgerDelta(point ocommon.Point, blockEraId uint) *LedgerDelta

func (*LedgerDelta) Release added in v0.18.0

func (d *LedgerDelta) Release()

type LedgerDeltaBatch added in v0.8.0

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

func NewLedgerDeltaBatch added in v0.18.0

func NewLedgerDeltaBatch() *LedgerDeltaBatch

func (*LedgerDeltaBatch) Release added in v0.18.0

func (b *LedgerDeltaBatch) Release()

type LedgerState

type LedgerState struct {
	Scheduler *Scheduler

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLedgerState

func NewLedgerState(cfg LedgerStateConfig) (*LedgerState, error)

func (*LedgerState) Chain

func (ls *LedgerState) Chain() *chain.Chain

func (*LedgerState) Close

func (ls *LedgerState) Close() error

func (*LedgerState) Datum added in v0.18.0

func (ls *LedgerState) Datum(hash []byte) (*models.Datum, error)

Datum looks up a datum by hash & adding this for implementing query.ReadData #741

func (*LedgerState) EvaluateTx added in v0.16.0

EvaluateTx evaluates the scripts in the provided transaction and returns the calculated fee, per-redeemer ExUnits, and total ExUnits

func (*LedgerState) GetBlock

func (ls *LedgerState) GetBlock(point ocommon.Point) (models.Block, error)

func (*LedgerState) GetChainFromPoint

func (ls *LedgerState) GetChainFromPoint(
	point ocommon.Point,
	inclusive bool,
) (*chain.ChainIterator, error)

GetChainFromPoint returns a ChainIterator starting at the specified point. If inclusive is true, the iterator will start at the requested point, otherwise it will start at the next block.

func (*LedgerState) GetCurrentPParams

func (ls *LedgerState) GetCurrentPParams() lcommon.ProtocolParameters

GetCurrentPParams returns the currentPParams value

func (*LedgerState) GetIntersectPoint

func (ls *LedgerState) GetIntersectPoint(
	points []ocommon.Point,
) (*ocommon.Point, error)

GetIntersectPoint returns the intersect between the specified points and the current chain

func (*LedgerState) Query

func (ls *LedgerState) Query(query any) (any, error)

func (*LedgerState) RecentChainPoints

func (ls *LedgerState) RecentChainPoints(count int) ([]ocommon.Point, error)

RecentChainPoints returns the requested count of recent chain points in descending order. This is used mostly for building a set of intersect points when acting as a chainsync client

func (*LedgerState) RecoverCommitTimestampConflict added in v0.11.0

func (ls *LedgerState) RecoverCommitTimestampConflict() error

func (*LedgerState) SetMempool added in v0.14.0

func (ls *LedgerState) SetMempool(mempool MempoolProvider)

Sets the mempool for accessing transactions

func (*LedgerState) SlotToEpoch added in v0.6.0

func (ls *LedgerState) SlotToEpoch(slot uint64) (models.Epoch, error)

SlotToEpoch returns a known epoch by slot number

func (*LedgerState) SlotToTime added in v0.6.0

func (ls *LedgerState) SlotToTime(slot uint64) (time.Time, error)

SlotToTime returns the current time for a given slot based on known epochs

func (*LedgerState) Start added in v0.11.0

func (ls *LedgerState) Start() error

func (*LedgerState) TimeToSlot added in v0.6.0

func (ls *LedgerState) TimeToSlot(t time.Time) (uint64, error)

TimeToSlot returns the slot number for a given time based on known epochs

func (*LedgerState) Tip

func (ls *LedgerState) Tip() ochainsync.Tip

Tip returns the current chain tip

func (*LedgerState) UtxoByRef

func (ls *LedgerState) UtxoByRef(
	txId []byte,
	outputIdx uint32,
) (*models.Utxo, error)

UtxoByRef returns a single UTxO by reference

func (*LedgerState) UtxosByAddress

func (ls *LedgerState) UtxosByAddress(
	addr ledger.Address,
) ([]models.Utxo, error)

UtxosByAddress returns all UTxOs that belong to the specified address

func (*LedgerState) ValidateTx

func (ls *LedgerState) ValidateTx(
	tx lcommon.Transaction,
) error

ValidateTx runs ledger validation on the provided transaction

type LedgerStateConfig

type LedgerStateConfig struct {
	PromRegistry               prometheus.Registerer
	Logger                     *slog.Logger
	Database                   *database.Database
	ChainManager               *chain.ChainManager
	EventBus                   *event.EventBus
	CardanoNodeConfig          *cardano.CardanoNodeConfig
	BlockfetchRequestRangeFunc BlockfetchRequestRangeFunc
	ValidateHistorical         bool
	ForgeBlocks                bool
}

type LedgerView

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

func (*LedgerView) CalculateRewards added in v0.18.0

func (lv *LedgerView) CalculateRewards(
	adaPots lcommon.AdaPots,
	rewardSnapshot lcommon.RewardSnapshot,
	rewardParams lcommon.RewardParameters,
) (*lcommon.RewardCalculationResult, error)

CalculateRewards calculates rewards for the given stake keys

func (*LedgerView) GetAdaPots added in v0.18.0

func (lv *LedgerView) GetAdaPots() lcommon.AdaPots

GetAdaPots returns the current Ada pots

func (*LedgerView) GetRewardSnapshot added in v0.18.0

func (lv *LedgerView) GetRewardSnapshot(
	epoch uint64,
) (lcommon.RewardSnapshot, error)

GetRewardSnapshot returns the current reward snapshot

func (*LedgerView) NetworkId

func (lv *LedgerView) NetworkId() uint

func (*LedgerView) PoolCurrentState added in v0.17.0

func (lv *LedgerView) PoolCurrentState(
	pkh lcommon.PoolKeyHash,
) (*lcommon.PoolRegistrationCertificate, *uint64, error)

It returns the most recent active pool registration certificate and the epoch of any pending retirement for the given pool key hash.

func (*LedgerView) PoolRegistration

func (lv *LedgerView) PoolRegistration(
	pkh lcommon.PoolKeyHash,
) ([]lcommon.PoolRegistrationCertificate, error)

func (*LedgerView) SlotToTime added in v0.17.0

func (lv *LedgerView) SlotToTime(slot uint64) (time.Time, error)

SlotToTime returns the current time for a given slot based on known epochs

func (*LedgerView) StakeRegistration

func (lv *LedgerView) StakeRegistration(
	stakingKey []byte,
) ([]lcommon.StakeRegistrationCertificate, error)

func (*LedgerView) TimeToSlot added in v0.17.0

func (lv *LedgerView) TimeToSlot(t time.Time) (uint64, error)

TimeToSlot returns the slot number for a given time based on known epochs

func (*LedgerView) UpdateAdaPots added in v0.18.0

func (lv *LedgerView) UpdateAdaPots(adaPots lcommon.AdaPots) error

UpdateAdaPots updates the Ada pots

func (*LedgerView) UtxoById

func (lv *LedgerView) UtxoById(
	utxoId lcommon.TransactionInput,
) (lcommon.Utxo, error)

type MempoolProvider added in v0.14.0

type MempoolProvider interface {
	Transactions() []mempool.MempoolTransaction
}

In ledger/state.go or a shared package

type ScheduledTask added in v0.14.0

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

type Scheduler added in v0.14.0

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

func NewScheduler added in v0.14.0

func NewScheduler(interval time.Duration) *Scheduler

func (*Scheduler) ChangeInterval added in v0.14.0

func (st *Scheduler) ChangeInterval(newInterval time.Duration)

ChangeInterval updates the tick interval of the Scheduler at runtime.

func (*Scheduler) Register added in v0.14.0

func (st *Scheduler) Register(
	interval int,
	taskFunc func(),
	runFailFunc func(),
)

Adds a new task to be scheduler

func (*Scheduler) Start added in v0.14.0

func (st *Scheduler) Start()

Start the timer (run goroutine once)

func (*Scheduler) Stop added in v0.14.0

func (st *Scheduler) Stop()

Stop the timer (terminates)

type TransactionRecord added in v0.18.0

type TransactionRecord struct {
	Tx    lcommon.Transaction
	Index int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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