@@ -102,6 +102,16 @@ var (
102102 // parameters.
103103 liquidtyParamsKey = []byte ("params" )
104104
105+ // keyLocatorKey is the key that stores the receiver key's locator info
106+ // for loop outs or the sender key's locator info for loop ins. This is
107+ // required for MuSig2 swaps. Only serialized/deserialized for swaps
108+ // that have protocol version >= ProtocolVersionHtlcV3.
109+ //
110+ // path: loopInBucket/loopOutBucket -> swapBucket[hash] -> keyLocatorKey
111+ //
112+ // value: concatenation of uint32 values [family, index].
113+ keyLocatorKey = []byte ("keylocator" )
114+
105115 byteOrder = binary .BigEndian
106116
107117 keyLength = 33
@@ -327,6 +337,16 @@ func (s *boltSwapStore) FetchLoopOutSwaps() ([]*LoopOut, error) {
327337 return err
328338 }
329339
340+ // Try to unmarshal the key locator.
341+ if contract .ProtocolVersion >= ProtocolVersionHtlcV3 {
342+ contract .ClientKeyLocator , err = UnmarshalKeyLocator (
343+ swapBucket .Get (keyLocatorKey ),
344+ )
345+ if err != nil {
346+ return err
347+ }
348+ }
349+
330350 loop := LoopOut {
331351 Loop : Loop {
332352 Events : updates ,
@@ -464,6 +484,16 @@ func (s *boltSwapStore) FetchLoopInSwaps() ([]*LoopIn, error) {
464484 return err
465485 }
466486
487+ // Try to unmarshal the key locator.
488+ if contract .ProtocolVersion >= ProtocolVersionHtlcV3 {
489+ contract .ClientKeyLocator , err = UnmarshalKeyLocator (
490+ swapBucket .Get (keyLocatorKey ),
491+ )
492+ if err != nil {
493+ return err
494+ }
495+ }
496+
467497 loop := LoopIn {
468498 Loop : Loop {
469499 Events : updates ,
@@ -583,6 +613,21 @@ func (s *boltSwapStore) CreateLoopOut(hash lntypes.Hash,
583613 return err
584614 }
585615
616+ // Store the key locator for swaps with taproot htlc.
617+ if swap .ProtocolVersion >= ProtocolVersionHtlcV3 {
618+ keyLocator , err := MarshalKeyLocator (
619+ swap .ClientKeyLocator ,
620+ )
621+ if err != nil {
622+ return err
623+ }
624+
625+ err = swapBucket .Put (keyLocatorKey , keyLocator )
626+ if err != nil {
627+ return err
628+ }
629+ }
630+
586631 // Finally, we'll create an empty updates bucket for this swap
587632 // to track any future updates to the swap itself.
588633 _ , err = swapBucket .CreateBucket (updatesBucketKey )
@@ -634,6 +679,21 @@ func (s *boltSwapStore) CreateLoopIn(hash lntypes.Hash,
634679 return err
635680 }
636681
682+ // Store the key locator for swaps with taproot htlc.
683+ if swap .ProtocolVersion >= ProtocolVersionHtlcV3 {
684+ keyLocator , err := MarshalKeyLocator (
685+ swap .ClientKeyLocator ,
686+ )
687+ if err != nil {
688+ return err
689+ }
690+
691+ err = swapBucket .Put (keyLocatorKey , keyLocator )
692+ if err != nil {
693+ return err
694+ }
695+ }
696+
637697 // Finally, we'll create an empty updates bucket for this swap
638698 // to track any future updates to the swap itself.
639699 _ , err = swapBucket .CreateBucket (updatesBucketKey )
0 commit comments