ledger

package
v0.0.0-...-667e438 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

README

Ledger Package

This package implements the ledger, which includes the blockchain and global state.

YA-fabric has refactored this module and provided a more robust implement, with entries easy to be used

Mutiple ledgers

In YA-fabric, developer can run mutiple ledger objects in an instance. All of them have their separated blockchain, state and block indexes. And they share a storage pool for graphics of states, and transactions, which can be accessed from the globalLedger singleton (Each ledger object also integrated the entry of globalLedger)

GetNewLedger API can be used to create new ledger, replace of the legacy "GetLedger". The later function can still be used for accessing a default ledger object

Concurrent supporting

A ledger object now can be read by mutiple-thread and written by single-thread (Single Write Mutiple Reads, or SWMR). User can use a snapshot of database to get data consistent in a query transction, even another transaction is just changing the underlying database

Execution and committing entries

TxExecState, a new designed object, is provided for executing transactions, replace the old API for world-states. The new object allow concurrent execution of txs, and in combination of the committing entries form a new environment for chaincode platform.

A series of committing objects, see ledger_commit.go and ledger_commit_sync.go is used for updating ledger now. They have a unified interface on handling each elements in the ledger (blocks, states and indexes) and can be applied by requirement of different scenes like committing a new block after executing a bunch of transactions, inserting a block, or syncing the whole world-state, etc.

Syncing of world-state

A practical syncing implement for the whole world-state, via the new Dividable interface, is avaliable now. So peers can transfer their world-state data with resumable, verifiable process, which may be able to save much traffic and computational cost.

Currently only buckettree has implied the 'diviable' interface

Documentation

Index

Constants

View Source
const (
	//ErrorTypeInvalidArgument used to indicate the invalid input to ledger method
	ErrorTypeInvalidArgument = ErrorType("InvalidArgument")
	//ErrorTypeOutOfBounds used to indicate that a request is out of bounds
	ErrorTypeOutOfBounds = ErrorType("OutOfBounds")
	//ErrorTypeResourceNotFound used to indicate if a resource is not found
	ErrorTypeResourceNotFound = ErrorType("ResourceNotFound")
	//ErrorTypeBlockNotFound used to indicate if a block is not found when looked up by it's hash
	ErrorTypeBlockNotFound = ErrorType("ErrorTypeBlockNotFound")
	//ErrorTypeFatalCommit used to indicate fatal error in commit: we obtain unexpected different
	//result (hashes) from different source (e.g.: by local execution and incoming block)
	ErrorTypeFatalCommit = ErrorType("ErrorTypeFatalError")
)

Variables

View Source
var (
	ErrNormalEnd = newLedgerError(ErrorType("None"), "ledger: normal end")

	// ErrOutOfBounds is returned if a request is out of bounds
	ErrOutOfBounds = newLedgerError(ErrorTypeOutOfBounds, "ledger: out of bounds")

	// ErrResourceNotFound is returned if a resource is not found
	ErrResourceNotFound = newLedgerError(ErrorTypeResourceNotFound, "ledger: resource not found")
)
View Source
var BuildPreviewBlock = buildBlock

Functions

func CleanTestLedger

func CleanTestLedger(t *testing.T)

func MakeTestLedgerGenesis

func MakeTestLedgerGenesis(t *testing.T)

func NewLedgerConfig

func NewLedgerConfig(vp *viper.Viper) *ledgerConfig

func SetDefaultLedger

func SetDefaultLedger(l *Ledger)

func UpgradeLedger

func UpgradeLedger(odb *db.OpenchainDB, checkonly bool) error

func UseLegacyModeOnLedger

func UseLegacyModeOnLedger()

Types

type BlockChainAccessor

type BlockChainAccessor interface {
	GetBlockByNumber(blockNumber uint64) (*protos.Block, error)
	GetBlockchainSize() uint64
	GetCurrentStateHash() (stateHash []byte, err error)
}

BlockChainAccessor interface for retreiving blocks by block number

type BlockChainModifier

type BlockChainModifier interface {
	ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error
	RollbackStateDelta(id interface{}) error
	CommitStateDelta(id interface{}) error
	EmptyState() error
	PutBlock(blockNumber uint64, block *protos.Block) error
}

