routing: change variable name numShardsInFlight -> numAttemptsInFlight
This commit is contained in:
1 parent
942697ae73
commit
3c8784dca3
2 files changed
+37
-37
No files matched your search
@@ -34,9 +34,9 @@ type paymentLifecycle struct {
|
|||||||
// paymentState holds a number of key insights learned from a given MPPayment
|
// paymentState holds a number of key insights learned from a given MPPayment
|
||||||
// that we use to determine what to do on each payment loop iteration.
|
// that we use to determine what to do on each payment loop iteration.
|
||||||
type paymentState struct {
|
type paymentState struct {
|
||||||
// numShardsInFlight specifies the number of HTLCs the payment is
|
// numAttemptsInFlight specifies the number of HTLCs the payment is
|
||||||
// waiting results for.
|
// waiting results for.
|
||||||
numShardsInFlight int
|
numAttemptsInFlight int
|
||||||
|
|
||||||
// remainingAmt specifies how much more money to be sent.
|
// remainingAmt specifies how much more money to be sent.
|
||||||
remainingAmt lnwire.MilliSatoshi
|
remainingAmt lnwire.MilliSatoshi
|
||||||
@@ -57,7 +57,7 @@ type paymentState struct {
|
|||||||
func (ps paymentState) terminated() bool {
|
func (ps paymentState) terminated() bool {
|
||||||
// If the payment is in final stage and we have no in flight shards to
|
// If the payment is in final stage and we have no in flight shards to
|
||||||
// wait result for, we consider the whole action terminated.
|
// wait result for, we consider the whole action terminated.
|
||||||
return ps.terminate && ps.numShardsInFlight == 0
|
return ps.terminate && ps.numAttemptsInFlight == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// needWaitForShards returns a bool to specify whether we need to wait for the
|
// needWaitForShards returns a bool to specify whether we need to wait for the
|
||||||
@@ -66,7 +66,7 @@ func (ps paymentState) needWaitForShards() bool {
|
|||||||
// If we have in flight shards and the payment is in final stage, we
|
// If we have in flight shards and the payment is in final stage, we
|
||||||
// need to wait for the outcomes from the shards. Or if we have no more
|
// need to wait for the outcomes from the shards. Or if we have no more
|
||||||
// money to be sent, we need to wait for the already launched shards.
|
// money to be sent, we need to wait for the already launched shards.
|
||||||
if ps.numShardsInFlight == 0 {
|
if ps.numAttemptsInFlight == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return ps.terminate || ps.remainingAmt == 0
|
return ps.terminate || ps.remainingAmt == 0
|
||||||
@@ -115,10 +115,10 @@ func (p *paymentLifecycle) fetchPaymentState() (*channeldb.MPPayment,
|
|||||||
|
|
||||||
// Update the payment state.
|
// Update the payment state.
|
||||||
state := &paymentState{
|
state := &paymentState{
|
||||||
numShardsInFlight: len(payment.InFlightHTLCs()),
|
numAttemptsInFlight: len(payment.InFlightHTLCs()),
|
||||||
remainingAmt: totalAmt - sentAmt,
|
remainingAmt: totalAmt - sentAmt,
|
||||||
remainingFees: feeBudget,
|
remainingFees: feeBudget,
|
||||||
terminate: terminate,
|
terminate: terminate,
|
||||||
}
|
}
|
||||||
|
|
||||||
return payment, state, nil
|
return payment, state, nil
|
||||||
@@ -179,7 +179,7 @@ lifecycle:
|
|||||||
|
|
||||||
log.Debugf("Payment %v in state terminate=%v, "+
|
log.Debugf("Payment %v in state terminate=%v, "+
|
||||||
"active_shards=%v, rem_value=%v, fee_limit=%v",
|
"active_shards=%v, rem_value=%v, fee_limit=%v",
|
||||||
p.identifier, ps.terminate, ps.numShardsInFlight,
|
p.identifier, ps.terminate, ps.numAttemptsInFlight,
|
||||||
ps.remainingAmt, ps.remainingFees,
|
ps.remainingAmt, ps.remainingFees,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ lifecycle:
|
|||||||
// Create a new payment attempt from the given payment session.
|
// Create a new payment attempt from the given payment session.
|
||||||
rt, err := p.paySession.RequestRoute(
|
rt, err := p.paySession.RequestRoute(
|
||||||
ps.remainingAmt, ps.remainingFees,
|
ps.remainingAmt, ps.remainingFees,
|
||||||
uint32(ps.numShardsInFlight),
|
uint32(ps.numAttemptsInFlight),
|
||||||
uint32(p.currentHeight),
|
uint32(p.currentHeight),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -273,7 +273,7 @@ lifecycle:
|
|||||||
// There is no route to try, and we have no active
|
// There is no route to try, and we have no active
|
||||||
// shards. This means that there is no way for us to
|
// shards. This means that there is no way for us to
|
||||||
// send the payment, so mark it failed with no route.
|
// send the payment, so mark it failed with no route.
|
||||||
if ps.numShardsInFlight == 0 {
|
if ps.numAttemptsInFlight == 0 {
|
||||||
failureCode := routeErr.FailureReason()
|
failureCode := routeErr.FailureReason()
|
||||||
log.Debugf("Marking payment %v permanently "+
|
log.Debugf("Marking payment %v permanently "+
|
||||||
"failed with no route: %v",
|
"failed with no route: %v",
|
||||||
|
|||||||
@@ -803,9 +803,9 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// Use the following three params, each is equivalent to a bool
|
// Use the following three params, each is equivalent to a bool
|
||||||
// statement, to construct 8 test cases so that we can
|
// statement, to construct 8 test cases so that we can
|
||||||
// exhaustively catch all possible states.
|
// exhaustively catch all possible states.
|
||||||
numShardsInFlight int
|
numAttemptsInFlight int
|
||||||
remainingAmt lnwire.MilliSatoshi
|
remainingAmt lnwire.MilliSatoshi
|
||||||
terminate bool
|
terminate bool
|
||||||
|
|
||||||
expectedTerminated bool
|
expectedTerminated bool
|
||||||
expectedNeedWaitForShards bool
|
expectedNeedWaitForShards bool
|
||||||
@@ -816,7 +816,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// remaining amount is zero, we need to wait for shards
|
// remaining amount is zero, we need to wait for shards
|
||||||
// to be finished and launch no more shards.
|
// to be finished and launch no more shards.
|
||||||
name: "state 100",
|
name: "state 100",
|
||||||
numShardsInFlight: 1,
|
numAttemptsInFlight: 1,
|
||||||
remainingAmt: lnwire.MilliSatoshi(0),
|
remainingAmt: lnwire.MilliSatoshi(0),
|
||||||
terminate: false,
|
terminate: false,
|
||||||
expectedTerminated: false,
|
expectedTerminated: false,
|
||||||
@@ -828,7 +828,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// wait for shards to be finished and launch no more
|
// wait for shards to be finished and launch no more
|
||||||
// shards.
|
// shards.
|
||||||
name: "state 101",
|
name: "state 101",
|
||||||
numShardsInFlight: 1,
|
numAttemptsInFlight: 1,
|
||||||
remainingAmt: lnwire.MilliSatoshi(0),
|
remainingAmt: lnwire.MilliSatoshi(0),
|
||||||
terminate: true,
|
terminate: true,
|
||||||
expectedTerminated: false,
|
expectedTerminated: false,
|
||||||
@@ -841,7 +841,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// remaining amount is not zero, we don't need to wait
|
// remaining amount is not zero, we don't need to wait
|
||||||
// for shards outcomes and should launch more shards.
|
// for shards outcomes and should launch more shards.
|
||||||
name: "state 110",
|
name: "state 110",
|
||||||
numShardsInFlight: 1,
|
numAttemptsInFlight: 1,
|
||||||
remainingAmt: lnwire.MilliSatoshi(1),
|
remainingAmt: lnwire.MilliSatoshi(1),
|
||||||
terminate: false,
|
terminate: false,
|
||||||
expectedTerminated: false,
|
expectedTerminated: false,
|
||||||
@@ -853,7 +853,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// remaining amount is not zero, we need to wait for
|
// remaining amount is not zero, we need to wait for
|
||||||
// shards outcomes because state is terminated.
|
// shards outcomes because state is terminated.
|
||||||
name: "state 111",
|
name: "state 111",
|
||||||
numShardsInFlight: 1,
|
numAttemptsInFlight: 1,
|
||||||
remainingAmt: lnwire.MilliSatoshi(1),
|
remainingAmt: lnwire.MilliSatoshi(1),
|
||||||
terminate: true,
|
terminate: true,
|
||||||
expectedTerminated: false,
|
expectedTerminated: false,
|
||||||
@@ -865,7 +865,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// need to wait for more shard outcomes because there
|
// need to wait for more shard outcomes because there
|
||||||
// are no active shards.
|
// are no active shards.
|
||||||
name: "state 000",
|
name: "state 000",
|
||||||
numShardsInFlight: 0,
|
numAttemptsInFlight: 0,
|
||||||
remainingAmt: lnwire.MilliSatoshi(0),
|
remainingAmt: lnwire.MilliSatoshi(0),
|
||||||
terminate: false,
|
terminate: false,
|
||||||
expectedTerminated: false,
|
expectedTerminated: false,
|
||||||
@@ -876,7 +876,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// true, the state is terminated, and we don't need to
|
// true, the state is terminated, and we don't need to
|
||||||
// wait for shards to be finished.
|
// wait for shards to be finished.
|
||||||
name: "state 001",
|
name: "state 001",
|
||||||
numShardsInFlight: 0,
|
numAttemptsInFlight: 0,
|
||||||
remainingAmt: lnwire.MilliSatoshi(0),
|
remainingAmt: lnwire.MilliSatoshi(0),
|
||||||
terminate: true,
|
terminate: true,
|
||||||
expectedTerminated: true,
|
expectedTerminated: true,
|
||||||
@@ -888,7 +888,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// remaining amount is not zero, we don't need to wait
|
// remaining amount is not zero, we don't need to wait
|
||||||
// for shards outcomes and should launch more shards.
|
// for shards outcomes and should launch more shards.
|
||||||
name: "state 010",
|
name: "state 010",
|
||||||
numShardsInFlight: 0,
|
numAttemptsInFlight: 0,
|
||||||
remainingAmt: lnwire.MilliSatoshi(1),
|
remainingAmt: lnwire.MilliSatoshi(1),
|
||||||
terminate: false,
|
terminate: false,
|
||||||
expectedTerminated: false,
|
expectedTerminated: false,
|
||||||
@@ -899,7 +899,7 @@ func TestPaymentState(t *testing.T) {
|
|||||||
// true, the state is terminated, and we don't need to
|
// true, the state is terminated, and we don't need to
|
||||||
// wait for shards outcomes.
|
// wait for shards outcomes.
|
||||||
name: "state 011",
|
name: "state 011",
|
||||||
numShardsInFlight: 0,
|
numAttemptsInFlight: 0,
|
||||||
remainingAmt: lnwire.MilliSatoshi(1),
|
remainingAmt: lnwire.MilliSatoshi(1),
|
||||||
terminate: true,
|
terminate: true,
|
||||||
expectedTerminated: true,
|
expectedTerminated: true,
|
||||||
@@ -913,9 +913,9 @@ func TestPaymentState(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
ps := &paymentState{
|
ps := &paymentState{
|
||||||
numShardsInFlight: tc.numShardsInFlight,
|
numAttemptsInFlight: tc.numAttemptsInFlight,
|
||||||
remainingAmt: tc.remainingAmt,
|
remainingAmt: tc.remainingAmt,
|
||||||
terminate: tc.terminate,
|
terminate: tc.terminate,
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(
|
require.Equal(
|
||||||
@@ -994,10 +994,10 @@ func TestUpdatePaymentState(t *testing.T) {
|
|||||||
totalAmt: 1000,
|
totalAmt: 1000,
|
||||||
feeLimit: 1,
|
feeLimit: 1,
|
||||||
expectedState: &paymentState{
|
expectedState: &paymentState{
|
||||||
numShardsInFlight: 1,
|
numAttemptsInFlight: 1,
|
||||||
remainingAmt: 1000 - 90,
|
remainingAmt: 1000 - 90,
|
||||||
remainingFees: 0,
|
remainingFees: 0,
|
||||||
terminate: false,
|
terminate: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1015,10 +1015,10 @@ func TestUpdatePaymentState(t *testing.T) {
|
|||||||
totalAmt: 1000,
|
totalAmt: 1000,
|
||||||
feeLimit: 100,
|
feeLimit: 100,
|
||||||
expectedState: &paymentState{
|
expectedState: &paymentState{
|
||||||
numShardsInFlight: 0,
|
numAttemptsInFlight: 0,
|
||||||
remainingAmt: 1000 - 90,
|
remainingAmt: 1000 - 90,
|
||||||
remainingFees: 100 - 10,
|
remainingFees: 100 - 10,
|
||||||
terminate: true,
|
terminate: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1034,10 +1034,10 @@ func TestUpdatePaymentState(t *testing.T) {
|
|||||||
totalAmt: 1000,
|
totalAmt: 1000,
|
||||||
feeLimit: 100,
|
feeLimit: 100,
|
||||||
expectedState: &paymentState{
|
expectedState: &paymentState{
|
||||||
numShardsInFlight: 0,
|
numAttemptsInFlight: 0,
|
||||||
remainingAmt: 1000,
|
remainingAmt: 1000,
|
||||||
remainingFees: 100,
|
remainingFees: 100,
|
||||||
terminate: true,
|
terminate: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user