diff --git a/chainntnfs/txnotifier.go b/chainntnfs/txnotifier.go index 84bd55e1..9e819ea4 100644 --- a/chainntnfs/txnotifier.go +++ b/chainntnfs/txnotifier.go @@ -26,7 +26,8 @@ var ( // ErrTxMaxConfs signals that the user requested a number of // confirmations beyond the reorg safety limit. - ErrTxMaxConfs = errors.New("too many confirmations requested") + ErrTxMaxConfs = fmt.Errorf("too many confirmations requested, max is %d", + MaxNumConfs) ) // rescanState indicates the progression of a registration before the notifier diff --git a/chainntnfs/txnotifier_test.go b/chainntnfs/txnotifier_test.go index dfaec89c..6a9a533f 100644 --- a/chainntnfs/txnotifier_test.go +++ b/chainntnfs/txnotifier_test.go @@ -99,6 +99,36 @@ func newMockHintCache() *mockHintCache { } } +// TestTxNotifierMaxConfs ensures that we are not able to register for more +// confirmations on a transaction than the maximum supported. +func TestTxNotifierMaxConfs(t *testing.T) { + t.Parallel() + + hintCache := newMockHintCache() + n := chainntnfs.NewTxNotifier( + 10, chainntnfs.ReorgSafetyLimit, hintCache, hintCache, + ) + + // Registering one confirmation above the maximum should fail with + // ErrTxMaxConfs. + ntfn := &chainntnfs.ConfNtfn{ + ConfID: 1, + TxID: &zeroHash, + NumConfirmations: chainntnfs.MaxNumConfs + 1, + Event: chainntnfs.NewConfirmationEvent( + chainntnfs.MaxNumConfs, + ), + } + if _, err := n.RegisterConf(ntfn); err != chainntnfs.ErrTxMaxConfs { + t.Fatalf("expected chainntnfs.ErrTxMaxConfs, got %v", err) + } + + ntfn.NumConfirmations-- + if _, err := n.RegisterConf(ntfn); err != nil { + t.Fatalf("unable to register conf ntfn: %v", err) + } +} + // TestTxNotifierFutureConfDispatch tests that the TxNotifier dispatches // registered notifications when a transaction confirms after registration. func TestTxNotifierFutureConfDispatch(t *testing.T) {