lnwallet/wallet: export InitFundingReserveMsg and required fields
This commit is contained in:
parent
643618b4f6
commit
51fc193ddc
@ -44,7 +44,7 @@ func (e *ErrInsufficientFunds) Error() string {
|
||||
e.amountSelected)
|
||||
}
|
||||
|
||||
// initFundingReserveReq is the first message sent to initiate the workflow
|
||||
// InitFundingReserveMsg is the first message sent to initiate the workflow
|
||||
// required to open a payment channel with a remote peer. The initial required
|
||||
// parameters are configurable across channels. These parameters are to be
|
||||
// chosen depending on the fee climate within the network, and time value of
|
||||
@ -54,44 +54,44 @@ func (e *ErrInsufficientFunds) Error() string {
|
||||
// pending reservations. Therefore, all channels in reservation limbo will be
|
||||
// periodically timed out after an idle period in order to avoid "exhaustion"
|
||||
// attacks.
|
||||
type initFundingReserveMsg struct {
|
||||
// chainHash denotes that chain to be used to ultimately open the
|
||||
type InitFundingReserveMsg struct {
|
||||
// ChainHash denotes that chain to be used to ultimately open the
|
||||
// target channel.
|
||||
chainHash *chainhash.Hash
|
||||
ChainHash *chainhash.Hash
|
||||
|
||||
// nodeId is the ID of the remote node we would like to open a channel
|
||||
// NodeID is the ID of the remote node we would like to open a channel
|
||||
// with.
|
||||
nodeID *btcec.PublicKey
|
||||
NodeID *btcec.PublicKey
|
||||
|
||||
// nodeAddr is the address port that we used to either establish or
|
||||
// NodeAddr is the address port that we used to either establish or
|
||||
// accept the connection which led to the negotiation of this funding
|
||||
// workflow.
|
||||
nodeAddr net.Addr
|
||||
NodeAddr net.Addr
|
||||
|
||||
// fundingAmount is the amount of funds requested for this channel.
|
||||
fundingAmount btcutil.Amount
|
||||
// FundingAmount is the amount of funds requested for this channel.
|
||||
FundingAmount btcutil.Amount
|
||||
|
||||
// capacity is the total capacity of the channel which includes the
|
||||
// Capacity is the total capacity of the channel which includes the
|
||||
// amount of funds the remote party contributes (if any).
|
||||
capacity btcutil.Amount
|
||||
Capacity btcutil.Amount
|
||||
|
||||
// commitFeePerKw is the starting accepted satoshis/Kw fee for the set
|
||||
// CommitFeePerKw is the starting accepted satoshis/Kw fee for the set
|
||||
// of initial commitment transactions. In order to ensure timely
|
||||
// confirmation, it is recommended that this fee should be generous,
|
||||
// paying some multiple of the accepted base fee rate of the network.
|
||||
commitFeePerKw SatPerKWeight
|
||||
CommitFeePerKw SatPerKWeight
|
||||
|
||||
// fundingFeePerKw is the fee rate in sat/kw to use for the initial
|
||||
// FundingFeePerKw is the fee rate in sat/kw to use for the initial
|
||||
// funding transaction.
|
||||
fundingFeePerKw SatPerKWeight
|
||||
FundingFeePerKw SatPerKWeight
|
||||
|
||||
// pushMSat is the number of milli-satoshis that should be pushed over
|
||||
// PushMSat is the number of milli-satoshis that should be pushed over
|
||||
// the responder as part of the initial channel creation.
|
||||
pushMSat lnwire.MilliSatoshi
|
||||
PushMSat lnwire.MilliSatoshi
|
||||
|
||||
// flags are the channel flags specified by the initiator in the
|
||||
// Flags are the channel flags specified by the initiator in the
|
||||
// open_channel message.
|
||||
flags lnwire.FundingFlag
|
||||
Flags lnwire.FundingFlag
|
||||
|
||||
// err is a channel in which all errors will be sent across. Will be
|
||||
// nil if this initial set is successful.
|
||||
@ -372,7 +372,7 @@ out:
|
||||
select {
|
||||
case m := <-l.msgChan:
|
||||
switch msg := m.(type) {
|
||||
case *initFundingReserveMsg:
|
||||
case *InitFundingReserveMsg:
|
||||
l.handleFundingReserveRequest(msg)
|
||||
case *fundingReserveCancelMsg:
|
||||
l.handleFundingCancelRequest(msg)
|
||||
@ -439,9 +439,9 @@ func (l *LightningWallet) InitChannelReservation(
|
||||
|
||||
// handleFundingReserveRequest processes a message intending to create, and
|
||||
// validate a funding reservation request.
|
||||
func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg) {
|
||||
func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg) {
|
||||
// It isn't possible to create a channel with zero funds committed.
|
||||
if req.fundingAmount+req.capacity == 0 {
|
||||
if req.FundingAmount+req.Capacity == 0 {
|
||||
err := ErrZeroCapacity()
|
||||
req.err <- err
|
||||
req.resp <- nil
|
||||
@ -450,18 +450,20 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
|
||||
|
||||
// If the funding request is for a different chain than the one the
|
||||
// wallet is aware of, then we'll reject the request.
|
||||
if !bytes.Equal(l.Cfg.NetParams.GenesisHash[:], req.chainHash[:]) {
|
||||
err := ErrChainMismatch(l.Cfg.NetParams.GenesisHash,
|
||||
req.chainHash)
|
||||
if !bytes.Equal(l.Cfg.NetParams.GenesisHash[:], req.ChainHash[:]) {
|
||||
err := ErrChainMismatch(
|
||||
l.Cfg.NetParams.GenesisHash, req.ChainHash,
|
||||
)
|
||||
req.err <- err
|
||||
req.resp <- nil
|
||||
return
|
||||
}
|
||||
|
||||
id := atomic.AddUint64(&l.nextFundingID, 1)
|
||||
reservation, err := NewChannelReservation(req.capacity, req.fundingAmount,
|
||||
req.commitFeePerKw, l, id, req.pushMSat,
|
||||
l.Cfg.NetParams.GenesisHash, req.flags)
|
||||
reservation, err := NewChannelReservation(
|
||||
req.Capacity, req.FundingAmount, req.CommitFeePerKw, l, id,
|
||||
req.PushMSat, l.Cfg.NetParams.GenesisHash, req.Flags,
|
||||
)
|
||||
if err != nil {
|
||||
req.err <- err
|
||||
req.resp <- nil
|
||||
@ -472,17 +474,17 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
|
||||
reservation.Lock()
|
||||
defer reservation.Unlock()
|
||||
|
||||
reservation.nodeAddr = req.nodeAddr
|
||||
reservation.partialState.IdentityPub = req.nodeID
|
||||
reservation.nodeAddr = req.NodeAddr
|
||||
reservation.partialState.IdentityPub = req.NodeID
|
||||
|
||||
// If we're on the receiving end of a single funder channel then we
|
||||
// don't need to perform any coin selection. Otherwise, attempt to
|
||||
// obtain enough coins to meet the required funding amount.
|
||||
if req.fundingAmount != 0 {
|
||||
if req.FundingAmount != 0 {
|
||||
// Coin selection is done on the basis of sat/kw, so we'll use
|
||||
// the fee rate passed in to perform coin selection.
|
||||
err := l.selectCoinsAndChange(
|
||||
req.fundingFeePerKw, req.fundingAmount,
|
||||
req.FundingFeePerKw, req.FundingAmount,
|
||||
reservation.ourContribution,
|
||||
)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user