mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
watchtower: refactor putClientSessionBody
Refactor the putClientSessionBody to take in a session sub-bucket rather than the top-level session bucket. This is mainly to make an upcoming commit diff easier to parse.
This commit is contained in:
parent
25afc8ad90
commit
4ea6c7d2ae
1 changed files with 20 additions and 14 deletions
|
@ -711,9 +711,14 @@ func (c *ClientDB) CreateClientSession(session *ClientSession) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sessionBkt, err := sessions.CreateBucket(session.ID[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Finally, write the client session's body in the sessions
|
||||
// bucket.
|
||||
return putClientSessionBody(sessions, session)
|
||||
return putClientSessionBody(sessionBkt, session)
|
||||
}, func() {})
|
||||
}
|
||||
|
||||
|
@ -1082,7 +1087,7 @@ func (c *ClientDB) CommitUpdate(id *SessionID,
|
|||
// eliminate serialization of full struct during CommitUpdate?
|
||||
// Can also read/write directly to byes [:2] without migration.
|
||||
session.SeqNum++
|
||||
err = putClientSessionBody(sessions, session)
|
||||
err = putClientSessionBody(sessionBkt, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1154,15 +1159,15 @@ func (c *ClientDB) AckUpdate(id *SessionID, seqNum uint16,
|
|||
// also read/write directly to byes [2:4] without migration.
|
||||
session.TowerLastApplied = lastApplied
|
||||
|
||||
// Can't fail because getClientSession succeeded.
|
||||
sessionBkt := sessions.NestedReadWriteBucket(id[:])
|
||||
|
||||
// Write the client session with the updated last applied value.
|
||||
err = putClientSessionBody(sessions, session)
|
||||
err = putClientSessionBody(sessionBkt, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Can't fail because of getClientSession succeeded.
|
||||
sessionBkt := sessions.NestedReadWriteBucket(id[:])
|
||||
|
||||
// If the commits sub-bucket doesn't exist, there can't possibly
|
||||
// be a corresponding committed update to remove.
|
||||
sessionCommits := sessionBkt.NestedReadWriteBucket(
|
||||
|
@ -1439,16 +1444,11 @@ func filterClientSessionCommits(sessionBkt kvdb.RBucket, s *ClientSession,
|
|||
|
||||
// putClientSessionBody stores the body of the ClientSession (everything but the
|
||||
// CommittedUpdates and AckedUpdates).
|
||||
func putClientSessionBody(sessions kvdb.RwBucket,
|
||||
func putClientSessionBody(sessionBkt kvdb.RwBucket,
|
||||
session *ClientSession) error {
|
||||
|
||||
sessionBkt, err := sessions.CreateBucketIfNotExists(session.ID[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
err = session.Encode(&b)
|
||||
err := session.Encode(&b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1461,8 +1461,14 @@ func putClientSessionBody(sessions kvdb.RwBucket,
|
|||
func markSessionStatus(sessions kvdb.RwBucket, session *ClientSession,
|
||||
status CSessionStatus) error {
|
||||
|
||||
sessionBkt, err := sessions.CreateBucketIfNotExists(session.ID[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
session.Status = status
|
||||
return putClientSessionBody(sessions, session)
|
||||
|
||||
return putClientSessionBody(sessionBkt, session)
|
||||
}
|
||||
|
||||
// getChanSummary loads a ClientChanSummary for the passed chanID.
|
||||
|
|
Loading…
Add table
Reference in a new issue