@@ -223,7 +223,7 @@ module Channel =
223
223
RemoteNextHTLCId = HTLCId.Zero
224
224
OriginChannels = Map.empty
225
225
// we will receive their next per-commitment point in the next msg, so we temporarily put a random byte array
226
- RemoteNextCommitInfo = DataEncoders.HexEncoder() .DecodeData( " 0101010101010101010101010101010101010101010101010101010101010101" ) |> Key |> fun k -> k.PubKey |> Choice2Of2
226
+ RemoteNextCommitInfo = DataEncoders.HexEncoder() .DecodeData( " 0101010101010101010101010101010101010101010101010101010101010101" ) |> Key |> fun k -> k.PubKey |> RemoteNextCommitInfo.Revoked
227
227
RemotePerCommitmentSecrets = ShaChain.Zero
228
228
ChannelId =
229
229
msg.ChannelId }
@@ -316,7 +316,7 @@ module Channel =
316
316
LocalNextHTLCId = HTLCId.Zero
317
317
RemoteNextHTLCId = HTLCId.Zero
318
318
OriginChannels = Map.empty
319
- RemoteNextCommitInfo = DataEncoders.HexEncoder() .DecodeData( " 0101010101010101010101010101010101010101010101010101010101010101" ) |> Key |> fun k -> k.PubKey |> Choice2Of2
319
+ RemoteNextCommitInfo = DataEncoders.HexEncoder() .DecodeData( " 0101010101010101010101010101010101010101010101010101010101010101" ) |> Key |> fun k -> k.PubKey |> RemoteNextCommitInfo.Revoked
320
320
RemotePerCommitmentSecrets = ShaChain.Zero
321
321
ChannelId = channelId }
322
322
let nextState = { WaitForFundingConfirmedData.Commitments = commitments
@@ -376,7 +376,7 @@ module Channel =
376
376
true ,
377
377
None)
378
378
let nextState = { NormalData.Buried = true
379
- Commitments = { state.Commitments with RemoteNextCommitInfo = Choice2Of2 ( msg.NextPerCommitmentPoint) }
379
+ Commitments = { state.Commitments with RemoteNextCommitInfo = RemoteNextCommitInfo.Revoked ( msg.NextPerCommitmentPoint) }
380
380
ShortChannelId = state.ShortChannelId
381
381
ChannelAnnouncement = None
382
382
ChannelUpdate = initialChannelUpdate
@@ -388,6 +388,32 @@ module Channel =
388
388
[] |> Ok
389
389
390
390
// ---------- normal operation ---------
391
+ | ChannelState.Normal state, GeewalletPayment cmd when state.LocalShutdown.IsSome || state.RemoteShutdown.IsSome ->
392
+ sprintf " Could not send geewallet payment %A since shutdown is already in progress." cmd
393
+ |> apiMisuse
394
+ | ChannelState.Normal state, GeewalletPayment cmd ->
395
+ result {
396
+ let payment : GeewalletPayment = {
397
+ ChannelId = state.Commitments.ChannelId
398
+ Amount = cmd.Amount
399
+ }
400
+ let commitments1 = state.Commitments.AddLocalProposal( payment)
401
+
402
+ let remoteCommit1 =
403
+ match commitments1.RemoteNextCommitInfo with
404
+ | RemoteNextCommitInfo.WaitingForRevocation info -> info.NextRemoteCommit
405
+ | RemoteNextCommitInfo.Revoked _ info -> commitments1.RemoteCommit
406
+ let! reduced = remoteCommit1.Spec.Reduce( commitments1.RemoteChanges.ACKed, commitments1.LocalChanges.Proposed) |> expectTransactionError
407
+ do ! Validation.checkOurGeewalletPaymentIsAcceptableWithCurrentSpec reduced commitments1 payment
408
+ return [ WeAcceptedCMDGeewalletPayment( payment, commitments1) ]
409
+ }
410
+ | ChannelState.Normal state, ApplyGeewalletPayment msg ->
411
+ result {
412
+ let commitments1 = state.Commitments.AddRemoteProposal( msg)
413
+ let! reduced = commitments1.LocalCommit.Spec.Reduce ( commitments1.LocalChanges.ACKed, commitments1.RemoteChanges.Proposed) |> expectTransactionError
414
+ do ! Validation.checkTheirGeewalletPaymentIsAcceptableWithCurrentSpec reduced commitments1 msg
415
+ return [ WeAcceptedGeewalletPayment commitments1 ]
416
+ }
391
417
| ChannelState.Normal state, AddHTLC cmd when state.LocalShutdown.IsSome || state.RemoteShutdown.IsSome ->
392
418
sprintf " Could not add new HTLC %A since shutdown is already in progress." cmd
393
419
|> apiMisuse
@@ -409,8 +435,8 @@ module Channel =
409
435
// we need to base the next current commitment on the last sig we sent, even if we didn't yet receive their revocation
410
436
let remoteCommit1 =
411
437
match commitments1.RemoteNextCommitInfo with
412
- | Choice1Of2 info -> info.NextRemoteCommit
413
- | Choice2Of2 _ info -> commitments1.RemoteCommit
438
+ | RemoteNextCommitInfo.WaitingForRevocation info -> info.NextRemoteCommit
439
+ | RemoteNextCommitInfo.Revoked _ info -> commitments1.RemoteCommit
414
440
let! reduced = remoteCommit1.Spec.Reduce( commitments1.RemoteChanges.ACKed, commitments1.LocalChanges.Proposed) |> expectTransactionError
415
441
do ! Validation.checkOurUpdateAddHTLCIsAcceptableWithCurrentSpec reduced commitments1 add
416
442
return [ WeAcceptedCMDAddHTLC( add, commitments1) ]
@@ -459,9 +485,9 @@ module Channel =
459
485
| _ when ( cm.LocalHasChanges() |> not ) ->
460
486
// Ignore SignCommitment Command (nothing to sign)
461
487
return []
462
- | Choice2Of2 _ ->
488
+ | RemoteNextCommitInfo.Revoked _ ->
463
489
return ! cm |> Commitments.sendCommit ( cs.Secp256k1Context) ( cs.KeysRepository) ( cs.Network)
464
- | Choice1Of2 _ ->
490
+ | RemoteNextCommitInfo.WaitingForRevocation _ ->
465
491
// Already in the process of signing
466
492
return []
467
493
}
@@ -472,17 +498,17 @@ module Channel =
472
498
| ChannelState.Normal state, ApplyRevokeAndACK msg ->
473
499
let cm = state.Commitments
474
500
match cm.RemoteNextCommitInfo with
475
- | Choice1Of2 _ when ( msg.PerCommitmentSecret.ToPubKey() <> cm.RemoteCommit.RemotePerCommitmentPoint) ->
501
+ | RemoteNextCommitInfo.WaitingForRevocation _ when ( msg.PerCommitmentSecret.ToPubKey() <> cm.RemoteCommit.RemotePerCommitmentPoint) ->
476
502
let errorMsg = sprintf " Invalid revoke_and_ack %A ; must be %A " msg.PerCommitmentSecret cm.RemoteCommit.RemotePerCommitmentPoint
477
503
invalidRevokeAndACK msg errorMsg
478
- | Choice2Of2 _ ->
504
+ | RemoteNextCommitInfo.Revoked _ ->
479
505
let errorMsg = sprintf " Unexpected revocation"
480
506
invalidRevokeAndACK msg errorMsg
481
- | Choice1Of2 ({ NextRemoteCommit = theirNextCommit }) ->
507
+ | RemoteNextCommitInfo.WaitingForRevocation ({ NextRemoteCommit = theirNextCommit }) ->
482
508
let commitments1 = { cm with LocalChanges = { cm.LocalChanges with Signed = []; ACKed = cm.LocalChanges.ACKed @ cm.LocalChanges.Signed }
483
509
RemoteChanges = { cm.RemoteChanges with Signed = [] }
484
510
RemoteCommit = theirNextCommit
485
- RemoteNextCommitInfo = Choice2Of2 ( msg.NextPerCommitmentPoint)
511
+ RemoteNextCommitInfo = RemoteNextCommitInfo.Revoked ( msg.NextPerCommitmentPoint)
486
512
RemotePerCommitmentSecrets = cm.RemotePerCommitmentSecrets.AddHash ( msg.PerCommitmentSecret.ToByteArray(), 0xffffffffffff UL - cm.RemoteCommit.Index) }
487
513
let result = [ WeAcceptedRevokeAndACK( commitments1) ]
488
514
result |> Ok
@@ -528,12 +554,12 @@ module Channel =
528
554
// Are we in the middle of a signature?
529
555
match cm.RemoteNextCommitInfo with
530
556
// yes.
531
- | Choice1Of2 waitingForRevocation ->
557
+ | RemoteNextCommitInfo.WaitingForRevocation waitingForRevocation ->
532
558
let nextCommitments = { state.Commitments with
533
- RemoteNextCommitInfo = Choice1Of2 ({ waitingForRevocation with ReSignASAP = true }) }
559
+ RemoteNextCommitInfo = RemoteNextCommitInfo.WaitingForRevocation ({ waitingForRevocation with ReSignASAP = true }) }
534
560
return [ AcceptedShutdownWhileWeHaveUnsignedOutgoingHTLCs( msg, nextCommitments) ]
535
561
// No. let's sign right away.
536
- | Choice2Of2 _ ->
562
+ | RemoteNextCommitInfo.Revoked _ ->
537
563
return [ ChannelStateRequestedSignCommitment; AcceptedShutdownWhileWeHaveUnsignedOutgoingHTLCs( msg, cm) ]
538
564
else
539
565
let ( localShutdown , sendList ) = match state.LocalShutdown with
@@ -600,9 +626,9 @@ module Channel =
600
626
| _ when ( not <| cm.LocalHasChanges()) ->
601
627
// nothing to sign
602
628
[] |> Ok
603
- | Choice2Of2 _ ->
629
+ | RemoteNextCommitInfo.Revoked _ ->
604
630
cm |> Commitments.sendCommit ( cs.Secp256k1Context) ( cs.KeysRepository) ( cs.Network)
605
- | Choice1Of2 _ waitForRevocation ->
631
+ | RemoteNextCommitInfo.WaitingForRevocation _ waitForRevocation ->
606
632
// Already in the process of signing.
607
633
[] |> Ok
608
634
| Shutdown state, ApplyCommitmentSigned msg ->
@@ -730,8 +756,12 @@ module Channel =
730
756
{ c with State = ChannelState.Normal data }
731
757
732
758
// ----- normal operation --------
759
+ | WeAcceptedCMDGeewalletPayment(_, newCommitments), ChannelState.Normal d ->
760
+ { c with State = ChannelState.Normal({ d with Commitments = newCommitments }) }
733
761
| WeAcceptedCMDAddHTLC(_, newCommitments), ChannelState.Normal d ->
734
762
{ c with State = ChannelState.Normal({ d with Commitments = newCommitments }) }
763
+ | WeAcceptedGeewalletPayment( newCommitments), ChannelState.Normal d ->
764
+ { c with State = ChannelState.Normal({ d with Commitments = newCommitments }) }
735
765
| WeAcceptedUpdateAddHTLC( newCommitments), ChannelState.Normal d ->
736
766
{ c with State = ChannelState.Normal({ d with Commitments = newCommitments }) }
737
767
0 commit comments