watchtower/wtdb: add CSessionStatus field to ClientSession
This commit adds persisted status bit-field to ClientSessions, that can be used to modify behavior of their handling in the client. Currently, only a default CSessionActive status is defined. However, the intention is that this could later be used to signal that a session is abandoned without needing to perform a db migration to add the field. As we move forward with testing, this will likely be useful if a session gets borked and we need a simple method of the client to temporarily ignore certain sessions. The field may be useful in signaling other types of status changes, though this was the primary motivation that warranted the addition.
This commit is contained in:
parent
9157c88f93
commit
28bf49807e
@ -128,6 +128,11 @@ func WriteElement(w io.Writer, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
case uint8:
|
||||
if err := binary.Write(w, byteOrder, e); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case bool:
|
||||
if err := binary.Write(w, byteOrder, e); err != nil {
|
||||
return err
|
||||
@ -289,6 +294,11 @@ func ReadElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
case *uint8:
|
||||
if err := binary.Read(r, byteOrder, e); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case *bool:
|
||||
if err := binary.Read(r, byteOrder, e); err != nil {
|
||||
return err
|
||||
|
@ -8,6 +8,16 @@ import (
|
||||
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
|
||||
)
|
||||
|
||||
// CSessionStatus is a bit-field representing the possible statuses of
|
||||
// ClientSessions.
|
||||
type CSessionStatus uint8
|
||||
|
||||
const (
|
||||
// CSessionActive indicates that the ClientSession is active and can be
|
||||
// used for backups.
|
||||
CSessionActive CSessionStatus = 0
|
||||
)
|
||||
|
||||
// ClientSession encapsulates a SessionInfo returned from a successful
|
||||
// session negotiation, and also records the tower and ephemeral secret used for
|
||||
// communicating with the tower.
|
||||
@ -76,6 +86,9 @@ type ClientSessionBody struct {
|
||||
// Policy holds the negotiated session parameters.
|
||||
Policy wtpolicy.Policy
|
||||
|
||||
// Status indicates the current state of the ClientSession.
|
||||
Status CSessionStatus
|
||||
|
||||
// RewardPkScript is the pkscript that the tower's reward will be
|
||||
// deposited to if a sweep transaction confirms and the sessions
|
||||
// specifies a reward output.
|
||||
@ -89,6 +102,7 @@ func (s *ClientSessionBody) Encode(w io.Writer) error {
|
||||
s.TowerLastApplied,
|
||||
uint64(s.TowerID),
|
||||
s.KeyIndex,
|
||||
uint8(s.Status),
|
||||
s.Policy,
|
||||
s.RewardPkScript,
|
||||
)
|
||||
@ -96,12 +110,16 @@ func (s *ClientSessionBody) Encode(w io.Writer) error {
|
||||
|
||||
// Decode reads a ClientSessionBody from the passed io.Reader.
|
||||
func (s *ClientSessionBody) Decode(r io.Reader) error {
|
||||
var towerID uint64
|
||||
var (
|
||||
towerID uint64
|
||||
status uint8
|
||||
)
|
||||
err := ReadElements(r,
|
||||
&s.SeqNum,
|
||||
&s.TowerLastApplied,
|
||||
&towerID,
|
||||
&s.KeyIndex,
|
||||
&status,
|
||||
&s.Policy,
|
||||
&s.RewardPkScript,
|
||||
)
|
||||
@ -110,6 +128,7 @@ func (s *ClientSessionBody) Decode(r io.Reader) error {
|
||||
}
|
||||
|
||||
s.TowerID = TowerID(towerID)
|
||||
s.Status = CSessionStatus(status)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user