Skip to content

Commit 03557e1

Browse files
committed
reservation: update reservation state machine
This commit updates the reservation statemachine to allow for locking and spending of the initial reservation.
1 parent a0a243d commit 03557e1

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

instantout/reservation/actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func (r *FSM) SubscribeToConfirmationAction(_ fsm.EventContext) fsm.EventType {
8686
r.reservation.InitiationHeight)
8787

8888
confChan, errConfChan, err := r.cfg.ChainNotifier.RegisterConfirmationsNtfn(
89-
r.ctx, nil, pkscript, DefaultConfTarget,
90-
r.reservation.InitiationHeight,
89+
r.ctx, nil, pkscript, 1,
90+
r.reservation.InitiationHeight-1,
9191
)
9292
if err != nil {
9393
r.Errorf("unable to subscribe to conf notification: %v", err)

instantout/reservation/fsm.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ var (
9696
// Failed is the state where the reservation has failed.
9797
Failed = fsm.StateType("Failed")
9898

99-
// Swept is the state where the reservation has been swept by the server.
99+
// SpendBroadcasted is the state where a spend tx has been broadcast.
100+
SpendBroadcasted = fsm.StateType("SpendBroadcasted")
101+
102+
// SpendConfirmed is the state where a spend tx has been confirmed.
103+
SpendConfirmed = fsm.StateType("SpendConfirmed")
104+
105+
// Swept is the state where the reservation has been swept by the
106+
// server.
100107
Swept = fsm.StateType("Swept")
101108
)
102109

@@ -125,6 +132,14 @@ var (
125132
// OnRecover is the event that is triggered when the reservation FSM
126133
// recovers from a restart.
127134
OnRecover = fsm.EventType("OnRecover")
135+
136+
// OnSpendBroadcasted is the event that is triggered when the spend
137+
// tx has been broadcast.
138+
OnSpendBroadcasted = fsm.EventType("OnSpendBroadcasted")
139+
140+
// OnSpendConfirmed is the event that is triggered when the spend
141+
// tx has been confirmed.
142+
OnSpendConfirmed = fsm.EventType("OnSpendConfirmed")
128143
)
129144

130145
// GetReservationStates returns the statemap that defines the reservation
@@ -155,14 +170,25 @@ func (f *FSM) GetReservationStates() fsm.States {
155170
},
156171
Confirmed: fsm.State{
157172
Transitions: fsm.Transitions{
158-
OnTimedOut: TimedOut,
159-
OnRecover: Confirmed,
173+
OnSpendBroadcasted: SpendBroadcasted,
174+
OnTimedOut: TimedOut,
175+
OnRecover: Confirmed,
160176
},
161177
Action: f.ReservationConfirmedAction,
162178
},
163179
TimedOut: fsm.State{
164180
Action: fsm.NoOpAction,
165181
},
182+
SpendBroadcasted: fsm.State{
183+
Transitions: fsm.Transitions{
184+
OnSpendConfirmed: SpendConfirmed,
185+
},
186+
Action: fsm.NoOpAction,
187+
},
188+
SpendConfirmed: fsm.State{
189+
Action: fsm.NoOpAction,
190+
},
191+
166192
Failed: fsm.State{
167193
Action: fsm.NoOpAction,
168194
},

instantout/reservation/manager.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,22 @@ func (m *Manager) RecoverReservations(ctx context.Context) error {
249249
func (m *Manager) GetReservations(ctx context.Context) ([]*Reservation, error) {
250250
return m.cfg.Store.ListReservations(ctx)
251251
}
252+
253+
// GetReservation returns the reservation for the given id.
254+
func (m *Manager) GetReservation(ctx context.Context, id ID) (*Reservation,
255+
error) {
256+
257+
return m.cfg.Store.GetReservation(ctx, id)
258+
}
259+
260+
// LockReservation locks the reservation for the given id.
261+
func (m *Manager) LockReservation(ctx context.Context, id ID) error {
262+
// TODO(sputn1ck): implement
263+
return nil
264+
}
265+
266+
// UnlockReservation unlocks the reservation for the given id.
267+
func (m *Manager) UnlockReservation(ctx context.Context, id ID) error {
268+
// TODO(sputn1ck): implement
269+
return nil
270+
}

instantout/reservation/reservation_fsm.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
stateDiagram-v2
33
[*] --> Init: OnServerRequest
44
Confirmed
5+
Confirmed --> SpendBroadcasted: OnSpendBroadcasted
56
Confirmed --> TimedOut: OnTimedOut
67
Confirmed --> Confirmed: OnRecover
78
Failed
89
Init
910
Init --> Failed: OnError
1011
Init --> WaitForConfirmation: OnBroadcast
1112
Init --> Failed: OnRecover
13+
SpendBroadcasted
14+
SpendBroadcasted --> SpendConfirmed: OnSpendConfirmed
15+
SpendConfirmed
1216
TimedOut
1317
WaitForConfirmation
1418
WaitForConfirmation --> WaitForConfirmation: OnRecover

0 commit comments

Comments
 (0)