From 5660a26b602da096bd103a453ddebeb301679f9d Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 30 Mar 2020 16:55:16 -0700 Subject: [PATCH] rpcserver: add wallet sync check to OpenChannel --- lntest/itest/lnd_test.go | 12 +++++++++--- rpcserver.go | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index f0ccc407..1a113399 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -214,9 +214,15 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest, net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode, p lntest.OpenChannelParams) *lnrpc.ChannelPoint { - chanOpenUpdate, err := net.OpenChannel( - ctx, alice, bob, p, - ) + // Wait until we are able to fund a channel successfully. This wait + // prevents us from erroring out when trying to create a channel while + // the node is starting up. + var chanOpenUpdate lnrpc.Lightning_OpenChannelClient + err := wait.NoError(func() error { + var err error + chanOpenUpdate, err = net.OpenChannel(ctx, alice, bob, p) + return err + }, defaultTimeout) if err != nil { t.Fatalf("unable to open channel: %v", err) } diff --git a/rpcserver.go b/rpcserver.go index e68e0ffd..4b5f56bc 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1616,6 +1616,17 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest, return ErrServerNotActive } + // Creation of channels before the wallet syncs up is currently + // disallowed. + isSynced, _, err := r.server.cc.wallet.IsSynced() + if err != nil { + return err + } + if !isSynced { + return errors.New("channels cannot be created before the " + + "wallet is fully synced") + } + localFundingAmt := btcutil.Amount(in.LocalFundingAmount) remoteInitialBalance := btcutil.Amount(in.PushSat) minHtlcIn := lnwire.MilliSatoshi(in.MinHtlcMsat)