ledger

package
v0.0.0-...-9098a98 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package ledger manages the states of the ledgers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownLedgerState = errors.New("unknown ledger state")
	ErrInsufficientForFee = errors.New("insufficient balance for fee")
	ErrInsufficientForTx  = errors.New("insufficient balance for tx")
	ErrInvalidSeqNum      = errors.New("invalid sequence number")
	ErrLedgerNotExist     = errors.New("ledger not exist")
)
View Source
var (
	GenesisVersion = uint32(1)
	// The sequence number of the genesis ledger header.
	GenesisSeqNum = uint64(1)
	// Maximum number of transactions in a transaction set.
	GenesisMaxTxSetSize = uint32(100)
	// There are in total 4.5 billion ULT and the smallest unit is a
	// ULU which is 1/1000000000 of a ULT. The number of tokens is
	// counted in ULU.
	GenesisTotalTokens = int64(4500000000000000000)
	// The base fee for a transaction is 1000 ULU.
	GenesisBaseFee = int64(1000)
	// The base reserve for an account (0.1 ULT).
	GenesisBaseReserve = int64(100000000)
)

Functions

func ValidateManagerContext

func ValidateManagerContext(mc *ManagerContext) error

Types

type CloseInfo

type CloseInfo struct {
	// Decree index.
	Index uint64
	// Encoded consensus value.
	Value string
	// Transaction set.
	TxSet *ultpb.TxSet
}

CloseInfo contains the information that the manager needs to close the current ledger.

type CloseInfoBuffer

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

CloseInfoBuffer caches unclosed ledger close info until local ledger state catch up with the network state.

func (*CloseInfoBuffer) Append

func (b *CloseInfoBuffer) Append(info *CloseInfo)

Append new info to the tail of the buffer by checking whether the new info is the expected next-to-the-sequence info.

func (*CloseInfoBuffer) Clear

func (b *CloseInfoBuffer) Clear()

Clear the buffer

func (*CloseInfoBuffer) PeekHead

func (b *CloseInfoBuffer) PeekHead() *CloseInfo

Return the first CloseInfo without removing it

func (*CloseInfoBuffer) PopHead

func (b *CloseInfoBuffer) PopHead() *CloseInfo

Return the first CloseInfo and remove it from internal buffer

func (*CloseInfoBuffer) Size

func (b *CloseInfoBuffer) Size() int

Returns the size of buffered CloseInfo

type DownloadRange

type DownloadRange struct {
	StartIndex uint64
	EndIndex   uint64
}

type Downloader

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

Downloader downloads missing ledgers from peers.

func NewDownloader

func NewDownloader(networkID string, seed string, db db.Database, pm *peer.Manager) *Downloader

Create a new instance of downloader.

func (*Downloader) AddTask

func (d *Downloader) AddTask(start uint64, end uint64) error

Add a download task with start index and end index.

func (*Downloader) Ready

func (d *Downloader) Ready() <-chan *CloseInfo

Ready returns downloaded ledgers from start index to end index.

func (*Downloader) Start

func (d *Downloader) Start()

Start the downloader.

func (*Downloader) Stop

func (d *Downloader) Stop()

Stop the downloader by notifying goroutines to stop.

type LedgerState

type LedgerState uint8

LedgerState represents the current states of ledger, the ledger is synced if it complies with the states received from peers or we need to trigger catch up process to sync with the newest states.

const (
	LedgerStateSynced LedgerState = iota
	LedgerStateSyncing
	LedgerStateNotSynced
)

type Manager

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

Ledger manager is responsible for all the operations on the ledger.

func NewManager

func NewManager(ctx *ManagerContext) *Manager

func (*Manager) AddTxSet

func (lm *Manager) AddTxSet(txsetHash string, txset *ultpb.TxSet) error

Add txset and save it to db and cache.

func (*Manager) CreateGenesisLedger

func (lm *Manager) CreateGenesisLedger() error

Create the genesis ledger and initialize master account.

func (*Manager) CurrLedgerHeader

func (lm *Manager) CurrLedgerHeader() *ultpb.LedgerHeader

Get the current latest ledger header.

func (*Manager) CurrLedgerHeaderHash

func (lm *Manager) CurrLedgerHeaderHash() string

Get the hash of current latest ledger header.

func (*Manager) GetLedger

func (lm *Manager) GetLedger(seq string) (*ultpb.Ledger, error)

Get the ledger by ledger sequence.

func (*Manager) GetLedgerHeader

func (lm *Manager) GetLedgerHeader(seq string) (*ultpb.LedgerHeader, error)

Get the ledger header by ledger sequence.

func (*Manager) GetTxSet

func (lm *Manager) GetTxSet(txsetHash string) (*ultpb.TxSet, error)

Get the txset of the corresponding txset hash.

func (*Manager) LedgerSynced

func (lm *Manager) LedgerSynced() bool

Check whether the ledger is synced.

func (*Manager) NextLedgerHeaderSeq

func (lm *Manager) NextLedgerHeaderSeq() uint64

Get the sequence number of next ledger header.

func (*Manager) RecoverFromCheckpoint

func (lm *Manager) RecoverFromCheckpoint() error

Recover the latest ledger states from checkpoint.

func (*Manager) RecvExtVal

func (lm *Manager) RecvExtVal(index uint64, value string, txset *ultpb.TxSet) error

Receive externalized consensus value and do appropriate operations depend on current state of the ledger.

func (*Manager) Start

func (lm *Manager) Start()

Start the ledger manager.

func (*Manager) Stop

func (lm *Manager) Stop()

Stop the ledger manager.

type ManagerContext

type ManagerContext struct {
	NetworkID string
	Seed      string
	Database  db.Database
	AM        *account.Manager
	TM        *tx.Manager
	PM        *peer.Manager
}

ManagerContext contains contextural information the ledger manager needs.

Jump to

Keyboard shortcuts

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