diff --git a/claimtrie/claimtrie.go b/claimtrie/claimtrie.go index 8de2b44c..5b6487a3 100644 --- a/claimtrie/claimtrie.go +++ b/claimtrie/claimtrie.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "path/filepath" - "runtime" "sort" "github.com/btcsuite/btcd/claimtrie/block" @@ -23,7 +22,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" - "sort" ) // ClaimTrie implements a Merkle Trie supporting linear history of commits. @@ -90,15 +88,16 @@ func New(cfg config.Config) (*ClaimTrie, error) { nodeManager := node.NewNormalizingManager(baseManager) cleanups = append(cleanups, nodeManager.Close) - // Initialize repository for MerkleTrie. - // The cleanup is delegated to MerkleTrie. - trieRepo, err := merkletrierepo.NewPebble(filepath.Join(cfg.DataDir, cfg.MerkleTrieRepoPebble.Path)) - if err != nil { - return nil, fmt.Errorf("new trie repo: %w", err) - } + var trie merkletrie.MerkleTrie + if cfg.RamTrie { + trie = merkletrie.NewRamTrie(nodeManager) + } else { - trie := merkletrie.New(nodeManager, trieRepo) - cleanups = append(cleanups, trie.Close) + // Initialize repository for MerkleTrie. The cleanup is delegated to MerkleTrie. + trieRepo, err := merkletrierepo.NewPebble(filepath.Join(cfg.DataDir, cfg.MerkleTrieRepoPebble.Path)) + if err != nil { + return nil, fmt.Errorf("new trie repo: %w", err) + } persistentTrie := merkletrie.NewPersistentTrie(nodeManager, trieRepo) cleanups = append(cleanups, persistentTrie.Close) @@ -404,8 +403,9 @@ func (ct *ClaimTrie) forwardNodeChange(chg change.Change) error { return fmt.Errorf("node manager handle change: %w", err) } - ct.changes = append(ct.changes, chg) - + if ct.chainRepo != nil { // for debugging only + ct.changes = append(ct.changes, chg) + } return nil } diff --git a/claimtrie/claimtrie_test.go b/claimtrie/claimtrie_test.go index 1a2f869f..4c1d6dba 100644 --- a/claimtrie/claimtrie_test.go +++ b/claimtrie/claimtrie_test.go @@ -235,7 +235,7 @@ func verifyBestIndex(t *testing.T, ct *ClaimTrie, name string, idx uint32, claim func TestRebuild(t *testing.T) { r := require.New(t) setup(t) - ct, err := New(true) + ct, err := New(cfg) r.NoError(err) r.NotNil(ct) defer func() { diff --git a/claimtrie/cmd/cmd/node.go b/claimtrie/cmd/cmd/node.go index b5eca50e..f64bae52 100644 --- a/claimtrie/cmd/cmd/node.go +++ b/claimtrie/cmd/cmd/node.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strconv" + "github.com/btcsuite/btcd/claimtrie/change" "github.com/btcsuite/btcd/claimtrie/node" "github.com/btcsuite/btcd/claimtrie/node/noderepo" @@ -110,7 +111,7 @@ var nodeChildrenCmd = &cobra.Command{ Args: cobra.RangeArgs(1, 1), RunE: func(cmd *cobra.Command, args []string) error { - repo, err := noderepo.NewPebble(localConfig.NodeRepoPebble.Path) + repo, err := noderepo.NewPebble(filepath.Join(cfg.DataDir, cfg.NodeRepoPebble.Path)) if err != nil { return fmt.Errorf("open node repo: %w", err) } diff --git a/claimtrie/config/config.go b/claimtrie/config/config.go index 99c2b118..1706689b 100644 --- a/claimtrie/config/config.go +++ b/claimtrie/config/config.go @@ -8,7 +8,7 @@ import ( var DefaultConfig = Config{ Record: false, - RamTrie: false, + RamTrie: true, // as it stands the other trie uses more RAM, more time, and 40GB+ of disk space DataDir: filepath.Join(btcutil.AppDataDir("chain", false), "data", "mainnet", "claim_dbs"), diff --git a/claimtrie/node/manager.go b/claimtrie/node/manager.go index 1d271bc7..310b3aa0 100644 --- a/claimtrie/node/manager.go +++ b/claimtrie/node/manager.go @@ -274,10 +274,10 @@ func (nm *BaseManager) aWorkaroundIsNeeded(n *Node, chg change.Change) bool { w := isInDelayPart2(chg) if w { if !needed { - fmt.Printf("FALSE NEGATIVE! %d: %s: %t\n", chg.Height, chg.Name, needed) + fmt.Printf("DELAY WORKAROUND FALSE NEGATIVE! %d: %s: %t\n", chg.Height, chg.Name, needed) } } else if needed { - fmt.Printf("FALSE POSITIVE! %d: %s: %t\n", chg.Height, chg.Name, needed) + fmt.Printf("DELAY WORKAROUND FALSE POSITIVE! %d: %s: %t\n", chg.Height, chg.Name, needed) } // return w // if you want to sync to 933294+ } diff --git a/claimtrie/node/manager_test.go b/claimtrie/node/manager_test.go index f12f9dac..086fc223 100644 --- a/claimtrie/node/manager_test.go +++ b/claimtrie/node/manager_test.go @@ -96,7 +96,7 @@ func TestSupportAmounts(t *testing.T) { r := require.New(t) - param.SetNetwork(wire.TestNet, "") + param.SetNetwork(wire.TestNet) repo, err := noderepo.NewPebble(t.TempDir()) r.NoError(err)