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)
|
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
|
// required to open a payment channel with a remote peer. The initial required
|
||||||
// parameters are configurable across channels. These parameters are to be
|
// parameters are configurable across channels. These parameters are to be
|
||||||
// chosen depending on the fee climate within the network, and time value of
|
// 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
|
// pending reservations. Therefore, all channels in reservation limbo will be
|
||||||
// periodically timed out after an idle period in order to avoid "exhaustion"
|
// periodically timed out after an idle period in order to avoid "exhaustion"
|
||||||
// attacks.
|
// attacks.
|
||||||
type initFundingReserveMsg struct {
|
type InitFundingReserveMsg struct {
|
||||||
// chainHash denotes that chain to be used to ultimately open the
|
// ChainHash denotes that chain to be used to ultimately open the
|
||||||
// target channel.
|
// 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.
|
// 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
|
// accept the connection which led to the negotiation of this funding
|
||||||
// workflow.
|
// workflow.
|
||||||
nodeAddr net.Addr
|
NodeAddr net.Addr
|
||||||
|
|
||||||
// fundingAmount is the amount of funds requested for this channel.
|
// FundingAmount is the amount of funds requested for this channel.
|
||||||
fundingAmount btcutil.Amount
|
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).
|
// 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
|
// of initial commitment transactions. In order to ensure timely
|
||||||
// confirmation, it is recommended that this fee should be generous,
|
// confirmation, it is recommended that this fee should be generous,
|
||||||
// paying some multiple of the accepted base fee rate of the network.
|
// 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.
|
// 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.
|
// 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.
|
// open_channel message.
|
||||||
flags lnwire.FundingFlag
|
Flags lnwire.FundingFlag
|
||||||
|
|
||||||
// err is a channel in which all errors will be sent across. Will be
|
// err is a channel in which all errors will be sent across. Will be
|
||||||
// nil if this initial set is successful.
|
// nil if this initial set is successful.
|
||||||
@ -372,7 +372,7 @@ out:
|
|||||||
select {
|
select {
|
||||||
case m := <-l.msgChan:
|
case m := <-l.msgChan:
|
||||||
switch msg := m.(type) {
|
switch msg := m.(type) {
|
||||||
case *initFundingReserveMsg:
|
case *InitFundingReserveMsg:
|
||||||
l.handleFundingReserveRequest(msg)
|
l.handleFundingReserveRequest(msg)
|
||||||
case *fundingReserveCancelMsg:
|
case *fundingReserveCancelMsg:
|
||||||
l.handleFundingCancelRequest(msg)
|
l.handleFundingCancelRequest(msg)
|
||||||
@ -439,9 +439,9 @@ func (l *LightningWallet) InitChannelReservation(
|
|||||||
|
|
||||||
// handleFundingReserveRequest processes a message intending to create, and
|
// handleFundingReserveRequest processes a message intending to create, and
|
||||||
// validate a funding reservation request.
|
// 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.
|
// 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()
|
err := ErrZeroCapacity()
|
||||||
req.err <- err
|
req.err <- err
|
||||||
req.resp <- nil
|
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
|
// If the funding request is for a different chain than the one the
|
||||||
// wallet is aware of, then we'll reject the request.
|
// wallet is aware of, then we'll reject the request.
|
||||||
if !bytes.Equal(l.Cfg.NetParams.GenesisHash[:], req.chainHash[:]) {
|
if !bytes.Equal(l.Cfg.NetParams.GenesisHash[:], req.ChainHash[:]) {
|
||||||
err := ErrChainMismatch(l.Cfg.NetParams.GenesisHash,
|
err := ErrChainMismatch(
|
||||||
req.chainHash)
|
l.Cfg.NetParams.GenesisHash, req.ChainHash,
|
||||||
|
)
|
||||||
req.err <- err
|
req.err <- err
|
||||||
req.resp <- nil
|
req.resp <- nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id := atomic.AddUint64(&l.nextFundingID, 1)
|
id := atomic.AddUint64(&l.nextFundingID, 1)
|
||||||
reservation, err := NewChannelReservation(req.capacity, req.fundingAmount,
|
reservation, err := NewChannelReservation(
|
||||||
req.commitFeePerKw, l, id, req.pushMSat,
|
req.Capacity, req.FundingAmount, req.CommitFeePerKw, l, id,
|
||||||
l.Cfg.NetParams.GenesisHash, req.flags)
|
req.PushMSat, l.Cfg.NetParams.GenesisHash, req.Flags,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
req.err <- err
|
req.err <- err
|
||||||
req.resp <- nil
|
req.resp <- nil
|
||||||
@ -472,17 +474,17 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
|
|||||||
reservation.Lock()
|
reservation.Lock()
|
||||||
defer reservation.Unlock()
|
defer reservation.Unlock()
|
||||||
|
|
||||||
reservation.nodeAddr = req.nodeAddr
|
reservation.nodeAddr = req.NodeAddr
|
||||||
reservation.partialState.IdentityPub = req.nodeID
|
reservation.partialState.IdentityPub = req.NodeID
|
||||||
|
|
||||||
// If we're on the receiving end of a single funder channel then we
|
// 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
|
// don't need to perform any coin selection. Otherwise, attempt to
|
||||||
// obtain enough coins to meet the required funding amount.
|
// 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
|
// Coin selection is done on the basis of sat/kw, so we'll use
|
||||||
// the fee rate passed in to perform coin selection.
|
// the fee rate passed in to perform coin selection.
|
||||||
err := l.selectCoinsAndChange(
|
err := l.selectCoinsAndChange(
|
||||||
req.fundingFeePerKw, req.fundingAmount,
|
req.FundingFeePerKw, req.FundingAmount,
|
||||||
reservation.ourContribution,
|
reservation.ourContribution,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user