rpc: make RPC permissions non static.

This commit fixes a but where restarting LND at the same process causes
It to fail.
The problem resides in the fact that an array of permissions is
initialized as a package variable and when creating the
RPCServer all subserver permissions are appended while checking for
duplicates.
On subsequent restart this array is left over from the previous run and
being populated again with the same permissions causing a duplicate
error.
The solution is simple, just to extract out the initial permissions to
a separate function and call it from the context is is needed.
This commit is contained in:
Roei Erez 2019-06-25 13:19:55 +03:00
parent 36983214e8
commit 46489050ef

View File

@ -168,9 +168,12 @@ var (
Action: "write",
},
}
)
// permissions maps RPC calls to the permissions they require.
permissions = map[string][]bakery.Op{
// mainRPCServerPermissions returns a mapping of the main RPC server calls to
// the permissions they require.
func mainRPCServerPermissions() map[string][]bakery.Op {
return map[string][]bakery.Op{
"/lnrpc.Lightning/SendCoins": {{
Entity: "onchain",
Action: "write",
@ -381,7 +384,7 @@ var (
Action: "read",
}},
}
)
}
// rpcServer is a gRPC, RPC front end to the lnd daemon.
// TODO(roasbeef): pagination support for the list-style calls
@ -520,6 +523,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
// Next, we need to merge the set of sub server macaroon permissions
// with the main RPC server permissions so we can unite them under a
// single set of interceptors.
permissions := mainRPCServerPermissions()
for _, subServerPerm := range subServerPerms {
for method, ops := range subServerPerm {
// For each new method:ops combo, we also ensure that