mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-29 08:28:50 +00:00
Added model and stubs for all main methods
This commit is contained in:
parent
d1df97c4c5
commit
94ddf0aab0
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain"
|
"github.com/kaspanet/kaspad/domain"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool_old"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -175,14 +175,14 @@ func (flow *handleRelayedTransactionsFlow) receiveTransactions(requestedTransact
|
|||||||
|
|
||||||
err = flow.Domain().MiningManager().ValidateAndInsertTransaction(tx, true)
|
err = flow.Domain().MiningManager().ValidateAndInsertTransaction(tx, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ruleErr := &mempool.RuleError{}
|
ruleErr := &mempool_old.RuleError{}
|
||||||
if !errors.As(err, ruleErr) {
|
if !errors.As(err, ruleErr) {
|
||||||
return errors.Wrapf(err, "failed to process transaction %s", txID)
|
return errors.Wrapf(err, "failed to process transaction %s", txID)
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldBan := true
|
shouldBan := true
|
||||||
if txRuleErr := (&mempool.TxRuleError{}); errors.As(ruleErr.Err, txRuleErr) {
|
if txRuleErr := (&mempool_old.TxRuleError{}); errors.As(ruleErr.Err, txRuleErr) {
|
||||||
if txRuleErr.RejectCode != mempool.RejectInvalid {
|
if txRuleErr.RejectCode != mempool_old.RejectInvalid {
|
||||||
shouldBan = false
|
shouldBan = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool_old"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -23,7 +23,7 @@ func HandleSubmitTransaction(context *rpccontext.Context, _ *router.Router, requ
|
|||||||
transactionID := consensushashing.TransactionID(domainTransaction)
|
transactionID := consensushashing.TransactionID(domainTransaction)
|
||||||
err = context.ProtocolManager.AddTransaction(domainTransaction)
|
err = context.ProtocolManager.AddTransaction(domainTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.As(err, &mempool.RuleError{}) {
|
if !errors.As(err, &mempool_old.RuleError{}) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/domain/dagconfig"
|
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/blocktemplatebuilder"
|
"github.com/kaspanet/kaspad/domain/miningmanager/blocktemplatebuilder"
|
||||||
mempoolpkg "github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
mempoolpkg "github.com/kaspanet/kaspad/domain/miningmanager/mempool_old"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Factory instantiates new mining managers
|
// Factory instantiates new mining managers
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
17
domain/miningmanager/mempool/mempool_utxo_set.go
Normal file
17
domain/miningmanager/mempool/mempool_utxo_set.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package mempool
|
||||||
|
|
||||||
|
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
|
||||||
|
type outpointToUTXOEntry map[externalapi.DomainOutpoint]externalapi.UTXOEntry
|
||||||
|
|
||||||
|
type mempoolUTXOSet struct {
|
||||||
|
poolUnspentOutputs outpointToUTXOEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mpus *mempoolUTXOSet) getParentsInPool(transaction *mempoolTransaction) ([]*mempoolTransaction, error) {
|
||||||
|
panic("mempoolUTXOSet.getParentsInPool not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mpus *mempoolUTXOSet) addTransaction(transaction *mempoolTransaction) error {
|
||||||
|
panic("mempoolUTXOSet.addTransaction not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
18
domain/miningmanager/mempool/model.go
Normal file
18
domain/miningmanager/mempool/model.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package mempool
|
||||||
|
|
||||||
|
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
|
||||||
|
type idToTransaction map[externalapi.DomainTransactionID]*mempoolTransaction
|
||||||
|
|
||||||
|
type mempoolTransaction struct {
|
||||||
|
transaction externalapi.DomainTransaction
|
||||||
|
parentsInPool idToTransaction
|
||||||
|
isHighPriority bool
|
||||||
|
addAtDAAScore uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type orphanTransaction struct {
|
||||||
|
transaction externalapi.DomainTransaction
|
||||||
|
isHighPriority bool
|
||||||
|
addedAtDAAScore uint64
|
||||||
|
}
|
||||||
35
domain/miningmanager/mempool/orphan_pool.go
Normal file
35
domain/miningmanager/mempool/orphan_pool.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package mempool
|
||||||
|
|
||||||
|
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
|
||||||
|
type orphanByPreviousOutpoint map[externalapi.DomainOutpoint]idToTransaction
|
||||||
|
|
||||||
|
type orphansPool struct {
|
||||||
|
allOrphans idToTransaction
|
||||||
|
orphanByPreviousOutpoint orphanByPreviousOutpoint
|
||||||
|
previousExpireScan uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (op *orphansPool) maybeAddOrphan(transaction *externalapi.DomainTransaction,
|
||||||
|
missingParents []*externalapi.DomainTransactionID, isHighPriority bool) error {
|
||||||
|
|
||||||
|
panic("orphansPool.maybeAddOrphan not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (op *orphansPool) processOrphansAfterAcceptedTransaction(acceptedTransaction *mempoolTransaction) (
|
||||||
|
acceptedOrphans []*mempoolTransaction, err error) {
|
||||||
|
|
||||||
|
panic("orphansPool.processOrphansAfterAcceptedTransaction not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (op *orphansPool) unorphanTransaction(orphanTransactionID *externalapi.DomainTransactionID) (mempoolTransaction, error) {
|
||||||
|
panic("orphansPool.unorphanTransaction not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (op *orphansPool) removeOrphan(orphanTransactionID *externalapi.DomainTransactionID) error {
|
||||||
|
panic("orphansPool.removeOrphan not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (op *orphansPool) expireOrphanTransactions() error {
|
||||||
|
panic("orphansPool.expireOrphanTransactions not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
26
domain/miningmanager/mempool/transactions_pool.go
Normal file
26
domain/miningmanager/mempool/transactions_pool.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package mempool
|
||||||
|
|
||||||
|
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
|
||||||
|
type outpointToTransaction map[externalapi.DomainOutpoint]*mempoolTransaction
|
||||||
|
|
||||||
|
type transactionsByFeeHeap []*mempoolTransaction
|
||||||
|
|
||||||
|
type transactionsPool struct {
|
||||||
|
allTransactions idToTransaction
|
||||||
|
highPriorityTransactions idToTransaction
|
||||||
|
chainedTransactionsByPreviousOutpoint outpointToTransaction
|
||||||
|
transactionsByFeeRate transactionsByFeeHeap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tp *transactionsPool) addTransaction(transaction *externalapi.DomainTransaction, parentsInPool []*mempoolTransaction) error {
|
||||||
|
panic("transactionsPool.addTransaction not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tp *transactionsPool) addMempoolTransaction(transaction mempoolTransaction) error {
|
||||||
|
panic("transactionsPool.addMempoolTransaction not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tp *transactionsPool) expireOldTransactions() error {
|
||||||
|
panic("transactionsPool.expireOldTransactions not implemented") // TODO (Mike)
|
||||||
|
}
|
||||||
@ -59,10 +59,10 @@ be an exhaustive list.
|
|||||||
Errors
|
Errors
|
||||||
|
|
||||||
Errors returned by this package are either the raw errors provided by underlying
|
Errors returned by this package are either the raw errors provided by underlying
|
||||||
calls or of type mempool.RuleError. Since there are two classes of rules
|
calls or of type mempool_old.RuleError. Since there are two classes of rules
|
||||||
(mempool acceptance rules and blockDAG (consensus) acceptance rules), the
|
(mempool acceptance rules and blockDAG (consensus) acceptance rules), the
|
||||||
mempool.RuleError type contains a single Err field which will, in turn, either
|
mempool_old.RuleError type contains a single Err field which will, in turn, either
|
||||||
be a mempool.TxRuleError or a ruleerrors.RuleError. The first indicates a
|
be a mempool_old.TxRuleError or a ruleerrors.RuleError. The first indicates a
|
||||||
violation of mempool acceptance rules while the latter indicates a violation of
|
violation of mempool acceptance rules while the latter indicates a violation of
|
||||||
consensus acceptance rules. This allows the caller to easily differentiate
|
consensus acceptance rules. This allows the caller to easily differentiate
|
||||||
between unexpected errors, such as database errors, versus errors due to rule
|
between unexpected errors, such as database errors, versus errors due to rule
|
||||||
@ -70,4 +70,4 @@ violations through type assertions. In addition, callers can programmatically
|
|||||||
determine the specific rule violation by type asserting the Err field to one of
|
determine the specific rule violation by type asserting the Err field to one of
|
||||||
the aforementioned types and examining their underlying ErrorCode field.
|
the aforementioned types and examining their underlying ErrorCode field.
|
||||||
*/
|
*/
|
||||||
package mempool
|
package mempool_old
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package mempool
|
package mempool_old
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
11
domain/miningmanager/mempool_old/log.go
Normal file
11
domain/miningmanager/mempool_old/log.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (c) 2013-2016 The btcsuite developers
|
||||||
|
// Use of this source code is governed by an ISC
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package mempool_old
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = logger.RegisterSubSystem("TXMP")
|
||||||
1045
domain/miningmanager/mempool_old/mempool.go
Normal file
1045
domain/miningmanager/mempool_old/mempool.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
package mempool
|
package mempool_old
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
@ -2,10 +2,11 @@
|
|||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package mempool
|
package mempool_old
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||||
|
|
||||||
consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package mempool
|
package mempool_old
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -1,10 +1,11 @@
|
|||||||
package miningmanager_test
|
package miningmanager_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool_old"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
"github.com/kaspanet/kaspad/domain/consensus"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/testapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/testapi"
|
||||||
@ -84,8 +85,8 @@ func TestImmatureSpend(t *testing.T) {
|
|||||||
miningManager := miningFactory.NewMiningManager(tc, &consensusConfig.Params)
|
miningManager := miningFactory.NewMiningManager(tc, &consensusConfig.Params)
|
||||||
tx := createTransactionWithUTXOEntry(t, 0)
|
tx := createTransactionWithUTXOEntry(t, 0)
|
||||||
err = miningManager.ValidateAndInsertTransaction(tx, false)
|
err = miningManager.ValidateAndInsertTransaction(tx, false)
|
||||||
txRuleError := &mempool.TxRuleError{}
|
txRuleError := &mempool_old.TxRuleError{}
|
||||||
if !errors.As(err, txRuleError) || txRuleError.RejectCode != mempool.RejectImmatureSpend {
|
if !errors.As(err, txRuleError) || txRuleError.RejectCode != mempool_old.RejectImmatureSpend {
|
||||||
t.Fatalf("Unexpected error %+v", err)
|
t.Fatalf("Unexpected error %+v", err)
|
||||||
}
|
}
|
||||||
transactionsFromMempool := miningManager.AllTransactions()
|
transactionsFromMempool := miningManager.AllTransactions()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user