watchtower/wtclient/interface: add LoadTower and mock impl
This commit is contained in:
parent
1c22474ad3
commit
7d99005dde
@ -221,6 +221,17 @@ func New(config *Config) (*TowerClient, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reload any towers from disk using the tower IDs contained in each
|
||||||
|
// candidate session.
|
||||||
|
for _, s := range c.candidateSessions {
|
||||||
|
tower, err := c.cfg.DB.LoadTower(s.TowerID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Tower = tower
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, load the sweep pkscripts that have been generated for all
|
// Finally, load the sweep pkscripts that have been generated for all
|
||||||
// previously registered channels.
|
// previously registered channels.
|
||||||
c.sweepPkScripts, err = c.cfg.DB.FetchChanPkScripts()
|
c.sweepPkScripts, err = c.cfg.DB.FetchChanPkScripts()
|
||||||
|
@ -19,6 +19,9 @@ type DB interface {
|
|||||||
// sessions.
|
// sessions.
|
||||||
CreateTower(*lnwire.NetAddress) (*wtdb.Tower, error)
|
CreateTower(*lnwire.NetAddress) (*wtdb.Tower, error)
|
||||||
|
|
||||||
|
// LoadTower retrieves a tower by its tower ID.
|
||||||
|
LoadTower(uint64) (*wtdb.Tower, error)
|
||||||
|
|
||||||
// CreateClientSession saves a newly negotiated client session to the
|
// CreateClientSession saves a newly negotiated client session to the
|
||||||
// client's database. This enables the session to be used across
|
// client's database. This enables the session to be used across
|
||||||
// restarts.
|
// restarts.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package wtdb
|
package wtdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -8,6 +9,12 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrTowerNotFound signals that the target tower was not found in the
|
||||||
|
// database.
|
||||||
|
ErrTowerNotFound = errors.New("tower not found")
|
||||||
|
)
|
||||||
|
|
||||||
// Tower holds the necessary components required to connect to a remote tower.
|
// Tower holds the necessary components required to connect to a remote tower.
|
||||||
// Communication is handled by brontide, and requires both a public key and an
|
// Communication is handled by brontide, and requires both a public key and an
|
||||||
// address.
|
// address.
|
||||||
|
@ -64,6 +64,18 @@ func (m *ClientDB) CreateTower(lnAddr *lnwire.NetAddress) (*wtdb.Tower, error) {
|
|||||||
return tower, nil
|
return tower, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadTower retrieves a tower by its tower ID.
|
||||||
|
func (m *ClientDB) LoadTower(towerID uint64) (*wtdb.Tower, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if tower, ok := m.towers[towerID]; ok {
|
||||||
|
return tower, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, wtdb.ErrTowerNotFound
|
||||||
|
}
|
||||||
|
|
||||||
// MarkBackupIneligible records that particular commit height is ineligible for
|
// MarkBackupIneligible records that particular commit height is ineligible for
|
||||||
// backup. This allows the client to track which updates it should not attempt
|
// backup. This allows the client to track which updates it should not attempt
|
||||||
// to retry after startup.
|
// to retry after startup.
|
||||||
@ -92,7 +104,6 @@ func (m *ClientDB) CreateClientSession(session *wtdb.ClientSession) error {
|
|||||||
|
|
||||||
m.activeSessions[session.ID] = &wtdb.ClientSession{
|
m.activeSessions[session.ID] = &wtdb.ClientSession{
|
||||||
TowerID: session.TowerID,
|
TowerID: session.TowerID,
|
||||||
Tower: session.Tower,
|
|
||||||
SessionKeyDesc: session.SessionKeyDesc,
|
SessionKeyDesc: session.SessionKeyDesc,
|
||||||
SessionPrivKey: session.SessionPrivKey,
|
SessionPrivKey: session.SessionPrivKey,
|
||||||
ID: session.ID,
|
ID: session.ID,
|
||||||
|
Loading…
Reference in New Issue
Block a user