Documentation ¶
Overview ¶
Package ledger manages the states of the ledgers.
Index ¶
- Variables
- func ValidateManagerContext(mc *ManagerContext) error
- type CloseInfo
- type CloseInfoBuffer
- type DownloadRange
- type Downloader
- type LedgerState
- type Manager
- func (lm *Manager) AddTxSet(txsetHash string, txset *ultpb.TxSet) error
- func (lm *Manager) CreateGenesisLedger() error
- func (lm *Manager) CurrLedgerHeader() *ultpb.LedgerHeader
- func (lm *Manager) CurrLedgerHeaderHash() string
- func (lm *Manager) GetLedger(seq string) (*ultpb.Ledger, error)
- func (lm *Manager) GetLedgerHeader(seq string) (*ultpb.LedgerHeader, error)
- func (lm *Manager) GetTxSet(txsetHash string) (*ultpb.TxSet, error)
- func (lm *Manager) LedgerSynced() bool
- func (lm *Manager) NextLedgerHeaderSeq() uint64
- func (lm *Manager) RecoverFromCheckpoint() error
- func (lm *Manager) RecvExtVal(index uint64, value string, txset *ultpb.TxSet) error
- func (lm *Manager) Start()
- func (lm *Manager) Stop()
- type ManagerContext
Constants ¶
This section is empty.
Variables ¶
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") )
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) 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 Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader downloads missing ledgers from peers.
func NewDownloader ¶
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) 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) CreateGenesisLedger ¶
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 ¶
Get the hash of current latest ledger header.
func (*Manager) GetLedgerHeader ¶
func (lm *Manager) GetLedgerHeader(seq string) (*ultpb.LedgerHeader, error)
Get the ledger header by ledger sequence.
func (*Manager) LedgerSynced ¶
Check whether the ledger is synced.
func (*Manager) NextLedgerHeaderSeq ¶
Get the sequence number of next ledger header.
func (*Manager) RecoverFromCheckpoint ¶
Recover the latest ledger states from checkpoint.
func (*Manager) RecvExtVal ¶
Receive externalized consensus value and do appropriate operations depend on current state of the ledger.