chainntnfs: initialize TxNotifier with new ReorgSafetyLimit

This commit is contained in:
Wilmer Paulino 2018-12-04 16:58:27 -08:00
parent 9d51114546
commit 7239e04696
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
7 changed files with 58 additions and 40 deletions

@ -20,11 +20,6 @@ const (
// notifierType uniquely identifies this concrete implementation of the // notifierType uniquely identifies this concrete implementation of the
// ChainNotifier interface. // ChainNotifier interface.
notifierType = "bitcoind" notifierType = "bitcoind"
// reorgSafetyLimit is assumed maximum depth of a chain reorganization.
// After this many confirmation, transaction confirmation info will be
// pruned.
reorgSafetyLimit = 100
) )
var ( var (
@ -138,8 +133,8 @@ func (b *BitcoindNotifier) Start() error {
} }
b.txNotifier = chainntnfs.NewTxNotifier( b.txNotifier = chainntnfs.NewTxNotifier(
uint32(currentHeight), reorgSafetyLimit, b.confirmHintCache, uint32(currentHeight), chainntnfs.ReorgSafetyLimit,
b.spendHintCache, b.confirmHintCache, b.spendHintCache,
) )
b.bestBlock = chainntnfs.BlockEpoch{ b.bestBlock = chainntnfs.BlockEpoch{

@ -30,8 +30,8 @@ func (b *BitcoindNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Has
} }
b.txNotifier = chainntnfs.NewTxNotifier( b.txNotifier = chainntnfs.NewTxNotifier(
uint32(bestHeight), reorgSafetyLimit, b.confirmHintCache, uint32(bestHeight), chainntnfs.ReorgSafetyLimit,
b.spendHintCache, b.confirmHintCache, b.spendHintCache,
) )
if generateBlocks != nil { if generateBlocks != nil {

@ -21,11 +21,6 @@ const (
// notifierType uniquely identifies this concrete implementation of the // notifierType uniquely identifies this concrete implementation of the
// ChainNotifier interface. // ChainNotifier interface.
notifierType = "btcd" notifierType = "btcd"
// reorgSafetyLimit is assumed maximum depth of a chain reorganization.
// After this many confirmation, transaction confirmation info will be
// pruned.
reorgSafetyLimit = 100
) )
var ( var (
@ -163,8 +158,8 @@ func (b *BtcdNotifier) Start() error {
} }
b.txNotifier = chainntnfs.NewTxNotifier( b.txNotifier = chainntnfs.NewTxNotifier(
uint32(currentHeight), reorgSafetyLimit, b.confirmHintCache, uint32(currentHeight), chainntnfs.ReorgSafetyLimit,
b.spendHintCache, b.confirmHintCache, b.spendHintCache,
) )
b.bestBlock = chainntnfs.BlockEpoch{ b.bestBlock = chainntnfs.BlockEpoch{

@ -29,8 +29,8 @@ func (b *BtcdNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Hash,
} }
b.txNotifier = chainntnfs.NewTxNotifier( b.txNotifier = chainntnfs.NewTxNotifier(
uint32(bestHeight), reorgSafetyLimit, b.confirmHintCache, uint32(bestHeight), chainntnfs.ReorgSafetyLimit,
b.spendHintCache, b.confirmHintCache, b.spendHintCache,
) )
b.chainUpdates.Start() b.chainUpdates.Start()

@ -25,12 +25,6 @@ const (
// notifierType uniquely identifies this concrete implementation of the // notifierType uniquely identifies this concrete implementation of the
// ChainNotifier interface. // ChainNotifier interface.
notifierType = "neutrino" 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 ( var (
@ -159,7 +153,7 @@ func (n *NeutrinoNotifier) Start() error {
} }
n.txNotifier = chainntnfs.NewTxNotifier( n.txNotifier = chainntnfs.NewTxNotifier(
n.bestHeight, reorgSafetyLimit, n.confirmHintCache, n.bestHeight, chainntnfs.ReorgSafetyLimit, n.confirmHintCache,
n.spendHintCache, n.spendHintCache,
) )

@ -49,8 +49,8 @@ func (n *NeutrinoNotifier) UnsafeStart(bestHeight int32,
} }
n.txNotifier = chainntnfs.NewTxNotifier( n.txNotifier = chainntnfs.NewTxNotifier(
uint32(bestHeight), reorgSafetyLimit, n.confirmHintCache, uint32(bestHeight), chainntnfs.ReorgSafetyLimit,
n.spendHintCache, n.confirmHintCache, n.spendHintCache,
) )
n.chainConn = &NeutrinoChainConn{n.p2pNode} n.chainConn = &NeutrinoChainConn{n.p2pNode}

@ -116,7 +116,9 @@ func TestTxNotifierFutureConfDispatch(t *testing.T) {
) )
hintCache := newMockHintCache() 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 // Create the test transactions and register them with the TxNotifier
// before including them in a block to receive future // before including them in a block to receive future
@ -294,7 +296,9 @@ func TestTxNotifierHistoricalConfDispatch(t *testing.T) {
) )
hintCache := newMockHintCache() 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 // Create the test transactions at a height before the TxNotifier's
// starting height so that they are confirmed once registering them. // starting height so that they are confirmed once registering them.
@ -436,7 +440,9 @@ func TestTxNotifierFutureSpendDispatch(t *testing.T) {
t.Parallel() t.Parallel()
hintCache := newMockHintCache() 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 // We'll start off by registering for a spend notification of an
// outpoint. // outpoint.
@ -520,7 +526,10 @@ func TestTxNotifierHistoricalSpendDispatch(t *testing.T) {
const startingHeight = 10 const startingHeight = 10
hintCache := newMockHintCache() 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 // We'll start by constructing the spending details of the outpoint
// below. // below.
@ -601,7 +610,10 @@ func TestTxNotifierMultipleHistoricalConfRescans(t *testing.T) {
const startingHeight = 10 const startingHeight = 10
hintCache := newMockHintCache() 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 // The first registration for a transaction in the notifier should
// request a historical confirmation rescan as it does not have a // request a historical confirmation rescan as it does not have a
@ -667,7 +679,10 @@ func TestTxNotifierMultipleHistoricalSpendRescans(t *testing.T) {
const startingHeight = 10 const startingHeight = 10
hintCache := newMockHintCache() 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 // The first registration for an outpoint in the notifier should request
// a historical spend rescan as it does not have a historical view of // a historical spend rescan as it does not have a historical view of
@ -745,7 +760,10 @@ func TestTxNotifierMultipleHistoricalNtfns(t *testing.T) {
) )
hintCache := newMockHintCache() 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 // We'll start off by registered 5 clients for a confirmation
// notification on the same transaction. // notification on the same transaction.
@ -900,7 +918,10 @@ func TestTxNotifierCancelSpend(t *testing.T) {
const startingHeight = 10 const startingHeight = 10
hintCache := newMockHintCache() 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 // We'll register two notification requests. Only the second one will be
// canceled. // canceled.
@ -992,7 +1013,9 @@ func TestTxNotifierConfReorg(t *testing.T) {
) )
hintCache := newMockHintCache() 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. // Tx 1 will be confirmed in block 9 and requires 2 confs.
tx1Hash := tx1.TxHash() tx1Hash := tx1.TxHash()
@ -1262,7 +1285,10 @@ func TestTxNotifierSpendReorg(t *testing.T) {
const startingHeight = 10 const startingHeight = 10
hintCache := newMockHintCache() 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 // 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 // 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. // Initialize our TxNotifier instance backed by a height hint cache.
hintCache := newMockHintCache() 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. // Create two test transactions and register them for notifications.
tx1 := wire.MsgTx{Version: 1} tx1 := wire.MsgTx{Version: 1}
@ -1682,7 +1711,10 @@ func TestTxNotifierSpendHintCache(t *testing.T) {
// Intiialize our TxNotifier instance backed by a height hint cache. // Intiialize our TxNotifier instance backed by a height hint cache.
hintCache := newMockHintCache() 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. // Create two test outpoints and register them for spend notifications.
op1 := wire.OutPoint{Hash: zeroHash, Index: 1} op1 := wire.OutPoint{Hash: zeroHash, Index: 1}
@ -1854,7 +1886,9 @@ func TestTxNotifierTearDown(t *testing.T) {
t.Parallel() t.Parallel()
hintCache := newMockHintCache() 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 // To begin the test, we'll register for a confirmation and spend
// notification. // notification.