[NOD-1413] Decouple the model package from everything (#949)

* [NOD-1416] Move processes/datastructures interfaces into the model package.

* [NOD-1416] Decouple the model from dbaccess.

* [NOD-1413] Implement DomainBlock and DomainTransaction.

* [NOD-1413] Decouple model from appmessage.

* [NOD-1413] Decouple model from util.

* [NOD-1413] Decouple model from subnetworkid.

* [NOD-1413] Remove an unused const.

* [NOD-1413] Add DomainHash and DomainTransactionID.

* [NOD-1413] Decouple model from daghash.

* [NOD-1413] Decouple model from mstime.

* [NOD-1413] Decouple model from go-secp256k1.

* [NOD-1413] Add a proxy over dbaccess.

* [NOD-1413] Add comments over all added types.

* [NOD-1413] Fix a comment.

* [NOD-1413] Get rid of DomainTime.

* [NOD-1413] Simplify BlockGHOSTDAGData.
This commit is contained in:
stasatdaglabs 2020-10-11 14:32:41 +03:00 committed by GitHub
parent 74d13e271e
commit e9951bc34a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 426 additions and 359 deletions

View File

@ -1,46 +1,43 @@
package consensus
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/processes"
"github.com/kaspanet/kaspad/util"
)
// Consensus maintains the current core state of the node
type Consensus interface {
BuildBlock(scriptPublicKey []byte, extraData []byte, transactionSelector model.TransactionSelector) *appmessage.MsgBlock
ValidateAndInsertBlock(block *appmessage.MsgBlock) error
UTXOByOutpoint(outpoint *appmessage.Outpoint) *model.UTXOEntry
ValidateTransaction(transaction *util.Tx, utxoEntries []*model.UTXOEntry) error
BuildBlock(scriptPublicKey []byte, extraData []byte, transactionSelector model.TransactionSelector) *model.DomainBlock
ValidateAndInsertBlock(block *model.DomainBlock) error
UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEntry
ValidateTransaction(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) error
}
type consensus struct {
blockProcessor processes.BlockProcessor
consensusStateManager processes.ConsensusStateManager
blockProcessor model.BlockProcessor
consensusStateManager model.ConsensusStateManager
}
// BuildBlock builds a block over the current state, with the transactions
// selected by the given transactionSelector
func (s *consensus) BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte,
transactionSelector model.TransactionSelector) *appmessage.MsgBlock {
transactionSelector model.TransactionSelector) *model.DomainBlock {
return s.blockProcessor.BuildBlock(coinbaseScriptPublicKey, coinbaseExtraData, transactionSelector)
}
// ValidateAndInsertBlock validates the given block and, if valid, applies it
// to the current state
func (s *consensus) ValidateAndInsertBlock(block *appmessage.MsgBlock) error {
func (s *consensus) ValidateAndInsertBlock(block *model.DomainBlock) error {
return s.blockProcessor.ValidateAndInsertBlock(block)
}
// UTXOByOutpoint returns a UTXOEntry matching the given outpoint
func (s *consensus) UTXOByOutpoint(outpoint *appmessage.Outpoint) *model.UTXOEntry {
func (s *consensus) UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEntry {
return s.consensusStateManager.UTXOByOutpoint(outpoint)
}
// ValidateTransaction validates the given transaction using
// the given utxoEntries
func (s *consensus) ValidateTransaction(transaction *util.Tx, utxoEntries []*model.UTXOEntry) error {
func (s *consensus) ValidateTransaction(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) error {
return s.consensusStateManager.ValidateTransaction(transaction, utxoEntries)
}

View File

@ -0,0 +1,22 @@
package database
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
)
// DomainDBContext is a proxy over a dbaccess.DatabaseContext
type DomainDBContext struct {
dbContext *dbaccess.DatabaseContext
}
// FetchBlockRelation retrieves the BlockRelation for the given blockHash
func (ddc *DomainDBContext) FetchBlockRelation(blockHash *model.DomainHash) (*model.BlockRelations, error) {
// TODO: return dbaccess.FetchBlockRelations(ddc.dbContext, blockHash)
return nil, nil
}
// NewDomainDBContext creates a new DomainDBContext
func NewDomainDBContext(dbContext *dbaccess.DatabaseContext) *DomainDBContext {
return &DomainDBContext{dbContext: dbContext}
}

View File

@ -0,0 +1,22 @@
package database
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
)
// DomainTxContext is a proxy over a dbaccess.TxContext
type DomainTxContext struct {
dbTx *dbaccess.TxContext
}
// StoreBlockRelation stores the given BlockRelation
func (dtc *DomainTxContext) StoreBlockRelation(blockHash *model.DomainHash, blockRelationData *model.BlockRelations) error {
// TODO: return dbaccess.StoreBlockRelation(ddc.dbTx, blockHash, blockRelationData)
return nil
}
// NewDomainTxContext creates a new DomainTXContext
func NewDomainTxContext(dbTx *dbaccess.TxContext) *DomainTxContext {
return &DomainTxContext{dbTx: dbTx}
}

View File

@ -2,8 +2,6 @@ package acceptancedatastore
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// AcceptanceDataStore represents a store of AcceptanceData
@ -16,11 +14,11 @@ func New() *AcceptanceDataStore {
}
// Insert inserts the given acceptanceData for the given blockHash
func (ads *AcceptanceDataStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, acceptanceData *model.BlockAcceptanceData) {
func (ads *AcceptanceDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, acceptanceData *model.BlockAcceptanceData) {
}
// Get gets the acceptanceData associated with the given blockHash
func (ads *AcceptanceDataStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.BlockAcceptanceData {
func (ads *AcceptanceDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.BlockAcceptanceData {
return nil
}

View File

@ -1,8 +1,7 @@
package blockindex
import (
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/domain/consensus/model"
)
// BlockIndex represents a store of known block hashes
@ -15,11 +14,11 @@ func New() *BlockIndex {
}
// Insert inserts the given blockHash
func (bi *BlockIndex) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash) {
func (bi *BlockIndex) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash) {
}
// Exists returns whether the given blockHash exists in the store
func (bi *BlockIndex) Exists(dbContext dbaccess.Context, blockHash *daghash.Hash) bool {
func (bi *BlockIndex) Exists(dbContext model.DBContextProxy, blockHash *model.DomainHash) bool {
return false
}

View File

@ -1,9 +1,7 @@
package blockmessagestore
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/domain/consensus/model"
)
// BlockMessageStore represents a store of MsgBlock
@ -16,11 +14,11 @@ func New() *BlockMessageStore {
}
// Insert inserts the given msgBlock for the given blockHash
func (bms *BlockMessageStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, msgBlock *appmessage.MsgBlock) {
func (bms *BlockMessageStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, msgBlock *model.DomainBlock) {
}
// Get gets the msgBlock associated with the given blockHash
func (bms *BlockMessageStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *appmessage.MsgBlock {
func (bms *BlockMessageStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.DomainBlock {
return nil
}

View File

@ -2,8 +2,6 @@ package blockrelationstore
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// BlockRelationStore represents a store of BlockRelations
@ -16,11 +14,11 @@ func New() *BlockRelationStore {
}
// Insert inserts the given blockRelationData for the given blockHash
func (brs *BlockRelationStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, blockRelationData *model.BlockRelations) {
func (brs *BlockRelationStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, blockRelationData *model.BlockRelations) {
}
// Get gets the blockRelationData associated with the given blockHash
func (brs *BlockRelationStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.BlockRelations {
func (brs *BlockRelationStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.BlockRelations {
return nil
}

View File

@ -2,8 +2,6 @@ package blockstatusstore
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// BlockStatusStore represents a store of BlockStatuses
@ -16,11 +14,11 @@ func New() *BlockStatusStore {
}
// Insert inserts the given blockStatus for the given blockHash
func (bss *BlockStatusStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, blockStatus model.BlockStatus) {
func (bss *BlockStatusStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, blockStatus model.BlockStatus) {
}
// Get gets the blockStatus associated with the given blockHash
func (bss *BlockStatusStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) model.BlockStatus {
func (bss *BlockStatusStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) model.BlockStatus {
return 0
}

View File

@ -1,9 +1,7 @@
package consensusstatestore
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
)
// ConsensusStateStore represents a store for the current consensus state
@ -16,11 +14,11 @@ func New() *ConsensusStateStore {
}
// Update updates the store with the given utxoDiff
func (css *ConsensusStateStore) Update(dbTx *dbaccess.TxContext, utxoDiff *model.UTXODiff) {
func (css *ConsensusStateStore) Update(dbTx model.DBTxProxy, utxoDiff *model.UTXODiff) {
}
// UTXOByOutpoint gets the utxoEntry associated with the given outpoint
func (css *ConsensusStateStore) UTXOByOutpoint(dbContext dbaccess.Context, outpoint *appmessage.Outpoint) *model.UTXOEntry {
func (css *ConsensusStateStore) UTXOByOutpoint(dbContext model.DBContextProxy, outpoint *model.DomainOutpoint) *model.UTXOEntry {
return nil
}

View File

@ -2,8 +2,6 @@ package ghostdagdatastore
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// GHOSTDAGDataStore represents a store of BlockGHOSTDAGData
@ -16,11 +14,11 @@ func New() *GHOSTDAGDataStore {
}
// Insert inserts the given blockGHOSTDAGData for the given blockHash
func (gds *GHOSTDAGDataStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, blockGHOSTDAGData *model.BlockGHOSTDAGData) {
func (gds *GHOSTDAGDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, blockGHOSTDAGData *model.BlockGHOSTDAGData) {
}
// Get gets the blockGHOSTDAGData associated with the given blockHash
func (gds *GHOSTDAGDataStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.BlockGHOSTDAGData {
func (gds *GHOSTDAGDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.BlockGHOSTDAGData {
return nil
}

View File

@ -1,75 +0,0 @@
package datastructures
import (
"github.com/kaspanet/go-secp256k1"
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// AcceptanceDataStore represents a store of AcceptanceData
type AcceptanceDataStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, acceptanceData *model.BlockAcceptanceData)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.BlockAcceptanceData
}
// BlockIndex represents a store of known block hashes
type BlockIndex interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash)
Exists(dbContext dbaccess.Context, blockHash *daghash.Hash) bool
}
// BlockMessageStore represents a store of MsgBlock
type BlockMessageStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, msgBlock *appmessage.MsgBlock)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *appmessage.MsgBlock
}
// BlockRelationStore represents a store of BlockRelations
type BlockRelationStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, blockRelationData *model.BlockRelations)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.BlockRelations
}
// BlockStatusStore represents a store of BlockStatuses
type BlockStatusStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, blockStatus model.BlockStatus)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) model.BlockStatus
}
// ConsensusStateStore represents a store for the current consensus state
type ConsensusStateStore interface {
Update(dbTx *dbaccess.TxContext, utxoDiff *model.UTXODiff)
UTXOByOutpoint(dbContext dbaccess.Context, outpoint *appmessage.Outpoint) *model.UTXOEntry
}
// GHOSTDAGDataStore represents a store of BlockGHOSTDAGData
type GHOSTDAGDataStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, blockGHOSTDAGData *model.BlockGHOSTDAGData)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.BlockGHOSTDAGData
}
// MultisetStore represents a store of Multisets
type MultisetStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, multiset *secp256k1.MultiSet)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *secp256k1.MultiSet
}
// PruningPointStore represents a store for the current pruning point
type PruningPointStore interface {
Update(dbTx *dbaccess.TxContext, blockHash *daghash.Hash)
Get(dbContext dbaccess.Context) *daghash.Hash
}
// ReachabilityDataStore represents a store of ReachabilityData
type ReachabilityDataStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, reachabilityData *model.ReachabilityData)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.ReachabilityData
}
// UTXODiffStore represents a store of UTXODiffs
type UTXODiffStore interface {
Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, utxoDiff *model.UTXODiff)
Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.UTXODiff
}

View File

@ -1,9 +1,7 @@
package multisetstore
import (
"github.com/kaspanet/go-secp256k1"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/domain/consensus/model"
)
// MultisetStore represents a store of Multisets
@ -16,11 +14,11 @@ func New() *MultisetStore {
}
// Insert inserts the given multiset for the given blockHash
func (ms *MultisetStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, multiset *secp256k1.MultiSet) {
func (ms *MultisetStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, multiset model.Multiset) {
}
// Get gets the multiset associated with the given blockHash
func (ms *MultisetStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *secp256k1.MultiSet {
func (ms *MultisetStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) model.Multiset {
return nil
}

View File

@ -1,8 +1,7 @@
package pruningpointstore
import (
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/domain/consensus/model"
)
// PruningPointStore represents a store for the current pruning point
@ -15,11 +14,11 @@ func New() *PruningPointStore {
}
// Update updates the pruning point to be the given blockHash
func (pps *PruningPointStore) Update(dbTx *dbaccess.TxContext, blockHash *daghash.Hash) {
func (pps *PruningPointStore) Update(dbTx model.DBTxProxy, blockHash *model.DomainHash) {
}
// Get gets the current pruning point
func (pps *PruningPointStore) Get(dbContext dbaccess.Context) *daghash.Hash {
func (pps *PruningPointStore) Get(dbContext model.DBContextProxy) *model.DomainHash {
return nil
}

View File

@ -2,8 +2,6 @@ package reachabilitydatastore
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// ReachabilityDataStore represents a store of ReachabilityData
@ -16,11 +14,11 @@ func New() *ReachabilityDataStore {
}
// Insert inserts the given reachabilityData for the given blockHash
func (rds *ReachabilityDataStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, reachabilityData *model.ReachabilityData) {
func (rds *ReachabilityDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, reachabilityData *model.ReachabilityData) {
}
// Get gets the reachabilityData associated with the given blockHash
func (rds *ReachabilityDataStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.ReachabilityData {
func (rds *ReachabilityDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.ReachabilityData {
return nil
}

View File

@ -2,8 +2,6 @@ package utxodiffstore
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// UTXODiffStore represents a store of UTXODiffs
@ -16,11 +14,11 @@ func New() *UTXODiffStore {
}
// Insert inserts the given utxoDiff for the given blockHash
func (uds *UTXODiffStore) Insert(dbTx *dbaccess.TxContext, blockHash *daghash.Hash, utxoDiff *model.UTXODiff) {
func (uds *UTXODiffStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, utxoDiff *model.UTXODiff) {
}
// Get gets the utxoDiff associated with the given blockHash
func (uds *UTXODiffStore) Get(dbContext dbaccess.Context, blockHash *daghash.Hash) *model.UTXODiff {
func (uds *UTXODiffStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.UTXODiff {
return nil
}

View File

@ -1,9 +1,5 @@
package model
import (
"github.com/kaspanet/kaspad/util"
)
// BlockAcceptanceData stores all transactions in a block with an indication
// if they were accepted or not by some other block
type BlockAcceptanceData struct {
@ -13,7 +9,7 @@ type BlockAcceptanceData struct {
// TransactionAcceptanceData stores a transaction together with an indication
// if it was accepted or not by some block
type TransactionAcceptanceData struct {
Tx *util.Tx
Tx *DomainTransaction
Fee uint64
IsAccepted bool
}

View File

@ -0,0 +1,21 @@
package model
// DomainBlock represents a Kaspa block
type DomainBlock struct {
Header *DomainBlockHeader
Transactions []*DomainTransaction
Hash *DomainHash
}
// DomainBlockHeader represents the header part of a Kaspa block
type DomainBlockHeader struct {
Version int32
ParentHashes []*DomainHash
HashMerkleRoot *DomainHash
AcceptedIDMerkleRoot *DomainHash
UTXOCommitment *DomainHash
TimeInMilliseconds int64
Bits uint32
Nonce uint64
}

View File

@ -1,36 +1,9 @@
package model
import "github.com/kaspanet/kaspad/util/daghash"
// BlockGHOSTDAGData represents GHOSTDAG data for some block
type BlockGHOSTDAGData struct {
blueScore uint64
selectedParent *daghash.Hash
mergeSetBlues []*daghash.Hash
mergeSetReds []*daghash.Hash
}
// MergeSetBlues returns the merge-set blues of this block
func (bgd *BlockGHOSTDAGData) MergeSetBlues() []*daghash.Hash {
return nil
}
// BlueScore returns the blue score of this block
func (bgd *BlockGHOSTDAGData) BlueScore() uint64 {
return 0
}
// MergeSetReds returns the merge-set reds of this block
func (bgd *BlockGHOSTDAGData) MergeSetReds() []*daghash.Hash {
return nil
}
// MergeSet returns the entire merge-set of this block
func (bgd *BlockGHOSTDAGData) MergeSet() []*daghash.Hash {
return nil
}
// SelectedParent returns this block's selected parent
func (bgd *BlockGHOSTDAGData) SelectedParent() *daghash.Hash {
return nil
BlueScore uint64
SelectedParent *DomainHash
MergeSetBlues []*DomainHash
MergeSetReds []*DomainHash
}

View File

@ -1,9 +1,7 @@
package model
import "github.com/kaspanet/kaspad/util/daghash"
// BlockRelations represents a block's parent/child relations
type BlockRelations struct {
Parents []*daghash.Hash
Children []*daghash.Hash
Parents []*DomainHash
Children []*DomainHash
}

View File

@ -0,0 +1,12 @@
package model
// DBContextProxy defines a proxy over domain data access
type DBContextProxy interface {
FetchBlockRelation(blockHash *DomainHash) (*BlockRelations, error)
}
// DBTxProxy is a proxy over domain data
// access that requires an open database transaction
type DBTxProxy interface {
StoreBlockRelation(blockHash *DomainHash, blockRelationData *BlockRelations) error
}

View File

@ -0,0 +1,4 @@
package model
// DomainHash is the domain representation of a daghash.Hash
type DomainHash [32]byte

View File

@ -0,0 +1,7 @@
package model
// AcceptanceDataStore represents a store of AcceptanceData
type AcceptanceDataStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, acceptanceData *BlockAcceptanceData)
Get(dbContext DBContextProxy, blockHash *DomainHash) *BlockAcceptanceData
}

View File

@ -0,0 +1,7 @@
package model
// BlockIndex represents a store of known block hashes
type BlockIndex interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash)
Exists(dbContext DBContextProxy, blockHash *DomainHash) bool
}

View File

@ -0,0 +1,7 @@
package model
// BlockMessageStore represents a store of MsgBlock
type BlockMessageStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, msgBlock *DomainBlock)
Get(dbContext DBContextProxy, blockHash *DomainHash) *DomainBlock
}

View File

@ -0,0 +1,7 @@
package model
// BlockRelationStore represents a store of BlockRelations
type BlockRelationStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, blockRelationData *BlockRelations)
Get(dbContext DBContextProxy, blockHash *DomainHash) *BlockRelations
}

View File

@ -0,0 +1,7 @@
package model
// BlockStatusStore represents a store of BlockStatuses
type BlockStatusStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, blockStatus BlockStatus)
Get(dbContext DBContextProxy, blockHash *DomainHash) BlockStatus
}

View File

@ -0,0 +1,7 @@
package model
// ConsensusStateStore represents a store for the current consensus state
type ConsensusStateStore interface {
Update(dbTx DBTxProxy, utxoDiff *UTXODiff)
UTXOByOutpoint(dbContext DBContextProxy, outpoint *DomainOutpoint) *UTXOEntry
}

View File

@ -0,0 +1,7 @@
package model
// GHOSTDAGDataStore represents a store of BlockGHOSTDAGData
type GHOSTDAGDataStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, blockGHOSTDAGData *BlockGHOSTDAGData)
Get(dbContext DBContextProxy, blockHash *DomainHash) *BlockGHOSTDAGData
}

View File

@ -0,0 +1,7 @@
package model
// MultisetStore represents a store of Multisets
type MultisetStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, multiset Multiset)
Get(dbContext DBContextProxy, blockHash *DomainHash) Multiset
}

View File

@ -0,0 +1,7 @@
package model
// PruningPointStore represents a store for the current pruning point
type PruningPointStore interface {
Update(dbTx DBTxProxy, blockHash *DomainHash)
Get(dbContext DBContextProxy) *DomainHash
}

View File

@ -0,0 +1,7 @@
package model
// ReachabilityDataStore represents a store of ReachabilityData
type ReachabilityDataStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, reachabilityData *ReachabilityData)
Get(dbContext DBContextProxy, blockHash *DomainHash) *ReachabilityData
}

