Show / Hide Table of Contents

Class DefaultStore

The default built-in IStore implementation. This stores data in the file system or in memory. It also uses LiteDB for some complex indices.

DefaultStore and DefaultKeyValueStore-backed TrieStateStore can be instantiated from a URI with default+file: scheme using LoadStore(Uri), e.g.:

  • default+file:///var/data/planet/
  • default+file:///c:/Users/john/AppData/Local/planet/
  • default+file:///var/data/planet/?secure=true (trie keys are hashed)

The following query string parameters are supported:

journaltrue (default) or false. Corresponds to DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)'s journal parameter.
index-cacheCorresponds to DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)'s indexCacheSize parameter. 50000 by default.
block-cacheCorresponds to DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)'s blockCacheSize parameter. 512 by default.
tx-cacheCorresponds to DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)'s txCacheSize parameter. 1024 by default.
flushtrue (default) or false. Corresponds to DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)'s flush parameter.
readonlytrue or false (default). Corresponds to DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)'s readOnly parameter.
states-dirCorresponds to 's path parameter. It is relative to the URI path, and defaults to states.
securetrue or false (default). Corresponds to TrieStateStore(IKeyValueStore, Boolean)'s secure parameter.
Inheritance
Object
BaseStore
DefaultStore
Implements
IStore
IDisposable
Inherited Members
BaseStore.GetBlock<T>(HashAlgorithmGetter, BlockHash)
BaseStore.GetBlockIndex(BlockHash)
BaseStore.GetFirstTxIdBlockHashIndex(TxId)
BaseStore.SerializeTxExecution(TxSuccess)
BaseStore.SerializeTxExecution(TxFailure)
BaseStore.DeserializeTxExecution(BlockHash, TxId, IValue, ILogger)
Namespace: Libplanet.Store
Assembly: Libplanet.dll
Syntax
public class DefaultStore : BaseStore, IStore, IDisposable

Constructors

| Improve this Doc View Source

DefaultStore(String, Boolean, Int32, Int32, Int32, Boolean, Boolean)

Creates a new DefaultStore.

Declaration
public DefaultStore(string path, bool journal = true, int indexCacheSize = 50000, int blockCacheSize = 512, int txCacheSize = 1024, bool flush = true, bool readOnly = false)
Parameters
Type Name Description
String path

The path of the directory where the storage files will be saved. If the path is null, the database is created in memory.

Boolean journal

Enables or disables double write check to ensure durability.

Int32 indexCacheSize

Max number of pages in the index cache.

Int32 blockCacheSize

The capacity of the block cache.

Int32 txCacheSize

The capacity of the transaction cache.

Boolean flush

Writes data direct to disk avoiding OS cache. Turned on by default.

Boolean readOnly

Opens database readonly mode. Turned off by default.

Methods

| Improve this Doc View Source

AppendIndex(Guid, BlockHash)

Appends a block to a chain.

Declaration
public override long AppendIndex(Guid chainId, BlockHash hash)
Parameters
Type Name Description
Guid chainId

The ID of a chain to append a block to.

BlockHash hash

The hash of a block to append. Assumes the block is already put into the store.

Returns
Type Description
Int64

The index of the appended block.

Overrides
BaseStore.AppendIndex(Guid, BlockHash)
| Improve this Doc View Source

ContainsBlock(BlockHash)

Determines whether the IStore contains Block<T> the specified blockHash.

Declaration
public override bool ContainsBlock(BlockHash blockHash)
Parameters
Type Name Description
BlockHash blockHash

The HashDigest<T> of the Block<T> to check if it is in the IStore.

Returns
Type Description
Boolean

true if the IStore contains Block<T> with the specified blockHash; otherwise, false.

Overrides
BaseStore.ContainsBlock(BlockHash)
| Improve this Doc View Source

ContainsTransaction(TxId)

Determines whether the IStore contains Transaction<T> the specified txId.

Declaration
public override bool ContainsTransaction(TxId txId)
Parameters
Type Name Description
TxId txId

The TxId of the Transaction<T> to check if it is in the IStore.

Returns
Type Description
Boolean

true if the IStore contains Transaction<T> with the specified txId; otherwise, false.

Overrides
BaseStore.ContainsTransaction(TxId)
| Improve this Doc View Source

CountBlocks()

Declaration
public override long CountBlocks()
Returns
Type Description
Int64
Overrides
BaseStore.CountBlocks()
| Improve this Doc View Source

CountIndex(Guid)

Declaration
public override long CountIndex(Guid chainId)
Parameters
Type Name Description
Guid chainId
Returns
Type Description
Int64
Overrides
BaseStore.CountIndex(Guid)
| Improve this Doc View Source

CountTransactions()

