lntemp: replace pubkeyStr with NodeID

This commit replaces the keys used in the maps `activeNodes` and
`standbyNodes` from `pubkeyStr` to `NodeID` such that even the node is
not properly started, we can still clean it up during shutdown.
This commit is contained in:
yyforyongyu 2022-07-28 16:20:51 +08:00
parent 1b741cb6cc
commit 352be086a1
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
2 changed files with 9 additions and 9 deletions

View file

@ -172,7 +172,7 @@ func (h *HarnessTest) SetupStandbyNodes() {
// each.
nodes := []*node.HarnessNode{h.Alice, h.Bob}
for _, hn := range nodes {
h.manager.standbyNodes[hn.PubKeyStr] = hn
h.manager.standbyNodes[hn.Cfg.NodeID] = hn
for i := 0; i < 10; i++ {
resp := hn.RPC.NewAddress(addrReq)
@ -342,9 +342,9 @@ func (h *HarnessTest) Subtest(t *testing.T) (*HarnessTest, func()) {
// shutdownNonStandbyNodes will shutdown any non-standby nodes.
func (h *HarnessTest) shutdownNonStandbyNodes() {
for pks, node := range h.manager.activeNodes {
for nid, node := range h.manager.activeNodes {
// If it's a standby node, skip.
_, ok := h.manager.standbyNodes[pks]
_, ok := h.manager.standbyNodes[nid]
if ok {
continue
}

View file

@ -33,11 +33,11 @@ type nodeManager struct {
// activeNodes is a map of all running nodes, format:
// {pubkey: *HarnessNode}.
activeNodes map[string]*node.HarnessNode
activeNodes map[uint32]*node.HarnessNode
// standbyNodes is a map of all the standby nodes, format:
// {pubkey: *HarnessNode}.
standbyNodes map[string]*node.HarnessNode
standbyNodes map[uint32]*node.HarnessNode
// nodeCounter is a monotonically increasing counter that's used as the
// node's unique ID.
@ -54,8 +54,8 @@ func newNodeManager(lndBinary string,
return &nodeManager{
lndBinary: lndBinary,
dbBackend: dbBackend,
activeNodes: make(map[string]*node.HarnessNode),
standbyNodes: make(map[string]*node.HarnessNode),
activeNodes: make(map[uint32]*node.HarnessNode),
standbyNodes: make(map[uint32]*node.HarnessNode),
}
}
@ -126,7 +126,7 @@ func (nm *nodeManager) newNode(t *testing.T, name string, extraArgs []string,
// retrieved their public keys via FetchNodeInfo.
func (nm *nodeManager) registerNode(node *node.HarnessNode) {
nm.Lock()
nm.activeNodes[node.PubKeyStr] = node
nm.activeNodes[node.Cfg.NodeID] = node
nm.Unlock()
}
@ -137,7 +137,7 @@ func (nm *nodeManager) shutdownNode(node *node.HarnessNode) error {
return err
}
delete(nm.activeNodes, node.PubKeyStr)
delete(nm.activeNodes, node.Cfg.NodeID)
return nil
}