mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-28 09:46:50 +00:00

* [NOD-1414] Add interfaces for Factory and State. * [NOD-1414] Create interfaces for algorithms and data stores. * [NOD-1414] Create empty implementations for algorithms and data stores. * [NOD-1414] Add new functions for all the implementations. * [NOD-1414] Begin filling in the interfaces. * [NOD-1414] Fill in the interfaces for the data structures. * [NOD-1414] Fill in the interfaces for the algorithms. * [NOD-1414] Fix a bug in package names. * [NOD-1414] Connect up the various interfaces. * [NOD-1414] Add stubs to all the implementations. * [NOD-1414] Create MiningManager and its Factory. * [NOD-1414] Add interfaces for mempool and blockTemplateBuilder. * [NOD-1414] Add implementation structs for miningManager. * [NOD-1414] Add stub implementations for mempool and blockTemplateBuilder. * [NOD-1414] Rename state to kaspadState. * [NOD-1414] Restructure where interfaces sit. * [NOD-1414] Restructure where interfaces sit in the algorithms package as well. * [NOD-1414] Move remaining models out of models.go. * [NOD-1414] Modified some interfaces. * [NOD-1414] Make go vet happy. * [NOD-1414] Move SerializedUTXOSet into PruningManager. * [NOD-1414] Modify FindNextPruningPoint to return found and nextPruningPointUTXOSet. * [NOD-1414] Add IsDAGAncestorOf. * [NOD-1414] Add PruningPoint(). * [NOD-1414] Add Entry() to ReadOnlyUTXOSet. * [NOD-1414] Add MergeSet() to BlockGHOSTDAGData. * [NOD-1414] Write comments for all the exported types and functions in miningmanager. * [NOD-1414] Add comments to the upper levels of KaspadState. * [NOD-1414] Replace AddNode with ReachabilityChangeset. * [NOD-1414] Add payAddress and extraData to GetBlockTemplate. * [NOD-1414] Add scriptPublicKey and extraData to BuildBlock. * [NOD-1414] Rename algorithms to processes. * [NOD-1414] Rename kaspadState to consensus. * [NOD-1414] Add ValidateAgainstPastUTXO and ValidateFinality. * [NOD-1414] Add BlockGHOSTDAGData to ReachabilityChangeset. * [NOD-1414] Fix the comment over Mempool. * [NOD-1414] Fix the comment over ValidateTransaction. * [NOD-1414] Fill up the data structures. * [NOD-1414] Add comments to remaining uncommented items in miningmanager. * [NOD-1414] Add comments to structs and constructors. * [NOD-1414] Rename Set to Insert. * [NOD-1414] Add comments to everything inside datastructures. * [NOD-1414] Add comments to everything inside models. * [NOD-1414] Add comments to the interfaces in processes. * [NOD-1414] Add comments to everything in processes. * [NOD-1414] Make go vet happy. * [NOD-1414] Rename scriptPublicKey to coinbaseScriptPublicKey. * [NOD-1414] Add handlers to the consensus. * [NOD-1414] Add highHash to blockAtDepth. * [NOD-1414] Add resolveFinalityConflict. * [NOD-1414] Reorg BlockValidator. * [NOD-1414] In ResolveFinalityConflicts, rename blockHash to newFinalityBlockHash. * [NOD-1414] Fix a comment. * [NOD-1414] Make reachability structs public. * [NOD-1414] Make UTXO structs public.
62 lines
2.5 KiB
Go
62 lines
2.5 KiB
Go
package model
|
|
|
|
// ReachabilityData holds the set of data required to answer
|
|
// reachability queries
|
|
type ReachabilityData struct {
|
|
TreeNode *ReachabilityTreeNode
|
|
FutureCoveringSet FutureCoveringTreeNodeSet
|
|
}
|
|
|
|
// ReachabilityTreeNode represents a node in the reachability tree
|
|
// of some DAG block. It mainly provides the ability to query *tree*
|
|
// reachability with O(1) query time. It does so by managing an
|
|
// index interval for each node and making sure all nodes in its
|
|
// subtree are indexed within the interval, so the query
|
|
// B ∈ subtree(A) simply becomes B.interval ⊂ A.interval.
|
|
//
|
|
// The main challenge of maintaining such intervals is that our tree
|
|
// is an ever-growing tree and as such pre-allocated intervals may
|
|
// not suffice as per future events. This is where the reindexing
|
|
// algorithm below comes into place.
|
|
// We use the reasonable assumption that the initial root interval
|
|
// (e.g., [0, 2^64-1]) should always suffice for any practical use-
|
|
// case, and so reindexing should always succeed unless more than
|
|
// 2^64 blocks are added to the DAG/tree.
|
|
type ReachabilityTreeNode struct {
|
|
Children []*ReachabilityTreeNode
|
|
Parent *ReachabilityTreeNode
|
|
|
|
// interval is the index interval containing all intervals of
|
|
// blocks in this node's subtree
|
|
Interval *ReachabilityInterval
|
|
}
|
|
|
|
// ReachabilityInterval represents an interval to be used within the
|
|
// tree reachability algorithm. See ReachabilityTreeNode for further
|
|
// details.
|
|
type ReachabilityInterval struct {
|
|
Start uint64
|
|
End uint64
|
|
}
|
|
|
|
// OrderedTreeNodeSet is an ordered set of reachabilityTreeNodes
|
|
// Note that this type does not validate order validity. It's the
|
|
// responsibility of the caller to construct instances of this
|
|
// type properly.
|
|
type OrderedTreeNodeSet []*ReachabilityTreeNode
|
|
|
|
// FutureCoveringTreeNodeSet represents a collection of blocks in the future of
|
|
// a certain block. Once a block B is added to the DAG, every block A_i in
|
|
// B's selected parent anticone must register B in its FutureCoveringTreeNodeSet. This allows
|
|
// to relatively quickly (O(log(|FutureCoveringTreeNodeSet|))) query whether B
|
|
// is a descendent (is in the "future") of any block that previously
|
|
// registered it.
|
|
//
|
|
// Note that FutureCoveringTreeNodeSet is meant to be queried only if B is not
|
|
// a reachability tree descendant of the block in question, as reachability
|
|
// tree queries are always O(1).
|
|
//
|
|
// See insertNode, hasAncestorOf, and reachabilityTree.isInPast for further
|
|
// details.
|
|
type FutureCoveringTreeNodeSet OrderedTreeNodeSet
|