Declaration
public override long CountTransactions()
Returns
Type Description
Int64
Overrides
BaseStore.CountTransactions()
| Improve this Doc View Source

DeleteBlock(BlockHash)

Removes a block from the store.

Declaration
public override bool DeleteBlock(BlockHash blockHash)
Parameters
Type Name Description
BlockHash blockHash

The hash of a block to remove.

Returns
Type Description
Boolean

false if such block does not exist. Otherwise true.

Overrides
BaseStore.DeleteBlock(BlockHash)
| Improve this Doc View Source

DeleteChainId(Guid)

Deletes an index, tx nonces, and state references in the given chainId. It also deletes chain itself. If there is no such chainId it does nothing.

Declaration
public override void DeleteChainId(Guid chainId)
Parameters
Type Name Description
Guid chainId

The ID of chain to delete.

Overrides
BaseStore.DeleteChainId(Guid)
Remarks

This does not delete blocks or transactions that belong to the index of the chainId, but only the index, tx nonces, and state references.

| Improve this Doc View Source

DeleteTransaction(TxId)

Declaration
public override bool DeleteTransaction(TxId txid)
Parameters
Type Name Description
TxId txid
Returns
Type Description
Boolean
Overrides
BaseStore.DeleteTransaction(TxId)
| Improve this Doc View Source

DeleteTxIdBlockHashIndex(TxId, BlockHash)

Deletes the index for the txId and blockHash.

Declaration
public override void DeleteTxIdBlockHashIndex(TxId txId, BlockHash blockHash)
Parameters
Type Name Description
TxId txId

The TxId of the Transaction<T>.

BlockHash blockHash

The BlockHash of the Block<T>.

Overrides
BaseStore.DeleteTxIdBlockHashIndex(TxId, BlockHash)
| Improve this Doc View Source

Dispose()

Declaration
public override void Dispose()
Overrides
BaseStore.Dispose()
| Improve this Doc View Source

ForkBlockIndexes(Guid, Guid, BlockHash)

Forks block indexes from sourceChainId to destinationChainId.

Declaration
public override void ForkBlockIndexes(Guid sourceChainId, Guid destinationChainId, BlockHash branchpoint)
Parameters
Type Name Description
Guid sourceChainId

The chain ID of block indexes to fork.

Guid destinationChainId

The chain ID of destination block indexes.

BlockHash branchpoint

The branchpoint Block<T> to fork.

Overrides
BaseStore.ForkBlockIndexes(Guid, Guid, BlockHash)
Exceptions
Type Condition
ChainIdNotFoundException

Thrown when the given sourceChainId does not exist.

See Also
IterateIndexes(Guid, Int32, Nullable<Int32>)
AppendIndex(Guid, BlockHash)
| Improve this Doc View Source

ForkTxNonces(Guid, Guid)

Forks Transaction<T> Nonces from sourceChainId to destinationChainId.

Declaration
public override void ForkTxNonces(Guid sourceChainId, Guid destinationChainId)
Parameters
Type Name Description
Guid sourceChainId

The chain Id of Transaction<T> Nonces to fork.

Guid destinationChainId

The chain Id of destination Transaction<T> Nonces.

Overrides
BaseStore.ForkTxNonces(Guid, Guid)
Exceptions
Type Condition
ChainIdNotFoundException

Thrown when the given sourceChainId does not exist.

| Improve this Doc View Source

GetBlockDigest(BlockHash)

Gets the corresponding stored BlockDigest to the given blockHash.

Declaration
public override BlockDigest? GetBlockDigest(BlockHash blockHash)
Parameters
Type Name Description
BlockHash blockHash

Hash to find.

Returns
Type Description
Nullable<BlockDigest>

A found BlockDigest, or null if no block having such blockHash is stored.

Overrides
BaseStore.GetBlockDigest(BlockHash)
| Improve this Doc View Source

GetBlockPerceivedTime(BlockHash)

Queries the perceived time of a block, if it has been recorded.

Declaration
public override DateTimeOffset? GetBlockPerceivedTime(BlockHash blockHash)
Parameters
Type Name Description
BlockHash blockHash

Hash to query.

Returns
Type Description
Nullable<DateTimeOffset>

The perceived time of a block, if it exists. Otherwise, null.

Overrides
BaseStore.GetBlockPerceivedTime(BlockHash)
| Improve this Doc View Source

GetCanonicalChainId()

Gets the ID of the current canonical chain.

Declaration
public override Guid? GetCanonicalChainId()
Returns
Type Description
Nullable<Guid>

The ID of the current canonical chain. Maybe null.

Overrides
BaseStore.GetCanonicalChainId()
See Also
SetCanonicalChainId(Guid)
| Improve this Doc View Source

