mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-29 00:23:14 +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/consensus/model/externalapi"
|
||||
"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/router"
|
||||
"github.com/pkg/errors"
|
||||
@ -175,14 +175,14 @@ func (flow *handleRelayedTransactionsFlow) receiveTransactions(requestedTransact
|
||||
|
||||
err = flow.Domain().MiningManager().ValidateAndInsertTransaction(tx, true)
|
||||
if err != nil {
|
||||
ruleErr := &mempool.RuleError{}
|
||||
ruleErr := &mempool_old.RuleError{}
|
||||
if !errors.As(err, ruleErr) {
|
||||
return errors.Wrapf(err, "failed to process transaction %s", txID)
|
||||
}
|
||||
|
||||
shouldBan := true
|
||||
if txRuleErr := (&mempool.TxRuleError{}); errors.As(ruleErr.Err, txRuleErr) {
|
||||
if txRuleErr.RejectCode != mempool.RejectInvalid {
|
||||
if txRuleErr := (&mempool_old.TxRuleError{}); errors.As(ruleErr.Err, txRuleErr) {
|
||||
if txRuleErr.RejectCode != mempool_old.RejectInvalid {
|
||||
shouldBan = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"github.com/kaspanet/kaspad/app/appmessage"
|
||||
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
||||
"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/pkg/errors"
|
||||
)
|
||||
@ -23,7 +23,7 @@ func HandleSubmitTransaction(context *rpccontext.Context, _ *router.Router, requ
|
||||
transactionID := consensushashing.TransactionID(domainTransaction)
|
||||
err = context.ProtocolManager.AddTransaction(domainTransaction)
|
||||
if err != nil {
|
||||
if !errors.As(err, &mempool.RuleError{}) {
|
||||
if !errors.As(err, &mempool_old.RuleError{}) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
"github.com/kaspanet/kaspad/domain/dagconfig"
|
||||
"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
|
||||
|
||||
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 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.RuleError type contains a single Err field which will, in turn, either
|
||||
be a mempool.TxRuleError or a ruleerrors.RuleError. The first indicates a
|
||||
mempool_old.RuleError type contains a single Err field which will, in turn, either
|
||||
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
|
||||
consensus acceptance rules. This allows the caller to easily differentiate
|
||||
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
|
||||
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
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package mempool
|
||||
package mempool_old
|
||||
|
||||
import (
|
||||
"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 (
|
||||
"math"
|
||||
@ -2,10 +2,11 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package mempool
|
||||
package mempool_old
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||
|
||||
consensusexternalapi "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package mempool
|
||||
package mempool_old
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -1,10 +1,11 @@
|
||||
package miningmanager_test
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool_old"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/testapi"
|
||||
@ -84,8 +85,8 @@ func TestImmatureSpend(t *testing.T) {
|
||||
miningManager := miningFactory.NewMiningManager(tc, &consensusConfig.Params)
|
||||
tx := createTransactionWithUTXOEntry(t, 0)
|
||||
err = miningManager.ValidateAndInsertTransaction(tx, false)
|
||||
txRuleError := &mempool.TxRuleError{}
|
||||
if !errors.As(err, txRuleError) || txRuleError.RejectCode != mempool.RejectImmatureSpend {
|
||||
txRuleError := &mempool_old.TxRuleError{}
|
||||
if !errors.As(err, txRuleError) || txRuleError.RejectCode != mempool_old.RejectImmatureSpend {
|
||||
t.Fatalf("Unexpected error %+v", err)
|
||||
}
|
||||
transactionsFromMempool := miningManager.AllTransactions()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user