funding: set push amount when opening channel
Now that we have the self channel balance populated on the bid orders
and have also validated all diffs, we can set the push amount when
opening the channel as asker.
@@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
+ "github.com/btcsuite/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/pool/auctioneerrpc"
"github.com/lightninglabs/pool/chaninfo"
@@ -133,17 +134,20 @@ func (m *Manager) deriveFundingShim(ourOrder order.Order,
askNonce, bidNonce order.Nonce
thawHeight uint32
+ selfChanBalance btcutil.Amount
)
if ourOrder.Type() == order.TypeBid {
bidNonce = ourOrder.Nonce()
askNonce = matchedOrder.Order.Nonce()
thawHeight = ourOrder.(*order.Bid).LeaseDuration
+ selfChanBalance = ourOrder.(*order.Bid).SelfChanBalance
} else {
bidNonce = matchedOrder.Order.Nonce()
askNonce = ourOrder.Nonce()
thawHeight = matchedOrder.Order.(*order.Bid).LeaseDuration
+ selfChanBalance = matchedOrder.Order.(*order.Bid).SelfChanBalance
}
pendingChanID := order.PendingChanKey(
@@ -189,7 +193,7 @@ func (m *Manager) deriveFundingShim(ourOrder order.Order,
// shim, and register it so we use the proper funding key when we
// receive the marker's incoming funding request.
chanPointShim := &lnrpc.ChanPointShim{
- Amt: int64(chanSize),
+ Amt: int64(chanSize + selfChanBalance),
ChanPoint: chanPoint,
LocalKey: &lnrpc.KeyDescriptor{
RawKeyBytes: ourMultiSigKey.PubKey.SerializeCompressed(),
@@ -439,6 +443,10 @@ func (m *Manager) BatchChannelSetup(batch *order.Batch,
continue
}
+ // We know the matched order must be a bid now since our
+ // order is an ask.
+ matchedOrderBid := matchedOrder.Order.(*order.Bid)
+
// Otherwise, we'll now initiate the funding request to
// establish all the channels generated by this order
// with the remote parties. It's the bidder's job to
@@ -448,11 +456,15 @@ func (m *Manager) BatchChannelSetup(batch *order.Batch,
//
// TODO(roasbeef): sat per byte from order?
// * also other params to set as well
- chanAmt := int64(matchedOrder.UnitsFilled.ToSatoshis())
+ chanAmt := matchedOrder.UnitsFilled.ToSatoshis()
+ chanAmt += matchedOrderBid.SelfChanBalance
fundingReq := &lnrpc.OpenChannelRequest{
NodePubkey: matchedOrder.NodeKey[:],
- LocalFundingAmount: chanAmt,
+ LocalFundingAmount: int64(chanAmt),
FundingShim: fundingShim,
+ PushSat: int64(
+ matchedOrderBid.SelfChanBalance,
+ ),
}
chanStream, err := m.BaseClient.OpenChannel(
setupCtx, fundingReq,