View File

@ -0,0 +1,7 @@
package model
// UTXODiffStore represents a store of UTXODiffs
type UTXODiffStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, utxoDiff *UTXODiff)
Get(dbContext DBContextProxy, blockHash *DomainHash) *UTXODiff
}

View File

@ -0,0 +1,8 @@
package model
// BlockProcessor is responsible for processing incoming blocks
// and creating blocks from the current state
type BlockProcessor interface {
BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte, transactionSelector TransactionSelector) *DomainBlock
ValidateAndInsertBlock(block *DomainBlock) error
}

View File

@ -0,0 +1,12 @@
package model
// BlockValidator exposes a set of validation classes, after which
// it's possible to determine whether a block is valid
type BlockValidator interface {
ValidateHeaderInIsolation(block *DomainBlock) error
ValidateBodyInIsolation(block *DomainBlock) error
ValidateHeaderInContext(block *DomainBlock) error
ValidateBodyInContext(block *DomainBlock) error
ValidateAgainstPastUTXO(block *DomainBlock) error
ValidateFinality(block *DomainBlock) error
}

View File

@ -0,0 +1,8 @@
package model
// ConsensusStateManager manages the node's consensus state
type ConsensusStateManager interface {
UTXOByOutpoint(outpoint *DomainOutpoint) *UTXOEntry
ValidateTransaction(transaction *DomainTransaction, utxoEntries []*UTXOEntry) error
CalculateConsensusStateChanges(block *DomainBlock) *ConsensusStateChanges
}

