Skip to content

Commit 3390258

Browse files
authored
Merge branch 'lightningnetwork:master' into negative_vbyte
2 parents abfd0fb + 9a6d34a commit 3390258

18 files changed

+3049
-2187
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
runs-on: ubuntu-latest
4949
steps:
5050
- name: Git checkout
51-
uses: actions/checkout@v4
51+
uses: actions/checkout@v5
5252
with:
5353
# Needed for some checks.
5454
fetch-depth: 0
@@ -115,7 +115,7 @@ jobs:
115115
runs-on: ubuntu-latest
116116
steps:
117117
- name: git checkout
118-
uses: actions/checkout@v4
118+
uses: actions/checkout@v5
119119
with:
120120
fetch-depth: 0
121121

@@ -143,7 +143,7 @@ jobs:
143143
runs-on: ubuntu-latest
144144
steps:
145145
- name: git checkout
146-
uses: actions/checkout@v4
146+
uses: actions/checkout@v5
147147
with:
148148
fetch-depth: 0
149149

@@ -179,7 +179,7 @@ jobs:
179179
sys: darwin-arm64 freebsd-arm linux-armv6 linux-armv7 linux-arm64 windows-arm
180180
steps:
181181
- name: Git checkout
182-
uses: actions/checkout@v4
182+
uses: actions/checkout@v5
183183

184184
- name: Clean up runner space
185185
uses: ./.github/actions/cleanup-space
@@ -216,7 +216,7 @@ jobs:
216216

217217
steps:
218218
- name: Git checkout
219-
uses: actions/checkout@v4
219+
uses: actions/checkout@v5
220220
with:
221221
fetch-depth: 0
222222

@@ -228,7 +228,7 @@ jobs:
228228
uses: ./.github/actions/rebase
229229

230230
- name: Git checkout fuzzing seeds
231-
uses: actions/checkout@v4
231+
uses: actions/checkout@v5
232232
with:
233233
repository: lightninglabs/lnd-fuzz
234234
path: lnd-fuzz
@@ -284,7 +284,7 @@ jobs:
284284
args: backend=neutrino cover=1
285285
steps:
286286
- name: Git checkout
287-
uses: actions/checkout@v4
287+
uses: actions/checkout@v5
288288
with:
289289
fetch-depth: 0
290290

@@ -374,7 +374,7 @@ jobs:
374374
args: backend=bitcoind dbbackend=postgres nativesql=true tags=test_native_sql
375375
steps:
376376
- name: Git checkout
377-
uses: actions/checkout@v4
377+
uses: actions/checkout@v5
378378
with:
379379
fetch-depth: 0
380380

@@ -444,7 +444,7 @@ jobs:
444444
runs-on: windows-latest
445445
steps:
446446
- name: Git checkout
447-
uses: actions/checkout@v4
447+
uses: actions/checkout@v5
448448
with:
449449
fetch-depth: 0
450450

@@ -496,7 +496,7 @@ jobs:
496496
runs-on: macos-14
497497
steps:
498498
- name: Git checkout
499-
uses: actions/checkout@v4
499+
uses: actions/checkout@v5
500500
with:
501501
fetch-depth: 0
502502

@@ -551,7 +551,7 @@ jobs:
551551

552552
steps:
553553
- name: Git checkout
554-
uses: actions/checkout@v4
554+
uses: actions/checkout@v5
555555

556556
- name: Clean up runner space
557557
uses: ./.github/actions/cleanup-space
@@ -567,7 +567,7 @@ jobs:
567567
runs-on: ubuntu-latest
568568
steps:
569569
- name: Git checkout
570-
uses: actions/checkout@v4
570+
uses: actions/checkout@v5
571571

572572
- name: Check for no-changelog label
573573
id: check-label
@@ -592,7 +592,7 @@ jobs:
592592
runs-on: ubuntu-latest
593593
steps:
594594
- name: Git checkout
595-
uses: actions/checkout@v4
595+
uses: actions/checkout@v5
596596

597597
- name: 🐳 Set up Docker Buildx
598598
uses: docker/setup-buildx-action@v3
@@ -613,7 +613,7 @@ jobs:
613613
614614
steps:
615615
- name: Checkout repository
616-
uses: actions/checkout@v4
616+
uses: actions/checkout@v5
617617

618618
- name: Delete caches older than 12 hours
619619
continue-on-error: true

chainntnfs/interface.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,20 @@ type TxConfirmation struct {
203203
Block *wire.MsgBlock
204204
}
205205

