rpcserver: add wallet sync check to OpenChannel

This commit is contained in:
Conner Fromknecht 2020-03-30 16:55:16 -07:00
parent f996203883
commit 5660a26b60
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 20 additions and 3 deletions

View File

@ -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)
}

View File

@ -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)