mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-12 21:00:03 +02:00
watchtower: fix formatting
In order to make upcoming commits in the PR easier to parse, this commit makes some basic formatting changes to some of the watchtower files.
This commit is contained in:
parent
b387e2c718
commit
f815c88ee4
@ -62,7 +62,8 @@ type DB interface {
|
|||||||
// still be able to accept state updates. An optional tower ID can be
|
// still be able to accept state updates. An optional tower ID can be
|
||||||
// used to filter out any client sessions in the response that do not
|
// used to filter out any client sessions in the response that do not
|
||||||
// correspond to this tower.
|
// correspond to this tower.
|
||||||
ListClientSessions(*wtdb.TowerID) (map[wtdb.SessionID]*wtdb.ClientSession, error)
|
ListClientSessions(*wtdb.TowerID) (
|
||||||
|
map[wtdb.SessionID]*wtdb.ClientSession, error)
|
||||||
|
|
||||||
// FetchChanSummaries loads a mapping from all registered channels to
|
// FetchChanSummaries loads a mapping from all registered channels to
|
||||||
// their channel summaries.
|
// their channel summaries.
|
||||||
@ -96,8 +97,8 @@ type DB interface {
|
|||||||
AckUpdate(id *wtdb.SessionID, seqNum, lastApplied uint16) error
|
AckUpdate(id *wtdb.SessionID, seqNum, lastApplied uint16) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthDialer connects to a remote node using an authenticated transport, such as
|
// AuthDialer connects to a remote node using an authenticated transport, such
|
||||||
// brontide. The dialer argument is used to specify a resolver, which allows
|
// as brontide. The dialer argument is used to specify a resolver, which allows
|
||||||
// this method to be used over Tor or clear net connections.
|
// this method to be used over Tor or clear net connections.
|
||||||
type AuthDialer func(localKey keychain.SingleKeyECDH,
|
type AuthDialer func(localKey keychain.SingleKeyECDH,
|
||||||
netAddr *lnwire.NetAddress,
|
netAddr *lnwire.NetAddress,
|
||||||
|
@ -113,7 +113,8 @@ var (
|
|||||||
// NewBoltBackendCreator returns a function that creates a new bbolt backend for
|
// NewBoltBackendCreator returns a function that creates a new bbolt backend for
|
||||||
// the watchtower database.
|
// the watchtower database.
|
||||||
func NewBoltBackendCreator(active bool, dbPath,
|
func NewBoltBackendCreator(active bool, dbPath,
|
||||||
dbFileName string) func(boltCfg *kvdb.BoltConfig) (kvdb.Backend, error) {
|
dbFileName string) func(boltCfg *kvdb.BoltConfig) (kvdb.Backend,
|
||||||
|
error) {
|
||||||
|
|
||||||
// If the watchtower client isn't active, we return a function that
|
// If the watchtower client isn't active, we return a function that
|
||||||
// always returns a nil DB to make sure we don't create empty database
|
// always returns a nil DB to make sure we don't create empty database
|
||||||
@ -575,7 +576,9 @@ func (c *ClientDB) CreateClientSession(session *ClientSession) error {
|
|||||||
|
|
||||||
// Check that client session with this session id doesn't
|
// Check that client session with this session id doesn't
|
||||||
// already exist.
|
// already exist.
|
||||||
existingSessionBytes := sessions.NestedReadWriteBucket(session.ID[:])
|
existingSessionBytes := sessions.NestedReadWriteBucket(
|
||||||
|
session.ID[:],
|
||||||
|
)
|
||||||
if existingSessionBytes != nil {
|
if existingSessionBytes != nil {
|
||||||
return ErrClientSessionAlreadyExists
|
return ErrClientSessionAlreadyExists
|
||||||
}
|
}
|
||||||
@ -662,7 +665,9 @@ func getSessionKeyIndex(keyIndexes kvdb.RwBucket, towerID TowerID,
|
|||||||
// ListClientSessions returns the set of all client sessions known to the db. An
|
// ListClientSessions returns the set of all client sessions known to the db. An
|
||||||
// optional tower ID can be used to filter out any client sessions in the
|
// optional tower ID can be used to filter out any client sessions in the
|
||||||
// response that do not correspond to this tower.
|
// response that do not correspond to this tower.
|
||||||
func (c *ClientDB) ListClientSessions(id *TowerID) (map[SessionID]*ClientSession, error) {
|
func (c *ClientDB) ListClientSessions(id *TowerID) (
|
||||||
|
map[SessionID]*ClientSession, error) {
|
||||||
|
|
||||||
var clientSessions map[SessionID]*ClientSession
|
var clientSessions map[SessionID]*ClientSession
|
||||||
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||||
sessions := tx.ReadBucket(cSessionBkt)
|
sessions := tx.ReadBucket(cSessionBkt)
|
||||||
@ -951,7 +956,9 @@ func (c *ClientDB) AckUpdate(id *SessionID, seqNum uint16,
|
|||||||
|
|
||||||
// If the commits sub-bucket doesn't exist, there can't possibly
|
// If the commits sub-bucket doesn't exist, there can't possibly
|
||||||
// be a corresponding committed update to remove.
|
// be a corresponding committed update to remove.
|
||||||
sessionCommits := sessionBkt.NestedReadWriteBucket(cSessionCommits)
|
sessionCommits := sessionBkt.NestedReadWriteBucket(
|
||||||
|
cSessionCommits,
|
||||||
|
)
|
||||||
if sessionCommits == nil {
|
if sessionCommits == nil {
|
||||||
return ErrCommittedUpdateNotFound
|
return ErrCommittedUpdateNotFound
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,9 @@ func newClientDBHarness(t *testing.T, init clientDBInit) *clientDBHarness {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *clientDBHarness) insertSession(session *wtdb.ClientSession, expErr error) {
|
func (h *clientDBHarness) insertSession(session *wtdb.ClientSession,
|
||||||
|
expErr error) {
|
||||||
|
|
||||||
h.t.Helper()
|
h.t.Helper()
|
||||||
|
|
||||||
err := h.db.CreateClientSession(session)
|
err := h.db.CreateClientSession(session)
|
||||||
@ -47,7 +49,9 @@ func (h *clientDBHarness) insertSession(session *wtdb.ClientSession, expErr erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *clientDBHarness) listSessions(id *wtdb.TowerID) map[wtdb.SessionID]*wtdb.ClientSession {
|
func (h *clientDBHarness) listSessions(
|
||||||
|
id *wtdb.TowerID) map[wtdb.SessionID]*wtdb.ClientSession {
|
||||||
|
|
||||||
h.t.Helper()
|
h.t.Helper()
|
||||||
|
|
||||||
sessions, err := h.db.ListClientSessions(id)
|
sessions, err := h.db.ListClientSessions(id)
|
||||||
@ -82,7 +86,8 @@ func (h *clientDBHarness) createTower(lnAddr *lnwire.NetAddress,
|
|||||||
|
|
||||||
tower, err := h.db.CreateTower(lnAddr)
|
tower, err := h.db.CreateTower(lnAddr)
|
||||||
if err != expErr {
|
if err != expErr {
|
||||||
h.t.Fatalf("expected create tower error: %v, got: %v", expErr, err)
|
h.t.Fatalf("expected create tower error: %v, got: %v", expErr,
|
||||||
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tower.ID == 0 {
|
if tower.ID == 0 {
|
||||||
@ -106,35 +111,38 @@ func (h *clientDBHarness) removeTower(pubKey *btcec.PublicKey, addr net.Addr,
|
|||||||
h.t.Helper()
|
h.t.Helper()
|
||||||
|
|
||||||
if err := h.db.RemoveTower(pubKey, addr); err != expErr {
|
if err := h.db.RemoveTower(pubKey, addr); err != expErr {
|
||||||
h.t.Fatalf("expected remove tower error: %v, got %v", expErr, err)
|
h.t.Fatalf("expected remove tower error: %v, got %v", expErr,
|
||||||
|
err)
|
||||||
}
|
}
|
||||||
if expErr != nil {
|
if expErr != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pubKeyStr := pubKey.SerializeCompressed()
|
||||||
|
|
||||||
if addr != nil {
|
if addr != nil {
|
||||||
tower, err := h.db.LoadTower(pubKey)
|
tower, err := h.db.LoadTower(pubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.t.Fatalf("expected tower %x to still exist",
|
h.t.Fatalf("expected tower %x to still exist",
|
||||||
pubKey.SerializeCompressed())
|
pubKeyStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
removedAddr := addr.String()
|
removedAddr := addr.String()
|
||||||
for _, towerAddr := range tower.Addresses {
|
for _, towerAddr := range tower.Addresses {
|
||||||
if towerAddr.String() == removedAddr {
|
if towerAddr.String() == removedAddr {
|
||||||
h.t.Fatalf("address %v not removed for tower %x",
|
h.t.Fatalf("address %v not removed for tower "+
|
||||||
removedAddr, pubKey.SerializeCompressed())
|
"%x", removedAddr, pubKeyStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tower, err := h.db.LoadTower(pubKey)
|
tower, err := h.db.LoadTower(pubKey)
|
||||||
if hasSessions && err != nil {
|
if hasSessions && err != nil {
|
||||||
h.t.Fatalf("expected tower %x with sessions to still "+
|
h.t.Fatalf("expected tower %x with sessions to still "+
|
||||||
"exist", pubKey.SerializeCompressed())
|
"exist", pubKeyStr)
|
||||||
}
|
}
|
||||||
if !hasSessions && err == nil {
|
if !hasSessions && err == nil {
|
||||||
h.t.Fatalf("expected tower %x with no sessions to not "+
|
h.t.Fatalf("expected tower %x with no sessions to not "+
|
||||||
"exist", pubKey.SerializeCompressed())
|
"exist", pubKeyStr)
|
||||||
}
|
}
|
||||||
if !hasSessions {
|
if !hasSessions {
|
||||||
return
|
return
|
||||||
@ -149,23 +157,29 @@ func (h *clientDBHarness) removeTower(pubKey *btcec.PublicKey, addr net.Addr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *clientDBHarness) loadTower(pubKey *btcec.PublicKey, expErr error) *wtdb.Tower {
|
func (h *clientDBHarness) loadTower(pubKey *btcec.PublicKey,
|
||||||
|
expErr error) *wtdb.Tower {
|
||||||
|
|
||||||
h.t.Helper()
|
h.t.Helper()
|
||||||
|
|
||||||
tower, err := h.db.LoadTower(pubKey)
|
tower, err := h.db.LoadTower(pubKey)
|
||||||
if err != expErr {
|
if err != expErr {
|
||||||
h.t.Fatalf("expected load tower error: %v, got: %v", expErr, err)
|
h.t.Fatalf("expected load tower error: %v, got: %v", expErr,
|
||||||
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tower
|
return tower
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *clientDBHarness) loadTowerByID(id wtdb.TowerID, expErr error) *wtdb.Tower {
|
func (h *clientDBHarness) loadTowerByID(id wtdb.TowerID,
|
||||||
|
expErr error) *wtdb.Tower {
|
||||||
|
|
||||||
h.t.Helper()
|
h.t.Helper()
|
||||||
|
|
||||||
tower, err := h.db.LoadTowerByID(id)
|
tower, err := h.db.LoadTowerByID(id)
|
||||||
if err != expErr {
|
if err != expErr {
|
||||||
h.t.Fatalf("expected load tower error: %v, got: %v", expErr, err)
|
h.t.Fatalf("expected load tower error: %v, got: %v", expErr,
|
||||||
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tower
|
return tower
|
||||||
@ -320,7 +334,9 @@ func testFilterClientSessions(h *clientDBHarness) {
|
|||||||
},
|
},
|
||||||
ID: sessionID,
|
ID: sessionID,
|
||||||
}, nil)
|
}, nil)
|
||||||
towerSessions[towerID] = append(towerSessions[towerID], sessionID)
|
towerSessions[towerID] = append(
|
||||||
|
towerSessions[towerID], sessionID,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should see the expected sessions for each tower when filtering
|
// We should see the expected sessions for each tower when filtering
|
||||||
|
Loading…
x
Reference in New Issue
Block a user