Skip to content

Commit

Permalink
[NOD-1413] Make some additional interface changes (#954)
Browse files Browse the repository at this point in the history
* [NOD-1413] Remove /cmd/addblock

* [NOD-1413] Define and implement TransactionValidator.

* [NOD-1413] Make changes to ConsensusStateManager's interface.

* [NOD-1413] Make changes to PruningManager's interface.

* [NOD-1413] Make changes to DAGTraversalManager's interface.

* [NOD-1413] Make changes to MultisetStore's interface.

* [NOD-1413] Make changes to UTXODiffStore's interface.

* [NOD-1413] Make changes to UTXODiffStore's interface harder.

* [NOD-1413] Make changes to AcceptanceDataStore's interface harder.

* [NOD-1413] Make changes to PruningStore's interface.

* [NOD-1413] Delete BlockIndex.

* [NOD-1413] Add FeeDataStore.

* [NOD-1413] Update BlockMessageStore's interface.

* [NOD-1413] Fix interface violations.

* [NOD-1413] Add FeeDataStore to BlockProcessor.

* [NOD-1413] Make go vet happy.

* [NOD-1413] Add missing fields to ConsensusStateChanges.

* [NOD-1413] Add another missing field to ConsensusStateChanges.

* [NOD-1413] Add a reference to blockStore in consensusStateManager.

* [NOD-1413] Add missing methods to UTXODiffStore.

* [NOD-1413] Rename pruningPointStore to pruningStore everywhere.

* [NOD-1413] Remove superfluous parameters from CalculateConsensusStateChanges.

* [NOD-1413] Add missing dependencies to PruningManager.

* [NOD-1413] Remove implementation-y functions from TransactionValidator's interface.

* [NOD-1413] Make go vet happy.

* [NOD-1413] Add a couple of methods to DAGTopologyManager.

* [NOD-1413] Fix a typo in a file name.

* [NOD-1413] Remove non-interface functions from Validator.
  • Loading branch information
stasatdaglabs committed Oct 13, 2020
1 parent 04ead57 commit 4f36acc
Show file tree
Hide file tree
Showing 36 changed files with 325 additions and 191 deletions.
9 changes: 5 additions & 4 deletions domain/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (

// Consensus maintains the current core state of the node
type Consensus interface {
BuildBlock(scriptPublicKey []byte, extraData []byte, transactionSelector model.TransactionSelector) *model.DomainBlock
BuildBlock(coinbaseScriptPublicKey []byte, coinbaseExtraData []byte, transactionSelector model.TransactionSelector) *model.DomainBlock
ValidateAndInsertBlock(block *model.DomainBlock) error
UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEntry
ValidateTransaction(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) error
ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error)
}

type consensus struct {
blockProcessor model.BlockProcessor
consensusStateManager model.ConsensusStateManager
transactionValidator model.TransactionValidator
}

// BuildBlock builds a block over the current state, with the transactions
Expand All @@ -38,6 +39,6 @@ func (s *consensus) UTXOByOutpoint(outpoint *model.DomainOutpoint) *model.UTXOEn

// ValidateTransaction validates the given transaction using
// the given utxoEntries
func (s *consensus) ValidateTransaction(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) error {
return s.consensusStateManager.ValidateTransaction(transaction, utxoEntries)
func (s *consensus) ValidateTransactionAndCalculateFee(transaction *model.DomainTransaction, utxoEntries []*model.UTXOEntry) (fee uint64, err error) {
return s.transactionValidator.ValidateTransactionAndCalculateFee(transaction, utxoEntries)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ func (ads *AcceptanceDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.Do
func (ads *AcceptanceDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.BlockAcceptanceData {
return nil
}

// Delete deletes the acceptanceData associated with the given blockHash
func (ads *AcceptanceDataStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) {

}
24 changes: 0 additions & 24 deletions domain/consensus/datastructures/blockindex/blockindex.go

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ func (bss *BlockStatusStore) Insert(dbTx model.DBTxProxy, blockHash *model.Domai
func (bss *BlockStatusStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) model.BlockStatus {
return 0
}

// Exists returns true if the blockStatus for the given blockHash exists
func (bss *BlockStatusStore) Exists(dbContext model.DBContextProxy, blockHash *model.DomainHash) bool {
return false
}
34 changes: 34 additions & 0 deletions domain/consensus/datastructures/blockstore/blockstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package blockstore

import (
"github.com/kaspanet/kaspad/domain/consensus/model"
)

// BlockStore represents a store of blocks
type BlockStore struct {
}

// New instantiates a new BlockStore
func New() *BlockStore {
return &BlockStore{}
}

// Insert inserts the given block for the given blockHash
func (bms *BlockStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, msgBlock *model.DomainBlock) {

}

// Block gets the block associated with the given blockHash
func (bms *BlockStore) Block(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.DomainBlock {
return nil
}

// Blocks gets the blocks associated with the given blockHashes
func (bms *BlockStore) Blocks(dbContext model.DBContextProxy, blockHashes []*model.DomainHash) []*model.DomainBlock {
return nil
}

// Delete deletes the block associated with the given blockHash
func (bms *BlockStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) {

}
22 changes: 22 additions & 0 deletions domain/consensus/datastructures/feedatastore/feedatastore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package feedatastore

import "github.com/kaspanet/kaspad/domain/consensus/model"

// FeeDataStore represents a store of fee data
type FeeDataStore struct {
}

// New instantiates a new FeeDataStore
func New() *FeeDataStore {
return &FeeDataStore{}
}

// Insert inserts the given fee for the given blockHash
func (ads *FeeDataStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, fee uint64) {

}

// Get gets the fee associated with the given blockHash
func (ads *FeeDataStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) uint64 {
return 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ func (ms *MultisetStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHas
func (ms *MultisetStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) model.Multiset {
return nil
}

// Delete deletes the multiset associated with the given blockHash
func (ms *MultisetStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) {

}

This file was deleted.

29 changes: 29 additions & 0 deletions domain/consensus/datastructures/pruningstore/pruningstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pruningstore

import (
"github.com/kaspanet/kaspad/domain/consensus/model"
)

// PruningStore represents a store for the current pruning state
type PruningStore struct {
}

// New instantiates a new PruningStore
func New() *PruningStore {
return &PruningStore{}
}

// Update updates the pruning state
func (pps *PruningStore) Update(dbTx model.DBTxProxy, pruningPointBlockHash *model.DomainHash, pruningPointUTXOSet model.ReadOnlyUTXOSet) {

}

// PruningPoint gets the current pruning point
func (pps *PruningStore) PruningPoint(dbContext model.DBContextProxy) *model.DomainHash {
return nil
}

// PruningPointSerializedUTXOSet returns the serialized UTXO set of the current pruning point
func (pps *PruningStore) PruningPointSerializedUTXOSet(dbContext model.DBContextProxy) []byte {
return nil
}
16 changes: 13 additions & 3 deletions domain/consensus/datastructures/utxodiffstore/utxodiffstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ func New() *UTXODiffStore {
}

// Insert inserts the given utxoDiff for the given blockHash
func (uds *UTXODiffStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, utxoDiff *model.UTXODiff) {
func (uds *UTXODiffStore) Insert(dbTx model.DBTxProxy, blockHash *model.DomainHash, utxoDiff *model.UTXODiff, utxoDiffChild *model.DomainHash) {

}

// Get gets the utxoDiff associated with the given blockHash
func (uds *UTXODiffStore) Get(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.UTXODiff {
// UTXODiff gets the utxoDiff associated with the given blockHash
func (uds *UTXODiffStore) UTXODiff(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.UTXODiff {
return nil
}

// UTXODiffChild gets the utxoDiff child associated with the given blockHash
func (uds *UTXODiffStore) UTXODiffChild(dbContext model.DBContextProxy, blockHash *model.DomainHash) *model.DomainHash {
return nil
}

// Delete deletes the utxoDiff associated with the given blockHash
func (uds *UTXODiffStore) Delete(dbTx model.DBTxProxy, blockHash *model.DomainHash) {

}
37 changes: 21 additions & 16 deletions domain/consensus/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package consensus

import (
"github.com/kaspanet/kaspad/domain/consensus/datastructures/acceptancedatastore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/blockindex"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/blockmessagestore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/blockrelationstore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/blockstatusstore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/blockstore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/consensusstatestore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/feedatastore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/ghostdagdatastore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/multisetstore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/pruningpointstore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/pruningstore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/reachabilitydatastore"
"github.com/kaspanet/kaspad/domain/consensus/datastructures/utxodiffstore"
"github.com/kaspanet/kaspad/domain/consensus/processes/blockprocessor"
"github.com/kaspanet/kaspad/domain/consensus/processes/blockvalidator"
"github.com/kaspanet/kaspad/domain/consensus/processes/consensusstatemanager"
"github.com/kaspanet/kaspad/domain/consensus/processes/dagtopologymanager"
"github.com/kaspanet/kaspad/domain/consensus/processes/dagtraversalmanager"
"github.com/kaspanet/kaspad/domain/consensus/processes/ghostdagmanager"
"github.com/kaspanet/kaspad/domain/consensus/processes/pruningmanager"
"github.com/kaspanet/kaspad/domain/consensus/processes/reachabilitytree"
validatorpkg "github.com/kaspanet/kaspad/domain/consensus/processes/validator"
"github.com/kaspanet/kaspad/domain/dagconfig"
"github.com/kaspanet/kaspad/infrastructure/db/dbaccess"
)
Expand All @@ -35,19 +35,18 @@ type factory struct{}
func (f *factory) NewConsensus(dagParams *dagconfig.Params, databaseContext *dbaccess.DatabaseContext) Consensus {
// Data Structures
acceptanceDataStore := acceptancedatastore.New()
blockIndex := blockindex.New()
blockMessageStore := blockmessagestore.New()
blockStore := blockstore.New()
blockRelationStore := blockrelationstore.New()
blockStatusStore := blockstatusstore.New()
multisetStore := multisetstore.New()
pruningPointStore := pruningpointstore.New()
pruningStore := pruningstore.New()
reachabilityDataStore := reachabilitydatastore.New()
utxoDiffStore := utxodiffstore.New()
consensusStateStore := consensusstatestore.New()
ghostdagDataStore := ghostdagdatastore.New()
feeDataStore := feedatastore.New()

// Processes
blockValidator := blockvalidator.New()
reachabilityTree := reachabilitytree.New(
blockRelationStore,
reachabilityDataStore)
Expand All @@ -61,30 +60,36 @@ func (f *factory) NewConsensus(dagParams *dagconfig.Params, databaseContext *dba
dagTraversalManager := dagtraversalmanager.New(
dagTopologyManager,
ghostdagManager)
pruningManager := pruningmanager.New(
dagTraversalManager,
pruningPointStore)
consensusStateManager := consensusstatemanager.New(
dagParams,
consensusStateStore,
multisetStore,
utxoDiffStore)
utxoDiffStore,
blockStore)
pruningManager := pruningmanager.New(
dagTraversalManager,
pruningStore,
dagTopologyManager,
blockStatusStore,
consensusStateManager)
validator := validatorpkg.New(consensusStateManager)
blockProcessor := blockprocessor.New(
dagParams,
databaseContext,
consensusStateManager,
pruningManager,
blockValidator,
validator,
dagTopologyManager,
reachabilityTree,
acceptanceDataStore,
blockIndex,
blockMessageStore,
blockStatusStore)
blockStore,
blockStatusStore,
feeDataStore)

return &consensus{
consensusStateManager: consensusStateManager,
blockProcessor: blockProcessor,
transactionValidator: validator,
}
}

Expand Down
9 changes: 7 additions & 2 deletions domain/consensus/model/consensusstatechanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package model
// 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
UTXODiff *UTXODiff
AcceptanceData *BlockAcceptanceData
VirtualUTXODiff *UTXODiff
NewTips []*DomainHash

NewBlockUTXODiff *UTXODiff
NewBlockMultiset Multiset
ParentDiffChanges *map[*DomainHash]UTXODiff
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package model
type AcceptanceDataStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, acceptanceData *BlockAcceptanceData)
Get(dbContext DBContextProxy, blockHash *DomainHash) *BlockAcceptanceData
Delete(dbTx DBTxProxy, blockHash *DomainHash)
}
9 changes: 9 additions & 0 deletions domain/consensus/model/interface_datastructures_block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

// BlockStore represents a store of blocks
type BlockStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, block *DomainBlock)
Block(dbContext DBContextProxy, blockHash *DomainHash) *DomainBlock
Blocks(dbContext DBContextProxy, blockHashes []*DomainHash) []*DomainBlock
Delete(dbTx DBTxProxy, blockHash *DomainHash)
}
7 changes: 0 additions & 7 deletions domain/consensus/model/interface_datastructures_blockindex.go

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package model
type BlockStatusStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, blockStatus BlockStatus)
Get(dbContext DBContextProxy, blockHash *DomainHash) BlockStatus
Exists(dbContext DBContextProxy, blockHash *DomainHash) bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package model

// FeeDataStore represents a store of fee data
type FeeDataStore interface {
Insert(dbTx DBTxProxy, blockHash *DomainHash, fee uint64)
Get(dbContext DBContextProxy, blockHash *DomainHash) uint64
}
Loading

0 comments on commit 4f36acc

Please sign in to comment.