mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 06:01:48 +02:00
rpcperms+lnd: gate RPC calls on RPC state
This commit makes us gate the calls to the RPC servers according to the current RPC state. This ensures we won't try to call the RPC server before it has been fully initialized, and that we won't call the walletUnlocker after the wallet already has been unlocked.
This commit is contained in:
26
lnd.go
26
lnd.go
@@ -334,11 +334,18 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new RPC interceptor chain that we'll add to the GRPC
|
||||
// server. This will be used to log the API calls invoked on the GRPC
|
||||
// server.
|
||||
// We'll create the WalletUnlockerService and check whether the wallet
|
||||
// already exists.
|
||||
pwService := createWalletUnlockerService(cfg)
|
||||
walletExists, err := pwService.WalletExists()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a new RPC interceptor that we'll add to the GRPC server. This
|
||||
// will be used to log the API calls invoked on the GRPC server.
|
||||
interceptorChain := rpcperms.NewInterceptorChain(
|
||||
rpcsLog, cfg.NoMacaroons,
|
||||
rpcsLog, cfg.NoMacaroons, walletExists,
|
||||
)
|
||||
rpcServerOpts := interceptorChain.CreateServerOpts()
|
||||
serverOpts = append(serverOpts, rpcServerOpts...)
|
||||
@@ -346,9 +353,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
grpcServer := grpc.NewServer(serverOpts...)
|
||||
defer grpcServer.Stop()
|
||||
|
||||
// We'll create the WalletUnlockerService and register this with the
|
||||
// GRPC server.
|
||||
pwService := createWalletUnlockerService(cfg)
|
||||
// Register the WalletUnlockerService with the GRPC server.
|
||||
lnrpc.RegisterWalletUnlockerServer(grpcServer, pwService)
|
||||
|
||||
// Initialize, and register our implementation of the gRPC interface
|
||||
@@ -410,6 +415,10 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Now that the wallet password has been provided, transition the RPC
|
||||
// state into Unlocked.
|
||||
interceptorChain.SetWalletUnlocked()
|
||||
|
||||
var macaroonService *macaroons.Service
|
||||
if !cfg.NoMacaroons {
|
||||
// Create the macaroon authentication/authorization service.
|
||||
@@ -739,6 +748,9 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
|
||||
}
|
||||
defer rpcServer.Stop()
|
||||
|
||||
// We transition the RPC state to Active, as the RPC server is up.
|
||||
interceptorChain.SetRPCActive()
|
||||
|
||||
// If we're not in regtest or simnet mode, We'll wait until we're fully
|
||||
// synced to continue the start up of the remainder of the daemon. This
|
||||
// ensures that we don't accept any possibly invalid state transitions, or
|
||||
|
Reference in New Issue
Block a user