mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-21 06:16:45 +00:00

* Update constants * Add to transaction SigOpCount * Update mass calculation, and move it from InContext to InIsolation * Update block validation accordingly * Add SigOpCount validation during TransactionInContext * Remove checking of mass vs maxMassAcceptedByBlock from consensusStateManager * Update mining manager with latest changes * Add SigOpCount to MsgTx.Copy() * Fix initTestTransactionAcceptanceDataForClone * Fix all tests in transaction_equal_clone_test.go * Fix TestBlockMass * Fix tests in transactionvalidator package * Add SigOpCount to sighash * Fix TestPruningDepth * Fix problems in libkaspawalelt * Fix integration tests * Fix CalculateSignatureHash tests * Remove remaining places talking about block size * Add sanity check to checkBlockMass to make sure all transactions have their mass filled * always add own sigOpCount to sigHash * Update protowire/rpc.md * Start working on removing any remaining reference to block/tx size * Update rpc transaction verbose data to include mass rather then size * Convert verboseData and block size check to mass * Remove remaining usages of tx size in mempool * Move transactionEstimatedSerializedSize to transactionvalidator * Add PopulateMass to fakeRelayInvsContext * Move PopulateMass to beggining of ValidateAndInsertTransaction + fix in it * Assign mass a new number for backward-compatibility
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package mempool
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
)
|
|
|
|
func (mp *mempool) validateAndInsertTransaction(transaction *externalapi.DomainTransaction, isHighPriority bool,
|
|
allowOrphan bool) (acceptedTransactions []*externalapi.DomainTransaction, err error) {
|
|
|
|
onEnd := logger.LogAndMeasureExecutionTime(log,
|
|
fmt.Sprintf("validateAndInsertTransaction %s", consensushashing.TransactionID(transaction)))
|
|
defer onEnd()
|
|
|
|
// Populate mass in the beginning, it will be used in multiple places throughout the validation and insertion.
|
|
mp.consensus.PopulateMass(transaction)
|
|
|
|
err = mp.validateTransactionPreUTXOEntry(transaction)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
parentsInPool, missingOutpoints, err := mp.fillInputsAndGetMissingParents(transaction)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(missingOutpoints) > 0 {
|
|
if !allowOrphan {
|
|
str := fmt.Sprintf("Transaction %s is an orphan, where allowOrphan = false",
|
|
consensushashing.TransactionID(transaction))
|
|
return nil, transactionRuleError(RejectBadOrphan, str)
|
|
}
|
|
|
|
return nil, mp.orphansPool.maybeAddOrphan(transaction, isHighPriority)
|
|
}
|
|
|
|
err = mp.validateTransactionInContext(transaction)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
mempoolTransaction, err := mp.transactionsPool.addTransaction(transaction, parentsInPool, isHighPriority)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
acceptedOrphans, err := mp.orphansPool.processOrphansAfterAcceptedTransaction(mempoolTransaction.Transaction())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
acceptedTransactions = append([]*externalapi.DomainTransaction{transaction}, acceptedOrphans...)
|
|
|
|
err = mp.transactionsPool.limitTransactionCount()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return acceptedTransactions, nil
|
|
}
|