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