From 5a99dcfe81edcb31acf9755d47ff8e34fe6b5b7a Mon Sep 17 00:00:00 2001 From: Brannon King Date: Tue, 26 Mar 2024 11:55:37 -0400 Subject: [PATCH] post-rebase fixes post-rebase fixes 2 --- addrmgr/addrmanager_internal_test.go | 5 +++ blockchain/claimtrie.go | 3 ++ blockchain/validate.go | 1 + claimtrie/claimtrie.go | 50 ---------------------------- claimtrie/claimtrie_test.go | 3 +- claimtrie/node/hashfork_manager.go | 1 + 6 files changed, 12 insertions(+), 51 deletions(-) diff --git a/addrmgr/addrmanager_internal_test.go b/addrmgr/addrmanager_internal_test.go index b2f5f3d140..451ad18ab5 100644 --- a/addrmgr/addrmanager_internal_test.go +++ b/addrmgr/addrmanager_internal_test.go @@ -99,7 +99,12 @@ func TestAddrManagerSerialization(t *testing.T) { expectedAddrs := make(map[string]*wire.NetAddress, numAddrs) for i := 0; i < numAddrs; i++ { addr := randAddr(t) + cnt := len(expectedAddrs) expectedAddrs[NetAddressKey(addr)] = addr + if len(expectedAddrs) == cnt { + i-- // accidentally generated a duplicate + continue + } addrMgr.AddAddress(addr, randAddr(t)) } diff --git a/blockchain/claimtrie.go b/blockchain/claimtrie.go index 2c3bcf8f15..a37b78232d 100644 --- a/blockchain/claimtrie.go +++ b/blockchain/claimtrie.go @@ -7,14 +7,17 @@ import ( "github.com/pkg/errors" + "github.com/lbryio/lbcd/chaincfg/chainhash" "github.com/lbryio/lbcd/txscript" "github.com/lbryio/lbcd/wire" btcutil "github.com/lbryio/lbcutil" "github.com/lbryio/lbcd/claimtrie" "github.com/lbryio/lbcd/claimtrie/change" + "github.com/lbryio/lbcd/claimtrie/merkletrie" "github.com/lbryio/lbcd/claimtrie/node" "github.com/lbryio/lbcd/claimtrie/normalization" + "github.com/lbryio/lbcd/claimtrie/param" ) func (b *BlockChain) SetClaimtrieHeader(block *btcutil.Block, view *UtxoViewpoint) error { diff --git a/blockchain/validate.go b/blockchain/validate.go index ba8e916267..9aae5244be 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -13,6 +13,7 @@ import ( "github.com/lbryio/lbcd/chaincfg" "github.com/lbryio/lbcd/chaincfg/chainhash" + "github.com/lbryio/lbcd/claimtrie/param" "github.com/lbryio/lbcd/txscript" "github.com/lbryio/lbcd/wire" btcutil "github.com/lbryio/lbcutil" diff --git a/claimtrie/claimtrie.go b/claimtrie/claimtrie.go index 21117e035b..3ad4a22657 100644 --- a/claimtrie/claimtrie.go +++ b/claimtrie/claimtrie.go @@ -458,56 +458,6 @@ func interruptRequested(interrupted <-chan struct{}) bool { return false } -func (ct *ClaimTrie) makeNameHashNext(names [][]byte, all bool, interrupt <-chan struct{}) chan NameHashNext { - inputs := make(chan []byte, 512) - outputs := make(chan NameHashNext, 512) - - var wg sync.WaitGroup - hashComputationWorker := func() { - for name := range inputs { - hash, next := ct.nodeManager.Hash(name) - outputs <- NameHashNext{name, hash, next} - } - wg.Done() - } - - threads := int(0.8 * float32(runtime.NumCPU())) - if threads < 1 { - threads = 1 - } - for threads > 0 { - threads-- - wg.Add(1) - go hashComputationWorker() - } - go func() { - if all { - ct.nodeManager.IterateNames(func(name []byte) bool { - if interruptRequested(interrupt) { - return false - } - clone := make([]byte, len(name)) - copy(clone, name) // iteration name buffer is reused on future loops - inputs <- clone - return true - }) - } else { - for _, name := range names { - if interruptRequested(interrupt) { - break - } - inputs <- name - } - } - close(inputs) - }() - go func() { - wg.Wait() - close(outputs) - }() - return outputs -} - func (ct *ClaimTrie) MerklePath(name []byte, n *node.Node, bid int) []merkletrie.HashSidePair { pairs := ct.merkleTrie.MerklePath(name) // TODO: organize this code better diff --git a/claimtrie/claimtrie_test.go b/claimtrie/claimtrie_test.go index 53beceea7f..a251a4b58a 100644 --- a/claimtrie/claimtrie_test.go +++ b/claimtrie/claimtrie_test.go @@ -8,6 +8,7 @@ import ( "github.com/lbryio/lbcd/claimtrie/change" "github.com/lbryio/lbcd/claimtrie/config" "github.com/lbryio/lbcd/claimtrie/merkletrie" + "github.com/lbryio/lbcd/claimtrie/node" "github.com/lbryio/lbcd/claimtrie/param" "github.com/lbryio/lbcd/chaincfg/chainhash" @@ -1054,7 +1055,7 @@ func TestMerklePath(t *testing.T) { r.NoError(err) for i := 0; i < 10; i++ { - err = ct.AppendBlock() + err = ct.AppendBlock(false) r.NoError(err) } diff --git a/claimtrie/node/hashfork_manager.go b/claimtrie/node/hashfork_manager.go index 840b5202e5..31477bba53 100644 --- a/claimtrie/node/hashfork_manager.go +++ b/claimtrie/node/hashfork_manager.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "github.com/lbryio/lbcd/chaincfg/chainhash" + "github.com/lbryio/lbcd/claimtrie/change" "github.com/lbryio/lbcd/claimtrie/param" )