Skip to content

Commit 627a830

Browse files
authored
Merge pull request #844 from sputn1ck/static_sweep_batching
static addr loopin: add support for sweepless sweep batching
2 parents 0d87b69 + 144b62c commit 627a830

File tree

19 files changed

+1098
-1253
lines changed

19 files changed

+1098
-1253
lines changed

loopd/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
633633
Store: staticAddressLoopInStore,
634634
WalletKit: d.lnd.WalletKit,
635635
ChainNotifier: d.lnd.ChainNotifier,
636+
NotificationManager: notificationManager,
636637
ChainParams: d.lnd.ChainParams,
637638
Signer: d.lnd.Signer,
638639
ValidateLoopInContract: loop.ValidateLoopInContract,

loopd/swapclient_server.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,14 +1796,11 @@ func toClientStaticAddressLoopInState(
17961796
case loopin.HtlcTimeoutSwept:
17971797
return looprpc.StaticAddressLoopInSwapState_HTLC_STATIC_ADDRESS_TIMEOUT_SWEPT
17981798

1799-
case loopin.FetchSignPushSweeplessSweepTx:
1800-
return looprpc.StaticAddressLoopInSwapState_FETCH_SIGN_PUSH_SWEEPLESS_SWEEP_TX
1801-
18021799
case loopin.Succeeded:
18031800
return looprpc.StaticAddressLoopInSwapState_SUCCEEDED
18041801

1805-
case loopin.SucceededSweeplessSigFailed:
1806-
return looprpc.StaticAddressLoopInSwapState_SUCCEEDED_SWEEPLESS_SIG_FAILED
1802+
case loopin.SucceededTransitioningFailed:
1803+
return looprpc.StaticAddressLoopInSwapState_SUCCEEDED_TRANSITIONING_FAILED
18071804

18081805
case loopin.UnlockDeposits:
18091806
return looprpc.StaticAddressLoopInSwapState_UNLOCK_DEPOSITS

looprpc/client.pb.go

Lines changed: 170 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,23 +1855,19 @@ enum StaticAddressLoopInSwapState {
18551855

18561856
/*
18571857
*/
1858-
FETCH_SIGN_PUSH_SWEEPLESS_SWEEP_TX = 8;
1858+
SUCCEEDED = 8;
18591859

18601860
/*
18611861
*/
1862-
SUCCEEDED = 9;
1862+
SUCCEEDED_TRANSITIONING_FAILED = 9;
18631863

18641864
/*
18651865
*/
1866-
SUCCEEDED_SWEEPLESS_SIG_FAILED = 10;
1866+
UNLOCK_DEPOSITS = 10;
18671867

18681868
/*
18691869
*/
1870-
UNLOCK_DEPOSITS = 11;
1871-
1872-
/*
1873-
*/
1874-
FAILED_STATIC_ADDRESS_SWAP = 12;
1870+
FAILED_STATIC_ADDRESS_SWAP = 11;
18751871
}
18761872

18771873
message StaticAddressLoopInRequest {

looprpc/client.swagger.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,9 +1634,8 @@
16341634
"SWEEP_STATIC_ADDRESS_HTLC_TIMEOUT",
16351635
"MONITOR_HTLC_TIMEOUT_SWEEP",
16361636
"HTLC_STATIC_ADDRESS_TIMEOUT_SWEPT",
1637-
"FETCH_SIGN_PUSH_SWEEPLESS_SWEEP_TX",
16381637
"SUCCEEDED",
1639-
"SUCCEEDED_SWEEPLESS_SIG_FAILED",
1638+
"SUCCEEDED_TRANSITIONING_FAILED",
16401639
"UNLOCK_DEPOSITS",
16411640
"FAILED_STATIC_ADDRESS_SWAP"
16421641
],

notifications/manager.go

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const (
2020
// NotificationTypeReservation is the notification type for reservation
2121
// notifications.
2222
NotificationTypeReservation
23+
24+
// NotificationTypeStaticLoopInSweepRequest is the notification type for
25+
// static loop in sweep requests.
26+
NotificationTypeStaticLoopInSweepRequest
2327
)
2428

2529
// Client is the interface that the notification manager needs to implement in
@@ -79,7 +83,8 @@ func (m *Manager) SubscribeReservations(ctx context.Context,
7983

8084
m.addSubscriber(NotificationTypeReservation, sub)
8185

82-
// Start a goroutine to remove the subscriber when the context is canceled
86+
// Start a goroutine to remove the subscriber when the context is
87+
// canceled.
8388
go func() {
8489
<-ctx.Done()
8590
m.removeSubscriber(NotificationTypeReservation, sub)
@@ -89,6 +94,34 @@ func (m *Manager) SubscribeReservations(ctx context.Context,
8994
return notifChan
9095
}
9196

97+
// SubscribeStaticLoopInSweepRequests subscribes to the static loop in sweep
98+
// requests.
99+
func (m *Manager) SubscribeStaticLoopInSweepRequests(ctx context.Context,
100+
) <-chan *swapserverrpc.ServerStaticLoopInSweepNotification {
101+
102+
notifChan := make(
103+
chan *swapserverrpc.ServerStaticLoopInSweepNotification, 1,
104+
)
105+
sub := subscriber{
106+
subCtx: ctx,
107+
recvChan: notifChan,
108+
}
109+
110+
m.addSubscriber(NotificationTypeStaticLoopInSweepRequest, sub)
111+
112+
// Start a goroutine to remove the subscriber when the context is
113+
// canceled.
114+
go func() {
115+
<-ctx.Done()
116+
m.removeSubscriber(
117+
NotificationTypeStaticLoopInSweepRequest, sub,
118+
)
119+
close(notifChan)
120+
}()
121+
122+
return notifChan
123+
}
124+
92125
// Run starts the notification manager. It will keep on running until the
93126
// context is canceled. It will subscribe to notifications and forward them to
94127
// the subscribers. On a first successful connection to the server, it will
@@ -160,7 +193,7 @@ func (m *Manager) subscribeNotifications(ctx context.Context,
160193
for {
161194
notification, err := notifStream.Recv()
162195
if err == nil && notification != nil {
163-
log.Debugf("Received notification: %v", notification)
196+
log.Tracef("Received notification: %v", notification)
164197
m.handleNotification(notification)
165198
continue
166199
}
@@ -173,13 +206,13 @@ func (m *Manager) subscribeNotifications(ctx context.Context,
173206

174207
// handleNotification handles an incoming notification from the server,
175208
// forwarding it to the appropriate subscribers.
176-
func (m *Manager) handleNotification(notification *swapserverrpc.
209+
func (m *Manager) handleNotification(ntfn *swapserverrpc.
177210
SubscribeNotificationsResponse) {
178211

179-
switch notification.Notification.(type) {
180-
case *swapserverrpc.SubscribeNotificationsResponse_ReservationNotification:
212+
switch ntfn.Notification.(type) {
213+
case *swapserverrpc.SubscribeNotificationsResponse_ReservationNotification: // nolint: lll
181214
// We'll forward the reservation notification to all subscribers.
182-
reservationNtfn := notification.GetReservationNotification()
215+
reservationNtfn := ntfn.GetReservationNotification()
183216
m.Lock()
184217
defer m.Unlock()
185218

@@ -189,10 +222,23 @@ func (m *Manager) handleNotification(notification *swapserverrpc.
189222

190223
recvChan <- reservationNtfn
191224
}
225+
case *swapserverrpc.SubscribeNotificationsResponse_StaticLoopInSweep: // nolint: lll
226+
// We'll forward the static loop in sweep request to all
227+
// subscribers.
228+
staticLoopInSweepRequestNtfn := ntfn.GetStaticLoopInSweep()
229+
m.Lock()
230+
defer m.Unlock()
231+
232+
for _, sub := range m.subscribers[NotificationTypeStaticLoopInSweepRequest] { // nolint: lll
233+
recvChan := sub.recvChan.(chan *swapserverrpc.
234+
ServerStaticLoopInSweepNotification)
235+
236+
recvChan <- staticLoopInSweepRequestNtfn
237+
}
192238

193239
default:
194240
log.Warnf("Received unknown notification type: %v",
195-
notification)
241+
ntfn)
196242
}
197243
}
198244

staticaddr/address/manager_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ func (m *mockStaticAddressClient) PushStaticAddressSweeplessSigs(ctx context.Con
5454
args.Error(1)
5555
}
5656

57-
func (m *mockStaticAddressClient) FetchSweeplessSweepTx(ctx context.Context,
58-
in *swapserverrpc.FetchSweeplessSweepTxRequest,
59-
opts ...grpc.CallOption) (
60-
*swapserverrpc.FetchSweeplessSweepTxResponse, error) {
61-
62-
args := m.Called(ctx, in, opts)
63-
64-
return args.Get(0).(*swapserverrpc.FetchSweeplessSweepTxResponse),
65-
args.Error(1)
66-
}
67-
6857
func (m *mockStaticAddressClient) PushStaticAddressHtlcSigs(ctx context.Context,
6958
in *swapserverrpc.PushStaticAddressHtlcSigsRequest,
7059
opts ...grpc.CallOption) (

staticaddr/deposit/manager_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ func (m *mockStaticAddressClient) PushStaticAddressSweeplessSigs(ctx context.Con
7373
args.Error(1)
7474
}
7575

76-
func (m *mockStaticAddressClient) FetchSweeplessSweepTx(ctx context.Context,
77-
in *swapserverrpc.FetchSweeplessSweepTxRequest,
78-
opts ...grpc.CallOption) (
79-
*swapserverrpc.FetchSweeplessSweepTxResponse, error) {
80-
81-
args := m.Called(ctx, in, opts)
82-
83-
return args.Get(0).(*swapserverrpc.FetchSweeplessSweepTxResponse),
84-
args.Error(1)
85-
}
86-
8776
func (m *mockStaticAddressClient) PushStaticAddressHtlcSigs(ctx context.Context,
8877
in *swapserverrpc.PushStaticAddressHtlcSigsRequest,
8978
opts ...grpc.CallOption) (

0 commit comments

Comments
 (0)