Skip to content

Commit

Permalink
Merge pull request lightninglabs#9 from ltcsuite/latest
Browse files Browse the repository at this point in the history
Latest
  • Loading branch information
losh11 authored Jun 18, 2020
2 parents b5c977b + baad32c commit 18e554f
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 86 deletions.
2 changes: 1 addition & 1 deletion bamboozle_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func runCheckCFCheckptSanityTestCase(t *testing.T, testCase *cfCheckptTestCase)
}
defer os.RemoveAll(tempDir)

db, err := walletdb.Create("bdb", tempDir+"/weks.db")
db, err := walletdb.Create("bdb", tempDir+"/weks.db", true)
if err != nil {
t.Fatalf("Error opening DB: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion banman/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func createTestBanStore(t *testing.T) (banman.Store, func()) {
}
dbPath := filepath.Join(dbDir, "test.db")

db, err := walletdb.Create("bdb", dbPath)
db, err := walletdb.Create("bdb", dbPath, true)
if err != nil {
os.RemoveAll(dbDir)
t.Fatalf("unable to create db: %v", err)
Expand Down
20 changes: 10 additions & 10 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,16 @@ func (b *blockManager) writeCFHeadersMsg(msg *wire.MsgCFHeaders,
return nil, 0, err
}

// We'll also set the new header tip and notify any peers that the tip
// has changed as well. Unlike the set of notifications below, this is
// for sub-system that only need to know the height has changed rather
// than know each new header that's been added to the tip.
b.newFilterHeadersMtx.Lock()
b.filterHeaderTip = lastHeight
b.filterHeaderTipHash = lastHash
b.newFilterHeadersMtx.Unlock()
b.newFilterHeadersSignal.Broadcast()

// Notify subscribers, and also update the filter header progress
// logger at the same time.
for i, header := range matchingBlockHeaders {
Expand All @@ -1281,16 +1291,6 @@ func (b *blockManager) writeCFHeadersMsg(msg *wire.MsgCFHeaders,
b.onBlockConnected(header, headerHeight)
}

// We'll also set the new header tip and notify any peers that the tip
// has changed as well. Unlike the set of notifications above, this is
// for sub-system that only need to know the height has changed rather
// than know each new header that's been added to the tip.
b.newFilterHeadersMtx.Lock()
b.filterHeaderTip = lastHeight
b.filterHeaderTipHash = lastHash
b.newFilterHeadersMtx.Unlock()
b.newFilterHeadersSignal.Broadcast()

return &lastHeader, lastHeight, nil
}

Expand Down
2 changes: 1 addition & 1 deletion blockmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func setupBlockManager() (*blockManager, headerfs.BlockHeaderStore,
"temporary directory: %s", err)
}

db, err := walletdb.Create("bdb", tempDir+"/weks.db")
db, err := walletdb.Create("bdb", tempDir+"/weks.db", true)
if err != nil {
os.RemoveAll(tempDir)
return nil, nil, nil, nil, fmt.Errorf("Error opening DB: %s",
Expand Down
38 changes: 19 additions & 19 deletions chainsync/filtercontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ var ErrCheckpointMismatch = fmt.Errorf("checkpoint doesn't match")
var filterHeaderCheckpoints = map[wire.BitcoinNet]map[uint32]*chainhash.Hash{
// Mainnet filter header checkpoints.
chaincfg.MainNetParams.Net: map[uint32]*chainhash.Hash{
50000: hashFromStr("40ef276cc92c0edf323ee0be4cda6d72007846470329a150547947d52064841c"),
100000: hashFromStr("16481d67008768cbbfde5a5a4440cb53cc7c6bf6fa7d619aafbcfaa4a708830e"),
150000: hashFromStr("60f41c9a1e84590c14783413df2b4d865d4b09fee90ee50b48999a3877e8bc5f"),
250000: hashFromStr("60f3a67c5f95e4b34048b9c6df43580f587da749d3adab6cc7293c255155de08"),
300000: hashFromStr("c3ce44651b1cce4b7b2fcd07861948363759f95c9a7e03e1ac7e4f79b9cc7763"),
350000: hashFromStr("43d979781b215b365cc94be7e5205aaf24607d64088a81e8c87e686051da720b"),
500000: hashFromStr("f8aaf8bb9ec1b9e2dae9c9e37e12d0be9712572bfbd1de15a4fda4b39539136c"),
550000: hashFromStr("6657d5df5779ee936841b3979a950467666e47d6dae74b77b8249fac1d226c6d"),
600000: hashFromStr("491a699439130c8898d488f4eb88528604ac6721dc2775b8567ef62847840174"),
650000: hashFromStr("8e0d153a67219128c5be6c1eafecb358d7c32fb78f7188dcce067a3340b57f54"),
700000: hashFromStr("9c458879fc6ec919c9040400618699e64b7ff175cf420788b3c68dadfdf8582a"),
801000: hashFromStr("c4fd4b38ecc56f1cb35037c2ff8395b48c477368d0edeec16bc7dd065314685e"),
901000: hashFromStr("62752d9fd50e1876a731087f6fcc28abad5f25d51d7eb04351f81bf80096f31f"),
50000: hashFromStr("40ef276cc92c0edf323ee0be4cda6d72007846470329a150547947d52064841c"),
100000: hashFromStr("16481d67008768cbbfde5a5a4440cb53cc7c6bf6fa7d619aafbcfaa4a708830e"),
150000: hashFromStr("60f41c9a1e84590c14783413df2b4d865d4b09fee90ee50b48999a3877e8bc5f"),
250000: hashFromStr("60f3a67c5f95e4b34048b9c6df43580f587da749d3adab6cc7293c255155de08"),
300000: hashFromStr("c3ce44651b1cce4b7b2fcd07861948363759f95c9a7e03e1ac7e4f79b9cc7763"),
350000: hashFromStr("43d979781b215b365cc94be7e5205aaf24607d64088a81e8c87e686051da720b"),
500000: hashFromStr("f8aaf8bb9ec1b9e2dae9c9e37e12d0be9712572bfbd1de15a4fda4b39539136c"),
550000: hashFromStr("6657d5df5779ee936841b3979a950467666e47d6dae74b77b8249fac1d226c6d"),
600000: hashFromStr("491a699439130c8898d488f4eb88528604ac6721dc2775b8567ef62847840174"),
650000: hashFromStr("8e0d153a67219128c5be6c1eafecb358d7c32fb78f7188dcce067a3340b57f54"),
700000: hashFromStr("9c458879fc6ec919c9040400618699e64b7ff175cf420788b3c68dadfdf8582a"),
801000: hashFromStr("c4fd4b38ecc56f1cb35037c2ff8395b48c477368d0edeec16bc7dd065314685e"),
901000: hashFromStr("62752d9fd50e1876a731087f6fcc28abad5f25d51d7eb04351f81bf80096f31f"),
1001000: hashFromStr("2e73db026373af029f37201515870f607b9ad9f541811e65208e228f3719ba95"),
1101000: hashFromStr("2f157ca9fd36cb5cf7bd5a881e40c112c82a35dab578dd8b57747211a68fe296"),
1201000: hashFromStr("9bfb167a5b3e41567315fe1ba8ecbb964cc7fac11b37c9e874a3beb79f6fca5d"),
Expand All @@ -44,12 +44,12 @@ var filterHeaderCheckpoints = map[wire.BitcoinNet]map[uint32]*chainhash.Hash{

// Testnet filter header checkpoints.
chaincfg.TestNet4Params.Net: map[uint32]*chainhash.Hash{
10000: hashFromStr("3b98491e48c3f89e6aba3466ab2f1ba802faef6e5ea92c7b0bcc20682ba44465"),
101000: hashFromStr("8b54ceec6cde1f1b20e6ac2b28dcf3d72c51799760e625b156fca8b7c5c0a558"),
303000: hashFromStr("3ff217c2f372bc3bb7273e085906183f8afac1858922c710e05d2f961357b21f"),
505000: hashFromStr("1b7ebeabbcc37731932b09a68f36b4a3a54aa6067805a3ea6c057d866e8549d1"),
707000: hashFromStr("ec15c1a28981cb19096b5b9aea2f2389fc41e755a1b0228f27f2976d50851e21"),
909000: hashFromStr("cd51428ecfbe42bcd3920c42eaa1ad14d5b2eecff7d8a57d70df9e0b247f5b4a"),
10000: hashFromStr("3b98491e48c3f89e6aba3466ab2f1ba802faef6e5ea92c7b0bcc20682ba44465"),
101000: hashFromStr("8b54ceec6cde1f1b20e6ac2b28dcf3d72c51799760e625b156fca8b7c5c0a558"),
303000: hashFromStr("3ff217c2f372bc3bb7273e085906183f8afac1858922c710e05d2f961357b21f"),
505000: hashFromStr("1b7ebeabbcc37731932b09a68f36b4a3a54aa6067805a3ea6c057d866e8549d1"),
707000: hashFromStr("ec15c1a28981cb19096b5b9aea2f2389fc41e755a1b0228f27f2976d50851e21"),
909000: hashFromStr("cd51428ecfbe42bcd3920c42eaa1ad14d5b2eecff7d8a57d70df9e0b247f5b4a"),
1111000: hashFromStr("52a74833414ded5b7bdc7e274b0107569adcdb09cdd9f75bf25ad8793aac437c"),
1313000: hashFromStr("c81c0db37c5bcf27ba973215770a8a17630cb85db5035f898c94d1964b9b856a"),
1351000: hashFromStr("fd0d8cd62d0ce53ae003c5bd32db4943f330e4a1cc9ea09be6a34325085016e4"),
Expand Down
26 changes: 26 additions & 0 deletions filterdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type FilterDatabase interface {
// target block hash cannot be found, then ErrFilterNotFound is to be
// returned.
FetchFilter(*chainhash.Hash, FilterType) (*gcs.Filter, error)

// PurgeFilters purge all filters with a given type from persistent storage.
PurgeFilters(FilterType) error
}

// FilterStore is an implementation of the FilterDatabase interface which is
Expand Down Expand Up @@ -107,6 +110,29 @@ func New(db walletdb.DB, params chaincfg.Params) (*FilterStore, error) {
}, nil
}

// PurgeFilters purge all filters with a given type from persistent storage.
//
// NOTE: This method is a part of the FilterDatabase interface.
func (f *FilterStore) PurgeFilters(fType FilterType) error {
return walletdb.Update(f.db, func(tx walletdb.ReadWriteTx) error {
filters := tx.ReadWriteBucket(filterBucket)

switch fType {
case RegularFilter:
if err := filters.DeleteNestedBucket(regBucket); err != nil {
return err
}
if _, err := filters.CreateBucket(regBucket); err != nil {
return err
}
default:
return fmt.Errorf("unknown filter type: %v", fType)
}

return nil
})
}

// putFilter stores a filter in the database according to the corresponding
// block hash. The passed bucket is expected to be the proper bucket for the
// passed filter type.
Expand Down
2 changes: 1 addition & 1 deletion filterdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func createTestDatabase() (func(), FilterDatabase, error) {
return nil, nil, err
}

db, err := walletdb.Create("bdb", tempDir+"/test.db")
db, err := walletdb.Create("bdb", tempDir+"/test.db", true)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ltcsuite/neutrino
require (
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/davecgh/go-spew v1.1.1
github.com/ltcsuite/lnd/queue v1.0.3
github.com/lightningnetwork/lnd/queue v1.0.4
github.com/ltcsuite/ltcd v0.20.1-beta
github.com/ltcsuite/ltcutil v0.0.0-20191227053721-6bec450ea6ad
github.com/ltcsuite/ltcwallet/wallet/txauthor v1.0.0
Expand Down
Loading

0 comments on commit 18e554f

Please sign in to comment.