BlockChainModifier interface for applying changes to the block chain

type BlockChainUtil

type BlockChainUtil interface {
	HashBlock(block *protos.Block) ([]byte, error)
	VerifyBlockchain(start, finish uint64) (uint64, error)
}

BlockChainUtil interface for interrogating the block chain

type BlockCommit

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

commit blocks, can work concurrent with mutiple block commiter, or state commiter

func NewBlockAgent

func NewBlockAgent(ledger *Ledger) *BlockCommit

func (BlockCommit) LastCommit

func (blkc BlockCommit) LastCommit() []byte

func (*BlockCommit) SyncCommitBlock

func (blkc *BlockCommit) SyncCommitBlock(blkn uint64, block *protos.Block) (err error)

commit a block in specified position, it make a "full" commit (including persistent index and transactions), notice it can not be concurrent with mutiple block commitings becasue the db written must be in sequence

type Error

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

Error can be used for throwing an error from ledger code.

func (*Error) Error

func (ledgerError *Error) Error() string

func (*Error) Type

func (ledgerError *Error) Type() ErrorType

Type returns the type of the error

type ErrorType

type ErrorType string

ErrorType represents the type of a ledger error

type Ledger

type Ledger struct {
	*LedgerGlobal
	// contains filtered or unexported fields
}

Ledger - the struct for openchain ledger Threadsafy: we purpose ledger is a read-safe object for multi-thread but NOT write-safe

func GetLedger

func GetLedger() (*Ledger, error)

GetLedger - gives a reference to a 'singleton' ledger

func GetNewLedger

func GetNewLedger(db *db.OpenchainDB, config *ledgerConfig) (*Ledger, error)

GetNewLedger - gives a reference to a new ledger TODO need better approach

func InitSecondaryTestLedger

func InitSecondaryTestLedger(t *testing.T) (*Ledger, func())

func InitSoleTestLedger

func InitSoleTestLedger(t *testing.T) (*Ledger, func())

func InitTestLedger

func InitTestLedger(t *testing.T) *Ledger

InitTestLedger provides a ledger for testing. This method creates a fresh db and constructs a ledger instance on that.

func (*Ledger) AddGlobalState

func (ledger *Ledger) AddGlobalState(parent []byte, state []byte) error

overload AddGlobalState in ledgerGlobal

func (*Ledger) ApplyStateDelta

func (ledger *Ledger) ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error

ApplyStateDelta applies a state delta to the current state. This is an in memory change only. You must call ledger.CommitStateDelta to persist the change to the DB. This should only be used as part of state synchronization. State deltas can be retrieved from another peer though the Ledger.GetStateDelta function or by creating state deltas with keys retrieved from Ledger.GetStateSnapshot(). For an example, see TestSetRawState in ledger_test.go Note that there is no order checking in this function and it is up to the caller to ensure that deltas are applied in the correct order. For example, if you are currently at block 8 and call this function with a delta retrieved from Ledger.GetStateDelta(10), you would now be in a bad state because you did not apply the delta for block 9. It's possible to roll the state forwards or backwards using stateDelta.RollBackwards. By default, a delta retrieved for block 3 can be used to roll forwards from state at block 2 to state at block 3. If stateDelta.RollBackwards=false, the delta retrieved for block 3 can be used to roll backwards from the state at block 3 to the state at block 2.

func (*Ledger) ApplyStateDeltaDirect

func (ledger *Ledger) ApplyStateDeltaDirect(delta *statemgmt.StateDelta)

func (*Ledger) BeginTxBatch

func (ledger *Ledger) BeginTxBatch(id interface{}) error

BeginTxBatch - gets invoked when next round of transaction-batch execution begins

func (*Ledger) CommitAndIndexStateDelta

func (ledger *Ledger) CommitAndIndexStateDelta(id interface{}, blockNumber uint64) error

CommitStateDelta will commit the state delta passed to ledger.ApplyStateDelta to the DB and persist it will the specified index (blockNumber)

func (*Ledger) CommitStateDelta

func (ledger *Ledger) CommitStateDelta(id interface{}) error

