ledger

package
v1.11.1 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 added in v1.11.1

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 added in v1.11.1

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

type HistoryDBSource added in v1.11.1

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 added in v1.11.1

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

NewHistoryDBSource constructs a new instance of HistoryDBSource

func (*HistoryDBSource) Close added in v1.11.1

func (source *HistoryDBSource) Close()

Close closes the internal go routines.

func (*HistoryDBSource) CurrentLedger added in v1.11.1

func (source *HistoryDBSource) CurrentLedger() uint32

CurrentLedger returns the current ledger.

func (*HistoryDBSource) NextLedger added in v1.11.1

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 added in v1.11.1

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 added in v1.11.1

func (c *State) CurrentStatus() Status

CurrentStatus returns the cached snapshot of ledger state

func (*State) RegisterMetrics added in v1.11.1

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

func (*State) SetAuroraStatus added in v1.11.1

func (c *State) SetAuroraStatus(next AuroraStatus)

SetAuroraStatus updates the cached snapshot of the ledger state of Aurora

func (*State) SetCoreStatus added in v1.11.1

func (c *State) SetCoreStatus(next CoreStatus)

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

func (*State) SetStatus added in v1.11.1

func (c *State) SetStatus(next Status)

SetStatus updates the cached snapshot of the ledger state

type StateInterface added in v1.11.1

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

type Status added in v1.11.1

type Status struct {
	CoreStatus
	AuroraStatus
}

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

type TestingSource added in v1.11.1

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

TestingSource is helper struct which implements the LedgerSource interface.

func NewTestingSource added in v1.11.1

func NewTestingSource(currentLedger uint32) *TestingSource

NewTestingSource returns a TestingSource.

func (*TestingSource) AddLedger added in v1.11.1

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 added in v1.11.1

func (source *TestingSource) Close()

func (*TestingSource) CurrentLedger added in v1.11.1

func (source *TestingSource) CurrentLedger() uint32

CurrentLedger returns the current ledger.

func (*TestingSource) NextLedger added in v1.11.1

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