View File

@ -0,0 +1,12 @@
package model
// DAGTopologyManager exposes methods for querying relationships
// between blocks in the DAG
type DAGTopologyManager interface {
Parents(blockHash *DomainHash) []*DomainHash
Children(blockHash *DomainHash) []*DomainHash
IsParentOf(blockHashA *DomainHash, blockHashB *DomainHash) bool
IsChildOf(blockHashA *DomainHash, blockHashB *DomainHash) bool
IsAncestorOf(blockHashA *DomainHash, blockHashB *DomainHash) bool
IsDescendantOf(blockHashA *DomainHash, blockHashB *DomainHash) bool
}

View File

@ -0,0 +1,8 @@
package model
// DAGTraversalManager exposes methods for travering blocks
// in the DAG
type DAGTraversalManager interface {
BlockAtDepth(highHash *DomainHash, depth uint64) *DomainHash
SelectedParentIterator(highHash *DomainHash) SelectedParentIterator
}

View File

@ -0,0 +1,7 @@
package model
// GHOSTDAGManager resolves and manages GHOSTDAG block data
type GHOSTDAGManager interface {
GHOSTDAG(blockParents []*DomainHash) *BlockGHOSTDAGData
BlockData(blockHash *DomainHash) *BlockGHOSTDAGData
}

