state

package
v0.0.0-...-4f0ab6e Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MinimumMerkleTree

type MinimumMerkleTree struct {
	Root     merkle.MerkleHash
	Size     int64
	LastPath merkle.MerklePath
}

MinimumMerkleTree storages a merkleTree's root,size and last path.

func (MinimumMerkleTree) Copy

Copy the MinimumMerkleTree and return a new tree.

type ShardStateManager

type ShardStateManager struct {
	// A delta merkle tree of the shard ledger, for updating all pending transaction proofs.
	Tree MinimumMerkleTree
	// The height of each shard.
	ShardHeights map[shard.Index]int64
	// contains filtered or unexported fields
}

ShardStateManager keeps state of the shard ledger.

func NewShardStateManager

func NewShardStateManager(root *merkle.MerkleHash,
	size int64,
	latestPath *merkle.MerklePath,
	ledgerInfo *wire.LedgerInfo,
	chain iblockchain.BlockChain) *ShardStateManager

NewShardStateManager initialize new ShardStateManager object with necessary info to build a delta merkle tree.

func (*ShardStateManager) ApplyUpdate

func (state *ShardStateManager) ApplyUpdate(update *Update) error

ApplyUpdate Applies a given StateUpdate (mutation).

func (*ShardStateManager) GetBlockHeadersToAppend

func (state *ShardStateManager) GetBlockHeadersToAppend(ledgerInfo *wire.LedgerInfo) ([]*wire.BlockHeader, error)

GetBlockHeadersToAppend retrieve continous block headers in each shard for the range from current ledger info to the given ledger info.

func (*ShardStateManager) GetLedgerRoot

func (state *ShardStateManager) GetLedgerRoot() merkle.MerkleHash

GetLedgerRoot returns the last updated ledger

func (*ShardStateManager) GetShardHeight

func (state *ShardStateManager) GetShardHeight(shardIndex shard.Index) int64

GetShardHeight returns the height of Specified shard

func (*ShardStateManager) GetUpdateWithFullBlock

func (state *ShardStateManager) GetUpdateWithFullBlock(block *wire.MsgBlock) (*Update, error)

GetUpdateWithFullBlock returns a new update instance which update with the given block. 1. marks spent outs in the merkle tree and updates the merkle root; 2. conditionally appends the merkle root of new outs from cached block headers, according to given full block header; 3. update merkle tree according to update action

func (*ShardStateManager) GetUpdateWithSlimBlock

func (state *ShardStateManager) GetUpdateWithSlimBlock(block *wire.SlimBlock) (*Update, error)

GetUpdateWithSlimBlock returns a new update instance which update with the given block. 1. marks spent outs in the merkle tree and updates the merkle root; 2. conditionally appends the merkle root of new outs from cached block headers, according to given full block header; 3. update merkle tree according to update action

func (*ShardStateManager) LedgerInfo

func (state *ShardStateManager) LedgerInfo() *wire.LedgerInfo

LedgerInfo returns all shards' ledgerInfo

func (*ShardStateManager) LocalLedgerInfo

func (state *ShardStateManager) LocalLedgerInfo() *wire.LedgerInfo

LocalLedgerInfo returns the ledgerInfo which blocks in state's chache may not update

func (*ShardStateManager) NewUpdate

func (state *ShardStateManager) NewUpdate() (*Update, error)

NewUpdate Creates a new empty Update (mutation) based on current state.

type Update

type Update struct {
	DeltaTree *merkle.DeltaMerkleTree
	// contains filtered or unexported fields
}

Update Represents an mutation of the Shard Ledger.

func (*Update) AddHeaders

func (update *Update) AddHeaders(headers ...*wire.BlockHeader) error

AddHeaders Adds new headers in given order into this update. Delta Ledger Tree will be appended with outs tree root in each header. Ledger Info will be update accordingly for each shard.

func (*Update) GetShardDataOutProof

func (update *Update) GetShardDataOutProof(oldOut, newOut *wire.OutState) (*merkle.MerklePath, error)

GetShardDataOutProof returns the proof of shard init data.

func (*Update) GetShardHeight

func (update *Update) GetShardHeight(shardIdx shard.Index) int64

GetShardHeight returns the shard's height given shardIndex.

func (*Update) MarkSpentOuts

func (update *Update) MarkSpentOuts(outPoint *wire.OutPoint, proof *merkle.MerklePath) error

MarkSpentOuts Add a modification of spent Out state to this mutation.

func (*Update) UpdateProofs

func (update *Update) UpdateProofs(proofs []merkle.MerklePath) ([]merkle.MerklePath, error)

UpdateProofs trys to update a slice of input proofs (merkle path) based on this mutation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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