mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
wtdb: create and remove tower should no longer change session status
This commit is contained in:
parent
cbf08940ca
commit
41582c0b8b
3 changed files with 18 additions and 66 deletions
|
@ -26,10 +26,9 @@ type DB interface {
|
|||
// RemoveTower modifies a tower's record within the database. If an
|
||||
// address is provided, then _only_ the address record should be removed
|
||||
// from the tower's persisted state. Otherwise, we'll attempt to mark
|
||||
// the tower as inactive by marking all of its sessions inactive. If any
|
||||
// of its sessions has unacked updates, then ErrTowerUnackedUpdates is
|
||||
// returned. If the tower doesn't have any sessions at all, it'll be
|
||||
// completely removed from the database.
|
||||
// the tower as inactive. If any of its sessions have unacked updates,
|
||||
// then ErrTowerUnackedUpdates is returned. If the tower doesn't have
|
||||
// any sessions at all, it'll be completely removed from the database.
|
||||
//
|
||||
// NOTE: An error is not returned if the tower doesn't exist.
|
||||
RemoveTower(*btcec.PublicKey, net.Addr) error
|
||||
|
|
|
@ -394,37 +394,6 @@ func (c *ClientDB) CreateTower(lnAddr *lnwire.NetAddress) (*Tower, error) {
|
|||
// address is a duplicate, this will result in no
|
||||
// change.
|
||||
tower.AddAddress(lnAddr.Address)
|
||||
|
||||
// If there are any client sessions that correspond to
|
||||
// this tower, we'll mark them as active to ensure we
|
||||
// load them upon restarts.
|
||||
towerSessIndex := towerToSessionIndex.NestedReadBucket(
|
||||
tower.ID.Bytes(),
|
||||
)
|
||||
if towerSessIndex == nil {
|
||||
return ErrTowerNotFound
|
||||
}
|
||||
|
||||
sessions := tx.ReadWriteBucket(cSessionBkt)
|
||||
if sessions == nil {
|
||||
return ErrUninitializedDB
|
||||
}
|
||||
|
||||
err = towerSessIndex.ForEach(func(k, _ []byte) error {
|
||||
session, err := getClientSessionBody(
|
||||
sessions, k,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return markSessionStatus(
|
||||
sessions, session, CSessionActive,
|
||||
)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// No such tower exists, create a new tower id for our
|
||||
// new tower. The error is unhandled since NextSequence
|
||||
|
@ -435,6 +404,7 @@ func (c *ClientDB) CreateTower(lnAddr *lnwire.NetAddress) (*Tower, error) {
|
|||
ID: TowerID(towerID),
|
||||
IdentityKey: lnAddr.IdentityKey,
|
||||
Addresses: []net.Addr{lnAddr.Address},
|
||||
Status: TowerStatusActive,
|
||||
}
|
||||
|
||||
towerIDBytes = tower.ID.Bytes()
|
||||
|
@ -468,10 +438,10 @@ func (c *ClientDB) CreateTower(lnAddr *lnwire.NetAddress) (*Tower, error) {
|
|||
|
||||
// RemoveTower modifies a tower's record within the database. If an address is
|
||||
// provided, then _only_ the address record should be removed from the tower's
|
||||
// persisted state. Otherwise, we'll attempt to mark the tower as inactive by
|
||||
// marking all of its sessions inactive. If any of its sessions has unacked
|
||||
// updates, then ErrTowerUnackedUpdates is returned. If the tower doesn't have
|
||||
// any sessions at all, it'll be completely removed from the database.
|
||||
// persisted state. Otherwise, we'll attempt to mark the tower as inactive. If
|
||||
// any of its sessions has unacked updates, then ErrTowerUnackedUpdates is
|
||||
// returned. If the tower doesn't have any sessions at all, it'll be completely
|
||||
// removed from the database.
|
||||
//
|
||||
// NOTE: An error is not returned if the tower doesn't exist.
|
||||
func (c *ClientDB) RemoveTower(pubKey *btcec.PublicKey, addr net.Addr) error {
|
||||
|
@ -570,19 +540,12 @@ func (c *ClientDB) RemoveTower(pubKey *btcec.PublicKey, addr net.Addr) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// We'll mark its sessions as inactive as long as they don't
|
||||
// have any pending updates to ensure we don't load them upon
|
||||
// restarts.
|
||||
// We'll do a check to ensure that the tower's sessions don't
|
||||
// have any pending back-ups.
|
||||
for _, session := range towerSessions {
|
||||
if committedUpdateCount[session.ID] > 0 {
|
||||
return ErrTowerUnackedUpdates
|
||||
}
|
||||
err := markSessionStatus(
|
||||
sessions, session, CSessionTerminal,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -145,12 +145,9 @@ func (h *clientDBHarness) removeTower(pubKey *btcec.PublicKey, addr net.Addr,
|
|||
return
|
||||
}
|
||||
|
||||
for _, session := range h.listSessions(&tower.ID) {
|
||||
require.Equal(h.t, wtdb.CSessionTerminal,
|
||||
session.Status, "expected status for session "+
|
||||
"%v to be %v, got %v", session.ID,
|
||||
wtdb.CSessionTerminal, session.Status)
|
||||
}
|
||||
require.EqualValues(
|
||||
h.t, wtdb.TowerStatusInactive, tower.Status,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -551,20 +548,13 @@ func testRemoveTower(h *clientDBHarness) {
|
|||
h.commitUpdate(&session.ID, update, nil)
|
||||
|
||||
// We should not be able to fully remove it from the database since
|
||||
// there's a session and it has unacked updates.
|
||||
// there's a session, and it has unacked updates.
|
||||
h.removeTower(pk, nil, true, wtdb.ErrTowerUnackedUpdates)
|
||||
|
||||
// Removing the tower after all sessions no longer have unacked updates
|
||||
// should result in the sessions becoming inactive.
|
||||
// should succeed.
|
||||
h.ackUpdate(&session.ID, 1, 1, nil)
|
||||
h.removeTower(pk, nil, true, nil)
|
||||
|
||||
// Creating the tower again should mark all of the sessions active once
|
||||
// again.
|
||||
h.createTower(&lnwire.NetAddress{
|
||||
IdentityKey: pk,
|
||||
Address: addr1,
|
||||
}, nil)
|
||||
}
|
||||
|
||||
// testTowerStatusChange tests that the Tower status is updated accordingly
|
||||
|
@ -613,11 +603,11 @@ func testTowerStatusChange(h *clientDBHarness) {
|
|||
assertTowerStatus(wtdb.TowerStatusActive)
|
||||
assertSessionStatus(wtdb.CSessionActive)
|
||||
|
||||
// Removing the tower should change its status and its session status
|
||||
// to inactive.
|
||||
// Removing the tower should change its status but its session
|
||||
// status should remain active.
|
||||
h.removeTower(tower.IdentityKey, nil, true, nil)
|
||||
assertTowerStatus(wtdb.TowerStatusInactive)
|
||||
assertSessionStatus(wtdb.CSessionTerminal)
|
||||
assertSessionStatus(wtdb.CSessionActive)
|
||||
|
||||
// Re-adding the tower in some way should re-active it and its session.
|
||||
h.createTower(towerAddr, nil)
|
||||
|
|
Loading…
Add table
Reference in a new issue