GetTransaction<T>(TxId)

Declaration
public override Transaction<T> GetTransaction<T>(TxId txid)
    where T : IAction, new()
Parameters
Type Name Description
TxId txid
Returns
Type Description
Transaction<T>
Type Parameters
Name Description
T
Overrides
BaseStore.GetTransaction<T>(TxId)
| Improve this Doc View Source

GetTxExecution(BlockHash, TxId)

Retrieves the recorded transaction execution summary.

Declaration
public override TxExecution GetTxExecution(BlockHash blockHash, TxId txid)
Parameters
Type Name Description
BlockHash blockHash

The Hash of the recorded transaction execution to retrieve.

TxId txid

The Id of the recorded transaction execution to retrieve.

Returns
Type Description
TxExecution

The recorded transaction execution summary. If it has been never recorded null is returned instead.

Overrides
BaseStore.GetTxExecution(BlockHash, TxId)
See Also
PutTxExecution(TxFailure)
PutTxExecution(TxSuccess)
| Improve this Doc View Source

GetTxNonce(Guid, Address)

Gets Transaction<T> nonce of the address.

Declaration
public override long GetTxNonce(Guid chainId, Address address)
Parameters
Type Name Description
Guid chainId

The ID of the chain to get Transaction<T> nonce.

Address address

The Address to get Transaction<T> nonce.

Returns
Type Description
Int64

A Transaction<T> nonce. If there is no previous Transaction<T>, return 0.

Overrides
BaseStore.GetTxNonce(Guid, Address)
See Also
IncreaseTxNonce(Guid, Address, Int64)
| Improve this Doc View Source

IncreaseTxNonce(Guid, Address, Int64)

Increases (or decreases if a negative delta is given) the tx nonce counter for signer.

Declaration
public override void IncreaseTxNonce(Guid chainId, Address signer, long delta = null)
Parameters
Type Name Description
Guid chainId

The ID of the chain to increase Transaction<T> nonce.

Address signer

The address of the account to increase tx nonce.

Int64 delta

How many to increase the counter. A negative number decreases the counter. 1 by default.

Overrides
BaseStore.IncreaseTxNonce(Guid, Address, Int64)
See Also
GetTxNonce(Guid, Address)
| Improve this Doc View Source

IndexBlockHash(Guid, Int64)

Determines the block hash by its index.

Declaration
public override BlockHash? IndexBlockHash(Guid chainId, long index)
Parameters
Type Name Description
Guid chainId

The chain ID of the index that contains the block.

Int64 index

The index of the block to query its hash. Negative indices mean the offset from the end. For example, -1 means the topmost block.

Returns
Type Description
Nullable<BlockHash>

The block hash of the index in the chain. If there is no such index, it returns null.

Overrides
BaseStore.IndexBlockHash(Guid, Int64)
| Improve this Doc View Source

IterateBlockHashes()

Lists all block hashes in the store, regardless of their belonging chains.

Declaration
public override IEnumerable<BlockHash> IterateBlockHashes()
Returns
Type Description
IEnumerable<BlockHash>

All block hashes in the store.

Overrides
BaseStore.IterateBlockHashes()
| Improve this Doc View Source

IterateIndexes(Guid, Int32, Nullable<Int32>)

Lists all block hashes in the .

Declaration
public override IEnumerable<BlockHash> IterateIndexes(Guid chainId, int offset, int? limit)
Parameters
Type Name Description
Guid chainId

The chain ID of the index that contains block hashes to iterate.

Int32 offset

The starting point to return block hashes.

Nullable<Int32> limit

The maximum number of block hashes to get.

Returns
Type Description
IEnumerable<BlockHash>

Block hashes in the index of the chainId, in ascending order; the genesis block goes first, and the tip block goes last.

Overrides
BaseStore.IterateIndexes(Guid, Int32, Nullable<Int32>)
| Improve this Doc View Source

IterateTransactionIds()

Declaration
public override IEnumerable<TxId> IterateTransactionIds()
Returns
Type Description
IEnumerable<TxId>
Overrides
BaseStore.IterateTransactionIds()
| Improve this Doc View Source

IterateTxIdBlockHashIndex(TxId)

Declaration
public override IEnumerable<BlockHash> IterateTxIdBlockHashIndex(TxId txId)
Parameters
Type Name Description
TxId txId
Returns
Type Description
IEnumerable<BlockHash>
Overrides
BaseStore.IterateTxIdBlockHashIndex(TxId)
| Improve this Doc View Source

ListChainIds()

Lists existing chain IDs.

Declaration
public override IEnumerable<Guid> ListChainIds()
Returns
Type Description
IEnumerable<Guid>

Existing chain IDs.

