Implemented mempoolUTXOSet.addTransaction

This commit is contained in:
Mike Zak 2021-06-08 10:27:06 +03:00
parent 099f023b5b
commit d88fe305c5
2 changed files with 36 additions and 1 deletions

View File

@ -2,7 +2,9 @@ package mempool
import ( import (
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/utils/utxo"
"github.com/kaspanet/kaspad/domain/miningmanager/mempool/model" "github.com/kaspanet/kaspad/domain/miningmanager/mempool/model"
"github.com/pkg/errors"
) )
type mempoolUTXOSet struct { type mempoolUTXOSet struct {
@ -37,7 +39,34 @@ func (mpus *mempoolUTXOSet) getParentsInPool(transaction *model.MempoolTransacti
} }
func (mpus *mempoolUTXOSet) addTransaction(transaction *model.MempoolTransaction) error { func (mpus *mempoolUTXOSet) addTransaction(transaction *model.MempoolTransaction) error {
panic("mempoolUTXOSet.addTransaction not implemented") // TODO (Mike) outpoint := &externalapi.DomainOutpoint{TransactionID: *transaction.TransactionID()}
for i, input := range transaction.Transaction.Inputs {
outpoint.Index = uint32(i)
// Sanity check for consistency
if existingTx, exists := mpus.transactionsByPreviousOutpoint[input.PreviousOutpoint]; exists {
return errors.Errorf("outpoint %s is already used by %s",
input.PreviousOutpoint, existingTx.TransactionID())
}
delete(mpus.poolUnspentOutputs, *outpoint)
mpus.transactionsByPreviousOutpoint[input.PreviousOutpoint] = transaction
}
for i, output := range transaction.Transaction.Outputs {
outpoint := externalapi.DomainOutpoint{TransactionID: *transaction.TransactionID(), Index: uint32(i)}
// Sanity check for consistency
if _, exists := mpus.poolUnspentOutputs[outpoint]; exists {
return errors.Errorf("outpoint %s already exists", outpoint)
}
mpus.poolUnspentOutputs[outpoint] =
utxo.NewUTXOEntry(output.Value, output.ScriptPublicKey, false, model.UnacceptedDAAScore)
}
return nil
} }
func (mpus *mempoolUTXOSet) removeTransaction(transactionID *externalapi.DomainTransactionID) error { func (mpus *mempoolUTXOSet) removeTransaction(transactionID *externalapi.DomainTransactionID) error {

View File

@ -0,0 +1,6 @@
package model
import "math"
// UnacceptedDAAScore is used to for UTXOEntries that were created by transactions in the mempool.
const UnacceptedDAAScore = math.MaxUint64