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. // each.
nodes := []*node.HarnessNode{h.Alice, h.Bob} nodes := []*node.HarnessNode{h.Alice, h.Bob}
for _, hn := range nodes { for _, hn := range nodes {
h.manager.standbyNodes[hn.PubKeyStr] = hn h.manager.standbyNodes[hn.Cfg.NodeID] = hn
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
resp := hn.RPC.NewAddress(addrReq) 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. // shutdownNonStandbyNodes will shutdown any non-standby nodes.
func (h *HarnessTest) shutdownNonStandbyNodes() { 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. // If it's a standby node, skip.
_, ok := h.manager.standbyNodes[pks] _, ok := h.manager.standbyNodes[nid]
if ok { if ok {
continue continue
} }

View file

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