channeldb: store the funding transaction broadcast height for channels

This commit expands the field within the OpenChannel struct in order to
start tracking the height that the funding transaction was initially
broadcast. Other sub-systems within lnd can now use this data to give a
more accurate height hint to the ChainNotifier, or to use during the
funding workflow to decide if a channel should be forgotten after it
fails to confirm for N blocks.
This commit is contained in:
Olaoluwa Osuntokun committed 2017-06-05 19:15:44 -07:00
1 parent fb4121ba6c
commit 66ba2e862c
3 files changed
+60 -26

No files matched your search

+17 -2
View File
@@ -654,7 +654,8 @@ func TestFetchPendingChannels(t *testing.T) {
Port: 18555,
}
if err := state.SyncPending(addr); err != nil {
const broadcastHeight = 99
if err := state.SyncPending(addr, broadcastHeight); err != nil {
t.Fatalf("unable to save and serialize channel state: %v", err)
}
@@ -668,6 +669,14 @@ func TestFetchPendingChannels(t *testing.T) {
"got %v", 1, len(pendingChannels))
}
// The broadcast height of the pending channel should've been set
// properly.
if pendingChannels[0].FundingBroadcastHeight != broadcastHeight {
t.Fatalf("broadcast height mismatch: expected %v, got %v",
pendingChannels[0].FundingBroadcastHeight,
broadcastHeight)
}
const openHeight = 100
err = cdb.MarkChannelAsOpen(pendingChannels[0].ChanID, openHeight)
if err != nil {
@@ -684,6 +693,11 @@ func TestFetchPendingChannels(t *testing.T) {
t.Fatalf("channel opening heights don't match: expected %v, "+
"got %v", openChans[0].OpeningHeight, openHeight)
}
if openChans[0].FundingBroadcastHeight != broadcastHeight {
t.Fatalf("broadcast height mismatch: expected %v, got %v",
openChans[0].FundingBroadcastHeight,
broadcastHeight)
}
pendingChannels, err = cdb.FetchPendingChannels()
if err != nil {
@@ -716,7 +730,8 @@ func TestFetchClosedChannels(t *testing.T) {
IP: net.ParseIP("127.0.0.1"),
Port: 18555,
}
if err := state.SyncPending(addr); err != nil {
const broadcastHeight = 99
if err := state.SyncPending(addr, broadcastHeight); err != nil {
t.Fatalf("unable to save and serialize channel state: %v", err)
}