----- Will be deprecated ---- CommitStateDelta will commit the state delta passed to ledger.ApplyStateDelta to the DB

func (*Ledger) CommitTransactions

func (ledger *Ledger) CommitTransactions(txids []string, blockNum uint64) error

func (*Ledger) CommitTxBatch

func (ledger *Ledger) CommitTxBatch(id interface{}, transactions []*protos.Transaction, transactionResults []*protos.TransactionResult, metadata []byte) error

CommitTxBatch - gets invoked when the current transaction-batch needs to be committed This function returns successfully iff the transactions details and state changes (that may have happened during execution of this transaction-batch) have been committed to permanent storage

func (*Ledger) CopyState

func (ledger *Ledger) CopyState(sourceChaincodeID string, destChaincodeID string) error

CopyState copies all the key-values from sourceChaincodeID to destChaincodeID

func (*Ledger) CreateSnapshot

func (ledger *Ledger) CreateSnapshot() (*LedgerSnapshot, uint64)

create a snapshot wrapper for current db, the corresponding blocknumber is also returned for verifing this snapshot is not enusred to sync with state and should be only used for block syncing and indexing should be avoiding used

func (*Ledger) CreateSyncingSnapshot

func (ledger *Ledger) CreateSyncingSnapshot(shash []byte) (*LedgerSnapshot, error)

func (*Ledger) DeleteALLStateKeysAndValues

func (ledger *Ledger) DeleteALLStateKeysAndValues() error

DeleteALLStateKeysAndValues deletes all keys and values from the state. This is generally only used during state synchronization when creating a new state from a snapshot.

func (*Ledger) DeleteState

func (ledger *Ledger) DeleteState(chaincodeID string, key string) error

DeleteState tracks the deletion of state for chaincodeID and key. Does not immediately writes to DB

func (*Ledger) EmptyState

func (ledger *Ledger) EmptyState() error

alias of DeleteALLStateKeysAndValues

func (*Ledger) GetBlockByNumber

func (ledger *Ledger) GetBlockByNumber(blockNumber uint64) (*protos.Block, error)

GetBlockByNumber return block given the number of the block on blockchain. Lowest block on chain is block number zero

func (*Ledger) GetBlockNumberByState

func (ledger *Ledger) GetBlockNumberByState(hash []byte) (uint64, error)

GetBlockNumberByState return given block nuber from a state, also used to check states

func (*Ledger) GetBlockNumberByTxid

func (ledger *Ledger) GetBlockNumberByTxid(txID string) (uint64, uint64, error)

func (*Ledger) GetBlockchainInfo

func (ledger *Ledger) GetBlockchainInfo() (*protos.BlockchainInfo, error)

GetBlockchainInfo returns information about the blockchain ledger such as height, current block hash, and previous block hash.

func (*Ledger) GetBlockchainSize

func (ledger *Ledger) GetBlockchainSize() uint64

GetBlockchainSize returns number of blocks in blockchain

func (*Ledger) GetCommitedTransaction

func (ledger *Ledger) GetCommitedTransaction(txID string) (*protos.Transaction, error)

func (*Ledger) GetCurrentStateHash

func (ledger *Ledger) GetCurrentStateHash() (stateHash []byte, err error)

GetCurrentStateHash returns the current non-committed hash of the in memory state

func (*Ledger) GetLedgerInfo

func (ledger *Ledger) GetLedgerInfo() (*LedgerInfo, error)

func (*Ledger) GetLedgerStatus

func (ledger *Ledger) GetLedgerStatus() *protos.LedgerState

func (*Ledger) GetRawBlockByNumber

func (ledger *Ledger) GetRawBlockByNumber(blockNumber uint64) (*protos.Block, error)

func (*Ledger) GetSnapshotState

func (ledger *Ledger) GetSnapshotState(chaincodeID string, key string, blknum uint64) ([]byte, uint64, error)

func (*Ledger) GetStableSyncingState

func (ledger *Ledger) GetStableSyncingState() *protos.StateFilter

TODO: use snapshot manager for syncing is not complete correct beacuse syncer may lost their available state because all nodes have trunced the target state, (consider a node is syncing some state A from another node B and B is off-line in the process, and time has passed so no other nodes will keep the state which A wish to sync) later we should use checkpoint for state syncing and a long hold node should be provided for alleviating this problem

