rpcperms: re-init mw lookup map after removal of one

After removing a registered middlware from the slice, we need to update
the index lookup map with the updated index for each middleware.
This commit is contained in:
Elle Mouton
2022-07-15 14:04:19 +02:00
parent af97b8f877
commit cc2fbd18b1
2 changed files with 10 additions and 0 deletions

View File

@@ -84,6 +84,9 @@
* [Fixes a key scope issue preventing new remote signing setups to be created * [Fixes a key scope issue preventing new remote signing setups to be created
with `v0.15.0-beta`](https://github.com/lightningnetwork/lnd/pull/6714). with `v0.15.0-beta`](https://github.com/lightningnetwork/lnd/pull/6714).
* [Re-initialise registered middleware index lookup map after removal of a
registered middleware](https://github.com/lightningnetwork/lnd/pull/6739)
## Code Health ## Code Health
### Code cleanup, refactor, typo fixes ### Code cleanup, refactor, typo fixes

View File

@@ -489,10 +489,17 @@ func (r *InterceptorChain) RemoveMiddleware(middlewareName string) {
return return
} }
delete(r.registeredMiddlewareNames, middlewareName) delete(r.registeredMiddlewareNames, middlewareName)
r.registeredMiddleware = append( r.registeredMiddleware = append(
r.registeredMiddleware[:index], r.registeredMiddleware[:index],
r.registeredMiddleware[index+1:]..., r.registeredMiddleware[index+1:]...,
) )
// Re-initialise the middleware look-up map with the updated indexes.
r.registeredMiddlewareNames = make(map[string]int)
for i, mw := range r.registeredMiddleware {
r.registeredMiddlewareNames[mw.middlewareName] = i
}
} }
// CustomCaveatSupported makes sure a middleware that handles the given custom // CustomCaveatSupported makes sure a middleware that handles the given custom