funding: disallow channel creation before lnd is synced to the chain

This commit adds a new restriction around funding channels at the
daemon level: lnd nodes will not allow either the initiation or the
acceptance of a channel before the node is fully synced to the best
known chain.

This fixes a class of bug that arises when a new node joins the network
and either attempts to open a channel or has a channel extended to them
before the node is fully synced to the network.
This commit is contained in:
Olaoluwa Osuntokun
2017-01-24 17:12:51 -08:00
parent 73d5daa2c3
commit a658fabf48
4 changed files with 60 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"io"
"math"
@ -331,6 +332,17 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
"allocation(us=%v, them=%v) numconfs=%v", in.TargetPeerId,
in.LocalFundingAmount, in.PushSat, in.NumConfs)
// Creation of channels before the wallet syncs up is currently
// disallowed.
isSynced, err := r.server.lnwallet.IsSynced()
if err != nil {
return nil, err
}
if !isSynced {
return nil, errors.New("channels cannot be created before the " +
"wallet is fully synced")
}
// Decode the provided target node's public key, parsing it into a pub
// key object. For all sync call, byte slices are expected to be
// encoded as hex strings.