func (*Ledger) GetState

func (ledger *Ledger) GetState(chaincodeID string, key string, committed bool) ([]byte, error)

GetState get state for chaincodeID and key. If committed is false, this first looks in memory and if missing, pulls from db. If committed is true, this pulls from the db only.

func (*Ledger) GetStateDelta

func (ledger *Ledger) GetStateDelta(blockNumber uint64) (*statemgmt.StateDelta, error)

GetStateDelta will return the state delta for the specified block if available. If not available because it has been discarded, returns nil,nil.

func (*Ledger) GetStateRangeScanIterator

func (ledger *Ledger) GetStateRangeScanIterator(chaincodeID string, startKey string, endKey string, committed bool) (statemgmt.RangeScanIterator, error)

GetStateRangeScanIterator returns an iterator to get all the keys (and values) between startKey and endKey (assuming lexical order of the keys) for a chaincodeID. If committed is true, the key-values are retrieved only from the db. If committed is false, the results from db are mergerd with the results in memory (giving preference to in-memory data) The key-values in the returned iterator are not guaranteed to be in any specific order

func (*Ledger) GetStateSnapshot

func (ledger *Ledger) GetStateSnapshot() (*state.StateSnapshot, error)

----- will be deprecated ----- GetStateSnapshot returns a point-in-time view of the global state for the current block. This should be used when transferring the state from one peer to another peer. You must call stateSnapshot.Release() once you are done with the snapshot to free up resources.

func (*Ledger) GetTXBatchPreviewBlockInfo

func (ledger *Ledger) GetTXBatchPreviewBlockInfo(id interface{},
	transactions []*protos.Transaction, metadata []byte) (*protos.BlockchainInfo, error)

GetTXBatchPreviewBlockInfo returns a preview block info that will contain the same information as GetBlockchainInfo will return after ledger.CommitTxBatch is called with the same parameters. If the state is modified by a transaction between these two calls, the contained hash will be different.

func (*Ledger) GetTempStateHash

func (ledger *Ledger) GetTempStateHash() ([]byte, error)

GetTempStateHash - Computes state hash by taking into account the state changes that may have taken place during the execution of current transaction-batch

func (*Ledger) GetTempStateHashWithTxDeltaStateHashes

func (ledger *Ledger) GetTempStateHashWithTxDeltaStateHashes() ([]byte, map[string][]byte, error)

GetTempStateHashWithTxDeltaStateHashes - In addition to the state hash (as defined in method GetTempStateHash), this method returns a map [txUuid of Tx --> cryptoHash(stateChangesMadeByTx)] Only successful txs appear in this map

func (*Ledger) GetTransactionsByRange

func (ledger *Ledger) GetTransactionsByRange(statehash []byte, beg int, end int) ([]*protos.Transaction, error)

GetTransactionByID return transaction by it's txId

func (*Ledger) HashBlock

func (*Ledger) HashBlock(block *protos.Block) ([]byte, error)

HashBlock returns the hash of the included block, useful for mocking

func (*Ledger) LedgerStateInfo

func (ledger *Ledger) LedgerStateInfo() (height uint64, hash []byte, avaliable bool)

func (*Ledger) PutBlock

func (ledger *Ledger) PutBlock(blockNumber uint64, block *protos.Block) error

PutBlock put a raw block on the chain and also commit the corresponding transactions

func (*Ledger) PutRawBlock

func (ledger *Ledger) PutRawBlock(block *protos.Block, blockNumber uint64) error

PutRawBlock just puts a raw block on the chain without handling the tx

func (*Ledger) RollbackStateDelta

func (ledger *Ledger) RollbackStateDelta(id interface{}) error

RollbackStateDelta will discard the state delta passed to ledger.ApplyStateDelta

func (*Ledger) RollbackTxBatch

func (ledger *Ledger) RollbackTxBatch(id interface{}) error

RollbackTxBatch - Discards all the state changes that may have taken place during the execution of current transaction-batch

func (*Ledger) SetState

func (ledger *Ledger) SetState(chaincodeID string, key string, value []byte) error

