2018-07-09 09:56:15 -07:00
|
|
|
package claim
|
2018-06-27 22:14:30 -07:00
|
|
|
|
|
|
|
import (
|
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-02 22:15:08 -07:00
|
|
|
"bytes"
|
2018-06-27 22:14:30 -07:00
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2018-06-27 22:14:30 -07:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
|
|
)
|
|
|
|
|
2018-07-13 22:10:23 -07:00
|
|
|
type (
|
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-02 22:15:08 -07:00
|
|
|
// Amount defines the amount in LBC.
|
2018-07-13 22:10:23 -07:00
|
|
|
Amount int64
|
2018-07-09 09:56:15 -07:00
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
// Height defines the height of a block.
|
|
|
|
Height int32
|
2018-07-13 22:10:23 -07:00
|
|
|
)
|
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
// New returns a Claim (or Support) initialized with specified op and amt.
|
|
|
|
func New(op OutPoint, amt Amount) *Claim {
|
|
|
|
return &Claim{OutPoint: op, Amt: amt}
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
2018-06-27 22:14:30 -07:00
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
// Claim defines a structure of a Claim (or Support).
|
2018-07-05 13:17:40 -07:00
|
|
|
type Claim struct {
|
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-02 22:15:08 -07:00
|
|
|
OutPoint OutPoint
|
2018-07-09 09:56:15 -07:00
|
|
|
ID ID
|
|
|
|
Amt Amount
|
|
|
|
Accepted Height
|
2018-07-05 13:17:40 -07:00
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
// Dynamic values.
|
|
|
|
EffAmt Amount
|
2018-07-09 09:56:15 -07:00
|
|
|
ActiveAt Height
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
func (c *Claim) setOutPoint(op OutPoint) *Claim { c.OutPoint = op; return c }
|
|
|
|
func (c *Claim) setID(id ID) *Claim { c.ID = id; return c }
|
|
|
|
func (c *Claim) setAmt(amt Amount) *Claim { c.Amt = amt; return c }
|
2018-08-05 17:43:38 -07:00
|
|
|
func (c *Claim) setAccepted(ht Height) *Claim { c.Accepted = ht; return c }
|
|
|
|
func (c *Claim) setActiveAt(ht Height) *Claim { c.ActiveAt = ht; return c }
|
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-02 22:15:08 -07:00
|
|
|
func (c *Claim) String() string { return claimToString(c) }
|
2018-07-13 22:10:23 -07:00
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
func (c *Claim) expireAt() Height {
|
|
|
|
if c.Accepted >= paramExtendedClaimExpirationForkHeight {
|
|
|
|
return c.Accepted + paramExtendedClaimExpirationTime
|
|
|
|
}
|
|
|
|
return c.Accepted + paramOriginalClaimExpirationTime
|
2018-06-27 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
2018-08-05 17:43:38 -07:00
|
|
|
func isActiveAt(c *Claim, ht Height) bool {
|
|
|
|
return c != nil && c.ActiveAt <= ht && c.expireAt() > ht
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
func equal(a, b *Claim) bool {
|
|
|
|
if a != nil && b != nil {
|
|
|
|
return a.OutPoint == b.OutPoint
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
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-02 22:15:08 -07:00
|
|
|
return a == nil && b == nil
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
// OutPoint tracks previous transaction outputs.
|
|
|
|
type OutPoint struct {
|
|
|
|
wire.OutPoint
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
// NewOutPoint returns a new outpoint with the provided hash and index.
|
|
|
|
func NewOutPoint(hash *chainhash.Hash, index uint32) *OutPoint {
|
|
|
|
return &OutPoint{
|
|
|
|
*wire.NewOutPoint(hash, index),
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-02 22:15:08 -07:00
|
|
|
func outPointLess(a, b OutPoint) bool {
|
|
|
|
switch cmp := bytes.Compare(a.Hash[:], b.Hash[:]); {
|
|
|
|
case cmp > 0:
|
|
|
|
return true
|
|
|
|
case cmp < 0:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return a.Index < b.Index
|
2018-07-13 22:10:23 -07:00
|
|
|
}
|
2018-06-27 22:14:30 -07:00
|
|
|
}
|