multi: move BackupState and RegisterChannel to Manager
This commit moves over the last two methods, `RegisterChannel` and `BackupState` from the `Client` to the `Manager` interface. With this change, we no longer need to pass around the individual clients around and now only need to pass the manager around. To do this change, all the goroutines that handle channel closes, closable sessions needed to be moved to the Manager and so a large part of this commit is just moving this code from the TowerClient to the Manager.
This commit is contained in:
10 files changed
+551
-471
No files matched your search
@@ -403,7 +403,6 @@ type testHarness struct {
|
||||
clientDB *wtdb.ClientDB
|
||||
clientCfg *wtclient.Config
|
||||
clientPolicy wtpolicy.Policy
|
||||
client wtclient.Client
|
||||
server *serverHarness
|
||||
net *mockNet
|
||||
|
||||
@@ -564,7 +563,7 @@ func (h *testHarness) startClient() {
|
||||
h.clientMgr, err = wtclient.NewManager(h.clientCfg)
|
||||
require.NoError(h.t, err)
|
||||
|
||||
h.client, err = h.clientMgr.NewClient(h.clientPolicy)
|
||||
_, err = h.clientMgr.NewClient(h.clientPolicy)
|
||||
require.NoError(h.t, err)
|
||||
require.NoError(h.t, h.clientMgr.Start())
|
||||
require.NoError(h.t, h.clientMgr.AddTower(towerAddr))
|
||||
@@ -668,7 +667,7 @@ func (h *testHarness) registerChannel(id uint64) {
|
||||
h.t.Helper()
|
||||
|
||||
chanID := chanIDFromInt(id)
|
||||
err := h.client.RegisterChannel(chanID)
|
||||
err := h.clientMgr.RegisterChannel(chanID, channeldb.SingleFunderBit)
|
||||
require.NoError(h.t, err)
|
||||
}
|
||||
|
||||
@@ -709,8 +708,8 @@ func (h *testHarness) backupState(id, i uint64, expErr error) {
|
||||
|
||||
chanID := chanIDFromInt(id)
|
||||
|
||||
err := h.client.BackupState(&chanID, retribution.RevokedStateNum)
|
||||
require.ErrorIs(h.t, expErr, err)
|
||||
err := h.clientMgr.BackupState(&chanID, retribution.RevokedStateNum)
|
||||
require.ErrorIs(h.t, err, expErr)
|
||||
}
|
||||
|
||||
// sendPayments instructs the channel identified by id to send amt to the remote
|
||||
@@ -1254,6 +1253,7 @@ var clientTests = []clientTest{
|
||||
// Restart the client and allow it to process the
|
||||
// committed update.
|
||||
h.startClient()
|
||||
h.registerChannel(chanID)
|
||||
|
||||
// Wait for the committed update to be accepted by the
|
||||
// tower.
|
||||
@@ -1555,6 +1555,7 @@ var clientTests = []clientTest{
|
||||
// Restart the client with a new policy.
|
||||
h.clientPolicy.MaxUpdates = 20
|
||||
h.startClient()
|
||||
h.registerChannel(chanID)
|
||||
|
||||
// Now, queue the second half of the retributions.
|
||||
h.backupStates(chanID, numUpdates/2, numUpdates, nil)
|
||||
@@ -1605,6 +1606,7 @@ var clientTests = []clientTest{
|
||||
// maintained across restarts.
|
||||
require.NoError(h.t, h.clientMgr.Stop())
|
||||
h.startClient()
|
||||
h.registerChannel(chanID)
|
||||
|
||||
// Try to back up the full range of retributions. Only
|
||||
// the second half should actually be sent.
|
||||
@@ -2126,6 +2128,7 @@ var clientTests = []clientTest{
|
||||
require.NoError(h.t, h.clientMgr.Stop())
|
||||
h.server.start()
|
||||
h.startClient()
|
||||
h.registerChannel(chanID)
|
||||
|
||||
// Back up a few more states.
|
||||
h.backupStates(chanID, numUpdates/2, numUpdates, nil)
|
||||
@@ -2520,7 +2523,7 @@ var clientTests = []clientTest{
|
||||
// Wait for channel to be "unregistered".
|
||||
chanID := chanIDFromInt(chanIDInt)
|
||||
err = wait.Predicate(func() bool {
|
||||
err := h.client.BackupState(&chanID, 0)
|
||||
err := h.clientMgr.BackupState(&chanID, 0)
|
||||
|
||||
return errors.Is(
|
||||
err, wtclient.ErrUnregisteredChannel,
|
||||
|
||||
Reference in new issue
Block a user