diff --git a/chainntnfs/bitcoindnotify/bitcoind.go b/chainntnfs/bitcoindnotify/bitcoind.go index 36f7ce19..5b0df594 100644 --- a/chainntnfs/bitcoindnotify/bitcoind.go +++ b/chainntnfs/bitcoindnotify/bitcoind.go @@ -20,11 +20,6 @@ const ( // notifierType uniquely identifies this concrete implementation of the // ChainNotifier interface. notifierType = "bitcoind" - - // reorgSafetyLimit is assumed maximum depth of a chain reorganization. - // After this many confirmation, transaction confirmation info will be - // pruned. - reorgSafetyLimit = 100 ) var ( @@ -138,8 +133,8 @@ func (b *BitcoindNotifier) Start() error { } b.txNotifier = chainntnfs.NewTxNotifier( - uint32(currentHeight), reorgSafetyLimit, b.confirmHintCache, - b.spendHintCache, + uint32(currentHeight), chainntnfs.ReorgSafetyLimit, + b.confirmHintCache, b.spendHintCache, ) b.bestBlock = chainntnfs.BlockEpoch{ diff --git a/chainntnfs/bitcoindnotify/bitcoind_dev.go b/chainntnfs/bitcoindnotify/bitcoind_dev.go index ceeeb8ab..99080b38 100644 --- a/chainntnfs/bitcoindnotify/bitcoind_dev.go +++ b/chainntnfs/bitcoindnotify/bitcoind_dev.go @@ -30,8 +30,8 @@ func (b *BitcoindNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Has } b.txNotifier = chainntnfs.NewTxNotifier( - uint32(bestHeight), reorgSafetyLimit, b.confirmHintCache, - b.spendHintCache, + uint32(bestHeight), chainntnfs.ReorgSafetyLimit, + b.confirmHintCache, b.spendHintCache, ) if generateBlocks != nil { diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 30b790dd..4e900608 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -21,11 +21,6 @@ const ( // notifierType uniquely identifies this concrete implementation of the // ChainNotifier interface. notifierType = "btcd" - - // reorgSafetyLimit is assumed maximum depth of a chain reorganization. - // After this many confirmation, transaction confirmation info will be - // pruned. - reorgSafetyLimit = 100 ) var ( @@ -163,8 +158,8 @@ func (b *BtcdNotifier) Start() error { } b.txNotifier = chainntnfs.NewTxNotifier( - uint32(currentHeight), reorgSafetyLimit, b.confirmHintCache, - b.spendHintCache, + uint32(currentHeight), chainntnfs.ReorgSafetyLimit, + b.confirmHintCache, b.spendHintCache, ) b.bestBlock = chainntnfs.BlockEpoch{ diff --git a/chainntnfs/btcdnotify/btcd_dev.go b/chainntnfs/btcdnotify/btcd_dev.go index 7e39d8a5..4723c0de 100644 --- a/chainntnfs/btcdnotify/btcd_dev.go +++ b/chainntnfs/btcdnotify/btcd_dev.go @@ -29,8 +29,8 @@ func (b *BtcdNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Hash, } b.txNotifier = chainntnfs.NewTxNotifier( - uint32(bestHeight), reorgSafetyLimit, b.confirmHintCache, - b.spendHintCache, + uint32(bestHeight), chainntnfs.ReorgSafetyLimit, + b.confirmHintCache, b.spendHintCache, ) b.chainUpdates.Start() diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index abc21671..3302b620 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -25,12 +25,6 @@ const ( // notifierType uniquely identifies this concrete implementation of the // ChainNotifier interface. notifierType = "neutrino" - - // reorgSafetyLimit is the chain depth beyond which it is assumed a block - // will not be reorganized out of the chain. This is used to determine when - // to prune old confirmation requests so that reorgs are handled correctly. - // The coinbase maturity period is a reasonable value to use. - reorgSafetyLimit = 100 ) var ( @@ -159,7 +153,7 @@ func (n *NeutrinoNotifier) Start() error { } n.txNotifier = chainntnfs.NewTxNotifier( - n.bestHeight, reorgSafetyLimit, n.confirmHintCache, + n.bestHeight, chainntnfs.ReorgSafetyLimit, n.confirmHintCache, n.spendHintCache, ) diff --git a/chainntnfs/neutrinonotify/neutrino_dev.go b/chainntnfs/neutrinonotify/neutrino_dev.go index 3a1b19b9..2cacf2b3 100644 --- a/chainntnfs/neutrinonotify/neutrino_dev.go +++ b/chainntnfs/neutrinonotify/neutrino_dev.go @@ -49,8 +49,8 @@ func (n *NeutrinoNotifier) UnsafeStart(bestHeight int32, } n.txNotifier = chainntnfs.NewTxNotifier( - uint32(bestHeight), reorgSafetyLimit, n.confirmHintCache, - n.spendHintCache, + uint32(bestHeight), chainntnfs.ReorgSafetyLimit, + n.confirmHintCache, n.spendHintCache, ) n.chainConn = &NeutrinoChainConn{n.p2pNode} diff --git a/chainntnfs/txnotifier_test.go b/chainntnfs/txnotifier_test.go index 521dfdcc..dfaec89c 100644 --- a/chainntnfs/txnotifier_test.go +++ b/chainntnfs/txnotifier_test.go @@ -116,7 +116,9 @@ func TestTxNotifierFutureConfDispatch(t *testing.T) { ) hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(10, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + 10, chainntnfs.ReorgSafetyLimit, hintCache, hintCache, + ) // Create the test transactions and register them with the TxNotifier // before including them in a block to receive future @@ -294,7 +296,9 @@ func TestTxNotifierHistoricalConfDispatch(t *testing.T) { ) hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(10, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + 10, chainntnfs.ReorgSafetyLimit, hintCache, hintCache, + ) // Create the test transactions at a height before the TxNotifier's // starting height so that they are confirmed once registering them. @@ -436,7 +440,9 @@ func TestTxNotifierFutureSpendDispatch(t *testing.T) { t.Parallel() hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(10, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + 10, chainntnfs.ReorgSafetyLimit, hintCache, hintCache, + ) // We'll start off by registering for a spend notification of an // outpoint. @@ -520,7 +526,10 @@ func TestTxNotifierHistoricalSpendDispatch(t *testing.T) { const startingHeight = 10 hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // We'll start by constructing the spending details of the outpoint // below. @@ -601,7 +610,10 @@ func TestTxNotifierMultipleHistoricalConfRescans(t *testing.T) { const startingHeight = 10 hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // The first registration for a transaction in the notifier should // request a historical confirmation rescan as it does not have a @@ -667,7 +679,10 @@ func TestTxNotifierMultipleHistoricalSpendRescans(t *testing.T) { const startingHeight = 10 hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // The first registration for an outpoint in the notifier should request // a historical spend rescan as it does not have a historical view of @@ -745,7 +760,10 @@ func TestTxNotifierMultipleHistoricalNtfns(t *testing.T) { ) hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // We'll start off by registered 5 clients for a confirmation // notification on the same transaction. @@ -900,7 +918,10 @@ func TestTxNotifierCancelSpend(t *testing.T) { const startingHeight = 10 hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // We'll register two notification requests. Only the second one will be // canceled. @@ -992,7 +1013,9 @@ func TestTxNotifierConfReorg(t *testing.T) { ) hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(7, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + 7, chainntnfs.ReorgSafetyLimit, hintCache, hintCache, + ) // Tx 1 will be confirmed in block 9 and requires 2 confs. tx1Hash := tx1.TxHash() @@ -1262,7 +1285,10 @@ func TestTxNotifierSpendReorg(t *testing.T) { const startingHeight = 10 hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // We'll have two outpoints that will be spent throughout the test. The // first will be spent and will not experience a reorg, while the second @@ -1482,7 +1508,10 @@ func TestTxNotifierConfirmHintCache(t *testing.T) { // Initialize our TxNotifier instance backed by a height hint cache. hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // Create two test transactions and register them for notifications. tx1 := wire.MsgTx{Version: 1} @@ -1682,7 +1711,10 @@ func TestTxNotifierSpendHintCache(t *testing.T) { // Intiialize our TxNotifier instance backed by a height hint cache. hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(startingHeight, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + startingHeight, chainntnfs.ReorgSafetyLimit, hintCache, + hintCache, + ) // Create two test outpoints and register them for spend notifications. op1 := wire.OutPoint{Hash: zeroHash, Index: 1} @@ -1854,7 +1886,9 @@ func TestTxNotifierTearDown(t *testing.T) { t.Parallel() hintCache := newMockHintCache() - n := chainntnfs.NewTxNotifier(10, 100, hintCache, hintCache) + n := chainntnfs.NewTxNotifier( + 10, chainntnfs.ReorgSafetyLimit, hintCache, hintCache, + ) // To begin the test, we'll register for a confirmation and spend // notification.