From 09b2c53b3fb555b3e1dca03be8baf7499618c2d1 Mon Sep 17 00:00:00 2001 From: D-Stacks Date: Fri, 24 Jun 2022 21:11:38 +0200 Subject: [PATCH] fix not found sending err, add to kaspactl --- cmd/kaspactl/commands.go | 2 ++ domain/txindex/store.go | 2 +- domain/txindex/txindex.go | 20 ++++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/kaspactl/commands.go b/cmd/kaspactl/commands.go index d56d1b886..9b68ad551 100644 --- a/cmd/kaspactl/commands.go +++ b/cmd/kaspactl/commands.go @@ -15,6 +15,8 @@ var commandTypes = []reflect.Type{ reflect.TypeOf(protowire.KaspadMessage_GetCurrentNetworkRequest{}), reflect.TypeOf(protowire.KaspadMessage_GetInfoRequest{}), + reflect.TypeOf(protowire.KaspadMessage_GetAcceptingBlockHashOfTxRequest{}), + reflect.TypeOf(protowire.KaspadMessage_GetBlockRequest{}), reflect.TypeOf(protowire.KaspadMessage_GetBlocksRequest{}), reflect.TypeOf(protowire.KaspadMessage_GetHeadersRequest{}), diff --git a/domain/txindex/store.go b/domain/txindex/store.go index dd71d1347..257026d3f 100644 --- a/domain/txindex/store.go +++ b/domain/txindex/store.go @@ -217,7 +217,7 @@ func (tis *txIndexStore) getTxAcceptingBlockHash(txID *externalapi.DomainTransac key := tis.convertTxIDToKey(txAcceptedIndexBucket, *txID) serializedAcceptingBlockHash, err := tis.database.Get(key) if err != nil { - if err == database.ErrNotFound { + if database.IsNotFoundError(err) { return nil, false, nil } return nil, false, err diff --git a/domain/txindex/txindex.go b/domain/txindex/txindex.go index 90a691b31..98c83bb01 100644 --- a/domain/txindex/txindex.go +++ b/domain/txindex/txindex.go @@ -5,6 +5,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/infrastructure/db/database" "github.com/kaspanet/kaspad/infrastructure/logger" ) @@ -139,7 +140,7 @@ func (ti *TXIndex) Update(virtualChangeSet *externalapi.VirtualChangeSet) (*TXAc ti.mutex.Lock() defer ti.mutex.Unlock() - log.Tracef("Updating TX index with VirtualSelectedParentChainChanges: %+v", virtualChangeSet.VirtualSelectedParentChainChanges) + log.Info("Updating TX index with VirtualSelectedParentChainChanges: %+v", virtualChangeSet.VirtualSelectedParentChainChanges) err := ti.removeTXIDs(virtualChangeSet.VirtualSelectedParentChainChanges, 1000) if err != nil { @@ -164,7 +165,6 @@ func (ti *TXIndex) Update(virtualChangeSet *externalapi.VirtualChangeSet) (*TXAc return nil, err } - log.Tracef("TX index updated with the TXAcceptanceChange: %+v", txIndexChanges) return txIndexChanges, nil } @@ -188,8 +188,12 @@ func (ti *TXIndex) addTXIDs(selectedParentChainChanges *externalapi.SelectedChai chainBlockAcceptanceData := chainBlocksAcceptanceData[i] for _, blockAcceptanceData := range chainBlockAcceptanceData { for _, transactionAcceptanceData := range blockAcceptanceData.TransactionAcceptanceData { - if transactionAcceptanceData.IsAccepted && transactionAcceptanceData.Transaction.ID != nil { - ti.store.add(*transactionAcceptanceData.Transaction.ID, addedChainBlock) + log.Info("TX index Adding: ", len(blockAcceptanceData.TransactionAcceptanceData)) + if transactionAcceptanceData.IsAccepted { + ti.store.add( + *consensushashing.TransactionID(transactionAcceptanceData.Transaction), + addedChainBlock, + ) } } } @@ -218,9 +222,13 @@ func (ti *TXIndex) removeTXIDs(selectedParentChainChanges *externalapi.SelectedC for i, removedChainBlock := range chainBlocksChunk { chainBlockAcceptanceData := chainBlocksAcceptanceData[i] for _, blockAcceptanceData := range chainBlockAcceptanceData { + log.Info("TX index Removing: ", len(blockAcceptanceData.TransactionAcceptanceData)) for _, transactionAcceptanceData := range blockAcceptanceData.TransactionAcceptanceData { - if transactionAcceptanceData.IsAccepted && transactionAcceptanceData.Transaction.ID != nil { - ti.store.remove(*transactionAcceptanceData.Transaction.ID, removedChainBlock) + if transactionAcceptanceData.IsAccepted { + ti.store.remove( + *consensushashing.TransactionID(transactionAcceptanceData.Transaction), + removedChainBlock, + ) } } }