View File

@ -0,0 +1,8 @@
package model
// PruningManager resolves and manages the current pruning point
type PruningManager interface {
FindNextPruningPoint(blockHash *DomainHash) (found bool, newPruningPoint *DomainHash, newPruningPointUTXOSet ReadOnlyUTXOSet)
PruningPoint() *DomainHash
SerializedUTXOSet() []byte
}

View File

@ -0,0 +1,9 @@
package model
// ReachabilityTree maintains a structure that allows to answer
// reachability queries in sub-linear time
type ReachabilityTree interface {
IsReachabilityTreeAncestorOf(blockHashA *DomainHash, blockHashB *DomainHash) bool
IsDAGAncestorOf(blockHashA *DomainHash, blockHashB *DomainHash) bool
ReachabilityChangeset(blockHash *DomainHash, blockGHOSTDAGData *BlockGHOSTDAGData) *ReachabilityChangeset
}

View File

@ -0,0 +1,7 @@
package model
// Multiset represents a secp256k1 multiset
type Multiset interface {
Add(data []byte)
Remove(data []byte)
}

View File

@ -1,10 +1,8 @@
package model
import "github.com/kaspanet/kaspad/util/daghash"
// ReachabilityChangeset holds the set of changes to make to a
// reachability tree to insert a new reachability node
type ReachabilityChangeset struct {
TreeNodeChanges map[*daghash.Hash]*ReachabilityTreeNode
FutureCoveringSetChanges map[*daghash.Hash]FutureCoveringTreeNodeSet
TreeNodeChanges map[*DomainHash]*ReachabilityTreeNode
FutureCoveringSetChanges map[*DomainHash]FutureCoveringTreeNodeSet
}