SetState sets state to given value for chaincodeID and key. Does not immideatly writes to DB

func (*Ledger) SetStateMultipleKeys

func (ledger *Ledger) SetStateMultipleKeys(chaincodeID string, kvs map[string][]byte) error

SetStateMultipleKeys sets the values for the multiple keys. This method is mainly to amortize the cost of grpc communication between chaincode shim peer

func (*Ledger) SubScribeNewBlock

func (ledger *Ledger) SubScribeNewBlock(f ...LedgerNewBlockNotify)

func (*Ledger) SubScribeNewState

func (ledger *Ledger) SubScribeNewState(f ...LedgerNewStateNotify)

func (*Ledger) Tag

func (ledger *Ledger) Tag() string

func (*Ledger) TestContinuouslBlockRange

func (ledger *Ledger) TestContinuouslBlockRange() (ret uint64)

test how height the blocks we have obtained continuously, return the FINAL block number (not the height)

func (*Ledger) TestExistedBlockRange

func (ledger *Ledger) TestExistedBlockRange(blockNumber uint64) uint64

func (*Ledger) TxBegin

func (ledger *Ledger) TxBegin(txID string)

TxBegin - Marks the begin of a new transaction in the ongoing batch

func (*Ledger) TxFinished

func (ledger *Ledger) TxFinished(txID string, txSuccessful bool)

TxFinished - Marks the finish of the on-going transaction. If txSuccessful is false, the state changes made by the transaction are discarded

func (*Ledger) UnderlyingDB

func (ledger *Ledger) UnderlyingDB() *db.OpenchainDB

func (*Ledger) VerifyBlockchain

func (ledger *Ledger) VerifyBlockchain(highBlock, lowBlock uint64) (uint64, error)

alias of verifychain

func (*Ledger) VerifyChain

func (ledger *Ledger) VerifyChain(highBlock, lowBlock uint64) (uint64, error)

VerifyChain will verify the integrity of the blockchain. This is accomplished by ensuring that the previous block hash stored in each block matches the actual hash of the previous block in the chain. The return value is the block number of lowest block in the range which can be verified as valid. The first block is assumed to be valid, and an error is only returned if the first block does not exist, or some other sort of irrecoverable ledger error such as the first block failing to hash is encountered. For example, if VerifyChain(0, 99) is called and previous hash values stored in blocks 8, 32, and 42 do not match the actual hashes of respective previous block 42 would be the return value from this function. highBlock is the high block in the chain to include in verification. If you wish to verify the entire chain, use ledger.GetBlockchainSize() - 1. lowBlock is the low block in the chain to include in verification. If you wish to verify the entire chain, use 0 for the genesis block.

type LedgerGlobal

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

Ledger - the struct for openchain ledger

func GetLedgerGlobal

func GetLedgerGlobal() (*LedgerGlobal, error)

GetLedger - gives a reference to a 'singleton' global ledger, it was the only singleton part (the ledger singleton is just for compatible)

func (*LedgerGlobal) AddCommitHook

func (ledger *LedgerGlobal) AddCommitHook(hf func([]string, uint64))

func (*LedgerGlobal) AddGlobalState

func (ledger *LedgerGlobal) AddGlobalState(parent []byte, state []byte) error

func (*LedgerGlobal) GetConsensusData

func (ledger *LedgerGlobal) GetConsensusData(statehash []byte) []byte

func (*LedgerGlobal) GetGlobalState

func (ledger *LedgerGlobal) GetGlobalState(statehash []byte) *protos.GlobalState

///////////////// global state related methods /////////////////////////////////////

func (*LedgerGlobal) GetPooledTxCount

func (ledger *LedgerGlobal) GetPooledTxCount() int

func (*LedgerGlobal) GetTransactionByID

func (ledger *LedgerGlobal) GetTransactionByID(txID string) (*protos.Transaction, error)

GetTransactionByID return transaction by it's txId

func (*LedgerGlobal) GetTransactionsByID

func (ledger *LedgerGlobal) GetTransactionsByID(txIDs []string) []*protos.Transaction

only return array of avaliable txs

func (*LedgerGlobal) GetTransactionsByIDAligned