Overrides
BaseStore.ListChainIds()
| Improve this Doc View Source

ListTxNonces(Guid)

Lists all Addresses that have ever signed Transaction<T>, and their corresponding Transaction<T> nonces.

Declaration
public override IEnumerable<KeyValuePair<Address, long>> ListTxNonces(Guid chainId)
Parameters
Type Name Description
Guid chainId

The ID of the chain to list Addresses and their Transaction<T> nonces.

Returns
Type Description
IEnumerable<KeyValuePair<Address, Int64>>

Pairs of an Address and its tx nonce. All nonces are greater than 0. (If there are underlying entries having zero nonces these must be hidden.)

Overrides
BaseStore.ListTxNonces(Guid)
See Also
GetTxNonce(Guid, Address)
| Improve this Doc View Source

PruneOutdatedChains(Boolean)

Delete all non-canonical chains.

Declaration
public override void PruneOutdatedChains(bool noopWithoutCanon = false)
Parameters
Type Name Description
Boolean noopWithoutCanon

Flag to determine whether the function throws exception when the canonical chain is not assigned. false by default. If it set to true, does not throw exception when there is no canonical chain. Otherwise, throws when there is no canonical chain.

Overrides
BaseStore.PruneOutdatedChains(Boolean)
| Improve this Doc View Source

PutBlock<T>(Block<T>)

Puts the given block in to the store. If the same block already exists in the store it does nothing.

Declaration
public override void PutBlock<T>(Block<T> block)
    where T : IAction, new()
Parameters
Type Name Description
Block<T> block

A Block<T> to put into the store.

Type Parameters
Name Description
T

An IAction class used with block.

Overrides
Libplanet.Store.BaseStore.PutBlock<T>(Libplanet.Blocks.Block<T>)
| Improve this Doc View Source

PutTransaction<T>(Transaction<T>)

Declaration
public override void PutTransaction<T>(Transaction<T> tx)
    where T : IAction, new()
Parameters
Type Name Description
Transaction<T> tx
Type Parameters
Name Description
T
Overrides
Libplanet.Store.BaseStore.PutTransaction<T>(Libplanet.Tx.Transaction<T>)
| Improve this Doc View Source

PutTxExecution(TxFailure)

Records the given txFailure.

Declaration
public override void PutTxExecution(TxFailure txFailure)
Parameters
Type Name Description
TxFailure txFailure

The failed transaction execution summary to record. Must not be null.

Overrides
BaseStore.PutTxExecution(TxFailure)
Remarks

If there is already the record for the same BlockHash and TxId, the record is silently overwritten.

See Also
PutTxExecution(TxSuccess)
GetTxExecution(BlockHash, TxId)
| Improve this Doc View Source

PutTxExecution(TxSuccess)

Records the given txSuccess.

Declaration
public override void PutTxExecution(TxSuccess txSuccess)
Parameters
Type Name Description
TxSuccess txSuccess

The successful transaction execution summary to record. Must not be null.

Overrides
BaseStore.PutTxExecution(TxSuccess)
Remarks

If there is already the record for the same BlockHash and TxId, the record is silently overwritten.

See Also
PutTxExecution(TxFailure)
GetTxExecution(BlockHash, TxId)
| Improve this Doc View Source

PutTxIdBlockHashIndex(TxId, BlockHash)

Records a index for given pair txId and blockHash. If there exist a record for txId already, it overwrites the record silently.

Declaration
public override void PutTxIdBlockHashIndex(TxId txId, BlockHash blockHash)
Parameters
Type Name Description
TxId txId

The TxId of the Transaction<T>.

BlockHash blockHash

The BlockHash of the Block<T>.

Overrides
BaseStore.PutTxIdBlockHashIndex(TxId, BlockHash)
| Improve this Doc View Source

SetBlockPerceivedTime(BlockHash, DateTimeOffset)

Records the perceived time of a block. If there is already a record, it is overwritten.

Declaration
public override void SetBlockPerceivedTime(BlockHash blockHash, DateTimeOffset perceivedTime)
Parameters
Type Name Description
BlockHash blockHash

Hash to record its perceived time.

DateTimeOffset perceivedTime

The perceived time to record.

Overrides
BaseStore.SetBlockPerceivedTime(BlockHash, DateTimeOffset)
| Improve this Doc View Source

SetCanonicalChainId(Guid)

Sets the canonical chain.

Declaration
public override void SetCanonicalChainId(Guid chainId)
Parameters
Type Name Description
Guid chainId

The ID of a new canonical chain.

Overrides
BaseStore.SetCanonicalChainId(Guid)
See Also
GetCanonicalChainId()

Implements

IStore
IDisposable

See Also

IStore
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2022 Planetarium