mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1460] Make the miningmanager package structure similar to consensus package's (#957)
* [NOD-1460] Move the miningmanager interfaces into its model package. * [NOD-1460] Decouple miningmanager model from appmessage. * [NOD-1460] Decouple miningmanager model from util. * [NOD-1460] Make miningmanager implementation structs unexported.
This commit is contained in:
parent
eef5f27a87
commit
db475bd511
@ -1,24 +1,26 @@
|
||||
package blocktemplatebuilder
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/app/appmessage"
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/model"
|
||||
)
|
||||
|
||||
// BlockTemplateBuilder creates block templates for a miner to consume
|
||||
type BlockTemplateBuilder struct {
|
||||
// blockTemplateBuilder creates block templates for a miner to consume
|
||||
type blockTemplateBuilder struct {
|
||||
consensus *consensus.Consensus
|
||||
mempool model.Mempool
|
||||
}
|
||||
|
||||
// New creates a new BlockTemplateBuilder
|
||||
func New(consensus *consensus.Consensus) *BlockTemplateBuilder {
|
||||
return &BlockTemplateBuilder{
|
||||
// New creates a new blockTemplateBuilder
|
||||
func New(consensus *consensus.Consensus, mempool model.Mempool) model.BlockTemplateBuilder {
|
||||
return &blockTemplateBuilder{
|
||||
consensus: consensus,
|
||||
mempool: mempool,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBlockTemplate creates a block template for a miner to consume
|
||||
func (btb *BlockTemplateBuilder) GetBlockTemplate(payAddress util.Address, extraData []byte) *appmessage.MsgBlock {
|
||||
func (btb *blockTemplateBuilder) GetBlockTemplate(payAddress model.DomainAddress, extraData []byte) *consensusmodel.DomainBlock {
|
||||
return nil
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package miningmanager
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/blocktemplatebuilder"
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
||||
mempoolpkg "github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
||||
)
|
||||
|
||||
// Factory instantiates new mining managers
|
||||
@ -15,9 +15,12 @@ type factory struct{}
|
||||
|
||||
// NewMiningManager instantiate a new mining manager
|
||||
func (f *factory) NewMiningManager(consensus *consensus.Consensus) MiningManager {
|
||||
mempool := mempoolpkg.New(consensus)
|
||||
blockTemplateBuilder := blocktemplatebuilder.New(consensus, mempool)
|
||||
|
||||
return &miningManager{
|
||||
mempool: mempool.New(consensus),
|
||||
blockTemplateBuilder: blocktemplatebuilder.New(consensus),
|
||||
mempool: mempool,
|
||||
blockTemplateBuilder: blockTemplateBuilder,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
package miningmanager
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/app/appmessage"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
)
|
||||
|
||||
// Mempool maintains a set of known transactions that
|
||||
// are intended to be mined into new blocks
|
||||
type Mempool interface {
|
||||
HandleNewBlock(block *appmessage.MsgBlock)
|
||||
Transactions() []*util.Tx
|
||||
ValidateAndInsertTransaction(transaction *appmessage.MsgTx) error
|
||||
}
|
||||
|
||||
// BlockTemplateBuilder builds block templates for miners to consume
|
||||
type BlockTemplateBuilder interface {
|
||||
GetBlockTemplate(payAddress util.Address, extraData []byte) *appmessage.MsgBlock
|
||||
}
|
@ -1,36 +1,36 @@
|
||||
package mempool
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/app/appmessage"
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/model"
|
||||
)
|
||||
|
||||
// Mempool maintains a set of known transactions that
|
||||
// mempool maintains a set of known transactions that
|
||||
// are intended to be mined into new blocks
|
||||
type Mempool struct {
|
||||
type mempool struct {
|
||||
consensus *consensus.Consensus
|
||||
}
|
||||
|
||||
// New create a new Mempool
|
||||
func New(consensus *consensus.Consensus) *Mempool {
|
||||
return &Mempool{
|
||||
// New creates a new mempool
|
||||
func New(consensus *consensus.Consensus) model.Mempool {
|
||||
return &mempool{
|
||||
consensus: consensus,
|
||||
}
|
||||
}
|
||||
|
||||
// HandleNewBlock handles a new block that was just added to the DAG
|
||||
func (mp *Mempool) HandleNewBlock(block *appmessage.MsgBlock) {
|
||||
func (mp *mempool) HandleNewBlock(block *consensusmodel.DomainBlock) {
|
||||
|
||||
}
|
||||
|
||||
// Transactions returns all the transactions in the mempool
|
||||
func (mp *Mempool) Transactions() []*util.Tx {
|
||||
func (mp *mempool) Transactions() []*consensusmodel.DomainTransaction {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateAndInsertTransaction validates the given transaction, and
|
||||
// adds it to the mempool
|
||||
func (mp *Mempool) ValidateAndInsertTransaction(transaction *appmessage.MsgTx) error {
|
||||
func (mp *mempool) ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
package miningmanager
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/app/appmessage"
|
||||
"github.com/kaspanet/kaspad/util"
|
||||
consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"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 util.Address, extraData []byte) *appmessage.MsgBlock
|
||||
HandleNewBlock(block *appmessage.MsgBlock)
|
||||
ValidateAndInsertTransaction(transaction *appmessage.MsgTx) error
|
||||
GetBlockTemplate(payAddress model.DomainAddress, extraData []byte) *consensusmodel.DomainBlock
|
||||
HandleNewBlock(block *consensusmodel.DomainBlock)
|
||||
ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error
|
||||
}
|
||||
|
||||
type miningManager struct {
|
||||
mempool Mempool
|
||||
blockTemplateBuilder BlockTemplateBuilder
|
||||
mempool model.Mempool
|
||||
blockTemplateBuilder model.BlockTemplateBuilder
|
||||
}
|
||||
|
||||
// GetBlockTemplate creates a block template for a miner to consume
|
||||
func (mm *miningManager) GetBlockTemplate(payAddress util.Address, extraData []byte) *appmessage.MsgBlock {
|
||||
func (mm *miningManager) GetBlockTemplate(payAddress model.DomainAddress, extraData []byte) *consensusmodel.DomainBlock {
|
||||
return mm.blockTemplateBuilder.GetBlockTemplate(payAddress, extraData)
|
||||
}
|
||||
|
||||
// HandleNewBlock handles a new block that was just added to the DAG
|
||||
func (mm *miningManager) HandleNewBlock(block *appmessage.MsgBlock) {
|
||||
func (mm *miningManager) HandleNewBlock(block *consensusmodel.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 *appmessage.MsgTx) error {
|
||||
func (mm *miningManager) ValidateAndInsertTransaction(transaction *consensusmodel.DomainTransaction) error {
|
||||
return mm.mempool.ValidateAndInsertTransaction(transaction)
|
||||
}
|
||||
|
7
domain/miningmanager/model/address.go
Normal file
7
domain/miningmanager/model/address.go
Normal file
@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
// DomainAddress is the domain representation of a kaspad
|
||||
// address
|
||||
type DomainAddress interface {
|
||||
ScriptAddress() []byte
|
||||
}
|
10
domain/miningmanager/model/interface_blocktemplatebuilder.go
Normal file
10
domain/miningmanager/model/interface_blocktemplatebuilder.go
Normal file
@ -0,0 +1,10 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
)
|
||||
|
||||
// BlockTemplateBuilder builds block templates for miners to consume
|
||||
type BlockTemplateBuilder interface {
|
||||
GetBlockTemplate(payAddress DomainAddress, extraData []byte) *consensusmodel.DomainBlock
|
||||
}
|
13
domain/miningmanager/model/interface_mempool.go
Normal file
13
domain/miningmanager/model/interface_mempool.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
consensusmodel "github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user