diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 180d38a63..a4ca0a0fb 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -488,17 +488,9 @@ func (p *paymentLifecycle) collectResult(attempt *channeldb.HTLCAttempt) ( log.Tracef("Collecting result for attempt %v", spew.Sdump(attempt)) - // We'll retrieve the hash specific to this shard from the - // shardTracker, since it will be needed to regenerate the circuit - // below. - hash, err := p.shardTracker.GetHash(attempt.AttemptID) - if err != nil { - return p.failAttempt(attempt.AttemptID, err) - } - // Regenerate the circuit for this attempt. _, circuit, err := generateSphinxPacket( - &attempt.Route, hash[:], attempt.SessionKey(), + &attempt.Route, attempt.Hash[:], attempt.SessionKey(), ) // TODO(yy): We generate this circuit to create the error decryptor, // which is then used in htlcswitch as the deobfuscator to decode the diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go index 72aa63141..55e36856c 100644 --- a/routing/payment_lifecycle_test.go +++ b/routing/payment_lifecycle_test.go @@ -260,10 +260,15 @@ func createDummyRoute(t *testing.T, amt lnwire.MilliSatoshi) *route.Route { func makeSettledAttempt(t *testing.T, total int, preimage lntypes.Preimage) *channeldb.HTLCAttempt { - return &channeldb.HTLCAttempt{ + a := &channeldb.HTLCAttempt{ HTLCAttemptInfo: makeAttemptInfo(t, total), Settle: &channeldb.HTLCSettleInfo{Preimage: preimage}, } + + hash := preimage.Hash() + a.Hash = &hash + + return a } func makeFailedAttempt(t *testing.T, total int) *channeldb.HTLCAttempt { @@ -279,6 +284,7 @@ func makeAttemptInfo(t *testing.T, amt int) channeldb.HTLCAttemptInfo { rt := createDummyRoute(t, lnwire.MilliSatoshi(amt)) return channeldb.HTLCAttemptInfo{ Route: *rt, + Hash: &lntypes.Hash{1, 2, 3}, } } @@ -1303,11 +1309,6 @@ func TestCollectResultExitOnErr(t *testing.T) { paymentAmt := 10_000 attempt := makeFailedAttempt(t, paymentAmt) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a dummy error. m.payer.On("GetAttemptResult", attempt.AttemptID, p.identifier, mock.Anything, @@ -1348,11 +1349,6 @@ func TestCollectResultExitOnResultErr(t *testing.T) { paymentAmt := 10_000 attempt := makeFailedAttempt(t, paymentAmt) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult", @@ -1399,11 +1395,6 @@ func TestCollectResultExitOnSwitchQuit(t *testing.T) { paymentAmt := 10_000 attempt := makeFailedAttempt(t, paymentAmt) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult", @@ -1431,11 +1422,6 @@ func TestCollectResultExitOnRouterQuit(t *testing.T) { paymentAmt := 10_000 attempt := makeFailedAttempt(t, paymentAmt) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult", @@ -1462,11 +1448,6 @@ func TestCollectResultExitOnLifecycleQuit(t *testing.T) { paymentAmt := 10_000 attempt := makeFailedAttempt(t, paymentAmt) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult", @@ -1495,11 +1476,6 @@ func TestCollectResultExitOnSettleErr(t *testing.T) { preimage := lntypes.Preimage{1} attempt := makeSettledAttempt(t, paymentAmt, preimage) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult", @@ -1542,11 +1518,6 @@ func TestCollectResultSuccess(t *testing.T) { preimage := lntypes.Preimage{1} attempt := makeSettledAttempt(t, paymentAmt, preimage) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult", @@ -1590,11 +1561,6 @@ func TestCollectResultAsyncSuccess(t *testing.T) { preimage := lntypes.Preimage{1} attempt := makeSettledAttempt(t, paymentAmt, preimage) - // Mock shardTracker to return the payment hash. - m.shardTracker.On("GetHash", - attempt.AttemptID, - ).Return(p.identifier, nil).Once() - // Mock the htlcswitch to return a the result chan. resultChan := make(chan *htlcswitch.PaymentResult, 1) m.payer.On("GetAttemptResult",