diff --git a/domain/consensus/consensus.go b/domain/consensus/consensus.go index 95646ea95..1bdad7eb7 100644 --- a/domain/consensus/consensus.go +++ b/domain/consensus/consensus.go @@ -2,14 +2,14 @@ package consensus import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // Consensus maintains the current core state of the node type Consensus interface { - BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte, transactionSelector model.TransactionSelector) (*model.DomainBlock, error) - ValidateAndInsertBlock(block *model.DomainBlock) error - UTXOByOutpoint(outpoint *model.DomainOutpoint) (*model.UTXOEntry, error) - ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error) + BuildBlock(coinbaseData *externalapi.CoinbaseData, transactions []*externalapi.DomainTransaction) (*externalapi.DomainBlock, error) + ValidateAndInsertBlock(block *externalapi.DomainBlock) error + ValidateTransactionAndPopulateWithConsensusData(transaction *externalapi.DomainTransaction) error } type consensus struct { @@ -20,25 +20,20 @@ type consensus struct { // 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) (*model.DomainBlock, error) { +func (s *consensus) BuildBlock(coinbaseData *externalapi.CoinbaseData, + transactions []*externalapi.DomainTransaction) (*externalapi.DomainBlock, error) { - return s.blockProcessor.BuildBlock(coinbaseScriptPublicKey, coinbaseExtraData, transactionSelector) + return s.blockProcessor.BuildBlock(coinbaseData, transactions) } // ValidateAndInsertBlock validates the given block and, if valid, applies it // to the current state -func (s *consensus) ValidateAndInsertBlock(block *model.DomainBlock) error { +func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock) error { return s.blockProcessor.ValidateAndInsertBlock(block) } -// UTXOByOutpoint returns a UTXOEntry matching the given outpoint -func (s *consensus) UTXOByOutpoint(outpoint *model.DomainOutpoint) (*model.UTXOEntry, error) { - return s.consensusStateManager.UTXOByOutpoint(outpoint) -} - -// ValidateTransaction validates the given transaction using -// the given utxoEntries -func (s *consensus) ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error) { - return s.transactionValidator.ValidateTransactionAndCalculateFee(transaction, utxoEntries) +// ValidateTransactionAndPopulateWithConsensusData validates the given transaction +// and populates it with any missing consensus data +func (s *consensus) ValidateTransactionAndPopulateWithConsensusData(transaction *externalapi.DomainTransaction) error { + return s.transactionValidator.ValidateTransactionAndPopulateWithConsensusData(transaction) } diff --git a/domain/consensus/database/dbcontext.go b/domain/consensus/database/dbcontext.go index 96f10090d..2e1d0a711 100644 --- a/domain/consensus/database/dbcontext.go +++ b/domain/consensus/database/dbcontext.go @@ -2,6 +2,7 @@ package database import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/infrastructure/db/dbaccess" ) @@ -11,7 +12,7 @@ type DomainDBContext struct { } // FetchBlockRelation retrieves the BlockRelation for the given blockHash -func (ddc *DomainDBContext) FetchBlockRelation(blockHash *model.DomainHash) (*model.BlockRelations, error) { +func (ddc *DomainDBContext) FetchBlockRelation(blockHash *externalapi.DomainHash) (*model.BlockRelations, error) { // TODO: return dbaccess.FetchBlockRelations(ddc.dbContext, blockHash) return nil, nil } diff --git a/domain/consensus/database/txcontext.go b/domain/consensus/database/txcontext.go index 78d639ff9..dc81fcd03 100644 --- a/domain/consensus/database/txcontext.go +++ b/domain/consensus/database/txcontext.go @@ -2,6 +2,7 @@ package database import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/infrastructure/db/dbaccess" ) @@ -11,7 +12,7 @@ type DomainTxContext struct { } // StoreBlockRelation stores the given BlockRelation -func (dtc *DomainTxContext) StoreBlockRelation(blockHash *model.DomainHash, blockRelationData *model.BlockRelations) error { +func (dtc *DomainTxContext) StoreBlockRelation(blockHash *externalapi.DomainHash, blockRelationData *model.BlockRelations) error { // TODO: return dbaccess.StoreBlockRelation(ddc.dbTx, blockHash, blockRelationData) return nil } diff --git a/domain/consensus/datastructures/acceptancedatastore/acceptancedatastore.go b/domain/consensus/datastructures/acceptancedatastore/acceptancedatastore.go index a0dcfb90f..e252ee4a5 100644 --- a/domain/consensus/datastructures/acceptancedatastore/acceptancedatastore.go +++ b/domain/consensus/datastructures/acceptancedatastore/acceptancedatastore.go @@ -2,6 +2,7 @@ package acceptancedatastore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // acceptanceDataStore represents a store of AcceptanceData @@ -14,16 +15,16 @@ func New() model.AcceptanceDataStore { } // Insert inserts the given acceptanceData for the given blockHash -func (ads *acceptanceDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, acceptanceData *model.BlockAcceptanceData) error { +func (ads *acceptanceDataStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, acceptanceData *model.BlockAcceptanceData) error { return nil } // Get gets the acceptanceData associated with the given blockHash -func (ads *acceptanceDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.BlockAcceptanceData, error) { +func (ads *acceptanceDataStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*model.BlockAcceptanceData, error) { return nil, nil } // Delete deletes the acceptanceData associated with the given blockHash -func (ads *acceptanceDataStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) error { +func (ads *acceptanceDataStore) Delete(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash) error { return nil } diff --git a/domain/consensus/datastructures/blockrelationstore/blockrelationstore.go b/domain/consensus/datastructures/blockrelationstore/blockrelationstore.go index a5afcca49..ef6545b50 100644 --- a/domain/consensus/datastructures/blockrelationstore/blockrelationstore.go +++ b/domain/consensus/datastructures/blockrelationstore/blockrelationstore.go @@ -2,6 +2,7 @@ package blockrelationstore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // blockRelationStore represents a store of BlockRelations @@ -14,11 +15,11 @@ func New() model.BlockRelationStore { } // Insert inserts the given blockRelationData for the given blockHash -func (brs *blockRelationStore) Update(dbTx model.DBTxProxy, blockHash *model.DomainHash, parentHashes []*model.DomainHash) error { +func (brs *blockRelationStore) Update(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, parentHashes []*externalapi.DomainHash) error { return nil } // Get gets the blockRelationData associated with the given blockHash -func (brs *blockRelationStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.BlockRelations, error) { +func (brs *blockRelationStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*model.BlockRelations, error) { return nil, nil } diff --git a/domain/consensus/datastructures/blockstatusstore/blockstatusstore.go b/domain/consensus/datastructures/blockstatusstore/blockstatusstore.go index 295ab7b3c..0b1445ce0 100644 --- a/domain/consensus/datastructures/blockstatusstore/blockstatusstore.go +++ b/domain/consensus/datastructures/blockstatusstore/blockstatusstore.go @@ -2,6 +2,7 @@ package blockstatusstore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // blockStatusStore represents a store of BlockStatuses @@ -14,16 +15,16 @@ func New() model.BlockStatusStore { } // Insert inserts the given blockStatus for the given blockHash -func (bss *blockStatusStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, blockStatus model.BlockStatus) error { +func (bss *blockStatusStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, blockStatus model.BlockStatus) error { return nil } // Get gets the blockStatus associated with the given blockHash -func (bss *blockStatusStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (model.BlockStatus, error) { +func (bss *blockStatusStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (model.BlockStatus, error) { return 0, nil } // Exists returns true if the blockStatus for the given blockHash exists -func (bss *blockStatusStore) Exists(dbContext model.DBContextProxy, blockHash *model.DomainHash) (bool, error) { +func (bss *blockStatusStore) Exists(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (bool, error) { return false, nil } diff --git a/domain/consensus/datastructures/blockstore/blockstore.go b/domain/consensus/datastructures/blockstore/blockstore.go index 3ad1452ff..46a03cc01 100644 --- a/domain/consensus/datastructures/blockstore/blockstore.go +++ b/domain/consensus/datastructures/blockstore/blockstore.go @@ -2,6 +2,7 @@ package blockstore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // blockStore represents a store of blocks @@ -14,21 +15,21 @@ func New() model.BlockStore { } // Insert inserts the given block for the given blockHash -func (bms *blockStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, msgBlock *model.DomainBlock) error { +func (bms *blockStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, msgBlock *externalapi.DomainBlock) error { return nil } // Block gets the block associated with the given blockHash -func (bms *blockStore) Block(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.DomainBlock, error) { +func (bms *blockStore) Block(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*externalapi.DomainBlock, error) { return nil, nil } // Blocks gets the blocks associated with the given blockHashes -func (bms *blockStore) Blocks(dbContext model.DBContextProxy, blockHashes []*model.DomainHash) ([]*model.DomainBlock, error) { +func (bms *blockStore) Blocks(dbContext model.DBContextProxy, blockHashes []*externalapi.DomainHash) ([]*externalapi.DomainBlock, error) { return nil, nil } // Delete deletes the block associated with the given blockHash -func (bms *blockStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) error { +func (bms *blockStore) Delete(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash) error { return nil } diff --git a/domain/consensus/datastructures/consensusstatestore/consensusstatestore.go b/domain/consensus/datastructures/consensusstatestore/consensusstatestore.go index 3f0c30b61..0ec33aac7 100644 --- a/domain/consensus/datastructures/consensusstatestore/consensusstatestore.go +++ b/domain/consensus/datastructures/consensusstatestore/consensusstatestore.go @@ -2,6 +2,7 @@ package consensusstatestore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // consensusStateStore represents a store for the current consensus state @@ -19,11 +20,11 @@ func (css *consensusStateStore) Update(dbTx model.DBTxProxy, consensusStateChang } // UTXOByOutpoint gets the utxoEntry associated with the given outpoint -func (css *consensusStateStore) UTXOByOutpoint(dbContext model.DBContextProxy, outpoint *model.DomainOutpoint) (*model.UTXOEntry, error) { +func (css *consensusStateStore) UTXOByOutpoint(dbContext model.DBContextProxy, outpoint *externalapi.DomainOutpoint) (*externalapi.UTXOEntry, error) { return nil, nil } // Tips returns the current tips -func (css *consensusStateStore) Tips(dbContext model.DBContextProxy) ([]*model.DomainHash, error) { +func (css *consensusStateStore) Tips(dbContext model.DBContextProxy) ([]*externalapi.DomainHash, error) { return nil, nil } diff --git a/domain/consensus/datastructures/feedatastore/feedatastore.go b/domain/consensus/datastructures/feedatastore/feedatastore.go index f8bdaa3cd..6a01815d1 100644 --- a/domain/consensus/datastructures/feedatastore/feedatastore.go +++ b/domain/consensus/datastructures/feedatastore/feedatastore.go @@ -1,6 +1,9 @@ package feedatastore -import "github.com/kaspanet/kaspad/domain/consensus/model" +import ( + "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" +) // feeDataStore represents a store of fee data type feeDataStore struct { @@ -12,11 +15,11 @@ func New() model.FeeDataStore { } // Insert inserts the given fee for the given blockHash -func (ads *feeDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, fee uint64) error { +func (ads *feeDataStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, fee uint64) error { return nil } // Get gets the fee associated with the given blockHash -func (ads *feeDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (uint64, error) { +func (ads *feeDataStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (uint64, error) { return 0, nil } diff --git a/domain/consensus/datastructures/ghostdagdatastore/ghostdagdatastore.go b/domain/consensus/datastructures/ghostdagdatastore/ghostdagdatastore.go index 99c010700..2d53c5cc7 100644 --- a/domain/consensus/datastructures/ghostdagdatastore/ghostdagdatastore.go +++ b/domain/consensus/datastructures/ghostdagdatastore/ghostdagdatastore.go @@ -2,6 +2,7 @@ package ghostdagdatastore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // ghostdagDataStore represents a store of BlockGHOSTDAGData @@ -14,11 +15,11 @@ func New() model.GHOSTDAGDataStore { } // Insert inserts the given blockGHOSTDAGData for the given blockHash -func (gds *ghostdagDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, blockGHOSTDAGData *model.BlockGHOSTDAGData) error { +func (gds *ghostdagDataStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, blockGHOSTDAGData *model.BlockGHOSTDAGData) error { return nil } // Get gets the blockGHOSTDAGData associated with the given blockHash -func (gds *ghostdagDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.BlockGHOSTDAGData, error) { +func (gds *ghostdagDataStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*model.BlockGHOSTDAGData, error) { return nil, nil } diff --git a/domain/consensus/datastructures/multisetstore/multisetstore.go b/domain/consensus/datastructures/multisetstore/multisetstore.go index 30fa93a22..743b95c55 100644 --- a/domain/consensus/datastructures/multisetstore/multisetstore.go +++ b/domain/consensus/datastructures/multisetstore/multisetstore.go @@ -2,6 +2,7 @@ package multisetstore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // multisetStore represents a store of Multisets @@ -14,16 +15,16 @@ func New() model.MultisetStore { } // Insert inserts the given multiset for the given blockHash -func (ms *multisetStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, multiset model.Multiset) error { +func (ms *multisetStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, multiset model.Multiset) error { return nil } // Get gets the multiset associated with the given blockHash -func (ms *multisetStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (model.Multiset, error) { +func (ms *multisetStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (model.Multiset, error) { return nil, nil } // Delete deletes the multiset associated with the given blockHash -func (ms *multisetStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) error { +func (ms *multisetStore) Delete(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash) error { return nil } diff --git a/domain/consensus/datastructures/pruningstore/pruningstore.go b/domain/consensus/datastructures/pruningstore/pruningstore.go index e1147eede..bc3076878 100644 --- a/domain/consensus/datastructures/pruningstore/pruningstore.go +++ b/domain/consensus/datastructures/pruningstore/pruningstore.go @@ -2,6 +2,7 @@ package pruningstore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // pruningStore represents a store for the current pruning state @@ -14,12 +15,12 @@ func New() model.PruningStore { } // Update updates the pruning state -func (pps *pruningStore) Update(dbTx model.DBTxProxy, pruningPointBlockHash *model.DomainHash, pruningPointUTXOSet model.ReadOnlyUTXOSet) error { +func (pps *pruningStore) Update(dbTx model.DBTxProxy, pruningPointBlockHash *externalapi.DomainHash, pruningPointUTXOSet model.ReadOnlyUTXOSet) error { return nil } // PruningPoint gets the current pruning point -func (pps *pruningStore) PruningPoint(dbContext model.DBContextProxy) (*model.DomainHash, error) { +func (pps *pruningStore) PruningPoint(dbContext model.DBContextProxy) (*externalapi.DomainHash, error) { return nil, nil } diff --git a/domain/consensus/datastructures/reachabilitydatastore/reachabilitydatastore.go b/domain/consensus/datastructures/reachabilitydatastore/reachabilitydatastore.go index d1990086e..0a47c49a3 100644 --- a/domain/consensus/datastructures/reachabilitydatastore/reachabilitydatastore.go +++ b/domain/consensus/datastructures/reachabilitydatastore/reachabilitydatastore.go @@ -2,6 +2,7 @@ package reachabilitydatastore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // reachabilityDataStore represents a store of ReachabilityData @@ -14,11 +15,11 @@ func New() model.ReachabilityDataStore { } // Insert inserts the given reachabilityData for the given blockHash -func (rds *reachabilityDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, reachabilityData *model.ReachabilityData) error { +func (rds *reachabilityDataStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, reachabilityData *model.ReachabilityData) error { return nil } // Get gets the reachabilityData associated with the given blockHash -func (rds *reachabilityDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.ReachabilityData, error) { +func (rds *reachabilityDataStore) Get(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*model.ReachabilityData, error) { return nil, nil } diff --git a/domain/consensus/datastructures/utxodiffstore/utxodiffstore.go b/domain/consensus/datastructures/utxodiffstore/utxodiffstore.go index 5248149c6..b6d711a4c 100644 --- a/domain/consensus/datastructures/utxodiffstore/utxodiffstore.go +++ b/domain/consensus/datastructures/utxodiffstore/utxodiffstore.go @@ -2,6 +2,7 @@ package utxodiffstore import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // utxoDiffStore represents a store of UTXODiffs @@ -14,21 +15,21 @@ func New() model.UTXODiffStore { } // Insert inserts the given utxoDiff for the given blockHash -func (uds *utxoDiffStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, utxoDiff *model.UTXODiff, utxoDiffChild *model.DomainHash) error { +func (uds *utxoDiffStore) Insert(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash, utxoDiff *model.UTXODiff, utxoDiffChild *externalapi.DomainHash) error { return nil } // UTXODiff gets the utxoDiff associated with the given blockHash -func (uds *utxoDiffStore) UTXODiff(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.UTXODiff, error) { +func (uds *utxoDiffStore) UTXODiff(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*model.UTXODiff, error) { return nil, nil } // UTXODiffChild gets the utxoDiff child associated with the given blockHash -func (uds *utxoDiffStore) UTXODiffChild(dbContext model.DBContextProxy, blockHash *model.DomainHash) (*model.DomainHash, error) { +func (uds *utxoDiffStore) UTXODiffChild(dbContext model.DBContextProxy, blockHash *externalapi.DomainHash) (*externalapi.DomainHash, error) { return nil, nil } // Delete deletes the utxoDiff associated with the given blockHash -func (uds *utxoDiffStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) error { +func (uds *utxoDiffStore) Delete(dbTx model.DBTxProxy, blockHash *externalapi.DomainHash) error { return nil } diff --git a/domain/consensus/model/acceptancedata.go b/domain/consensus/model/acceptancedata.go index f595fc730..2d994bc10 100644 --- a/domain/consensus/model/acceptancedata.go +++ b/domain/consensus/model/acceptancedata.go @@ -1,5 +1,7 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // BlockAcceptanceData stores all transactions in a block with an indication // if they were accepted or not by some other block type BlockAcceptanceData struct { @@ -9,7 +11,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 *DomainTransaction + Tx *externalapi.DomainTransaction Fee uint64 IsAccepted bool } diff --git a/domain/consensus/model/blockrelations.go b/domain/consensus/model/blockrelations.go index 8eecdd04d..5f326ef82 100644 --- a/domain/consensus/model/blockrelations.go +++ b/domain/consensus/model/blockrelations.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // BlockRelations represents a block's parent/child relations type BlockRelations struct { - Parents []*DomainHash - Children []*DomainHash + Parents []*externalapi.DomainHash + Children []*externalapi.DomainHash } diff --git a/domain/consensus/model/consensusstatechanges.go b/domain/consensus/model/consensusstatechanges.go index 190b722ef..d046c5605 100644 --- a/domain/consensus/model/consensusstatechanges.go +++ b/domain/consensus/model/consensusstatechanges.go @@ -1,13 +1,15 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ConsensusStateChanges represents a set of changes that need to be made // to transition the current consensus state to a new one type ConsensusStateChanges struct { AcceptanceData *BlockAcceptanceData VirtualUTXODiff *UTXODiff - NewTips []*DomainHash + NewTips []*externalapi.DomainHash NewBlockUTXODiff *UTXODiff NewBlockMultiset Multiset - ParentDiffChanges *map[*DomainHash]UTXODiff + ParentDiffChanges *map[*externalapi.DomainHash]UTXODiff } diff --git a/domain/consensus/model/database.go b/domain/consensus/model/database.go index ef0327812..8f901f14f 100644 --- a/domain/consensus/model/database.go +++ b/domain/consensus/model/database.go @@ -1,12 +1,14 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // DBContextProxy defines a proxy over domain data access type DBContextProxy interface { - FetchBlockRelation(blockHash *DomainHash) (*BlockRelations, error) + FetchBlockRelation(blockHash *externalapi.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 + StoreBlockRelation(blockHash *externalapi.DomainHash, blockRelationData *BlockRelations) error } diff --git a/domain/consensus/model/block.go b/domain/consensus/model/externalapi/block.go similarity index 96% rename from domain/consensus/model/block.go rename to domain/consensus/model/externalapi/block.go index c8e96ba37..045db3748 100644 --- a/domain/consensus/model/block.go +++ b/domain/consensus/model/externalapi/block.go @@ -1,4 +1,4 @@ -package model +package externalapi // DomainBlock represents a Kaspa block type DomainBlock struct { diff --git a/domain/consensus/model/externalapi/coinbasedata.go b/domain/consensus/model/externalapi/coinbasedata.go new file mode 100644 index 000000000..6f278a40d --- /dev/null +++ b/domain/consensus/model/externalapi/coinbasedata.go @@ -0,0 +1,8 @@ +package externalapi + +// CoinbaseData contains data by which a coinbase transaction +// is built +type CoinbaseData struct { + scriptPublicKey []byte + extraData []byte +} diff --git a/domain/consensus/model/hash.go b/domain/consensus/model/externalapi/hash.go similarity index 81% rename from domain/consensus/model/hash.go rename to domain/consensus/model/externalapi/hash.go index 02a48f4cb..30034b234 100644 --- a/domain/consensus/model/hash.go +++ b/domain/consensus/model/externalapi/hash.go @@ -1,4 +1,4 @@ -package model +package externalapi // DomainHash is the domain representation of a daghash.Hash type DomainHash [32]byte diff --git a/domain/consensus/model/subnetworkid.go b/domain/consensus/model/externalapi/subnetworkid.go similarity index 96% rename from domain/consensus/model/subnetworkid.go rename to domain/consensus/model/externalapi/subnetworkid.go index 4ce7431c9..c185d2622 100644 --- a/domain/consensus/model/subnetworkid.go +++ b/domain/consensus/model/externalapi/subnetworkid.go @@ -1,4 +1,4 @@ -package model +package externalapi // DomainSubnetworkID is the domain representation of a Subnetwork ID type DomainSubnetworkID [20]byte diff --git a/domain/consensus/model/transaction.go b/domain/consensus/model/externalapi/transaction.go similarity index 92% rename from domain/consensus/model/transaction.go rename to domain/consensus/model/externalapi/transaction.go index d56172d6a..86da60415 100644 --- a/domain/consensus/model/transaction.go +++ b/domain/consensus/model/externalapi/transaction.go @@ -1,4 +1,4 @@ -package model +package externalapi // DomainTransaction represents a Kaspa transaction type DomainTransaction struct { @@ -11,9 +11,8 @@ type DomainTransaction struct { PayloadHash *DomainHash Payload []byte - Hash *DomainHash - ID *DomainTransactionID - Index int + Fee uint64 + Mass uint64 } // DomainTransactionInput represents a Kaspa transaction input @@ -21,6 +20,8 @@ type DomainTransactionInput struct { PreviousOutpoint *DomainOutpoint SignatureScript []byte Sequence uint64 + + UTXOEntry *UTXOEntry } // DomainOutpoint represents a Kaspa transaction outpoint diff --git a/domain/consensus/model/utxoentry.go b/domain/consensus/model/externalapi/utxoentry.go similarity index 95% rename from domain/consensus/model/utxoentry.go rename to domain/consensus/model/externalapi/utxoentry.go index 74b72a545..d6cfd50e3 100644 --- a/domain/consensus/model/utxoentry.go +++ b/domain/consensus/model/externalapi/utxoentry.go @@ -1,4 +1,4 @@ -package model +package externalapi // UTXOEntry houses details about an individual transaction output in a utxo // set such as whether or not it was contained in a coinbase tx, the blue diff --git a/domain/consensus/model/ghostdag.go b/domain/consensus/model/ghostdag.go index cb3775486..335d634af 100644 --- a/domain/consensus/model/ghostdag.go +++ b/domain/consensus/model/ghostdag.go @@ -1,12 +1,14 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // BlockGHOSTDAGData represents GHOSTDAG data for some block type BlockGHOSTDAGData struct { BlueScore uint64 - SelectedParent *DomainHash - MergeSetBlues []*DomainHash - MergeSetReds []*DomainHash - BluesAnticoneSizes map[DomainHash]KType + SelectedParent *externalapi.DomainHash + MergeSetBlues []*externalapi.DomainHash + MergeSetReds []*externalapi.DomainHash + BluesAnticoneSizes map[externalapi.DomainHash]KType } // KType defines the size of GHOSTDAG consensus algorithm K parameter. diff --git a/domain/consensus/model/interface_datastructures_acceptancedatastore.go b/domain/consensus/model/interface_datastructures_acceptancedatastore.go index 862149a77..c70fe8996 100644 --- a/domain/consensus/model/interface_datastructures_acceptancedatastore.go +++ b/domain/consensus/model/interface_datastructures_acceptancedatastore.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // AcceptanceDataStore represents a store of AcceptanceData type AcceptanceDataStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, acceptanceData *BlockAcceptanceData) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (*BlockAcceptanceData, error) - Delete(dbTx DBTxProxy, blockHash *DomainHash) error + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, acceptanceData *BlockAcceptanceData) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*BlockAcceptanceData, error) + Delete(dbTx DBTxProxy, blockHash *externalapi.DomainHash) error } diff --git a/domain/consensus/model/interface_datastructures_block.go b/domain/consensus/model/interface_datastructures_block.go index ff941ccae..64f02fb5a 100644 --- a/domain/consensus/model/interface_datastructures_block.go +++ b/domain/consensus/model/interface_datastructures_block.go @@ -1,9 +1,11 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // BlockStore represents a store of blocks type BlockStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, block *DomainBlock) error - Block(dbContext DBContextProxy, blockHash *DomainHash) (*DomainBlock, error) - Blocks(dbContext DBContextProxy, blockHashes []*DomainHash) ([]*DomainBlock, error) - Delete(dbTx DBTxProxy, blockHash *DomainHash) error + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, block *externalapi.DomainBlock) error + Block(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*externalapi.DomainBlock, error) + Blocks(dbContext DBContextProxy, blockHashes []*externalapi.DomainHash) ([]*externalapi.DomainBlock, error) + Delete(dbTx DBTxProxy, blockHash *externalapi.DomainHash) error } diff --git a/domain/consensus/model/interface_datastructures_blockrelationstore.go b/domain/consensus/model/interface_datastructures_blockrelationstore.go index 416f35078..c9a708cbc 100644 --- a/domain/consensus/model/interface_datastructures_blockrelationstore.go +++ b/domain/consensus/model/interface_datastructures_blockrelationstore.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // BlockRelationStore represents a store of BlockRelations type BlockRelationStore interface { - Update(dbTx DBTxProxy, blockHash *DomainHash, parentHashes []*DomainHash) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (*BlockRelations, error) + Update(dbTx DBTxProxy, blockHash *externalapi.DomainHash, parentHashes []*externalapi.DomainHash) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*BlockRelations, error) } diff --git a/domain/consensus/model/interface_datastructures_blockstatusstore.go b/domain/consensus/model/interface_datastructures_blockstatusstore.go index bb7dda4db..c79faaad1 100644 --- a/domain/consensus/model/interface_datastructures_blockstatusstore.go +++ b/domain/consensus/model/interface_datastructures_blockstatusstore.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // BlockStatusStore represents a store of BlockStatuses type BlockStatusStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, blockStatus BlockStatus) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (BlockStatus, error) - Exists(dbContext DBContextProxy, blockHash *DomainHash) (bool, error) + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, blockStatus BlockStatus) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (BlockStatus, error) + Exists(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (bool, error) } diff --git a/domain/consensus/model/interface_datastructures_consensusstatestore.go b/domain/consensus/model/interface_datastructures_consensusstatestore.go index 53038f9a6..ca94fa63d 100644 --- a/domain/consensus/model/interface_datastructures_consensusstatestore.go +++ b/domain/consensus/model/interface_datastructures_consensusstatestore.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ConsensusStateStore represents a store for the current consensus state type ConsensusStateStore interface { Update(dbTx DBTxProxy, consensusStateChanges *ConsensusStateChanges) error - UTXOByOutpoint(dbContext DBContextProxy, outpoint *DomainOutpoint) (*UTXOEntry, error) - Tips(dbContext DBContextProxy) ([]*DomainHash, error) + UTXOByOutpoint(dbContext DBContextProxy, outpoint *externalapi.DomainOutpoint) (*externalapi.UTXOEntry, error) + Tips(dbContext DBContextProxy) ([]*externalapi.DomainHash, error) } diff --git a/domain/consensus/model/interface_datastructures_feedatastore.go b/domain/consensus/model/interface_datastructures_feedatastore.go index 45ebca497..f5d38ad44 100644 --- a/domain/consensus/model/interface_datastructures_feedatastore.go +++ b/domain/consensus/model/interface_datastructures_feedatastore.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // FeeDataStore represents a store of fee data type FeeDataStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, fee uint64) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (uint64, error) + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, fee uint64) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (uint64, error) } diff --git a/domain/consensus/model/interface_datastructures_ghostdagdatastore.go b/domain/consensus/model/interface_datastructures_ghostdagdatastore.go index 66e1188cc..424d38856 100644 --- a/domain/consensus/model/interface_datastructures_ghostdagdatastore.go +++ b/domain/consensus/model/interface_datastructures_ghostdagdatastore.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // GHOSTDAGDataStore represents a store of BlockGHOSTDAGData type GHOSTDAGDataStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, blockGHOSTDAGData *BlockGHOSTDAGData) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (*BlockGHOSTDAGData, error) + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, blockGHOSTDAGData *BlockGHOSTDAGData) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*BlockGHOSTDAGData, error) } diff --git a/domain/consensus/model/interface_datastructures_multisetstore.go b/domain/consensus/model/interface_datastructures_multisetstore.go index b63cc871a..c203db864 100644 --- a/domain/consensus/model/interface_datastructures_multisetstore.go +++ b/domain/consensus/model/interface_datastructures_multisetstore.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // MultisetStore represents a store of Multisets type MultisetStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, multiset Multiset) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (Multiset, error) - Delete(dbTx DBTxProxy, blockHash *DomainHash) error + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, multiset Multiset) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (Multiset, error) + Delete(dbTx DBTxProxy, blockHash *externalapi.DomainHash) error } diff --git a/domain/consensus/model/interface_datastructures_pruningstore.go b/domain/consensus/model/interface_datastructures_pruningstore.go index 0828adbed..58ed9000c 100644 --- a/domain/consensus/model/interface_datastructures_pruningstore.go +++ b/domain/consensus/model/interface_datastructures_pruningstore.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // PruningStore represents a store for the current pruning state type PruningStore interface { - Update(dbTx DBTxProxy, pruningPointBlockHash *DomainHash, pruningPointUTXOSet ReadOnlyUTXOSet) error - PruningPoint(dbContext DBContextProxy) (*DomainHash, error) + Update(dbTx DBTxProxy, pruningPointBlockHash *externalapi.DomainHash, pruningPointUTXOSet ReadOnlyUTXOSet) error + PruningPoint(dbContext DBContextProxy) (*externalapi.DomainHash, error) PruningPointSerializedUTXOSet(dbContext DBContextProxy) ([]byte, error) } diff --git a/domain/consensus/model/interface_datastructures_reachabilitydatastore.go b/domain/consensus/model/interface_datastructures_reachabilitydatastore.go index dd550aba3..e1eb54a5f 100644 --- a/domain/consensus/model/interface_datastructures_reachabilitydatastore.go +++ b/domain/consensus/model/interface_datastructures_reachabilitydatastore.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ReachabilityDataStore represents a store of ReachabilityData type ReachabilityDataStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, reachabilityData *ReachabilityData) error - Get(dbContext DBContextProxy, blockHash *DomainHash) (*ReachabilityData, error) + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, reachabilityData *ReachabilityData) error + Get(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*ReachabilityData, error) } diff --git a/domain/consensus/model/interface_datastructures_utxodiffstore.go b/domain/consensus/model/interface_datastructures_utxodiffstore.go index 884055df5..7933cf7c4 100644 --- a/domain/consensus/model/interface_datastructures_utxodiffstore.go +++ b/domain/consensus/model/interface_datastructures_utxodiffstore.go @@ -1,9 +1,11 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // UTXODiffStore represents a store of UTXODiffs type UTXODiffStore interface { - Insert(dbTx DBTxProxy, blockHash *DomainHash, utxoDiff *UTXODiff, utxoDiffChild *DomainHash) error - UTXODiff(dbContext DBContextProxy, blockHash *DomainHash) (*UTXODiff, error) - UTXODiffChild(dbContext DBContextProxy, blockHash *DomainHash) (*DomainHash, error) - Delete(dbTx DBTxProxy, blockHash *DomainHash) error + Insert(dbTx DBTxProxy, blockHash *externalapi.DomainHash, utxoDiff *UTXODiff, utxoDiffChild *externalapi.DomainHash) error + UTXODiff(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*UTXODiff, error) + UTXODiffChild(dbContext DBContextProxy, blockHash *externalapi.DomainHash) (*externalapi.DomainHash, error) + Delete(dbTx DBTxProxy, blockHash *externalapi.DomainHash) error } diff --git a/domain/consensus/model/interface_processes_blockprocessor.go b/domain/consensus/model/interface_processes_blockprocessor.go index 7562e32be..87abc889c 100644 --- a/domain/consensus/model/interface_processes_blockprocessor.go +++ b/domain/consensus/model/interface_processes_blockprocessor.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // 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, error) - ValidateAndInsertBlock(block *DomainBlock) error + BuildBlock(coinbaseData *externalapi.CoinbaseData, transactions []*externalapi.DomainTransaction) (*externalapi.DomainBlock, error) + ValidateAndInsertBlock(block *externalapi.DomainBlock) error } diff --git a/domain/consensus/model/interface_processes_blockvalidator.go b/domain/consensus/model/interface_processes_blockvalidator.go index 2ff856359..124031713 100644 --- a/domain/consensus/model/interface_processes_blockvalidator.go +++ b/domain/consensus/model/interface_processes_blockvalidator.go @@ -1,12 +1,14 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // 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 + ValidateHeaderInIsolation(block *externalapi.DomainBlock) error + ValidateBodyInIsolation(block *externalapi.DomainBlock) error + ValidateHeaderInContext(block *externalapi.DomainBlock) error + ValidateBodyInContext(block *externalapi.DomainBlock) error + ValidateAgainstPastUTXO(block *externalapi.DomainBlock) error + ValidateFinality(block *externalapi.DomainBlock) error } diff --git a/domain/consensus/model/interface_processes_consensusstatemanager.go b/domain/consensus/model/interface_processes_consensusstatemanager.go index 97fa08de8..ca2bcf593 100644 --- a/domain/consensus/model/interface_processes_consensusstatemanager.go +++ b/domain/consensus/model/interface_processes_consensusstatemanager.go @@ -1,12 +1,14 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ConsensusStateManager manages the node's consensus state type ConsensusStateManager interface { - UTXOByOutpoint(outpoint *DomainOutpoint) (*UTXOEntry, error) - CalculateConsensusStateChanges(block *DomainBlock, isDisqualified bool) (stateChanges *ConsensusStateChanges, + UTXOByOutpoint(outpoint *externalapi.DomainOutpoint) (*externalapi.UTXOEntry, error) + CalculateConsensusStateChanges(block *externalapi.DomainBlock, isDisqualified bool) (stateChanges *ConsensusStateChanges, utxoDiffChanges *UTXODiffChanges, virtualGHOSTDAGData *BlockGHOSTDAGData, err error) CalculateAcceptanceDataAndUTXOMultiset(blockGHOSTDAGData *BlockGHOSTDAGData) (*BlockAcceptanceData, Multiset, error) - Tips() ([]*DomainHash, error) + Tips() ([]*externalapi.DomainHash, error) VirtualData() (medianTime int64, blueScore uint64, err error) - RestorePastUTXOSet(blockHash *DomainHash) (ReadOnlyUTXOSet, error) + RestorePastUTXOSet(blockHash *externalapi.DomainHash) (ReadOnlyUTXOSet, error) } diff --git a/domain/consensus/model/interface_processes_dagtopologymanager.go b/domain/consensus/model/interface_processes_dagtopologymanager.go index b41cf3bb7..e0c0ca2ea 100644 --- a/domain/consensus/model/interface_processes_dagtopologymanager.go +++ b/domain/consensus/model/interface_processes_dagtopologymanager.go @@ -1,14 +1,16 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // DAGTopologyManager exposes methods for querying relationships // between blocks in the DAG type DAGTopologyManager interface { - Parents(blockHash *DomainHash) ([]*DomainHash, error) - Children(blockHash *DomainHash) ([]*DomainHash, error) - IsParentOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) - IsChildOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) - IsAncestorOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) - IsDescendantOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) - IsAncestorOfAny(blockHash *DomainHash, potentialDescendants []*DomainHash) (bool, error) - IsInSelectedParentChainOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) + Parents(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error) + Children(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error) + IsParentOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) + IsChildOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) + IsAncestorOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) + IsDescendantOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) + IsAncestorOfAny(blockHash *externalapi.DomainHash, potentialDescendants []*externalapi.DomainHash) (bool, error) + IsInSelectedParentChainOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) } diff --git a/domain/consensus/model/interface_processes_dagtraversalmanager.go b/domain/consensus/model/interface_processes_dagtraversalmanager.go index 663dec356..b483555cb 100644 --- a/domain/consensus/model/interface_processes_dagtraversalmanager.go +++ b/domain/consensus/model/interface_processes_dagtraversalmanager.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // DAGTraversalManager exposes methods for travering blocks // in the DAG type DAGTraversalManager interface { - HighestChainBlockBelowBlueScore(highHash *DomainHash, blueScore uint64) (*DomainHash, error) - SelectedParentIterator(highHash *DomainHash) (SelectedParentIterator, error) + HighestChainBlockBelowBlueScore(highHash *externalapi.DomainHash, blueScore uint64) (*externalapi.DomainHash, error) + SelectedParentIterator(highHash *externalapi.DomainHash) (SelectedParentIterator, error) } diff --git a/domain/consensus/model/interface_processes_difficultymanager.go b/domain/consensus/model/interface_processes_difficultymanager.go index c79a885af..8006a269d 100644 --- a/domain/consensus/model/interface_processes_difficultymanager.go +++ b/domain/consensus/model/interface_processes_difficultymanager.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // DifficultyManager provides a method to resolve the // difficulty value of a block type DifficultyManager interface { - RequiredDifficulty(parents []*DomainHash) (uint32, error) + RequiredDifficulty(parents []*externalapi.DomainHash) (uint32, error) } diff --git a/domain/consensus/model/interface_processes_ghostdagmanager.go b/domain/consensus/model/interface_processes_ghostdagmanager.go index fdac46174..32503a267 100644 --- a/domain/consensus/model/interface_processes_ghostdagmanager.go +++ b/domain/consensus/model/interface_processes_ghostdagmanager.go @@ -1,10 +1,12 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // GHOSTDAGManager resolves and manages GHOSTDAG block data type GHOSTDAGManager interface { - GHOSTDAG(blockParents []*DomainHash) (*BlockGHOSTDAGData, error) - BlockData(blockHash *DomainHash) (*BlockGHOSTDAGData, error) + GHOSTDAG(blockParents []*externalapi.DomainHash) (*BlockGHOSTDAGData, error) + BlockData(blockHash *externalapi.DomainHash) (*BlockGHOSTDAGData, error) ChooseSelectedParent( - blockHashA *DomainHash, blockAGHOSTDAGData *BlockGHOSTDAGData, - blockHashB *DomainHash, blockBGHOSTDAGData *BlockGHOSTDAGData) *DomainHash + blockHashA *externalapi.DomainHash, blockAGHOSTDAGData *BlockGHOSTDAGData, + blockHashB *externalapi.DomainHash, blockBGHOSTDAGData *BlockGHOSTDAGData) *externalapi.DomainHash } diff --git a/domain/consensus/model/interface_processes_pruningmanager.go b/domain/consensus/model/interface_processes_pruningmanager.go index 1dfd984e9..4ad9073bc 100644 --- a/domain/consensus/model/interface_processes_pruningmanager.go +++ b/domain/consensus/model/interface_processes_pruningmanager.go @@ -1,9 +1,11 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // PruningManager resolves and manages the current pruning point type PruningManager interface { FindNextPruningPoint(blockGHOSTDAGData *BlockGHOSTDAGData) (found bool, - newPruningPoint *DomainHash, newPruningPointUTXOSet ReadOnlyUTXOSet, err error) - PruningPoint() (*DomainHash, error) + newPruningPoint *externalapi.DomainHash, newPruningPointUTXOSet ReadOnlyUTXOSet, err error) + PruningPoint() (*externalapi.DomainHash, error) SerializedUTXOSet() ([]byte, error) } diff --git a/domain/consensus/model/interface_processes_reachabilitytree.go b/domain/consensus/model/interface_processes_reachabilitytree.go index 5b5bf4f01..0b0211767 100644 --- a/domain/consensus/model/interface_processes_reachabilitytree.go +++ b/domain/consensus/model/interface_processes_reachabilitytree.go @@ -1,9 +1,11 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ReachabilityTree maintains a structure that allows to answer // reachability queries in sub-linear time type ReachabilityTree interface { - IsReachabilityTreeAncestorOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) - IsDAGAncestorOf(blockHashA *DomainHash, blockHashB *DomainHash) (bool, error) - ReachabilityChangeset(blockHash *DomainHash, blockGHOSTDAGData *BlockGHOSTDAGData) (*ReachabilityChangeset, error) + IsReachabilityTreeAncestorOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) + IsDAGAncestorOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) + ReachabilityChangeset(blockHash *externalapi.DomainHash, blockGHOSTDAGData *BlockGHOSTDAGData) (*ReachabilityChangeset, error) } diff --git a/domain/consensus/model/interface_processes_transactionvalidator.go b/domain/consensus/model/interface_processes_transactionvalidator.go index 78694a4f0..f3bb3b1a4 100644 --- a/domain/consensus/model/interface_processes_transactionvalidator.go +++ b/domain/consensus/model/interface_processes_transactionvalidator.go @@ -1,7 +1,9 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // TransactionValidator exposes a set of validation classes, after which // it's possible to determine whether a transaction is valid type TransactionValidator interface { - ValidateTransactionAndCalculateFee(transaction *DomainTransaction, utxoEntries []*UTXOEntry) (fee uint64, err error) + ValidateTransactionAndPopulateWithConsensusData(transaction *externalapi.DomainTransaction) error } diff --git a/domain/consensus/model/multiset.go b/domain/consensus/model/multiset.go index ff40219a4..30ec0fdc2 100644 --- a/domain/consensus/model/multiset.go +++ b/domain/consensus/model/multiset.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // Multiset represents a secp256k1 multiset type Multiset interface { Add(data []byte) Remove(data []byte) - Hash() *DomainHash + Hash() *externalapi.DomainHash } diff --git a/domain/consensus/model/reachabilitychangeset.go b/domain/consensus/model/reachabilitychangeset.go index 2cc2e1696..c4db28140 100644 --- a/domain/consensus/model/reachabilitychangeset.go +++ b/domain/consensus/model/reachabilitychangeset.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ReachabilityChangeset holds the set of changes to make to a // reachability tree to insert a new reachability node type ReachabilityChangeset struct { - TreeNodeChanges map[*DomainHash]*ReachabilityTreeNode - FutureCoveringSetChanges map[*DomainHash]FutureCoveringTreeNodeSet + TreeNodeChanges map[*externalapi.DomainHash]*ReachabilityTreeNode + FutureCoveringSetChanges map[*externalapi.DomainHash]FutureCoveringTreeNodeSet } diff --git a/domain/consensus/model/readonlyutxoset.go b/domain/consensus/model/readonlyutxoset.go index cc2055514..4e36b8dce 100644 --- a/domain/consensus/model/readonlyutxoset.go +++ b/domain/consensus/model/readonlyutxoset.go @@ -1,14 +1,16 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // ReadOnlyUTXOSet represents a UTXOSet that can only be read from type ReadOnlyUTXOSet interface { Iterator() ReadOnlyUTXOSetIterator - Entry(outpoint *DomainOutpoint) *UTXOEntry + Entry(outpoint *externalapi.DomainOutpoint) *externalapi.UTXOEntry } // ReadOnlyUTXOSetIterator is an iterator over all entries in a // ReadOnlyUTXOSet type ReadOnlyUTXOSetIterator interface { Next() bool - Get() (outpoint *DomainOutpoint, utxoEntry *UTXOEntry) + Get() (outpoint *externalapi.DomainOutpoint, utxoEntry *externalapi.UTXOEntry) } diff --git a/domain/consensus/model/selectedparentiterator.go b/domain/consensus/model/selectedparentiterator.go index ec202c241..520da27b5 100644 --- a/domain/consensus/model/selectedparentiterator.go +++ b/domain/consensus/model/selectedparentiterator.go @@ -1,8 +1,10 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // SelectedParentIterator is an iterator over the selected parent // chain of some block type SelectedParentIterator interface { Next() bool - Get() *DomainHash + Get() *externalapi.DomainHash } diff --git a/domain/consensus/model/transactionselector.go b/domain/consensus/model/transactionselector.go index 45ac94b3e..6a1a22d77 100644 --- a/domain/consensus/model/transactionselector.go +++ b/domain/consensus/model/transactionselector.go @@ -1,5 +1,7 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // TransactionSelector is a function for selecting transaction from // some ReadOnlyUTXOSet -type TransactionSelector func(readOnlyUTXOSet ReadOnlyUTXOSet) []*DomainTransaction +type TransactionSelector func(readOnlyUTXOSet ReadOnlyUTXOSet) []*externalapi.DomainTransaction diff --git a/domain/consensus/model/utxodiff.go b/domain/consensus/model/utxodiff.go index 16f996c60..3d8bcd5eb 100644 --- a/domain/consensus/model/utxodiff.go +++ b/domain/consensus/model/utxodiff.go @@ -1,5 +1,7 @@ package model +import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + // UTXODiff represents a diff between two UTXO Sets. type UTXODiff struct { ToAdd UTXOCollection @@ -7,4 +9,4 @@ type UTXODiff struct { } // UTXOCollection represents a set of UTXOs indexed by their outpoints -type UTXOCollection map[DomainOutpoint]*UTXOEntry +type UTXOCollection map[externalapi.DomainOutpoint]*externalapi.UTXOEntry diff --git a/domain/consensus/processes/blockprocessor/blockprocessor.go b/domain/consensus/processes/blockprocessor/blockprocessor.go index 0230ea968..30a0d718b 100644 --- a/domain/consensus/processes/blockprocessor/blockprocessor.go +++ b/domain/consensus/processes/blockprocessor/blockprocessor.go @@ -3,6 +3,7 @@ package blockprocessor import ( "github.com/kaspanet/kaspad/domain/consensus/database" "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/domain/dagconfig" ) @@ -64,14 +65,14 @@ 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) (*model.DomainBlock, error) { +func (bp *blockProcessor) BuildBlock(coinbaseData *externalapi.CoinbaseData, + transactions []*externalapi.DomainTransaction) (*externalapi.DomainBlock, error) { return nil, nil } // ValidateAndInsertBlock validates the given block and, if valid, applies it // to the current state -func (bp *blockProcessor) ValidateAndInsertBlock(block *model.DomainBlock) error { +func (bp *blockProcessor) ValidateAndInsertBlock(block *externalapi.DomainBlock) error { return nil } diff --git a/domain/consensus/processes/consensusstatemanager/consensusstatemanager.go b/domain/consensus/processes/consensusstatemanager/consensusstatemanager.go index 9a773030b..89971b661 100644 --- a/domain/consensus/processes/consensusstatemanager/consensusstatemanager.go +++ b/domain/consensus/processes/consensusstatemanager/consensusstatemanager.go @@ -3,6 +3,7 @@ package consensusstatemanager import ( "github.com/kaspanet/kaspad/domain/consensus/database" "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/domain/dagconfig" ) @@ -41,13 +42,13 @@ func New( } // UTXOByOutpoint returns a UTXOEntry matching the given outpoint -func (csm *consensusStateManager) UTXOByOutpoint(outpoint *model.DomainOutpoint) (*model.UTXOEntry, error) { +func (csm *consensusStateManager) UTXOByOutpoint(outpoint *externalapi.DomainOutpoint) (*externalapi.UTXOEntry, error) { return nil, 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 *model.DomainBlock, isDisqualified bool) ( +func (csm *consensusStateManager) CalculateConsensusStateChanges(block *externalapi.DomainBlock, isDisqualified bool) ( stateChanges *model.ConsensusStateChanges, utxoDiffChanges *model.UTXODiffChanges, virtualGHOSTDAGData *model.BlockGHOSTDAGData, err error) { @@ -63,7 +64,7 @@ func (csm *consensusStateManager) CalculateAcceptanceDataAndUTXOMultiset(blockGH } // Tips returns the current DAG tips -func (csm *consensusStateManager) Tips() ([]*model.DomainHash, error) { +func (csm *consensusStateManager) Tips() ([]*externalapi.DomainHash, error) { return nil, nil } @@ -73,6 +74,6 @@ func (csm *consensusStateManager) VirtualData() (medianTime int64, blueScore uin } // RestoreUTXOSet calculates and returns the UTXOSet of the given blockHash -func (csm *consensusStateManager) RestorePastUTXOSet(blockHash *model.DomainHash) (model.ReadOnlyUTXOSet, error) { +func (csm *consensusStateManager) RestorePastUTXOSet(blockHash *externalapi.DomainHash) (model.ReadOnlyUTXOSet, error) { return nil, nil } diff --git a/domain/consensus/processes/dagtopologymanager/dagtopologymanager.go b/domain/consensus/processes/dagtopologymanager/dagtopologymanager.go index 04fa02b61..1f71f6935 100644 --- a/domain/consensus/processes/dagtopologymanager/dagtopologymanager.go +++ b/domain/consensus/processes/dagtopologymanager/dagtopologymanager.go @@ -3,6 +3,7 @@ package dagtopologymanager import ( "github.com/kaspanet/kaspad/domain/consensus/database" "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // dagTopologyManager exposes methods for querying relationships @@ -27,7 +28,7 @@ func New( } // Parents returns the DAG parents of the given blockHash -func (dtm *dagTopologyManager) Parents(blockHash *model.DomainHash) ([]*model.DomainHash, error) { +func (dtm *dagTopologyManager) Parents(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error) { blockRelations, err := dtm.blockRelationStore.Get(dtm.databaseContext, blockHash) if err != nil { return nil, err @@ -36,7 +37,7 @@ func (dtm *dagTopologyManager) Parents(blockHash *model.DomainHash) ([]*model.Do } // Children returns the DAG children of the given blockHash -func (dtm *dagTopologyManager) Children(blockHash *model.DomainHash) ([]*model.DomainHash, error) { +func (dtm *dagTopologyManager) Children(blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error) { blockRelations, err := dtm.blockRelationStore.Get(dtm.databaseContext, blockHash) if err != nil { return nil, err @@ -45,7 +46,7 @@ func (dtm *dagTopologyManager) Children(blockHash *model.DomainHash) ([]*model.D } // IsParentOf returns true if blockHashA is a direct DAG parent of blockHashB -func (dtm *dagTopologyManager) IsParentOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (dtm *dagTopologyManager) IsParentOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { blockRelations, err := dtm.blockRelationStore.Get(dtm.databaseContext, blockHashB) if err != nil { return false, err @@ -54,7 +55,7 @@ func (dtm *dagTopologyManager) IsParentOf(blockHashA *model.DomainHash, blockHas } // IsChildOf returns true if blockHashA is a direct DAG child of blockHashB -func (dtm *dagTopologyManager) IsChildOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (dtm *dagTopologyManager) IsChildOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { blockRelations, err := dtm.blockRelationStore.Get(dtm.databaseContext, blockHashB) if err != nil { return false, err @@ -63,26 +64,26 @@ func (dtm *dagTopologyManager) IsChildOf(blockHashA *model.DomainHash, blockHash } // IsAncestorOf returns true if blockHashA is a DAG ancestor of blockHashB -func (dtm *dagTopologyManager) IsAncestorOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (dtm *dagTopologyManager) IsAncestorOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { return dtm.reachabilityTree.IsDAGAncestorOf(blockHashA, blockHashB) } // IsDescendantOf returns true if blockHashA is a DAG descendant of blockHashB -func (dtm *dagTopologyManager) IsDescendantOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (dtm *dagTopologyManager) IsDescendantOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { return dtm.reachabilityTree.IsDAGAncestorOf(blockHashB, blockHashA) } // IsAncestorOfAny returns true if `blockHash` is an ancestor of at least one of `potentialDescendants` -func (dtm *dagTopologyManager) IsAncestorOfAny(blockHash *model.DomainHash, potentialDescendants []*model.DomainHash) (bool, error) { +func (dtm *dagTopologyManager) IsAncestorOfAny(blockHash *externalapi.DomainHash, potentialDescendants []*externalapi.DomainHash) (bool, error) { return false, nil } // IsInSelectedParentChainOf returns true if blockHashA is in the selected parent chain of blockHashB -func (dtm *dagTopologyManager) IsInSelectedParentChainOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (dtm *dagTopologyManager) IsInSelectedParentChainOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { return false, nil } -func isHashInSlice(hash *model.DomainHash, hashes []*model.DomainHash) bool { +func isHashInSlice(hash *externalapi.DomainHash, hashes []*externalapi.DomainHash) bool { for _, h := range hashes { if *h == *hash { return true diff --git a/domain/consensus/processes/dagtraversalmanager/dagtraversalmanager.go b/domain/consensus/processes/dagtraversalmanager/dagtraversalmanager.go index 9a1c274a3..8752d4fbe 100644 --- a/domain/consensus/processes/dagtraversalmanager/dagtraversalmanager.go +++ b/domain/consensus/processes/dagtraversalmanager/dagtraversalmanager.go @@ -2,6 +2,7 @@ package dagtraversalmanager import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // dagTraversalManager exposes methods for travering blocks @@ -23,7 +24,7 @@ func New( // SelectedParentIterator creates an iterator over the selected // parent chain of the given highHash -func (dtm *dagTraversalManager) SelectedParentIterator(highHash *model.DomainHash) (model.SelectedParentIterator, error) { +func (dtm *dagTraversalManager) SelectedParentIterator(highHash *externalapi.DomainHash) (model.SelectedParentIterator, error) { return nil, nil } @@ -31,6 +32,6 @@ func (dtm *dagTraversalManager) SelectedParentIterator(highHash *model.DomainHas // highest block with a blue score lower than the given // blueScore in the block with the given highHash's selected // parent chain -func (dtm *dagTraversalManager) HighestChainBlockBelowBlueScore(highHash *model.DomainHash, blueScore uint64) (*model.DomainHash, error) { +func (dtm *dagTraversalManager) HighestChainBlockBelowBlueScore(highHash *externalapi.DomainHash, blueScore uint64) (*externalapi.DomainHash, error) { return nil, nil } diff --git a/domain/consensus/processes/difficultymanager/difficultymanager.go b/domain/consensus/processes/difficultymanager/difficultymanager.go index cd3231338..f43d972be 100644 --- a/domain/consensus/processes/difficultymanager/difficultymanager.go +++ b/domain/consensus/processes/difficultymanager/difficultymanager.go @@ -2,6 +2,7 @@ package difficultymanager import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // DifficultyManager provides a method to resolve the @@ -18,6 +19,6 @@ func New(ghostdagManager model.GHOSTDAGManager) model.DifficultyManager { } // RequiredDifficulty returns the difficulty required for some block -func (dm *difficultyManager) RequiredDifficulty(parents []*model.DomainHash) (uint32, error) { +func (dm *difficultyManager) RequiredDifficulty(parents []*externalapi.DomainHash) (uint32, error) { return 0, nil } diff --git a/domain/consensus/processes/ghostdagmanager/compare.go b/domain/consensus/processes/ghostdagmanager/compare.go index 616fe6d17..7cc71d6b7 100644 --- a/domain/consensus/processes/ghostdagmanager/compare.go +++ b/domain/consensus/processes/ghostdagmanager/compare.go @@ -1,9 +1,12 @@ package ghostdagmanager -import "github.com/kaspanet/kaspad/domain/consensus/model" +import ( + "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" +) -func (gm *ghostdagManager) findSelectedParent(parentHashes []*model.DomainHash) (*model.DomainHash, error) { - var selectedParent *model.DomainHash +func (gm *ghostdagManager) findSelectedParent(parentHashes []*externalapi.DomainHash) (*externalapi.DomainHash, error) { + var selectedParent *externalapi.DomainHash for _, hash := range parentHashes { if selectedParent == nil { selectedParent = hash @@ -20,7 +23,7 @@ func (gm *ghostdagManager) findSelectedParent(parentHashes []*model.DomainHash) return selectedParent, nil } -func (gm *ghostdagManager) less(blockA, blockB *model.DomainHash) (bool, error) { +func (gm *ghostdagManager) less(blockA, blockB *externalapi.DomainHash) (bool, error) { blockAGHOSTDAGData, err := gm.ghostdagDataStore.Get(gm.databaseContext, blockA) if err != nil { return false, err @@ -34,8 +37,8 @@ func (gm *ghostdagManager) less(blockA, blockB *model.DomainHash) (bool, error) } func (gm *ghostdagManager) ChooseSelectedParent( - blockHashA *model.DomainHash, blockAGHOSTDAGData *model.BlockGHOSTDAGData, - blockHashB *model.DomainHash, blockBGHOSTDAGData *model.BlockGHOSTDAGData) *model.DomainHash { + blockHashA *externalapi.DomainHash, blockAGHOSTDAGData *model.BlockGHOSTDAGData, + blockHashB *externalapi.DomainHash, blockBGHOSTDAGData *model.BlockGHOSTDAGData) *externalapi.DomainHash { blockABlueScore := blockAGHOSTDAGData.BlueScore blockBBlueScore := blockBGHOSTDAGData.BlueScore @@ -51,7 +54,7 @@ func (gm *ghostdagManager) ChooseSelectedParent( return blockHashA } -func hashesLess(a, b *model.DomainHash) bool { +func hashesLess(a, b *externalapi.DomainHash) bool { // We compare the hashes backwards because Hash is stored as a little endian byte array. for i := len(a) - 1; i >= 0; i-- { switch { diff --git a/domain/consensus/processes/ghostdagmanager/ghostdag.go b/domain/consensus/processes/ghostdagmanager/ghostdag.go index fab480808..1d75c08bc 100644 --- a/domain/consensus/processes/ghostdagmanager/ghostdag.go +++ b/domain/consensus/processes/ghostdagmanager/ghostdag.go @@ -2,6 +2,7 @@ package ghostdagmanager import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/pkg/errors" ) @@ -23,11 +24,11 @@ import ( // BluesAnticoneSizes. // // For further details see the article https://eprint.iacr.org/2018/104.pdf -func (gm *ghostdagManager) GHOSTDAG(blockParents []*model.DomainHash) (*model.BlockGHOSTDAGData, error) { +func (gm *ghostdagManager) GHOSTDAG(blockParents []*externalapi.DomainHash) (*model.BlockGHOSTDAGData, error) { newBlockData := &model.BlockGHOSTDAGData{ - MergeSetBlues: make([]*model.DomainHash, 0), - MergeSetReds: make([]*model.DomainHash, 0), - BluesAnticoneSizes: make(map[model.DomainHash]model.KType), + MergeSetBlues: make([]*externalapi.DomainHash, 0), + MergeSetReds: make([]*externalapi.DomainHash, 0), + BluesAnticoneSizes: make(map[externalapi.DomainHash]model.KType), } selectedParent, err := gm.findSelectedParent(blockParents) @@ -68,12 +69,12 @@ func (gm *ghostdagManager) GHOSTDAG(blockParents []*model.DomainHash) (*model.Bl } type chainBlockData struct { - hash *model.DomainHash + hash *externalapi.DomainHash blockData *model.BlockGHOSTDAGData } -func (gm *ghostdagManager) checkBlueCandidate(newBlockData *model.BlockGHOSTDAGData, blueCandidate *model.DomainHash) ( - isBlue bool, candidateAnticoneSize model.KType, candidateBluesAnticoneSizes map[model.DomainHash]model.KType, err error) { +func (gm *ghostdagManager) checkBlueCandidate(newBlockData *model.BlockGHOSTDAGData, blueCandidate *externalapi.DomainHash) ( + isBlue bool, candidateAnticoneSize model.KType, candidateBluesAnticoneSizes map[externalapi.DomainHash]model.KType, err error) { // The maximum length of node.blues can be K+1 because // it contains the selected parent. @@ -81,7 +82,7 @@ func (gm *ghostdagManager) checkBlueCandidate(newBlockData *model.BlockGHOSTDAGD return false, 0, nil, nil } - candidateBluesAnticoneSizes = make(map[model.DomainHash]model.KType, gm.k) + candidateBluesAnticoneSizes = make(map[externalapi.DomainHash]model.KType, gm.k) // Iterate over all blocks in the blue set of newNode that are not in the past // of blueCandidate, and check for each one of them if blueCandidate potentially @@ -120,8 +121,8 @@ func (gm *ghostdagManager) checkBlueCandidate(newBlockData *model.BlockGHOSTDAGD } func (gm *ghostdagManager) checkBlueCandidateWithChainBlock(newBlockData *model.BlockGHOSTDAGData, - chainBlock chainBlockData, blueCandidate *model.DomainHash, - candidateBluesAnticoneSizes map[model.DomainHash]model.KType, + chainBlock chainBlockData, blueCandidate *externalapi.DomainHash, + candidateBluesAnticoneSizes map[externalapi.DomainHash]model.KType, candidateAnticoneSize *model.KType) (isBlue, isRed bool, err error) { // If blueCandidate is in the future of chainBlock, it means @@ -184,7 +185,7 @@ func (gm *ghostdagManager) checkBlueCandidateWithChainBlock(newBlockData *model. // blueAnticoneSize returns the blue anticone size of 'block' from the worldview of 'context'. // Expects 'block' to be in the blue set of 'context' -func (gm *ghostdagManager) blueAnticoneSize(block *model.DomainHash, context *model.BlockGHOSTDAGData) (model.KType, error) { +func (gm *ghostdagManager) blueAnticoneSize(block *externalapi.DomainHash, context *model.BlockGHOSTDAGData) (model.KType, error) { for current := context; current != nil; { if blueAnticoneSize, ok := current.BluesAnticoneSizes[*block]; ok { return blueAnticoneSize, nil diff --git a/domain/consensus/processes/ghostdagmanager/ghostdagmanager.go b/domain/consensus/processes/ghostdagmanager/ghostdagmanager.go index e6212ead0..dc3c65b50 100644 --- a/domain/consensus/processes/ghostdagmanager/ghostdagmanager.go +++ b/domain/consensus/processes/ghostdagmanager/ghostdagmanager.go @@ -3,6 +3,7 @@ package ghostdagmanager import ( "github.com/kaspanet/kaspad/domain/consensus/database" "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/infrastructure/db/dbaccess" ) @@ -31,6 +32,6 @@ func New( // BlockData returns previously calculated GHOSTDAG data for // the given blockHash -func (gm *ghostdagManager) BlockData(blockHash *model.DomainHash) (*model.BlockGHOSTDAGData, error) { +func (gm *ghostdagManager) BlockData(blockHash *externalapi.DomainHash) (*model.BlockGHOSTDAGData, error) { return gm.ghostdagDataStore.Get(gm.databaseContext, blockHash) } diff --git a/domain/consensus/processes/ghostdagmanager/mergeset.go b/domain/consensus/processes/ghostdagmanager/mergeset.go index 65ab33e67..b30f7287c 100644 --- a/domain/consensus/processes/ghostdagmanager/mergeset.go +++ b/domain/consensus/processes/ghostdagmanager/mergeset.go @@ -1,17 +1,17 @@ package ghostdagmanager import ( - "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "sort" ) -func (gm *ghostdagManager) mergeSet(selecteParent *model.DomainHash, - blockParents []*model.DomainHash) ([]*model.DomainHash, error) { +func (gm *ghostdagManager) mergeSet(selecteParent *externalapi.DomainHash, + blockParents []*externalapi.DomainHash) ([]*externalapi.DomainHash, error) { - mergeSetMap := make(map[model.DomainHash]struct{}, gm.k) - mergeSetSlice := make([]*model.DomainHash, 0, gm.k) - selectedParentPast := make(map[model.DomainHash]struct{}) - queue := []*model.DomainHash{} + mergeSetMap := make(map[externalapi.DomainHash]struct{}, gm.k) + mergeSetSlice := make([]*externalapi.DomainHash, 0, gm.k) + selectedParentPast := make(map[externalapi.DomainHash]struct{}) + queue := []*externalapi.DomainHash{} // Queueing all parents (other than the selected parent itself) for processing. for _, parent := range blockParents { if *parent == *selecteParent { @@ -23,7 +23,7 @@ func (gm *ghostdagManager) mergeSet(selecteParent *model.DomainHash, } for len(queue) > 0 { - var current *model.DomainHash + var current *externalapi.DomainHash current, queue = queue[0], queue[1:] // For each parent of the current block we check whether it is in the past of the selected parent. If not, // we add the it to the resulting anticone-set and queue it for further processing. @@ -64,7 +64,7 @@ func (gm *ghostdagManager) mergeSet(selecteParent *model.DomainHash, return mergeSetSlice, nil } -func (gm *ghostdagManager) sortMergeSet(mergeSetSlice []*model.DomainHash) error { +func (gm *ghostdagManager) sortMergeSet(mergeSetSlice []*externalapi.DomainHash) error { var err error sort.Slice(mergeSetSlice, func(i, j int) bool { if err != nil { diff --git a/domain/consensus/processes/pruningmanager/pruningmanager.go b/domain/consensus/processes/pruningmanager/pruningmanager.go index bb363d303..07c4a72ae 100644 --- a/domain/consensus/processes/pruningmanager/pruningmanager.go +++ b/domain/consensus/processes/pruningmanager/pruningmanager.go @@ -2,6 +2,7 @@ package pruningmanager import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // pruningManager resolves and manages the current pruning point @@ -32,13 +33,13 @@ func New( // FindNextPruningPoint finds the next pruning point from the // given blockHash. If none found, returns false func (pm *pruningManager) FindNextPruningPoint(blockGHOSTDAGData *model.BlockGHOSTDAGData) (found bool, - newPruningPoint *model.DomainHash, newPruningPointUTXOSet model.ReadOnlyUTXOSet, err error) { + newPruningPoint *externalapi.DomainHash, newPruningPointUTXOSet model.ReadOnlyUTXOSet, err error) { return false, nil, nil, nil } // PruningPoint returns the hash of the current pruning point -func (pm *pruningManager) PruningPoint() (*model.DomainHash, error) { +func (pm *pruningManager) PruningPoint() (*externalapi.DomainHash, error) { return nil, nil } diff --git a/domain/consensus/processes/reachabilitytree/reachabilitytree.go b/domain/consensus/processes/reachabilitytree/reachabilitytree.go index 144eafd48..3dbc1274a 100644 --- a/domain/consensus/processes/reachabilitytree/reachabilitytree.go +++ b/domain/consensus/processes/reachabilitytree/reachabilitytree.go @@ -2,6 +2,7 @@ package reachabilitytree import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // reachabilityTree maintains a structure that allows to answer @@ -24,19 +25,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 *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (rt *reachabilityTree) IsReachabilityTreeAncestorOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { return false, nil } // IsDAGAncestorOf returns true if blockHashA is an ancestor of // blockHashB in the DAG. -func (rt *reachabilityTree) IsDAGAncestorOf(blockHashA *model.DomainHash, blockHashB *model.DomainHash) (bool, error) { +func (rt *reachabilityTree) IsDAGAncestorOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) { return false, nil } // 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 *model.DomainHash, +func (rt *reachabilityTree) ReachabilityChangeset(blockHash *externalapi.DomainHash, blockGHOSTDAGData *model.BlockGHOSTDAGData) (*model.ReachabilityChangeset, error) { return nil, nil diff --git a/domain/consensus/processes/validator/validator.go b/domain/consensus/processes/validator/validator.go index f42b87fd9..d78fbd1b5 100644 --- a/domain/consensus/processes/validator/validator.go +++ b/domain/consensus/processes/validator/validator.go @@ -2,6 +2,7 @@ package validator import ( "github.com/kaspanet/kaspad/domain/consensus/model" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // validator exposes a set of validation classes, after which @@ -31,40 +32,40 @@ func New( // ValidateHeaderInIsolation validates block headers in isolation from the current // consensus state -func (v *validator) ValidateHeaderInIsolation(block *model.DomainBlock) error { +func (v *validator) ValidateHeaderInIsolation(block *externalapi.DomainBlock) error { return nil } // ValidateHeaderInContext validates block headers in the context of the current // consensus state -func (v *validator) ValidateHeaderInContext(block *model.DomainBlock) error { +func (v *validator) ValidateHeaderInContext(block *externalapi.DomainBlock) error { return nil } // ValidateBodyInIsolation validates block bodies in isolation from the current // consensus state -func (v *validator) ValidateBodyInIsolation(block *model.DomainBlock) error { +func (v *validator) ValidateBodyInIsolation(block *externalapi.DomainBlock) error { return nil } // ValidateBodyInContext validates block bodies in the context of the current // consensus state -func (v *validator) ValidateBodyInContext(block *model.DomainBlock) error { +func (v *validator) ValidateBodyInContext(block *externalapi.DomainBlock) error { return nil } // ValidateAgainstPastUTXO validates the block against the UTXO of its past -func (v *validator) ValidateAgainstPastUTXO(block *model.DomainBlock) error { +func (v *validator) ValidateAgainstPastUTXO(block *externalapi.DomainBlock) error { return nil } // ValidateFinality makes sure the block does not violate finality -func (v *validator) ValidateFinality(block *model.DomainBlock) error { +func (v *validator) ValidateFinality(block *externalapi.DomainBlock) error { return nil } -// ValidateTransactionAndCalculateFee validates the given transaction using -// the given utxoEntries. It also returns the transaction's fee -func (v *validator) ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error) { - return 0, nil +// ValidateTransactionAndPopulateWithConsensusData validates the given transaction +// and populates it with any missing consensus data +func (v *validator) ValidateTransactionAndPopulateWithConsensusData(transaction *externalapi.DomainTransaction) error { + return nil } diff --git a/domain/miningmanager/blocktemplatebuilder/blocktemplatebuilder.go b/domain/miningmanager/blocktemplatebuilder/blocktemplatebuilder.go index e6148e593..cdbe91e7e 100644 --- a/domain/miningmanager/blocktemplatebuilder/blocktemplatebuilder.go +++ b/domain/miningmanager/blocktemplatebuilder/blocktemplatebuilder.go @@ -2,18 +2,18 @@ package blocktemplatebuilder import ( "github.com/kaspanet/kaspad/domain/consensus" - consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model" - "github.com/kaspanet/kaspad/domain/miningmanager/model" + consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + miningmanagerapi "github.com/kaspanet/kaspad/domain/miningmanager/model" ) // blockTemplateBuilder creates block templates for a miner to consume type blockTemplateBuilder struct { consensus *consensus.Consensus - mempool model.Mempool + mempool miningmanagerapi.Mempool } // New creates a new blockTemplateBuilder -func New(consensus *consensus.Consensus, mempool model.Mempool) model.BlockTemplateBuilder { +func New(consensus *consensus.Consensus, mempool miningmanagerapi.Mempool) miningmanagerapi.BlockTemplateBuilder { return &blockTemplateBuilder{ consensus: consensus, mempool: mempool, @@ -21,6 +21,6 @@ func New(consensus *consensus.Consensus, mempool model.Mempool) model.BlockTempl } // GetBlockTemplate creates a block template for a miner to consume -func (btb *blockTemplateBuilder) GetBlockTemplate(payAddress model.DomainAddress, extraData []byte) *consensusmodel.DomainBlock { +func (btb *blockTemplateBuilder) GetBlockTemplate(coinbaseData *consensusexternalapi.CoinbaseData) *consensusexternalapi.DomainBlock { return nil } diff --git a/domain/miningmanager/mempool/mempool.go b/domain/miningmanager/mempool/mempool.go index 57300107d..93bc4038d 100644 --- a/domain/miningmanager/mempool/mempool.go +++ b/domain/miningmanager/mempool/mempool.go @@ -2,8 +2,8 @@ package mempool import ( "github.com/kaspanet/kaspad/domain/consensus" - consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model" - "github.com/kaspanet/kaspad/domain/miningmanager/model" + consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + miningmanagermodel "github.com/kaspanet/kaspad/domain/miningmanager/model" ) // mempool maintains a set of known transactions that @@ -13,24 +13,24 @@ type mempool struct { } // New creates a new mempool -func New(consensus *consensus.Consensus) model.Mempool { +func New(consensus *consensus.Consensus) miningmanagermodel.Mempool { return &mempool{ consensus: consensus, } } // HandleNewBlock handles a new block that was just added to the DAG -func (mp *mempool) HandleNewBlock(block *consensusmodel.DomainBlock) { +func (mp *mempool) HandleNewBlock(block *consensusexternalapi.DomainBlock) { } // Transactions returns all the transactions in the mempool -func (mp *mempool) Transactions() []*consensusmodel.DomainTransaction { +func (mp *mempool) Transactions() []*consensusexternalapi.DomainTransaction { return nil } // ValidateAndInsertTransaction validates the given transaction, and // adds it to the mempool -func (mp *mempool) ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error { +func (mp *mempool) ValidateAndInsertTransaction(transaction *consensusexternalapi.DomainTransaction) error { return nil } diff --git a/domain/miningmanager/miningmanager.go b/domain/miningmanager/miningmanager.go index 52cb98cf3..d09912955 100644 --- a/domain/miningmanager/miningmanager.go +++ b/domain/miningmanager/miningmanager.go @@ -1,36 +1,36 @@ package miningmanager import ( - consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model" - "github.com/kaspanet/kaspad/domain/miningmanager/model" + consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + miningmanagermodel "github.com/kaspanet/kaspad/domain/miningmanager/model" ) // MiningManager creates block templates for mining as well as maintaining // known transactions that have no yet been added to any block type MiningManager interface { - GetBlockTemplate(payAddress model.DomainAddress, extraData []byte) *consensusmodel.DomainBlock - HandleNewBlock(block *consensusmodel.DomainBlock) - ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error + GetBlockTemplate(coinbaseData *consensusexternalapi.CoinbaseData) *consensusexternalapi.DomainBlock + HandleNewBlock(block *consensusexternalapi.DomainBlock) + ValidateAndInsertTransaction(transaction *consensusexternalapi.DomainTransaction) error } type miningManager struct { - mempool model.Mempool - blockTemplateBuilder model.BlockTemplateBuilder + mempool miningmanagermodel.Mempool + blockTemplateBuilder miningmanagermodel.BlockTemplateBuilder } // GetBlockTemplate creates a block template for a miner to consume -func (mm *miningManager) GetBlockTemplate(payAddress model.DomainAddress, extraData []byte) *consensusmodel.DomainBlock { - return mm.blockTemplateBuilder.GetBlockTemplate(payAddress, extraData) +func (mm *miningManager) GetBlockTemplate(coinbaseData *consensusexternalapi.CoinbaseData) *consensusexternalapi.DomainBlock { + return mm.blockTemplateBuilder.GetBlockTemplate(coinbaseData) } // HandleNewBlock handles a new block that was just added to the DAG -func (mm *miningManager) HandleNewBlock(block *consensusmodel.DomainBlock) { +func (mm *miningManager) HandleNewBlock(block *consensusexternalapi.DomainBlock) { mm.mempool.HandleNewBlock(block) } // ValidateAndInsertTransaction validates the given transaction, and // adds it to the set of known transactions that have not yet been // added to any block -func (mm *miningManager) ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error { +func (mm *miningManager) ValidateAndInsertTransaction(transaction *consensusexternalapi.DomainTransaction) error { return mm.mempool.ValidateAndInsertTransaction(transaction) } diff --git a/domain/miningmanager/model/address.go b/domain/miningmanager/model/address.go deleted file mode 100644 index a298e630a..000000000 --- a/domain/miningmanager/model/address.go +++ /dev/null @@ -1,7 +0,0 @@ -package model - -// DomainAddress is the domain representation of a kaspad -// address -type DomainAddress interface { - ScriptAddress() []byte -} diff --git a/domain/miningmanager/model/interface_blocktemplatebuilder.go b/domain/miningmanager/model/interface_blocktemplatebuilder.go index 991f6b51a..770d3ee13 100644 --- a/domain/miningmanager/model/interface_blocktemplatebuilder.go +++ b/domain/miningmanager/model/interface_blocktemplatebuilder.go @@ -1,10 +1,10 @@ package model import ( - consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model" + consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // BlockTemplateBuilder builds block templates for miners to consume type BlockTemplateBuilder interface { - GetBlockTemplate(payAddress DomainAddress, extraData []byte) *consensusmodel.DomainBlock + GetBlockTemplate(coinbaseData *consensusexternalapi.CoinbaseData) *consensusexternalapi.DomainBlock } diff --git a/domain/miningmanager/model/interface_mempool.go b/domain/miningmanager/model/interface_mempool.go index e44486f14..74cdff2e9 100644 --- a/domain/miningmanager/model/interface_mempool.go +++ b/domain/miningmanager/model/interface_mempool.go @@ -1,13 +1,13 @@ package model import ( - consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model" + consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" ) // Mempool maintains a set of known transactions that // are intended to be mined into new blocks type Mempool interface { - HandleNewBlock(block *consensusmodel.DomainBlock) - Transactions() []*consensusmodel.DomainTransaction - ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error + HandleNewBlock(block *consensusexternalapi.DomainBlock) + Transactions() []*consensusexternalapi.DomainTransaction + ValidateAndInsertTransaction(transaction *consensusexternalapi.DomainTransaction) error }