wtclient: add DeactivateTower method

This commit adds the DeactiateTower method to the wtclient.ClientManager
interface along with its implementation. A test is also added for the
new method.
This commit is contained in:
Elle Mouton
2023-12-05 13:01:18 +02:00
parent 4548e72f79
commit beb9b2eeb8
4 changed files with 253 additions and 17 deletions

View File

@@ -2688,6 +2688,88 @@ var clientTests = []clientTest{
require.NoError(h.t, err)
},
},
{
name: "de-activate a tower",
cfg: harnessCfg{
localBalance: localBalance,
remoteBalance: remoteBalance,
policy: wtpolicy.Policy{
TxPolicy: defaultTxPolicy,
MaxUpdates: 5,
},
},
fn: func(h *testHarness) {
const (
numUpdates = 10
chanIDInt = 0
)
// Advance the channel with a few updates.
hints := h.advanceChannelN(chanIDInt, numUpdates)
// Backup a few these updates and wait for them to
// arrive at the server.
h.backupStates(chanIDInt, 0, numUpdates/2, nil)
h.server.waitForUpdates(hints[:numUpdates/2], waitTime)
// Lookup the tower and assert that it currently is
// seen as an active session candidate.
resp, err := h.clientMgr.LookupTower(
h.server.addr.IdentityKey,
)
require.NoError(h.t, err)
tower, ok := resp[blob.TypeAltruistTaprootCommit]
require.True(h.t, ok)
require.True(h.t, tower.ActiveSessionCandidate)
// Deactivate the tower.
err = h.clientMgr.DeactivateTower(
h.server.addr.IdentityKey,
)
require.NoError(h.t, err)
// Assert that it is no longer seen as an active
// session candidate.
resp, err = h.clientMgr.LookupTower(
h.server.addr.IdentityKey,
)
require.NoError(h.t, err)
tower, ok = resp[blob.TypeAltruistTaprootCommit]
require.True(h.t, ok)
require.False(h.t, tower.ActiveSessionCandidate)
// Add a new tower.
server2 := newServerHarness(
h.t, h.net, towerAddr2Str, nil,
)
server2.start()
h.addTower(server2.addr)
// Backup a few more states and assert that they appear
// on the second tower server.
h.backupStates(
chanIDInt, numUpdates/2, numUpdates-1, nil,
)
server2.waitForUpdates(
hints[numUpdates/2:numUpdates-1], waitTime,
)
// Reactivate the first tower.
err = h.clientMgr.AddTower(h.server.addr)
require.NoError(h.t, err)
// Deactivate the second tower.
err = h.clientMgr.DeactivateTower(
server2.addr.IdentityKey,
)
require.NoError(h.t, err)
// Backup the last backup and assert that it appears
// on the first tower.
h.backupStates(chanIDInt, numUpdates-1, numUpdates, nil)
h.server.waitForUpdates(hints[numUpdates-1:], waitTime)
},
},
}
// TestClient executes the client test suite, asserting the ability to backup