do map preallocation in mempoolbyaddresses

This commit is contained in:
D-Stacks 2022-07-26 19:37:42 +02:00
parent 2a49523057
commit a6c9a80d13
2 changed files with 8 additions and 8 deletions

View File

@ -340,8 +340,8 @@ func (op *orphansPool) getOrphanTransactionsByAddresses() (
sending model.ScriptPublicKeyStringToDomainTransaction, sending model.ScriptPublicKeyStringToDomainTransaction,
receiving model.ScriptPublicKeyStringToDomainTransaction, receiving model.ScriptPublicKeyStringToDomainTransaction,
err error) { err error) {
sending = make(model.ScriptPublicKeyStringToDomainTransaction) sending = make(model.ScriptPublicKeyStringToDomainTransaction, op.orphanTransactionCount())
receiving = make(model.ScriptPublicKeyStringToDomainTransaction) receiving = make(model.ScriptPublicKeyStringToDomainTransaction, op.orphanTransactionCount())
var transaction *externalapi.DomainTransaction var transaction *externalapi.DomainTransaction
for _, mempoolTransaction := range op.allOrphans { for _, mempoolTransaction := range op.allOrphans {
transaction = mempoolTransaction.Transaction().Clone() //these pointers leave the mempool, hence we clone. transaction = mempoolTransaction.Transaction().Clone() //these pointers leave the mempool, hence we clone.

View File

@ -136,7 +136,7 @@ func (tp *transactionsPool) allReadyTransactions() []*externalapi.DomainTransact
for _, mempoolTransaction := range tp.allTransactions { for _, mempoolTransaction := range tp.allTransactions {
if len(mempoolTransaction.ParentTransactionsInPool()) == 0 { if len(mempoolTransaction.ParentTransactionsInPool()) == 0 {
result = append(result, mempoolTransaction.Transaction().Clone()) result = append(result, mempoolTransaction.Transaction().Clone()) //this pointer leaves the mempool, and gets its utxo set to nil, hence we clone.
} }
} }
@ -208,7 +208,7 @@ func (tp *transactionsPool) limitTransactionCount() error {
func (tp *transactionsPool) getTransaction(transactionID *externalapi.DomainTransactionID, clone bool) (*externalapi.DomainTransaction, bool) { func (tp *transactionsPool) getTransaction(transactionID *externalapi.DomainTransactionID, clone bool) (*externalapi.DomainTransaction, bool) {
if mempoolTransaction, ok := tp.allTransactions[*transactionID]; ok { if mempoolTransaction, ok := tp.allTransactions[*transactionID]; ok {
if clone { if clone {
return mempoolTransaction.Transaction().Clone(), true return mempoolTransaction.Transaction().Clone(), true //this pointer leaves the mempool, hence we clone.
} }
return mempoolTransaction.Transaction(), true return mempoolTransaction.Transaction(), true
} }
@ -219,11 +219,11 @@ func (tp *transactionsPool) getTransactionsByAddresses() (
sending model.ScriptPublicKeyStringToDomainTransaction, sending model.ScriptPublicKeyStringToDomainTransaction,
receiving model.ScriptPublicKeyStringToDomainTransaction, receiving model.ScriptPublicKeyStringToDomainTransaction,
err error) { err error) {
sending = make(model.ScriptPublicKeyStringToDomainTransaction) sending = make(model.ScriptPublicKeyStringToDomainTransaction, tp.transactionCount())
receiving = make(model.ScriptPublicKeyStringToDomainTransaction) receiving = make(model.ScriptPublicKeyStringToDomainTransaction, tp.transactionCount())
var transaction *externalapi.DomainTransaction var transaction *externalapi.DomainTransaction
for _, mempoolTransaction := range tp.allTransactions { for _, mempoolTransaction := range tp.allTransactions {
transaction = mempoolTransaction.Transaction().Clone() transaction = mempoolTransaction.Transaction().Clone() //this pointer leaves the mempool, hence we clone.
for _, input := range transaction.Inputs { for _, input := range transaction.Inputs {
if input.UTXOEntry == nil { if input.UTXOEntry == nil {
return nil, nil, errors.Errorf("Mempool transaction %s is missing an UTXOEntry. This should be fixed, and not happen", consensushashing.TransactionID(transaction).String()) return nil, nil, errors.Errorf("Mempool transaction %s is missing an UTXOEntry. This should be fixed, and not happen", consensushashing.TransactionID(transaction).String())
@ -241,7 +241,7 @@ func (tp *transactionsPool) getAllTransactions() []*externalapi.DomainTransactio
allTransactions := make([]*externalapi.DomainTransaction, len(tp.allTransactions)) allTransactions := make([]*externalapi.DomainTransaction, len(tp.allTransactions))
i := 0 i := 0
for _, mempoolTransaction := range tp.allTransactions { for _, mempoolTransaction := range tp.allTransactions {
allTransactions[i] = mempoolTransaction.Transaction().Clone() allTransactions[i] = mempoolTransaction.Transaction().Clone() //this pointer leaves the mempool, hence we clone.
i++ i++
} }
return allTransactions return allTransactions