multi: unexport session key and add constructor for htlc attempt info

This commit is contained in:
carla 2021-05-19 09:03:46 +02:00
parent 6c330d3121
commit eb068bf666
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
7 changed files with 35 additions and 24 deletions

@ -181,7 +181,7 @@ func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) {
HTLCAttemptInfo: HTLCAttemptInfo{ HTLCAttemptInfo: HTLCAttemptInfo{
AttemptID: attempt.attemptID, AttemptID: attempt.attemptID,
Route: attempt.route, Route: attempt.route,
SessionKey: attempt.sessionKey, sessionKey: attempt.sessionKey,
}, },
} }

@ -21,8 +21,8 @@ type HTLCAttemptInfo struct {
// AttemptID is the unique ID used for this attempt. // AttemptID is the unique ID used for this attempt.
AttemptID uint64 AttemptID uint64
// SessionKey is the ephemeral key used for this attempt. // sessionKey is the ephemeral key used for this attempt.
SessionKey *btcec.PrivateKey sessionKey *btcec.PrivateKey
// Route is the route attempted to send the HTLC. // Route is the route attempted to send the HTLC.
Route route.Route Route route.Route
@ -38,6 +38,25 @@ type HTLCAttemptInfo struct {
Hash *lntypes.Hash Hash *lntypes.Hash
} }
// NewHtlcAttemptInfo creates a htlc attempt.
func NewHtlcAttemptInfo(attemptID uint64, sessionKey *btcec.PrivateKey,
route route.Route, attemptTime time.Time,
hash *lntypes.Hash) *HTLCAttemptInfo {
return &HTLCAttemptInfo{
AttemptID: attemptID,
sessionKey: sessionKey,
Route: route,
AttemptTime: attemptTime,
Hash: hash,
}
}
// SessionKey returns the ephemeral key used for a htlc attempt.
func (h *HTLCAttemptInfo) SessionKey() *btcec.PrivateKey {
return h.sessionKey
}
// HTLCAttempt contains information about a specific HTLC attempt for a given // HTLCAttempt contains information about a specific HTLC attempt for a given
// payment. It contains the HTLCAttemptInfo used to send the HTLC, as well // payment. It contains the HTLCAttemptInfo used to send the HTLC, as well
// as a timestamp and any known outcome of the attempt. // as a timestamp and any known outcome of the attempt.

@ -45,7 +45,7 @@ func genInfo() (*PaymentCreationInfo, *HTLCAttemptInfo,
}, },
&HTLCAttemptInfo{ &HTLCAttemptInfo{
AttemptID: 0, AttemptID: 0,
SessionKey: priv, sessionKey: priv,
Route: *testRoute.Copy(), Route: *testRoute.Copy(),
}, preimage, nil }, preimage, nil
} }

@ -919,7 +919,7 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) {
} }
func serializeHTLCAttemptInfo(w io.Writer, a *HTLCAttemptInfo) error { func serializeHTLCAttemptInfo(w io.Writer, a *HTLCAttemptInfo) error {
if err := WriteElements(w, a.SessionKey); err != nil { if err := WriteElements(w, a.sessionKey); err != nil {
return err return err
} }
@ -945,7 +945,7 @@ func serializeHTLCAttemptInfo(w io.Writer, a *HTLCAttemptInfo) error {
func deserializeHTLCAttemptInfo(r io.Reader) (*HTLCAttemptInfo, error) { func deserializeHTLCAttemptInfo(r io.Reader) (*HTLCAttemptInfo, error) {
a := &HTLCAttemptInfo{} a := &HTLCAttemptInfo{}
err := ReadElements(r, &a.SessionKey) err := ReadElements(r, &a.sessionKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -70,7 +70,7 @@ func makeFakeInfo() (*PaymentCreationInfo, *HTLCAttemptInfo) {
a := &HTLCAttemptInfo{ a := &HTLCAttemptInfo{
AttemptID: 44, AttemptID: 44,
SessionKey: priv, sessionKey: priv,
Route: testRoute, Route: testRoute,
AttemptTime: time.Unix(100, 0), AttemptTime: time.Unix(100, 0),
Hash: &hash, Hash: &hash,
@ -124,8 +124,6 @@ func TestSentPaymentSerialization(t *testing.T) {
s.Route = route.Route{} s.Route = route.Route{}
if !reflect.DeepEqual(s, newWireInfo) { if !reflect.DeepEqual(s, newWireInfo) {
s.SessionKey.Curve = nil
newWireInfo.SessionKey.Curve = nil
t.Fatalf("Payments do not match after "+ t.Fatalf("Payments do not match after "+
"serialization/deserialization %v vs %v", "serialization/deserialization %v vs %v",
spew.Sdump(s), spew.Sdump(newWireInfo), spew.Sdump(s), spew.Sdump(newWireInfo),

@ -331,11 +331,9 @@ func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.HTLCAttemptInfo,
CreationTime: time.Unix(time.Now().Unix(), 0), CreationTime: time.Unix(time.Now().Unix(), 0),
PaymentRequest: []byte("hola"), PaymentRequest: []byte("hola"),
}, },
&channeldb.HTLCAttemptInfo{ channeldb.NewHtlcAttemptInfo(
AttemptID: 1, 1, priv, testRoute, time.Time{}, nil,
SessionKey: priv, ), preimage, nil
Route: testRoute,
}, preimage, nil
} }
func genPreimage() ([32]byte, error) { func genPreimage() ([32]byte, error) {

@ -499,7 +499,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
// Regenerate the circuit for this attempt. // Regenerate the circuit for this attempt.
_, circuit, err := generateSphinxPacket( _, circuit, err := generateSphinxPacket(
&attempt.Route, hash[:], attempt.SessionKey, &attempt.Route, hash[:], attempt.SessionKey(),
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -677,15 +677,11 @@ func (p *shardHandler) createNewPaymentAttempt(rt *route.Route, lastShard bool)
rt.Hops[0].ChannelID, rt.Hops[0].ChannelID,
) )
// We now have all the information needed to populate // We now have all the information needed to populate the current
// the current attempt information. // attempt information.
attempt := &channeldb.HTLCAttemptInfo{ attempt := channeldb.NewHtlcAttemptInfo(
AttemptID: attemptID, attemptID, sessionKey, *rt, p.router.cfg.Clock.Now(), &hash,
AttemptTime: p.router.cfg.Clock.Now(), )
SessionKey: sessionKey,
Route: *rt,
Hash: &hash,
}
return firstHop, htlcAdd, attempt, nil return firstHop, htlcAdd, attempt, nil
} }