@@ -1768,11 +1768,17 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
1768
1768
// this new pending commitment. Once they revoked their prior state, we'll swap
1769
1769
// these pointers, causing the tip and the tail to point to the same entry.
1770
1770
func (c * OpenChannel ) RemoteCommitChainTip () (* CommitDiff , error ) {
1771
+ return c .RemoteCommitChainTipFrom (false )
1772
+ }
1773
+
1774
+ // RemoteCommitChainTip returns the "tip" of the current remote commitment
1775
+ // chain. The confirmed bool indicates which bucket to retrieve the data from.
1776
+ func (c * OpenChannel ) RemoteCommitChainTipFrom (confirmed bool ) (* CommitDiff ,
1777
+ error ) {
1778
+
1771
1779
var cd * CommitDiff
1772
1780
err := c .Db .View (func (tx * bbolt.Tx ) error {
1773
- chanBucket , err := fetchChanBucket (
1774
- tx , c .IdentityPub , & c .FundingOutpoint , c .ChainHash ,
1775
- )
1781
+ chanBucket , err := c .fetchChanBucket (tx , confirmed )
1776
1782
switch err {
1777
1783
case nil :
1778
1784
case ErrNoChanDBExists , ErrNoActiveChannels , ErrChannelNotFound :
@@ -2439,15 +2445,63 @@ func (c *OpenChannel) Snapshot() *ChannelSnapshot {
2439
2445
return snapshot
2440
2446
}
2441
2447
2448
+ // fetchPendingCloseChanBucket is a helper function that returns the bucket
2449
+ // where a channel's pending close data resides in given the outpoint.
2450
+ func fetchPendingCloseChanBucket (tx * bbolt.Tx , outPoint * wire.OutPoint ) (
2451
+ * bbolt.Bucket , error ) {
2452
+
2453
+ // First fetch the top level bucket which stores all data related to
2454
+ // current, active channels.
2455
+ historicalBucket := tx .Bucket (historicalChannelBucket )
2456
+ if historicalBucket == nil {
2457
+ return nil , ErrNoChanDBExists
2458
+ }
2459
+
2460
+ // With the bucket for the node and chain fetched, we can now go down
2461
+ // another level, for this channel itself.
2462
+ var chanPointBuf bytes.Buffer
2463
+ if err := writeOutpoint (& chanPointBuf , outPoint ); err != nil {
2464
+ return nil , err
2465
+ }
2466
+ chanBucket := historicalBucket .Bucket (chanPointBuf .Bytes ())
2467
+ if chanBucket == nil {
2468
+ return nil , ErrChannelNotFound
2469
+ }
2470
+
2471
+ return chanBucket , nil
2472
+ }
2473
+
2474
+ // fetchChanBucket returns either the open or the confirmed channel bucket.
2475
+ func (c * OpenChannel ) fetchChanBucket (tx * bbolt.Tx , confirmed bool ) (
2476
+ * bbolt.Bucket , error ) {
2477
+
2478
+ if confirmed {
2479
+ return fetchPendingCloseChanBucket (tx , & c .FundingOutpoint )
2480
+ }
2481
+
2482
+ return fetchChanBucket (
2483
+ tx , c .IdentityPub , & c .FundingOutpoint , c .ChainHash ,
2484
+ )
2485
+ }
2486
+
2442
2487
// LatestCommitments returns the two latest commitments for both the local and
2443
2488
// remote party. These commitments are read from disk to ensure that only the
2444
2489
// latest fully committed state is returned. The first commitment returned is
2445
2490
// the local commitment, and the second returned is the remote commitment.
2446
- func (c * OpenChannel ) LatestCommitments () (* ChannelCommitment , * ChannelCommitment , error ) {
2491
+ func (c * OpenChannel ) LatestCommitments () (* ChannelCommitment ,
2492
+ * ChannelCommitment , error ) {
2493
+
2494
+ return c .LatestCommitmentsFrom (false )
2495
+ }
2496
+
2497
+ // LatestCommitmentsFrom returns the two latest commitments for both the local
2498
+ // and remote party. The confirmed boolean indicates the bucket to read the data
2499
+ // from.
2500
+ func (c * OpenChannel ) LatestCommitmentsFrom (confirmed bool ) (* ChannelCommitment ,
2501
+ * ChannelCommitment , error ) {
2502
+
2447
2503
err := c .Db .View (func (tx * bbolt.Tx ) error {
2448
- chanBucket , err := fetchChanBucket (
2449
- tx , c .IdentityPub , & c .FundingOutpoint , c .ChainHash ,
2450
- )
2504
+ chanBucket , err := c .fetchChanBucket (tx , confirmed )
2451
2505
if err != nil {
2452
2506
return err
2453
2507
}
0 commit comments