Added model and stubs for all main methods

This commit is contained in:
Mike Zak 2021-06-06 12:11:33 +03:00
parent d1df97c4c5
commit 94ddf0aab0
17 changed files with 1193 additions and 1039 deletions

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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

View 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)
}

View 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
}

View 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)
}

View 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)
}

View File

@ -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

View File

@ -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"

View 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")

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
package mempool
package mempool_old
import (
"math"

View File

@ -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"

View File

@ -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"

View File

@ -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()