Merge pull request #2561 from Roasbeef/lax-max-in-flight-verification
Revert "funding+lnwallet: ensure max_htlc_value_in_flight smaller tha…
This commit is contained in:
commit
441307e8f7
@ -1090,7 +1090,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
||||
MaxAcceptedHtlcs: msg.MaxAcceptedHTLCs,
|
||||
CsvDelay: msg.CsvDelay,
|
||||
}
|
||||
err = reservation.CommitConstraints(channelConstraints, amt)
|
||||
err = reservation.CommitConstraints(channelConstraints)
|
||||
if err != nil {
|
||||
fndgLog.Errorf("Unacceptable channel constraints: %v", err)
|
||||
f.failFundingFlow(fmsg.peer, fmsg.msg.PendingChannelID, err)
|
||||
@ -1254,9 +1254,7 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
|
||||
MaxAcceptedHtlcs: msg.MaxAcceptedHTLCs,
|
||||
CsvDelay: msg.CsvDelay,
|
||||
}
|
||||
err = resCtx.reservation.CommitConstraints(
|
||||
channelConstraints, resCtx.chanAmt,
|
||||
)
|
||||
err = resCtx.reservation.CommitConstraints(channelConstraints)
|
||||
if err != nil {
|
||||
fndgLog.Warnf("Unacceptable channel constraints: %v", err)
|
||||
f.failFundingFlow(fmsg.peer, fmsg.msg.PendingChannelID, err)
|
||||
|
@ -2657,69 +2657,3 @@ func TestFundingManagerMaxConfs(t *testing.T) {
|
||||
string(err.Data))
|
||||
}
|
||||
}
|
||||
|
||||
// TestFundingManagerRejectInvalidMaxValueInFlight makes sure that the funding
|
||||
// manager will act accordingly when the remote is requiring us to use a
|
||||
// max_value_in_flight larger than the channel capacity.
|
||||
func TestFundingManagerRejectInvalidMaxValueInFlight(t *testing.T) {
|
||||
alice, bob := setupFundingManagers(t, defaultMaxPendingChannels)
|
||||
defer tearDownFundingManagers(t, alice, bob)
|
||||
|
||||
localAmt := btcutil.Amount(500000)
|
||||
pushAmt := btcutil.Amount(0)
|
||||
capacity := localAmt + pushAmt
|
||||
|
||||
// Make Alice require a max_htlc_value_in_flight greater than the
|
||||
// channel capacity.
|
||||
alice.fundingMgr.cfg.RequiredRemoteMaxValue = func(
|
||||
_ btcutil.Amount) lnwire.MilliSatoshi {
|
||||
return lnwire.NewMSatFromSatoshis(capacity) + 100
|
||||
}
|
||||
|
||||
// Create a funding request and start the workflow.
|
||||
updateChan := make(chan *lnrpc.OpenStatusUpdate)
|
||||
errChan := make(chan error, 1)
|
||||
initReq := &openChanReq{
|
||||
targetPubkey: bob.privKey.PubKey(),
|
||||
chainHash: *activeNetParams.GenesisHash,
|
||||
localFundingAmt: 500000,
|
||||
pushAmt: lnwire.NewMSatFromSatoshis(10),
|
||||
private: true,
|
||||
updates: updateChan,
|
||||
err: errChan,
|
||||
}
|
||||
|
||||
alice.fundingMgr.initFundingWorkflow(bob, initReq)
|
||||
|
||||
// Alice should have sent the OpenChannel message to Bob.
|
||||
var aliceMsg lnwire.Message
|
||||
select {
|
||||
case aliceMsg = <-alice.msgChan:
|
||||
case err := <-initReq.err:
|
||||
t.Fatalf("error init funding workflow: %v", err)
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatalf("alice did not send OpenChannel message")
|
||||
}
|
||||
|
||||
openChannelReq, ok := aliceMsg.(*lnwire.OpenChannel)
|
||||
if !ok {
|
||||
errorMsg, gotError := aliceMsg.(*lnwire.Error)
|
||||
if gotError {
|
||||
t.Fatalf("expected OpenChannel to be sent "+
|
||||
"from bob, instead got error: %v",
|
||||
lnwire.ErrorCode(errorMsg.Data[0]))
|
||||
}
|
||||
t.Fatalf("expected OpenChannel to be sent from "+
|
||||
"alice, instead got %T", aliceMsg)
|
||||
}
|
||||
|
||||
// Let Bob handle the init message.
|
||||
bob.fundingMgr.processFundingOpen(openChannelReq, alice)
|
||||
|
||||
// Assert Bob responded with an ErrMaxValueInFlightTooLarge error.
|
||||
err := assertFundingMsgSent(t, bob.msgChan, "Error").(*lnwire.Error)
|
||||
if !strings.Contains(string(err.Data), "maxValueInFlight too large") {
|
||||
t.Fatalf("expected ErrMaxValueInFlightTooLarge error, "+
|
||||
"got \"%v\"", string(err.Data))
|
||||
}
|
||||
}
|
||||
|
@ -132,16 +132,6 @@ func ErrNumConfsTooLarge(numConfs, maxNumConfs uint32) error {
|
||||
}
|
||||
}
|
||||
|
||||
// ErrMaxValueInFlightTooLarge returns an error indicating that the 'max HTLC
|
||||
// value in flight' the remote required is too large to be accepted.
|
||||
func ErrMaxValueInFlightTooLarge(maxValInFlight,
|
||||
maxMaxValInFlight lnwire.MilliSatoshi) ReservationError {
|
||||
return ReservationError{
|
||||
fmt.Errorf("maxValueInFlight too large: %v, max is %v",
|
||||
maxValInFlight, maxMaxValInFlight),
|
||||
}
|
||||
}
|
||||
|
||||
// ErrChanTooSmall returns an error indicating that an incoming channel request
|
||||
// was too small. We'll reject any incoming channels if they're below our
|
||||
// configured value for the min channel size we'll accept.
|
||||
|
@ -437,9 +437,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
MaxAcceptedHtlcs: lnwallet.MaxHTLCNumber / 2,
|
||||
CsvDelay: csvDelay,
|
||||
}
|
||||
err = aliceChanReservation.CommitConstraints(
|
||||
channelConstraints, fundingAmount*2,
|
||||
)
|
||||
err = aliceChanReservation.CommitConstraints(channelConstraints)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
@ -473,9 +471,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
if err != nil {
|
||||
t.Fatalf("bob unable to init channel reservation: %v", err)
|
||||
}
|
||||
err = bobChanReservation.CommitConstraints(
|
||||
channelConstraints, fundingAmount*2,
|
||||
)
|
||||
err = bobChanReservation.CommitConstraints(channelConstraints)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
@ -873,9 +869,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
MaxAcceptedHtlcs: lnwallet.MaxHTLCNumber / 2,
|
||||
CsvDelay: csvDelay,
|
||||
}
|
||||
err = aliceChanReservation.CommitConstraints(
|
||||
channelConstraints, fundingAmt,
|
||||
)
|
||||
err = aliceChanReservation.CommitConstraints(channelConstraints)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
@ -909,9 +903,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob reservation: %v", err)
|
||||
}
|
||||
err = bobChanReservation.CommitConstraints(
|
||||
channelConstraints, fundingAmt,
|
||||
)
|
||||
err = bobChanReservation.CommitConstraints(channelConstraints)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
|
@ -286,9 +286,7 @@ func (r *ChannelReservation) SetNumConfsRequired(numConfs uint16) {
|
||||
// of satoshis that can be transferred in a single commitment. This function
|
||||
// will also attempt to verify the constraints for sanity, returning an error
|
||||
// if the parameters are seemed unsound.
|
||||
func (r *ChannelReservation) CommitConstraints(c *channeldb.ChannelConstraints,
|
||||
capacity btcutil.Amount) error {
|
||||
|
||||
func (r *ChannelReservation) CommitConstraints(c *channeldb.ChannelConstraints) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
||||
@ -343,15 +341,7 @@ func (r *ChannelReservation) CommitConstraints(c *channeldb.ChannelConstraints,
|
||||
)
|
||||
}
|
||||
|
||||
// Fail if the maxValueInFlight is greater than the channel capacity.
|
||||
capacityMsat := lnwire.NewMSatFromSatoshis(capacity)
|
||||
if c.MaxPendingAmount > capacityMsat {
|
||||
return ErrMaxValueInFlightTooLarge(
|
||||
c.MaxPendingAmount, capacityMsat,
|
||||
)
|
||||
}
|
||||
|
||||
// Our dust limit should always be less than or equal our proposed
|
||||
// Our dust limit should always be less than or equal to our proposed
|
||||
// channel reserve.
|
||||
if r.ourContribution.DustLimit > c.ChanReserve {
|
||||
r.ourContribution.DustLimit = c.ChanReserve
|
||||
|
Loading…
Reference in New Issue
Block a user