206+
// TxUpdateInfo contains information about a transaction before it has reached
207+
// its required number of confirmations. Transactions are registered for
208+
// notification for a specific number of "required" confirmations, this struct
209+
// will update the caller incrementally after each new block is found as long as
210+
// the transaction is not yet fully regarded as confirmed.
211+
type TxUpdateInfo struct {
212+
// BlockHeight is the height of the block that contains the transaction.
213+
BlockHeight uint32
214+
215+
// NumConfsLeft is the number of confirmations left for the transaction
216+
// to be regarded as fully confirmed.
217+
NumConfsLeft uint32
218+
}
219+
206220
// ConfirmationEvent encapsulates a confirmation notification. With this struct,
207221
// callers can be notified of: the instance the target txid reaches the targeted
208222
// number of confirmations, how many confirmations are left for the target txid
@@ -229,11 +243,12 @@ type ConfirmationEvent struct {
229243

230244
// Updates is a channel that will sent upon, at every incremental
231245
// confirmation, how many confirmations are left to declare the
232-
// transaction as fully confirmed.
246+
// transaction as fully confirmed, along with the height of the block
247+
// that contains the transaction.
233248
//
234249
// NOTE: This channel must be buffered with the number of required
235250
// confirmations.
236-
Updates chan uint32
251+
Updates chan TxUpdateInfo
237252

238253
// NegativeConf is a channel that will be sent upon if the transaction
239254
// confirms, but is later reorged out of the chain. The integer sent
@@ -262,7 +277,7 @@ func NewConfirmationEvent(numConfs uint32, cancel func()) *ConfirmationEvent {
262277
// the channel so we need to create a larger buffer to avoid
263278
// blocking the notifier.
264279
Confirmed: make(chan *TxConfirmation, 1),
265-
Updates: make(chan uint32, numConfs),
280+
Updates: make(chan TxUpdateInfo, numConfs),
266281
NegativeConf: make(chan int32, 1),
267282
Done: make(chan struct{}, 1),
268283
Cancel: cancel,

chainntnfs/txnotifier.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,12 @@ func (n *TxNotifier) dispatchConfDetails(
947947

948948
// We'll send a 0 value to the Updates channel,
949949
// indicating that the transaction/output script has already
950-
// been confirmed.
951-
err := n.notifyNumConfsLeft(ntfn, 0)
950+
// been confirmed, and include the block height at which the
951+
// transaction was included.
952+
err := n.notifyNumConfsLeft(ntfn, TxUpdateInfo{
953+
NumConfsLeft: 0,
954+
BlockHeight: details.BlockHeight,
955+
})
952956
if err != nil {
953957
return err
954958
}
@@ -977,7 +981,10 @@ func (n *TxNotifier) dispatchConfDetails(
977981
// confirmations are left for the transaction/output script to
978982
// be confirmed.
979983
numConfsLeft := confHeight - n.currentHeight
980-
err := n.notifyNumConfsLeft(ntfn, numConfsLeft)
984+
err := n.notifyNumConfsLeft(ntfn, TxUpdateInfo{
985+
NumConfsLeft: numConfsLeft,
986+
BlockHeight: details.BlockHeight,
987+
})
981988
if err != nil {
982989
return err
983990
}
@@ -1731,7 +1738,10 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
17311738
for confRequest := range confRequests {
17321739
confSet := n.confNotifications[confRequest]
17331740
for _, ntfn := range confSet.ntfns {
1734-
txConfHeight := confSet.details.BlockHeight +
1741+
// blockHeight is the height of the block which
1742+
// contains the transaction.
1743+
blockHeight := confSet.details.BlockHeight
1744+
txConfHeight := blockHeight +
17351745
ntfn.NumConfirmations - 1
17361746
numConfsLeft := txConfHeight - height
17371747

@@ -1744,7 +1754,10 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
17441754
continue
17451755
}
17461756

1747-
err := n.notifyNumConfsLeft(ntfn, numConfsLeft)
1757+
err := n.notifyNumConfsLeft(ntfn, TxUpdateInfo{
1758+
NumConfsLeft: numConfsLeft,
1759+
BlockHeight: blockHeight,
1760+
})
17481761
if err != nil {
17491762
return err
17501763
}
@@ -2011,6 +2024,20 @@ func (n *TxNotifier) dispatchConfReorg(ntfn *ConfNtfn,
20112024
if !ntfn.dispatched {
20122025
confHeight := heightDisconnected + ntfn.NumConfirmations - 1
20132026
ntfnSet, exists := n.ntfnsByConfirmHeight[confHeight]
2027+
2028+
// We also signal the reorg to the notifier in case the
2029+
// subscriber is also interested in the reorgs before the
2030+
// transaction received its required confirmation.
2031+
//
2032+
// Because as soon as a new block is connected which has the
2033+
// transaction included again we preemptively read the buffered
2034+
// channel.
2035+
select {
2036+
case ntfn.Event.NegativeConf <- int32(n.reorgDepth):
2037+
case <-n.quit:
2038+
return ErrTxNotifierExiting
2039+
}
2040+
20142041
if exists {
20152042
delete(ntfnSet, ntfn)
20162043
}
@@ -2099,25 +2126,28 @@ func (n *TxNotifier) TearDown() {
20992126
}
21002127

21012128
// notifyNumConfsLeft sends the number of confirmations left to the
2102-
// notification subscriber through the Event.Updates channel.
2129+
// notification subscriber through the Event.Updates channel, along with the
2130+
// block height in which the transaction was included.
21032131
//
21042132
// NOTE: must be used with the TxNotifier's lock held.
2105-
func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn, num uint32) error {
2133+
func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn,
2134+
info TxUpdateInfo) error {
2135+
21062136
// If the number left is no less than the recorded value, we can skip
21072137
// sending it as it means this same value has already been sent before.
2108-
if num >= ntfn.numConfsLeft {
2138+
if info.NumConfsLeft >= ntfn.numConfsLeft {
21092139
Log.Debugf("Skipped dispatched update (numConfsLeft=%v) for "+
2110-
"request %v conf_id=%v", num, ntfn.ConfRequest,
2111-
ntfn.ConfID)
2140+
"request %v conf_id=%v", info.NumConfsLeft,
2141+
ntfn.ConfRequest, ntfn.ConfID)
21122142

21132143
return nil
21142144
}
21152145

21162146
// Update the number of confirmations left to the notification.
2117-
ntfn.numConfsLeft = num
2147+
ntfn.numConfsLeft = info.NumConfsLeft
21182148

21192149
select {
2120-
case ntfn.Event.Updates <- num:
2150+
case ntfn.Event.Updates <- info:
21212151
case <-n.quit:
21222152
return ErrTxNotifierExiting
21232153
}

0 commit comments

Comments
 (0)