func (ledger *LedgerGlobal) GetTransactionsByIDAligned(txIDs []string) []*protos.Transaction

func (*LedgerGlobal) GetTxForExecution

func (ledger *LedgerGlobal) GetTxForExecution(txIDs []string, preh protos.TxPreHandler) ([]*protos.TransactionHandlingContext, []string)

return tx arrays, has same lens of the incoming txIDs, for any id unavaliable, nil is returned

func (*LedgerGlobal) IteratePooledTransactions

func (ledger *LedgerGlobal) IteratePooledTransactions(ctx context.Context) (chan *protos.TransactionHandlingContext, error)

func (*LedgerGlobal) MustGetTransactionByID

func (ledger *LedgerGlobal) MustGetTransactionByID(txID string) *protos.Transaction

func (*LedgerGlobal) PoolTransaction

func (ledger *LedgerGlobal) PoolTransaction(txe *protos.TransactionHandlingContext)

func (*LedgerGlobal) PruneTransactions

func (ledger *LedgerGlobal) PruneTransactions(txs []*protos.Transaction)

func (*LedgerGlobal) PutTransactions

func (ledger *LedgerGlobal) PutTransactions(txs []*protos.Transaction) error

type LedgerInfo

type LedgerInfo struct {
	//base info
	*protos.BlockchainInfo

	//NOTICE following integer fields are all "HEIGHT" of
	//the chain, that is, the final block number PLUS 1
	//the queryable height for main modules,
	//the height of states decide the height
	//in base info
	Avaliable struct {
		Blocks  uint64
		States  uint64
		Indexes uint64
	}

	//the persisted height for main modules,
	//any state above this heigh can be easily
	//rollback to
	//notice some of the fields may higher than
	//current active height, according to the commit
	//strategy it was applied to
	Persisted struct {
		Blocks  uint64
		States  uint64
		Indexes uint64
	}

	States struct {
		//can query state current
		Avaliable bool
		//states's most available hash, if avaliable is false, it shows the
		//targethash it is syncing to, or it has the persisted statehash
		AvaliableHash []byte
	}
}

type LedgerNewBlockNotify

type LedgerNewBlockNotify func(blkn uint64, blk *protos.Block)

only the "raw" block (i.e. without transactions) is notified

type LedgerNewStateNotify

type LedgerNewStateNotify func(statepos uint64, statehash []byte)

type LedgerSnapshot

type LedgerSnapshot struct {
	*db.DBSnapshot
	// contains filtered or unexported fields
}

func (*LedgerSnapshot) GetBlockByNumber

func (sledger *LedgerSnapshot) GetBlockByNumber(blockNumber uint64) (*protos.Block, error)

func (*LedgerSnapshot) GetBlockNumberByState

func (sledger *LedgerSnapshot) GetBlockNumberByState(hash []byte) (uint64, error)

notice the indexs in snapshot is not ensured to be latest (e.g. in the asyncindexers)

func (*LedgerSnapshot) GetBlockchainSize

func (sledger *LedgerSnapshot) GetBlockchainSize() (uint64, error)

func (*LedgerSnapshot) GetParitalRangeIterator

func (sledger *LedgerSnapshot) GetParitalRangeIterator() (statemgmt.PartialRangeIterator, error)

func (*LedgerSnapshot) GetRawBlockByNumber

func (sledger *LedgerSnapshot) GetRawBlockByNumber(blockNumber uint64) (*protos.Block, error)

func (*LedgerSnapshot) GetStateDelta

func (sledger *LedgerSnapshot) GetStateDelta(blockNumber uint64) (*statemgmt.StateDelta, error)

func (*LedgerSnapshot) GetStateSnapshot

func (sledger *LedgerSnapshot) GetStateSnapshot() (*state.StateSnapshot, error)

func (*LedgerSnapshot) TestContinuouslBlockRange

func (sledger *LedgerSnapshot) TestContinuouslBlockRange() (uint64, error)

test how height the blocks we have obtained continuously

type PartialSync

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

state syncing commiter

func AssignSyncAgent

func AssignSyncAgent(ledger *Ledger) (PartialSync, error)

func NewSyncAgent

