mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1462] Simplify consensus external API (#958)
* [NOD-1461] Change the external api interface to not having anything besides DomainTransactions and DomainBlocks. * [NOD-1462] Move external api types to a separate package. * [NOD-1462] Clarify which model we're using in miningmanager. * [NOD-1462] Extract coinbase data to its own struct. * [NOD-1462] Add a comment above CoinbaseData. * [NOD-1462] Fix the comment above CoinbaseData.
This commit is contained in:
parent
9a62fae012
commit
a96a5fd2ef
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package model
|
||||
package externalapi
|
||||
|
||||
// DomainBlock represents a Kaspa block
|
||||
type DomainBlock struct {
|
8
domain/consensus/model/externalapi/coinbasedata.go
Normal file
8
domain/consensus/model/externalapi/coinbasedata.go
Normal file
@ -0,0 +1,8 @@
|
||||
package externalapi
|
||||
|
||||
// CoinbaseData contains data by which a coinbase transaction
|
||||
// is built
|
||||
type CoinbaseData struct {
|
||||
scriptPublicKey []byte
|
||||
extraData []byte
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package model
|
||||
package externalapi
|
||||
|
||||
// DomainHash is the domain representation of a daghash.Hash
|
||||
type DomainHash [32]byte
|
@ -1,4 +1,4 @@
|
||||
package model
|
||||
package externalapi
|
||||
|
||||
// DomainSubnetworkID is the domain representation of a Subnetwork ID
|
||||
type DomainSubnetworkID [20]byte
|
@ -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
|
@ -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
|
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
package model
|
||||
|
||||
// DomainAddress is the domain representation of a kaspad
|
||||
// address
|
||||
type DomainAddress interface {
|
||||
ScriptAddress() []byte
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user