Wire Sysio Wire Sysion 1.0.0
|
detail More...
#include <incremental_merkle.hpp>
Public Member Functions | |
incremental_merkle_impl () | |
incremental_merkle_impl (const incremental_merkle_impl &)=default | |
incremental_merkle_impl (incremental_merkle_impl &&)=default | |
incremental_merkle_impl & | operator= (const incremental_merkle_impl &)=default |
incremental_merkle_impl & | operator= (incremental_merkle_impl &&)=default |
template<typename Allocator , std::enable_if_t<!std::is_same< std::decay_t< Allocator >, incremental_merkle_impl >::value, int > = 0> | |
incremental_merkle_impl (Allocator &&alloc) | |
const DigestType & | append (const DigestType &digest) |
DigestType | get_root () const |
Public Attributes | |
uint64_t | _node_count |
Container< DigestType, Args... > | _active_nodes |
A balanced merkle tree built in such that the set of leaf nodes can be appended to without triggering the reconstruction of inner nodes that represent a complete subset of previous nodes.
to achieve this new nodes can either imply an set of future nodes that achieve a balanced tree OR realize one of these future nodes.
Once a sub-tree contains only realized nodes its sub-root will never change. This allows proofs based on this merkle to be very stable after some time has past only needing to update or add a single value to maintain validity.
Definition at line 95 of file incremental_merkle.hpp.
|
inline |
Definition at line 97 of file incremental_merkle.hpp.
|
default |
|
default |
|
inline |
Definition at line 107 of file incremental_merkle.hpp.
|
inline |
Add a node to the incremental tree and recalculate the _active_nodes so they are prepared for the next append.
The algorithm for this is to start at the new node and retreat through the tree for any node that is the concatenation of a fully-realized node and a partially realized node we must record the value of the fully-realized node in the new _active_nodes so that the next append can fetch it. Fully realized nodes and Fully implied nodes do not have an effect on the _active_nodes.
For convention AND to allow appends when the _node_count is a power-of-2, the current root of the incremental tree is always appended to the end of the new _active_nodes.
In practice, this can be done iteratively by recording any "left" value that is to be combined with an implied node.
If the appended node is a "left" node in its pair, it will immediately push itself into the new active nodes list.
If the new node is a "right" node it will begin collapsing upward in the tree, reading and discarding the "left" node data from the old active nodes list, until it becomes a "left" node. It must then push the "top" of its current collapsed sub-tree into the new active nodes list.
Once any value has been added to the new active nodes, all remaining "left" nodes should be present in the order they are needed in the previous active nodes as an artifact of the previous append. As they are read from the old active nodes, they will need to be copied in to the new active nodes list as they are still needed for future appends.
As a result, if an append collapses the entire tree while always being the "right" node, the new list of active nodes will be empty and by definition the tree contains a power-of-2 number of nodes.
Regardless of the contents of the new active nodes list, the top "collapsed" value is appended. If this tree is not a power-of-2 number of nodes, this node will not be used in the next append but still serves as a conventional place to access the root of the current tree. If this is a power-of-2 number of nodes, this node will be needed during then collapse phase of the next append so, it serves double duty as a legitimate active node and the conventional storage location of the root.
digest | - the node to add |
Definition at line 168 of file incremental_merkle.hpp.
|
inline |
l return the current root of the incremental merkle
Definition at line 233 of file incremental_merkle.hpp.
|
default |
|
default |
Container<DigestType, Args...> sysio::chain::incremental_merkle_impl< DigestType, Container, Args >::_active_nodes |
Definition at line 243 of file incremental_merkle.hpp.
uint64_t sysio::chain::incremental_merkle_impl< DigestType, Container, Args >::_node_count |
Definition at line 242 of file incremental_merkle.hpp.