ledger

package
v0.0.0-...-095633c Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ledger provides useful utilities concerning ledgers within hcnet, specifically as a central location to store a cached snapshot of the state of both aurora's and hcnet-core's views of the ledger. This package is intended to be at the lowest levels of aurora's dependency tree, please keep it free of dependencies to other aurora packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuroraStatus

type AuroraStatus struct {
	HistoryLatest         int32     `db:"history_latest"`
	HistoryLatestClosedAt time.Time `db:"history_latest_closed_at"`
	HistoryElder          int32     `db:"history_elder"`
	ExpHistoryLatest      uint32    `db:"exp_history_latest"`
}

type CoreStatus

type CoreStatus struct {
	CoreLatest int32 `db:"core_latest"`
}

type HistoryDBSource

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

HistoryDBSource utility struct to pass the SSE update frequency and a function to get the current ledger state.

func NewHistoryDBSource

func NewHistoryDBSource(updateFrequency time.Duration, state *State) *HistoryDBSource

NewHistoryDBSource constructs a new instance of HistoryDBSource

func (*HistoryDBSource) Close

func (source *HistoryDBSource) Close()

Close closes the internal go routines.

func (*HistoryDBSource) CurrentLedger

func (source *HistoryDBSource) CurrentLedger() uint32

CurrentLedger returns the current ledger.

func (*HistoryDBSource) NextLedger

func (source *HistoryDBSource) NextLedger(currentSequence uint32) chan uint32

NextLedger returns a channel which yields every time there is a new ledger with a sequence number larger than currentSequence.

type Source

type Source interface {
	CurrentLedger() uint32
	NextLedger(currentSequence uint32) chan uint32
	Close()
}

Source exposes two helpers methods to help you find out the current ledger and yield every time there is a new ledger. Call `Close` when source is no longer used.

type State

type State struct {
	sync.RWMutex

	Metrics struct {
		HistoryLatestLedgerCounter        prometheus.CounterFunc
		HistoryLatestLedgerClosedAgoGauge prometheus.GaugeFunc
		HistoryElderLedgerCounter         prometheus.CounterFunc
		CoreLatestLedgerCounter           prometheus.CounterFunc
	}
	// contains filtered or unexported fields
}

State is an in-memory data structure which holds a snapshot of both aurora's and hcnet-core's view of the network

func (*State) CurrentStatus

func (c *State) CurrentStatus() Status

CurrentStatus returns the cached snapshot of ledger state

func (*State) RegisterMetrics

func (c *State) RegisterMetrics(registry *prometheus.Registry)

func (*State) SetAuroraStatus

func (c *State) SetAuroraStatus(next AuroraStatus)

SetAuroraStatus updates the cached snapshot of the ledger state of Aurora

func (*State) SetCoreStatus

func (c *State) SetCoreStatus(next CoreStatus)

SetCoreStatus updates the cached snapshot of the ledger state of Hcnet-Core

func (*State) SetStatus

func (c *State) SetStatus(next Status)

SetStatus updates the cached snapshot of the ledger state

type StateInterface

type StateInterface interface {
	CurrentStatus() Status
	SetStatus(next Status)
	SetCoreStatus(next CoreStatus)
	SetAuroraStatus(next AuroraStatus)
	RegisterMetrics(registry *prometheus.Registry)
}

type Status

type Status struct {
	CoreStatus
	AuroraStatus
}

Status represents a snapshot of both aurora's and hcnet-core's view of the ledger.

type TestingSource

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

TestingSource is helper struct which implements the LedgerSource interface.

func NewTestingSource

func NewTestingSource(currentLedger uint32) *TestingSource

NewTestingSource returns a TestingSource.

func (*TestingSource) AddLedger

func (source *TestingSource) AddLedger(nextSequence uint32)

AddLedger adds a new sequence to the newLedgers channel. AddLedger() will block until the new sequence is read

func (*TestingSource) Close

func (source *TestingSource) Close()

func (*TestingSource) CurrentLedger

func (source *TestingSource) CurrentLedger() uint32

CurrentLedger returns the current ledger.

func (*TestingSource) NextLedger

func (source *TestingSource) NextLedger(currentSequence uint32) chan uint32

NextLedger returns a channel which yields every time there is a new ledger.

Jump to

Keyboard shortcuts

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