|
|
|
@ -16,6 +16,7 @@ import (
|
|
|
|
|
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
|
|
|
|
"github.com/lightninglabs/lndclient"
|
|
|
|
|
"github.com/lightninglabs/loop"
|
|
|
|
|
"github.com/lightninglabs/loop/instantout"
|
|
|
|
|
"github.com/lightninglabs/loop/loopd/perms"
|
|
|
|
|
"github.com/lightninglabs/loop/loopdb"
|
|
|
|
|
|
|
|
|
@ -23,6 +24,7 @@ import (
|
|
|
|
|
loop_looprpc "github.com/lightninglabs/loop/looprpc"
|
|
|
|
|
|
|
|
|
|
loop_swaprpc "github.com/lightninglabs/loop/swapserverrpc"
|
|
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
|
|
|
|
"github.com/lightningnetwork/lnd/macaroons"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
@ -66,10 +68,6 @@ type Daemon struct {
|
|
|
|
|
// same process.
|
|
|
|
|
swapClientServer
|
|
|
|
|
|
|
|
|
|
// reservationManager is the manager that handles all reservation state
|
|
|
|
|
// machines.
|
|
|
|
|
reservationManager *reservation.Manager
|
|
|
|
|
|
|
|
|
|
// ErrChan is an error channel that users of the Daemon struct must use
|
|
|
|
|
// to detect runtime errors and also whether a shutdown is fully
|
|
|
|
|
// completed.
|
|
|
|
@ -426,6 +424,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|
|
|
|
swapClient.Conn,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Create an instantout server client.
|
|
|
|
|
instantOutClient := loop_swaprpc.NewInstantSwapServerClient(
|
|
|
|
|
swapClient.Conn,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Both the client RPC server and the swap server client should stop
|
|
|
|
|
// on main context cancel. So we create it early and pass it down.
|
|
|
|
|
d.mainCtx, d.mainCtxCancel = context.WithCancel(context.Background())
|
|
|
|
@ -483,7 +486,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the reservation rpc server.
|
|
|
|
|
// Create the reservation services.
|
|
|
|
|
reservationStore := reservation.NewSQLStore(baseDb)
|
|
|
|
|
reservationConfig := &reservation.Config{
|
|
|
|
|
Store: reservationStore,
|
|
|
|
@ -493,10 +496,29 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|
|
|
|
FetchL402: swapClient.Server.FetchL402,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.reservationManager = reservation.NewReservationManager(
|
|
|
|
|
reservationManager := reservation.NewReservationManager(
|
|
|
|
|
reservationConfig,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Create the instantout services.
|
|
|
|
|
instantOutStore := instantout.NewSQLStore(
|
|
|
|
|
baseDb, clock.NewDefaultClock(), reservationStore,
|
|
|
|
|
d.lnd.ChainParams,
|
|
|
|
|
)
|
|
|
|
|
instantOutConfig := &instantout.Config{
|
|
|
|
|
Store: instantOutStore,
|
|
|
|
|
LndClient: d.lnd.Client,
|
|
|
|
|
RouterClient: d.lnd.Router,
|
|
|
|
|
ChainNotifier: d.lnd.ChainNotifier,
|
|
|
|
|
Signer: d.lnd.Signer,
|
|
|
|
|
Wallet: d.lnd.WalletKit,
|
|
|
|
|
ReservationManager: reservationManager,
|
|
|
|
|
InstantOutClient: instantOutClient,
|
|
|
|
|
Network: d.lnd.ChainParams,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instantOutManager := instantout.NewInstantOutManager(instantOutConfig)
|
|
|
|
|
|
|
|
|
|
// Now finally fully initialize the swap client RPC server instance.
|
|
|
|
|
d.swapClientServer = swapClientServer{
|
|
|
|
|
config: d.cfg,
|
|
|
|
@ -508,7 +530,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|
|
|
|
subscribers: make(map[int]chan<- interface{}),
|
|
|
|
|
statusChan: make(chan loop.SwapInfo),
|
|
|
|
|
mainCtx: d.mainCtx,
|
|
|
|
|
reservationManager: d.reservationManager,
|
|
|
|
|
reservationManager: reservationManager,
|
|
|
|
|
instantOutManager: instantOutManager,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve all currently existing swaps from the database.
|
|
|
|
@ -599,6 +622,28 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// Start the instant out manager.
|
|
|
|
|
d.wg.Add(1)
|
|
|
|
|
go func() {
|
|
|
|
|
defer d.wg.Done()
|
|
|
|
|
|
|
|
|
|
getInfo, err := d.lnd.Client.GetInfo(d.mainCtx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.internalErrChan <- err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Info("Starting instantout manager")
|
|
|
|
|
defer log.Info("Instantout manager stopped")
|
|
|
|
|
|
|
|
|
|
err = d.instantOutManager.Run(
|
|
|
|
|
d.mainCtx, int32(getInfo.BlockHeight),
|
|
|
|
|
)
|
|
|
|
|
if err != nil && !errors.Is(err, context.Canceled) {
|
|
|
|
|
d.internalErrChan <- err
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// Last, start our internal error handler. This will return exactly one
|
|
|
|
|
// error or nil on the main error channel to inform the caller that
|
|
|
|
|
// something went wrong or that shutdown is complete. We don't add to
|
|
|
|
|