View File

@ -1,16 +1,14 @@
package model
import "github.com/kaspanet/kaspad/app/appmessage"
// ReadOnlyUTXOSet represents a UTXOSet that can only be read from
type ReadOnlyUTXOSet interface {
Iterator() ReadOnlyUTXOSetIterator
Entry(outpoint *appmessage.Outpoint) *UTXOEntry
Entry(outpoint *DomainOutpoint) *UTXOEntry
}
// ReadOnlyUTXOSetIterator is an iterator over all entries in a
// ReadOnlyUTXOSet
type ReadOnlyUTXOSetIterator interface {
Next() bool
Get() (outpoint *appmessage.Outpoint, utxoEntry *UTXOEntry)
Get() (outpoint *DomainOutpoint, utxoEntry *UTXOEntry)
}

View File

@ -1,10 +1,8 @@
package model
import "github.com/kaspanet/kaspad/util/daghash"
// SelectedParentIterator is an iterator over the selected parent
// chain of some block
type SelectedParentIterator interface {
Next() bool
Get() *daghash.Hash
Get() *DomainHash
}

View File

@ -0,0 +1,15 @@
package model
// DomainSubnetworkID is the domain representation of a Subnetwork ID
type DomainSubnetworkID [20]byte
var (
// SubnetworkIDNative is the default subnetwork ID which is used for transactions without related payload data
SubnetworkIDNative = &DomainSubnetworkID{}
// SubnetworkIDCoinbase is the subnetwork ID which is used for the coinbase transaction
SubnetworkIDCoinbase = &DomainSubnetworkID{1}
// SubnetworkIDRegistry is the subnetwork ID which is used for adding new sub networks to the registry
SubnetworkIDRegistry = &DomainSubnetworkID{2}
)

View File

@ -0,0 +1,39 @@
package model
// DomainTransaction represents a Kaspa transaction
type DomainTransaction struct {
Version int32
Inputs []*DomainTransactionInput
Outputs []*DomainTransactionOutput
LockTime uint64
SubnetworkID *DomainSubnetworkID
Gas uint64
PayloadHash *DomainHash
Payload []byte
Hash *DomainHash
ID *DomainTransactionID
Index int
}
// DomainTransactionInput represents a Kaspa transaction input
type DomainTransactionInput struct {
PreviousOutpoint *DomainOutpoint
SignatureScript []byte
Sequence uint64
}
// DomainOutpoint represents a Kaspa transaction outpoint
type DomainOutpoint struct {
ID *DomainTransactionID
Index uint32
}
// DomainTransactionOutput represents a Kaspad transaction output
type DomainTransactionOutput struct {
Value uint64
ScriptPublicKey []byte
}
// DomainTransactionID represents the ID of a Kaspa transaction
type DomainTransactionID DomainHash

View File

@ -1,7 +1,5 @@
package model
import "github.com/kaspanet/kaspad/util"
// TransactionSelector is a function for selecting transaction from
// some ReadOnlyUTXOSet
type TransactionSelector func(readOnlyUTXOSet ReadOnlyUTXOSet) []*util.Tx
type TransactionSelector func(readOnlyUTXOSet ReadOnlyUTXOSet) []*DomainTransaction

View File

