Commit graph

19 commits

Author SHA1 Message Date
Tzu-Jung Lee
372cd7a72f commit: add locks 2018-08-14 19:46:51 -07:00
Tzu-Jung Lee
c53f755595 nmodemgr, ct: add Value to AddClaim() and UpdateClaim() 2018-08-14 19:45:54 -07:00
Tzu-Jung Lee
d06dc8d547 claim: return error for invalid ID string 2018-08-14 19:42:45 -07:00
Tzu-Jung Lee
38ec2ba48c docs: add quick start guide to example section 2018-08-08 12:22:08 -07:00
Tzu-Jung Lee
ee78f16ecc wip: truncate the change list iwhen dumpping. 2018-08-08 12:22:08 -07:00
Tzu-Jung Lee
f7a4ec80a5 fixup: add missing file 2018-08-07 19:39:58 -07:00
Tzu-Jung Lee
a7fe59dd49 wip: commits, nodes, and trie are all backed with storage. 2018-08-07 19:29:05 -07:00
Tzu-Jung Lee
4651558b98 wip: a few updates so far.
(the code is not cleaned up yet, especially DB related part)

1. Separate claim nodes from the Trie to NodeMgr (Node Manager).

   The Trie is mainly responsible for rsolving the MerkleHash.

   The Node Manager, which manages all the claim nodes implements
   KeyValue interface.

   	type KeyValue interface{
		Get(Key) error
		Set(Key, Value) error
	}

   When the Trie traverses to the Value node, it consults the KV
   with the prefix to get the value, which is the Hash of Best Claim.

2. Versioined/Snapshot based/Copy-on-Write Merkle Trie.

   Every resolved trie node is saved to the TrieDB (leveldb) with it's
   Hash as Key and content as Value.

   The content has the following format:

      Char (1B) Hash (32B) {0 to 256 entries }
      VHash (32B) (0 or 1 entry)

    The nodes are immutable and content(hash)-addressable. This gives
    the benefit of de-dup for free.

3. The NodeManager implements Replay, and can construct any past state.

   After experimentng on Memento vs Replay with the real dataset on the
   mainnet. I decided to go with Replay (at least for now) for a few reasons:

   a. Concurrency and usability.

      In the real world scenario, the ClaimTrie is always working on the
      Tip of the chain to accept Claim Script, update its own state and
      generate the Hash.

      On the other hand, most of the client requests are interested in
      the past state with minimal number of confirmations required.

      With Memento, the ClaimTrie has to either:

      	a. Pin down the node, and likely the ClaimTrie itself as well, as
	   it doesn't have the latest state (in terms of the whole Trie) to
	   resolve the Hash. Undo the changes and redo the changes after
	   serving the request.

	b. Copy the current state of the node and rollback that node to
	   serve the request in the background.

      With Replay, the ClaimTrie can simply spin a background task
      without any pause.

      The history of the nodes is immutable and read-only, so there is
      contention in reconstructing a node.

   b. Negligible performance difference.

      Most of the nodes only have few commands to playback.
      The time to playback is negligible, and will be dominated by the
      I/O if the node was flushed to the disk.

   c. Simplicity.

      Implementing undo saves more changes of states during
      the process, and has to pay much more attention to the bidding rules.
2018-08-05 15:12:35 -07:00
Tzu-Jung Lee
f4a5c5ee8d trie: change the Value.Hash() to return pointer.
When nil is returned by Hash(), the merkle generation will treat it as a
nil node, and ignore the hash along the way.
2018-07-16 23:20:11 -07:00
Tzu-Jung Lee
374a75fea6 misc changes 2018-07-16 08:25:52 -07:00
Tzu-Jung Lee
a5627ecfcc claimnode: Add the example on the whitepaper as a testcase.
Note: all the test cases will be reworked to a more compact form.
2018-07-11 12:40:13 -07:00
Tzu-Jung Lee
5e642e642f claimnode: Support to BestClaim becomes Active immediately. 2018-07-11 11:51:20 -07:00
Tzu-Jung Lee
212fd1983a trie: update merkle hash when stage is commited 2018-07-11 09:54:41 -07:00
Tzu-Jung Lee
d3419ea775 cleanup: refactor, bugfix, and comment. 2018-07-11 01:22:18 -07:00
Tzu-Jung Lee
8e1ae77aad cleanup: bring the merkletrie in as trie. 2018-07-09 10:48:33 -07:00
Tzu-Jung Lee
ed4478bc72 cleanup: reorg the code for dependencies.
Move self-contained pieces into their own package.
This spells out the depedencies and the context each
sub-package focuses on.

Not the final structure as it's WIP.
Just tying the knots while climbing up the rope.
2018-07-09 10:48:33 -07:00
Tzu-Jung Lee
fa2e276f3d fix Bidding logics, and port some tests cases from lbrycrd 2018-07-08 22:12:57 -07:00
Tzu-Jung Lee
84c64c1018 wip: misc updates
AddClaim / AddSupport is working with minimal testing done so far.
RemoveClaim / RemoveSupport is implemented, but not tested yet.

Some known issues:

Currently, we update the BestClaim for each node in a lazy fashion.
Each node could add/remove claims/supports without recalculating hash
until its being obeserved externally.

However, due to the "Takeover Delay" bidding rule, as the block number
increases, the bestClaim might changes implicitly. The Trie can't detect
this passively, and would need some mechanism for this.
2018-07-03 22:03:55 -07:00
Tzu-Jung Lee
8eae587539 initial import 2018-07-03 14:56:10 -07:00