Skip to content

Commit

Permalink
routing: change variable name numShardsInFlight -> numAttemptsInFlight
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu authored and backend-engineer1 committed Oct 6, 2023
1 parent 4bd1778 commit 03b69dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
22 changes: 11 additions & 11 deletions routing/payment_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down
52 changes: 26 additions & 26 deletions routing/payment_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
},
},
{
Expand All @@ -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,
},
},
{
Expand All @@ -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,
},
},
}
Expand Down

0 comments on commit 03b69dd

Please sign in to comment.