func NewSyncAgent(ledger *Ledger, blkn uint64, stateHash []byte) (PartialSync, error)

func (PartialSync) ApplySyncData

func (syncer PartialSync) ApplySyncData(data *protos.SyncStateChunk) error

func (PartialSync) AssignTasks

func (syncer PartialSync) AssignTasks() ([]*protos.SyncOffset, error)

func (PartialSync) CleanTask

func (syncer PartialSync) CleanTask()

func (PartialSync) FinishTask

func (syncer PartialSync) FinishTask() error

func (PartialSync) GetTarget

func (syncer PartialSync) GetTarget() []byte

type StateAccessor

type StateAccessor interface {
	GetStateSnapshot() (*state.StateSnapshot, error)
	GetStateDelta(blockNumber uint64) (*statemgmt.StateDelta, error)
	GetGlobalState(statehash []byte) *protos.GlobalState
}

StateAccessor interface for query states of current history and global

type StateManager

type StateManager interface {
	AddGlobalState(parent []byte, state []byte) error
}

StateManager interface for manage history view and global states

type TxEvaluateAndCommit

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

full tx commiter, to build new block and corresponding state on top of current chain from the execution results of a bunch of txs. CANNOT concurrent with other commiter

func NewTxEvaluatingAgent

func NewTxEvaluatingAgent(ledger *Ledger) (*TxEvaluateAndCommit, error)

func (*TxEvaluateAndCommit) AddExecResult

func (tec *TxEvaluateAndCommit) AddExecResult(txRes *protos.TransactionResult)

func (*TxEvaluateAndCommit) AddExecSuccessResult

func (tec *TxEvaluateAndCommit) AddExecSuccessResult(s TxExecStates, txRes *protos.TransactionResult)

func (*TxEvaluateAndCommit) AssignExecRT

func (tec *TxEvaluateAndCommit) AssignExecRT() TxExecStates

func (*TxEvaluateAndCommit) FullCommit

func (tec *TxEvaluateAndCommit) FullCommit(metadata []byte, transactions []*protos.Transaction) error

commit current results and persist them

func (*TxEvaluateAndCommit) LastCommitPosition

func (tec *TxEvaluateAndCommit) LastCommitPosition() uint64

func (*TxEvaluateAndCommit) LastCommitState

func (tec *TxEvaluateAndCommit) LastCommitState() []byte

func (*TxEvaluateAndCommit) Ledger

func (tec *TxEvaluateAndCommit) Ledger() *Ledger

func (*TxEvaluateAndCommit) MergeExec

func (tec *TxEvaluateAndCommit) MergeExec(s TxExecStates)

func (*TxEvaluateAndCommit) PreviewBlock

func (tec *TxEvaluateAndCommit) PreviewBlock(position uint64, blk *protos.Block) (*protos.Block, error)

preview build required part of a block for commiting

func (*TxEvaluateAndCommit) StateCommitOne

func (tec *TxEvaluateAndCommit) StateCommitOne(refBlockNumber uint64, refBlock *protos.Block) error

push state forward one, refblock can be used for verify the expected state

type TxExecStates

type TxExecStates struct {
	*state.TxExecStates
}

func NewQueryExecState

func NewQueryExecState(l *Ledger) TxExecStates

func (TxExecStates) AppyInvokingResult

func (s TxExecStates) AppyInvokingResult(l *Ledger)

func (TxExecStates) Get

func (s TxExecStates) Get(chaincodeID string, key string, l *Ledger) (ret []byte, err error)

func (TxExecStates) GetRangeScanIterator

func (s TxExecStates) GetRangeScanIterator(chaincodeID string, startKey string, endKey string, l *Ledger) (statemgmt.RangeScanIterator, error)

func (*TxExecStates) InitForInvoking

func (s *TxExecStates) InitForInvoking(l *Ledger)

----------- leagacy API following ------------

func (*TxExecStates) InitForQuerying

func (s *TxExecStates) InitForQuerying(l *Ledger)

func (TxExecStates) IsEmpty

func (s TxExecStates) IsEmpty() bool

func (TxExecStates) Uninited

func (s TxExecStates) Uninited() bool

Directories

Path Synopsis
raw

Jump to

Keyboard shortcuts

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