@ -1,7 +1,5 @@
package model
import "github.com/kaspanet/kaspad/app/appmessage"
// UTXODiff represents a diff between two UTXO Sets.
type UTXODiff struct {
ToAdd UTXOCollection
@ -9,4 +7,4 @@ type UTXODiff struct {
}
// UTXOCollection represents a set of UTXOs indexed by their outpoints
type UTXOCollection map[appmessage.Outpoint]*UTXOEntry
type UTXOCollection map[DomainOutpoint]*UTXOEntry

View File

@ -1,10 +1,7 @@
package blockprocessor
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/datastructures"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/processes"
"github.com/kaspanet/kaspad/domain/dagconfig"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
)
@ -15,30 +12,30 @@ type BlockProcessor struct {
dagParams *dagconfig.Params
databaseContext *dbaccess.DatabaseContext
consensusStateManager processes.ConsensusStateManager
pruningManager processes.PruningManager
blockValidator processes.BlockValidator
dagTopologyManager processes.DAGTopologyManager
reachabilityTree processes.ReachabilityTree
acceptanceDataStore datastructures.AcceptanceDataStore
blockIndex datastructures.BlockIndex
blockMessageStore datastructures.BlockMessageStore
blockStatusStore datastructures.BlockStatusStore
consensusStateManager model.ConsensusStateManager
pruningManager model.PruningManager
blockValidator model.BlockValidator
dagTopologyManager model.DAGTopologyManager
reachabilityTree model.ReachabilityTree
acceptanceDataStore model.AcceptanceDataStore
blockIndex model.BlockIndex
blockMessageStore model.BlockMessageStore
blockStatusStore model.BlockStatusStore
}
// New instantiates a new BlockProcessor
func New(
dagParams *dagconfig.Params,
databaseContext *dbaccess.DatabaseContext,
consensusStateManager processes.ConsensusStateManager,
pruningManager processes.PruningManager,
blockValidator processes.BlockValidator,
dagTopologyManager processes.DAGTopologyManager,
reachabilityTree processes.ReachabilityTree,
acceptanceDataStore datastructures.AcceptanceDataStore,
blockIndex datastructures.BlockIndex,
blockMessageStore datastructures.BlockMessageStore,
blockStatusStore datastructures.BlockStatusStore) *BlockProcessor {
consensusStateManager model.ConsensusStateManager,
pruningManager model.PruningManager,
blockValidator model.BlockValidator,
dagTopologyManager model.DAGTopologyManager,
reachabilityTree model.ReachabilityTree,
acceptanceDataStore model.AcceptanceDataStore,
blockIndex model.BlockIndex,
blockMessageStore model.BlockMessageStore,
blockStatusStore model.BlockStatusStore) *BlockProcessor {
return &BlockProcessor{
dagParams: dagParams,
@ -59,13 +56,13 @@ func New(
// BuildBlock builds a block over the current state, with the transactions
// selected by the given transactionSelector
func (bp *BlockProcessor) BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte,
transactionSelector model.TransactionSelector) *appmessage.MsgBlock {
transactionSelector model.TransactionSelector) *model.DomainBlock {
return nil
}
// ValidateAndInsertBlock validates the given block and, if valid, applies it
// to the current state
func (bp *BlockProcessor) ValidateAndInsertBlock(block *appmessage.MsgBlock) error {
func (bp *BlockProcessor) ValidateAndInsertBlock(block *model.DomainBlock) error {
return nil
}

View File

@ -1,6 +1,8 @@
package blockvalidator
import "github.com/kaspanet/kaspad/app/appmessage"
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
)
// BlockValidator exposes a set of validation classes, after which
// it's possible to determine whether a block is valid
@ -14,34 +16,34 @@ func New() *BlockValidator {
// ValidateHeaderInIsolation validates block headers in isolation from the current
// consensus state
func (bv *BlockValidator) ValidateHeaderInIsolation(block *appmessage.MsgBlock) error {
func (bv *BlockValidator) ValidateHeaderInIsolation(block *model.DomainBlock) error {
return nil
}
// ValidateHeaderInContext validates block headers in the context of the current
// consensus state
func (bv *BlockValidator) ValidateHeaderInContext(block *appmessage.MsgBlock) error {
func (bv *BlockValidator) ValidateHeaderInContext(block *model.DomainBlock) error {
return nil
}
// ValidateBodyInIsolation validates block bodies in isolation from the current
// consensus state
func (bv *BlockValidator) ValidateBodyInIsolation(block *appmessage.MsgBlock) error {
func (bv *BlockValidator) ValidateBodyInIsolation(block *model.DomainBlock) error {
return nil
}
// ValidateBodyInContext validates block bodies in the context of the current
// consensus state
func (bv *BlockValidator) ValidateBodyInContext(block *appmessage.MsgBlock) error {
func (bv *BlockValidator) ValidateBodyInContext(block *model.DomainBlock) error {
return nil
}
// ValidateAgainstPastUTXO validates the block against the UTXO of its past
func (bv *BlockValidator) ValidateAgainstPastUTXO(block *appmessage.MsgBlock) error {
func (bv *BlockValidator) ValidateAgainstPastUTXO(block *model.DomainBlock) error {
return nil
}
// ValidateFinality makes sure the block does not violate finality
func (bv *BlockValidator) ValidateFinality(block *appmessage.MsgBlock) error {
func (bv *BlockValidator) ValidateFinality(block *model.DomainBlock) error {
return nil
}

View File

@ -1,28 +1,25 @@
package consensusstatemanager
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/datastructures"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/dagconfig"
"github.com/kaspanet/kaspad/util"
)
// ConsensusStateManager manages the node's consensus state
type ConsensusStateManager struct {
dagParams *dagconfig.Params
consensusStateStore datastructures.ConsensusStateStore
multisetStore datastructures.MultisetStore
utxoDiffStore datastructures.UTXODiffStore
consensusStateStore model.ConsensusStateStore
multisetStore model.MultisetStore
utxoDiffStore model.UTXODiffStore
}
// New instantiates a new ConsensusStateManager
func New(
dagParams *dagconfig.Params,
consensusStateStore datastructures.ConsensusStateStore,
multisetStore datastructures.MultisetStore,
utxoDiffStore datastructures.UTXODiffStore) *ConsensusStateManager {
consensusStateStore model.ConsensusStateStore,
multisetStore model.MultisetStore,
utxoDiffStore model.UTXODiffStore) *ConsensusStateManager {
return &ConsensusStateManager{
dagParams: dagParams,
@ -33,18 +30,18 @@ func New(
}
// UTXOByOutpoint returns a UTXOEntry matching the given outpoint
func (csm *ConsensusStateManager) UTXOByOutpoint(outpoint *appmessage.Outpoint) *model.UTXOEntry {
func (csm *ConsensusStateManager) UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEntry {
return nil
}
// ValidateTransaction validates the given transaction using
// the given utxoEntries
func (csm *ConsensusStateManager) ValidateTransaction(transaction *util.Tx, utxoEntries []*model.UTXOEntry) error {
func (csm *ConsensusStateManager) ValidateTransaction(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) error {
return nil
}
// CalculateConsensusStateChanges returns a set of changes that must occur in order
// to transition the current consensus state into the one including the given block
func (csm *ConsensusStateManager) CalculateConsensusStateChanges(block *appmessage.MsgBlock) *model.ConsensusStateChanges {
func (csm *ConsensusStateManager) CalculateConsensusStateChanges(block *model.DomainBlock) *model.ConsensusStateChanges {
return nil
}

View File

@ -1,25 +1,24 @@
package dagtopologymanager
import (
"github.com/kaspanet/kaspad/domain/consensus/datastructures"
"github.com/kaspanet/kaspad/domain/consensus/processes"
"github.com/kaspanet/kaspad/domain/consensus/database"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
"github.com/kaspanet/kaspad/util/daghash"
)
// DAGTopologyManager exposes methods for querying relationships
// between blocks in the DAG
type DAGTopologyManager struct {
reachabilityTree processes.ReachabilityTree
blockRelationStore datastructures.BlockRelationStore
reachabilityTree model.ReachabilityTree
blockRelationStore model.BlockRelationStore
databaseContext *dbaccess.DatabaseContext
}
// New instantiates a new DAGTopologyManager
func New(
databaseContext *dbaccess.DatabaseContext,
reachabilityTree processes.ReachabilityTree,
blockRelationStore datastructures.BlockRelationStore) *DAGTopologyManager {
reachabilityTree model.ReachabilityTree,
blockRelationStore model.BlockRelationStore) *DAGTopologyManager {
return &DAGTopologyManager{
databaseContext: databaseContext,
reachabilityTree: reachabilityTree,
@ -28,36 +27,40 @@ func New(
}
// Parents returns the DAG parents of the given blockHash
func (dtm *DAGTopologyManager) Parents(blockHash *daghash.Hash) []*daghash.Hash {
return dtm.blockRelationStore.Get(dtm.databaseContext, blockHash).Parents
func (dtm *DAGTopologyManager) Parents(blockHash *model.DomainHash) []*model.DomainHash {
dbContext := database.NewDomainDBContext(dtm.databaseContext)
return dtm.blockRelationStore.Get(dbContext, blockHash).Parents
}
// Children returns the DAG children of the given blockHash
func (dtm *DAGTopologyManager) Children(blockHash *daghash.Hash) []*daghash.Hash {
return dtm.blockRelationStore.Get(dtm.databaseContext, blockHash).Children
func (dtm *DAGTopologyManager) Children(blockHash *model.DomainHash) []*model.DomainHash {
dbContext := database.NewDomainDBContext(dtm.databaseContext)
return dtm.blockRelationStore.Get(dbContext, blockHash).Children
}
// IsParentOf returns true if blockHashA is a direct DAG parent of blockHashB
func (dtm *DAGTopologyManager) IsParentOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool {
return isHashInSlice(blockHashA, dtm.blockRelationStore.Get(dtm.databaseContext, blockHashB).Parents)
func (dtm *DAGTopologyManager) IsParentOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) bool {
dbContext := database.NewDomainDBContext(dtm.databaseContext)
return isHashInSlice(blockHashA, dtm.blockRelationStore.Get(dbContext, blockHashB).Parents)
}
// IsChildOf returns true if blockHashA is a direct DAG child of blockHashB
func (dtm *DAGTopologyManager) IsChildOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool {
return isHashInSlice(blockHashA, dtm.blockRelationStore.Get(dtm.databaseContext, blockHashB).Children)
func (dtm *DAGTopologyManager) IsChildOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) bool {
dbContext := database.NewDomainDBContext(dtm.databaseContext)
return isHashInSlice(blockHashA, dtm.blockRelationStore.Get(dbContext, blockHashB).Children)
}
// IsAncestorOf returns true if blockHashA is a DAG ancestor of blockHashB
func (dtm *DAGTopologyManager) IsAncestorOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool {
func (dtm *DAGTopologyManager) IsAncestorOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) bool {
return dtm.reachabilityTree.IsDAGAncestorOf(blockHashA, blockHashB)
}
// IsDescendantOf returns true if blockHashA is a DAG descendant of blockHashB
func (dtm *DAGTopologyManager) IsDescendantOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool {
func (dtm *DAGTopologyManager) IsDescendantOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) bool {
return dtm.reachabilityTree.IsDAGAncestorOf(blockHashB, blockHashA)
}
func isHashInSlice(hash *daghash.Hash, hashes []*daghash.Hash) bool {
func isHashInSlice(hash *model.DomainHash, hashes []*model.DomainHash) bool {
for _, h := range hashes {
if *h == *hash {
return true

View File

@ -2,21 +2,19 @@ package dagtraversalmanager
import (
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/processes"
"github.com/kaspanet/kaspad/util/daghash"
)
// DAGTraversalManager exposes methods for travering blocks
// in the DAG
type DAGTraversalManager struct {
dagTopologyManager processes.DAGTopologyManager
ghostdagManager processes.GHOSTDAGManager
dagTopologyManager model.DAGTopologyManager
ghostdagManager model.GHOSTDAGManager
}
// New instantiates a new DAGTraversalManager
func New(
dagTopologyManager processes.DAGTopologyManager,
ghostdagManager processes.GHOSTDAGManager) *DAGTraversalManager {
dagTopologyManager model.DAGTopologyManager,
ghostdagManager model.GHOSTDAGManager) *DAGTraversalManager {
return &DAGTraversalManager{
dagTopologyManager: dagTopologyManager,
ghostdagManager: ghostdagManager,
@ -25,12 +23,12 @@ func New(
// BlockAtDepth returns the hash of the block that's at the
// given depth from the given highHash
func (dtm *DAGTraversalManager) BlockAtDepth(highHash *daghash.Hash, depth uint64) *daghash.Hash {
func (dtm *DAGTraversalManager) BlockAtDepth(highHash *model.DomainHash, depth uint64) *model.DomainHash {
return nil
}
// SelectedParentIterator creates an iterator over the selected
// parent chain of the given highHash
func (dtm *DAGTraversalManager) SelectedParentIterator(highHash *daghash.Hash) model.SelectedParentIterator {
func (dtm *DAGTraversalManager) SelectedParentIterator(highHash *model.DomainHash) model.SelectedParentIterator {
return nil
}

View File

@ -1,22 +1,19 @@
package ghostdagmanager
import (
"github.com/kaspanet/kaspad/domain/consensus/datastructures"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/processes"
"github.com/kaspanet/kaspad/util/daghash"
)
// GHOSTDAGManager resolves and manages GHOSTDAG block data
type GHOSTDAGManager struct {
dagTopologyManager processes.DAGTopologyManager
ghostdagDataStore datastructures.GHOSTDAGDataStore
dagTopologyManager model.DAGTopologyManager
ghostdagDataStore model.GHOSTDAGDataStore
}
// New instantiates a new GHOSTDAGManager
func New(
dagTopologyManager processes.DAGTopologyManager,
ghostdagDataStore datastructures.GHOSTDAGDataStore) *GHOSTDAGManager {
dagTopologyManager model.DAGTopologyManager,
ghostdagDataStore model.GHOSTDAGDataStore) *GHOSTDAGManager {
return &GHOSTDAGManager{
dagTopologyManager: dagTopologyManager,
ghostdagDataStore: ghostdagDataStore,
@ -25,12 +22,12 @@ func New(
// GHOSTDAG calculates GHOSTDAG data for the block represented
// by the given blockParents
func (gm *GHOSTDAGManager) GHOSTDAG(blockParents []*daghash.Hash) *model.BlockGHOSTDAGData {
func (gm *GHOSTDAGManager) GHOSTDAG(blockParents []*model.DomainHash) *model.BlockGHOSTDAGData {
return nil
}
// BlockData returns previously calculated GHOSTDAG data for
// the given blockHash
func (gm *GHOSTDAGManager) BlockData(blockHash *daghash.Hash) *model.BlockGHOSTDAGData {
func (gm *GHOSTDAGManager) BlockData(blockHash *model.DomainHash) *model.BlockGHOSTDAGData {
return nil
}

View File

@ -1,72 +0,0 @@
package processes
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/util"
"github.com/kaspanet/kaspad/util/daghash"
)
// BlockProcessor is responsible for processing incoming blocks
// and creating blocks from the current state
type BlockProcessor interface {
BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte, transactionSelector model.TransactionSelector) *appmessage.MsgBlock
ValidateAndInsertBlock(block *appmessage.MsgBlock) error
}
// BlockValidator exposes a set of validation classes, after which
// it's possible to determine whether a block is valid
type BlockValidator interface {
ValidateHeaderInIsolation(block *appmessage.MsgBlock) error
ValidateBodyInIsolation(block *appmessage.MsgBlock) error
ValidateHeaderInContext(block *appmessage.MsgBlock) error
ValidateBodyInContext(block *appmessage.MsgBlock) error
ValidateAgainstPastUTXO(block *appmessage.MsgBlock) error
ValidateFinality(block *appmessage.MsgBlock) error
}
// ConsensusStateManager manages the node's consensus state
type ConsensusStateManager interface {
UTXOByOutpoint(outpoint *appmessage.Outpoint) *model.UTXOEntry
ValidateTransaction(transaction *util.Tx, utxoEntries []*model.UTXOEntry) error
CalculateConsensusStateChanges(block *appmessage.MsgBlock) *model.ConsensusStateChanges
}
// DAGTopologyManager exposes methods for querying relationships
// between blocks in the DAG
type DAGTopologyManager interface {
Parents(blockHash *daghash.Hash) []*daghash.Hash
Children(blockHash *daghash.Hash) []*daghash.Hash
IsParentOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool
IsChildOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool
IsAncestorOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool
IsDescendantOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool
}
// DAGTraversalManager exposes methods for travering blocks
// in the DAG
type DAGTraversalManager interface {
BlockAtDepth(highHash *daghash.Hash, depth uint64) *daghash.Hash
SelectedParentIterator(highHash *daghash.Hash) model.SelectedParentIterator
}
// GHOSTDAGManager resolves and manages GHOSTDAG block data
type GHOSTDAGManager interface {
GHOSTDAG(blockParents []*daghash.Hash) *model.BlockGHOSTDAGData
BlockData(blockHash *daghash.Hash) *model.BlockGHOSTDAGData
}
// PruningManager resolves and manages the current pruning point
type PruningManager interface {
FindNextPruningPoint(blockHash *daghash.Hash) (found bool, newPruningPoint *daghash.Hash, newPruningPointUTXOSet model.ReadOnlyUTXOSet)
PruningPoint() *daghash.Hash
SerializedUTXOSet() []byte
}
// ReachabilityTree maintains a structure that allows to answer
// reachability queries in sub-linear time
type ReachabilityTree interface {
IsReachabilityTreeAncestorOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool
IsDAGAncestorOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool
ReachabilityChangeset(blockHash *daghash.Hash, blockGHOSTDAGData *model.BlockGHOSTDAGData) *model.ReachabilityChangeset
}

View File

@ -1,22 +1,19 @@
package pruningmanager
import (
"github.com/kaspanet/kaspad/domain/consensus/datastructures"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/processes"
"github.com/kaspanet/kaspad/util/daghash"
)
// PruningManager resolves and manages the current pruning point
type PruningManager struct {
dagTraversalManager processes.DAGTraversalManager
pruningPointStore datastructures.PruningPointStore
dagTraversalManager model.DAGTraversalManager
pruningPointStore model.PruningPointStore
}
// New instantiates a new PruningManager
func New(
dagTraversalManager processes.DAGTraversalManager,
pruningPointStore datastructures.PruningPointStore) *PruningManager {
dagTraversalManager model.DAGTraversalManager,
pruningPointStore model.PruningPointStore) *PruningManager {
return &PruningManager{
dagTraversalManager: dagTraversalManager,
pruningPointStore: pruningPointStore,
@ -25,14 +22,14 @@ func New(
// FindNextPruningPoint finds the next pruning point from the
// given blockHash. If none found, returns false
func (pm *PruningManager) FindNextPruningPoint(blockHash *daghash.Hash) (found bool,
newPruningPoint *daghash.Hash, newPruningPointUTXOSet model.ReadOnlyUTXOSet) {
func (pm *PruningManager) FindNextPruningPoint(blockHash *model.DomainHash) (found bool,
newPruningPoint *model.DomainHash, newPruningPointUTXOSet model.ReadOnlyUTXOSet) {
return false, nil, nil
}
// PruningPoint returns the hash of the current pruning point
func (pm *PruningManager) PruningPoint() *daghash.Hash {
func (pm *PruningManager) PruningPoint() *model.DomainHash {
return nil
}

View File

@ -1,22 +1,20 @@
package reachabilitytree
import (
"github.com/kaspanet/kaspad/domain/consensus/datastructures"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/util/daghash"
)
// ReachabilityTree maintains a structure that allows to answer
// reachability queries in sub-linear time
type ReachabilityTree struct {
blockRelationStore datastructures.BlockRelationStore
reachabilityDataStore datastructures.ReachabilityDataStore
blockRelationStore model.BlockRelationStore
reachabilityDataStore model.ReachabilityDataStore
}
// New instantiates a new ReachabilityTree
func New(
blockRelationStore datastructures.BlockRelationStore,
reachabilityDataStore datastructures.ReachabilityDataStore) *ReachabilityTree {
blockRelationStore model.BlockRelationStore,
reachabilityDataStore model.ReachabilityDataStore) *ReachabilityTree {
return &ReachabilityTree{
blockRelationStore: blockRelationStore,
reachabilityDataStore: reachabilityDataStore,
@ -26,19 +24,19 @@ func New(
// IsReachabilityTreeAncestorOf returns true if blockHashA is an
// ancestor of blockHashB in the reachability tree. Note that this
// does not necessarily mean that it isn't its ancestor in the DAG.
func (rt *ReachabilityTree) IsReachabilityTreeAncestorOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool {
func (rt *ReachabilityTree) IsReachabilityTreeAncestorOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) bool {
return false
}
// IsDAGAncestorOf returns true if blockHashA is an ancestor of
// blockHashB in the DAG.
func (rt *ReachabilityTree) IsDAGAncestorOf(blockHashA *daghash.Hash, blockHashB *daghash.Hash) bool {
func (rt *ReachabilityTree) IsDAGAncestorOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) bool {
return false
}
// ReachabilityChangeset returns a set of changes that need to occur
// in order to add the given blockHash into the reachability tree.
func (rt *ReachabilityTree) ReachabilityChangeset(blockHash *daghash.Hash,
func (rt *ReachabilityTree) ReachabilityChangeset(blockHash *model.DomainHash,
blockGHOSTDAGData *model.BlockGHOSTDAGData) *model.ReachabilityChangeset {
return nil