-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggestion: use a merkle skip list to quickly calculate rolling consensus hashes and support quick querying #146
Comments
Given the consensus hash at 7 (call it ch[7]), the client wants to verify that a given operation is in block 5. Wouldn't the client need to do the following?
I don't see how the client can skip downloading ops[6], since the client's penultimate goal is to verify ch[5](so it can verify ops[5]). But in order to verify ch[5], the client needs to execute steps 3 and 4. Let me see if I can work through another example here. Let's say the client has ch[15] but wants to verify that an untrusted op is in ops[3]. To do so, the client would:
Does this look correct to you? |
@jcnelson It just hit me that we can just use the merkle root of the ops for a given block. That means that we only need to be served a bunch of hashes and the single set of ops for the block in question. |
This is implemented in my patchset, in virtualchain. The consensus hash is generated by taking the root of a Merkle tree constructed from the sorted list of previous consensus hashes concatenated with the root of another Merkle tree constructed from the tx-ordered serialized record hashes discovered in the underlying blockchain. Basically, the algorithm is:
Then, I only need to fetch actual operations when looking up the name's data. In all other cases, I only need to fetch the Merkle root over all of a block's operations. |
Added |
Hell yeah! Light nodes FTW! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The goal here is to calculate consensus hashes from all previous consensus hashes in O(log(T) + n) instead of O(T) where T is the number of blocks (and thus consensus hashes) since the beginning of time and n is the number of name operations in the current block.
Saving consensus hashes at all points in time is valuable so that one can easily validate all of the operations that were seen at time t. This is really nice for lightweight node support. Plus we've already established from previous discussions that saving all name operations at every point in time is valuable for verifying a database one gets from a peer for bootstrapping purposes.
Here's how we can calculate the consensus hashes...
I define a merkle skip list as a rolling merkle root calculation, where at time t the merkle tree is built from the data added at time t, plus a sublinear set of all previous merkle roots. Then the newly calculated merkle root is saved for future calculations.
As an example, if we define the first seen blockstore block as t=0, then the consensus hashes for t=0 to t=7 can be saved, and the hash at t=7 could be calculated by combining all of the name operations at time t=7 with the consensus hashes at times t=6, t=4, and t=0.
Here is a full table of all the merkle tree calculations at every step through t=7:
Note that the merkle root for any given block validates all merkle roots from the beginning of time, but only requires O(log(T) + n) calculations, as mentioned above. We can assume that T will grow into the hundreds of thousands while n will likely remain in the hundreds or thousands (given limits on block size).
Also note that if we have a trusted consensus hash for block 7 and ask an untrusted node for the proof that a given operation in block 5, we only need to be served the block ops from blocks 7 and 5. We don't need to see all previous block ops.
I'm not sure what to call this data structure but I'll call it a merkle skip list for now. Other thoughts on this are welcome.
The text was updated successfully, but these errors were encountered: