Class DelayedRenderer<T>
Decorates an IRenderer<T> instance and delays the events until blocks are confirmed the certain number of blocks. When blocks are recognized the delayed events relevant to these blocks are relayed to the decorated IRenderer<T>.
Implements
Namespace: Libplanet.Blockchain.Renderers
Assembly: Libplanet.dll
Syntax
public class DelayedRenderer<T> : object, IRenderer<T> where T : IAction, new()
Type Parameters
Name | Description |
---|---|
T | An IAction type. It should match to BlockChain<T>'s type parameter. |
Remarks
Since IActionRenderer<T> is a subtype of IRenderer<T>, DelayedRenderer(IRenderer<T>, IComparer<IBlockExcerpt>, IStore, HashAlgorithmGetter, Int32) constructor can take an IActionRenderer<T> instance as well. However, even it takes an action renderer, action-level fine-grained events won't hear. For action renderers, please use DelayedActionRenderer<T> instead.
Examples
IStore store = GetStore();
IBlockPolicy<ExampleAction> policy = GetPolicy();
IRenderer<ExampleAction> renderer = new SomeRenderer();
// Wraps the renderer with DelayedRenderer; the SomeRenderer instance becomes to receive
// event messages only after the relevent blocks are confirmed by 3+ blocks.
renderer = new DelayedRenderer<ExampleAction>(renderer, policy, store, confirmations: 3);
// You must pass the same policy & store to the BlockChain<T>() constructor:
var chain = new BlockChain<ExampleAction>(
...,
policy: policy,
store: store,
renderers: new[] { renderer });
Constructors
| Improve this Doc View SourceDelayedRenderer(IRenderer<T>, IComparer<IBlockExcerpt>, IStore, HashAlgorithmGetter, Int32)
Creates a new DelayedRenderer<T> instance decorating the given
renderer
.
Declaration
public DelayedRenderer(IRenderer<T> renderer, IComparer<IBlockExcerpt> canonicalChainComparer, IStore store, HashAlgorithmGetter hashAlgorithmGetter, int confirmations)
Parameters
Type | Name | Description |
---|---|---|
IRenderer<T> | renderer | The renderer to decorate which has the actual implementations and receives delayed events. |
IComparer<IBlockExcerpt> | canonicalChainComparer | The same canonical chain comparer to Policy. |
IStore | store | The same store to what BlockChain<T> uses. |
HashAlgorithmGetter | hashAlgorithmGetter | The function to determine hash algorithm used for proof-of-work mining. |
Int32 | confirmations | The required number of confirmations to recognize a block.
It must be greater than zero (note that zero |
Properties
| Improve this Doc View SourceCanonicalChainComparer
The same canonical chain comparer to Policy.
Declaration
public IComparer<IBlockExcerpt> CanonicalChainComparer { get; }
Property Value
Type | Description |
---|---|
IComparer<IBlockExcerpt> |
See Also
| Improve this Doc View SourceConfirmations
The required number of confirmations to recognize a block.
For example, the required confirmations are 2, the block #N is recognized after the block #N+1 and the block #N+2 are discovered.
Declaration
public int Confirmations { get; }
Property Value
Type | Description |
---|---|
Int32 |
Confirmed
Declaration
protected ConcurrentDictionary<BlockHash, uint> Confirmed { get; }
Property Value
Type | Description |
---|---|
ConcurrentDictionary<BlockHash, UInt32> |
HashAlgorithmGetter
The function to determine hash algorithm used for proof-of-work mining.
Declaration
public HashAlgorithmGetter HashAlgorithmGetter { get; }
Property Value
Type | Description |
---|---|
HashAlgorithmGetter |
Logger
The logger to record internal state changes.
Declaration
protected ILogger Logger { get; }
Property Value
Type | Description |
---|---|
ILogger |
Renderer
The inner renderer which has the actual implementations and receives delayed events.
Declaration
public IRenderer<T> Renderer { get; }
Property Value
Type | Description |
---|---|
IRenderer<T> |
Store
The same store to what BlockChain<T> uses.
Declaration
public IStore Store { get; }
Property Value
Type | Description |
---|---|
IStore |
Tip
The recognized topmost block. If not enough blocks are discovered yet,
this property can be null
.
Declaration
public Block<T> Tip { get; }
Property Value
Type | Description |
---|---|
Block<T> |
Methods
| Improve this Doc View SourceDiscoverBlock(Block<T>, Block<T>)
Declaration
protected void DiscoverBlock(Block<T> oldTip, Block<T> newTip)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | |
Block<T> | newTip |
OnTipChanged(Block<T>, Block<T>, Block<T>)
The callback method which is invoked when the new Tip is recognized and changed.
Declaration
protected virtual void OnTipChanged(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The previously recognized topmost block. |
Block<T> | newTip | The topmost block recognized this time. |
Block<T> | branchpoint | A branchpoint between |
RenderBlock(Block<T>, Block<T>)
Does things that should be done right after a new Block<T> is appended to a BlockChain<T> (so that its Tip has changed).
Declaration
public virtual void RenderBlock(Block<T> oldTip, Block<T> newTip)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The previous Tip. |
Block<T> | newTip | The current Tip. |
Remarks
It is guaranteed to be called only once for a block, and only after applied to the blockchain, unless it has been stale due to reorg (for that case, RenderReorg(Block<T>, Block<T>, Block<T>) is called in advance).
RenderReorg(Block<T>, Block<T>, Block<T>)
Does things that should be done right before reorg happens to a BlockChain<T>.
Declaration
public virtual void RenderReorg(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The Tip right before reorg. |
Block<T> | newTip | The Tip after reorg. |
Block<T> | branchpoint | The highest common Block<T> between
|
Remarks
For every call to this method, calls to
RenderBlock(Block<T>, Block<T>) and
RenderReorgEnd(Block<T>, Block<T>, Block<T>) methods with the same
newTip
is made too. Note that this method is guaranteed to be called
before RenderBlock(Block<T>, Block<T>) method for the same
newTip
.
RenderReorgEnd(Block<T>, Block<T>, Block<T>)
Does things that should be done right after reorg happens to a BlockChain<T>.
Declaration
public virtual void RenderReorgEnd(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The Tip right before reorg. |
Block<T> | newTip | The Tip after reorg. |
Block<T> | branchpoint | The highest common Block<T> between
|
Remarks
Note that this method is guaranteed to be called after
RenderReorg(Block<T>, Block<T>, Block<T>) and
RenderBlock(Block<T>, Block<T>) methods for the same
newTip
.