|
69 | 69 | // value: string label |
70 | 70 | labelKey = []byte("label") |
71 | 71 |
|
| 72 | + // protocolVersionKey is used to optionally store the protocol version |
| 73 | + // for the serialized swap contract. It is nested within the sub-bucket |
| 74 | + // for each active swap. |
| 75 | + // |
| 76 | + // path: loopInBucket/loopOutBucket -> swapBucket[hash] -> protocolVersionKey |
| 77 | + // |
| 78 | + // value: protocol version as specified in server.proto |
| 79 | + protocolVersionKey = []byte("protocol-version") |
| 80 | + |
72 | 81 | // outgoingChanSetKey is the key that stores a list of channel ids that |
73 | 82 | // restrict the loop out swap payment. |
74 | 83 | // |
@@ -276,6 +285,18 @@ func (s *boltSwapStore) FetchLoopOutSwaps() ([]*LoopOut, error) { |
276 | 285 | return err |
277 | 286 | } |
278 | 287 |
|
| 288 | + // Try to unmarshal the protocol version for the swap. |
| 289 | + // If the protocol version is not stored (which is |
| 290 | + // the case for old clients), we'll assume the |
| 291 | + // ProtocolVersionUnrecorded instead. |
| 292 | + contract.ProtocolVersion, err = |
| 293 | + UnmarshalProtocolVersion( |
| 294 | + swapBucket.Get(protocolVersionKey), |
| 295 | + ) |
| 296 | + if err != nil { |
| 297 | + return err |
| 298 | + } |
| 299 | + |
279 | 300 | loop := LoopOut{ |
280 | 301 | Loop: Loop{ |
281 | 302 | Events: updates, |
@@ -401,6 +422,18 @@ func (s *boltSwapStore) FetchLoopInSwaps() ([]*LoopIn, error) { |
401 | 422 | return err |
402 | 423 | } |
403 | 424 |
|
| 425 | + // Try to unmarshal the protocol version for the swap. |
| 426 | + // If the protocol version is not stored (which is |
| 427 | + // the case for old clients), we'll assume the |
| 428 | + // ProtocolVersionUnrecorded instead. |
| 429 | + contract.ProtocolVersion, err = |
| 430 | + UnmarshalProtocolVersion( |
| 431 | + swapBucket.Get(protocolVersionKey), |
| 432 | + ) |
| 433 | + if err != nil { |
| 434 | + return err |
| 435 | + } |
| 436 | + |
404 | 437 | loop := LoopIn{ |
405 | 438 | Loop: Loop{ |
406 | 439 | Events: updates, |
@@ -512,6 +545,14 @@ func (s *boltSwapStore) CreateLoopOut(hash lntypes.Hash, |
512 | 545 | return err |
513 | 546 | } |
514 | 547 |
|
| 548 | + // Store the current protocol version. |
| 549 | + err = swapBucket.Put(protocolVersionKey, |
| 550 | + MarshalProtocolVersion(swap.ProtocolVersion), |
| 551 | + ) |
| 552 | + if err != nil { |
| 553 | + return err |
| 554 | + } |
| 555 | + |
515 | 556 | // Finally, we'll create an empty updates bucket for this swap |
516 | 557 | // to track any future updates to the swap itself. |
517 | 558 | _, err = swapBucket.CreateBucket(updatesBucketKey) |
@@ -550,6 +591,14 @@ func (s *boltSwapStore) CreateLoopIn(hash lntypes.Hash, |
550 | 591 | return err |
551 | 592 | } |
552 | 593 |
|
| 594 | + // Store the current protocol version. |
| 595 | + err = swapBucket.Put(protocolVersionKey, |
| 596 | + MarshalProtocolVersion(swap.ProtocolVersion), |
| 597 | + ) |
| 598 | + if err != nil { |
| 599 | + return err |
| 600 | + } |
| 601 | + |
553 | 602 | // Write label to disk if we have one. |
554 | 603 | if err := putLabel(swapBucket, swap.Label); err != nil { |
555 | 604 | return err |
|
0 commit comments