multi: unexport session key and add constructor for htlc attempt info
This commit is contained in:
7 files changed
+35
-24
No files matched your search
@@ -181,7 +181,7 @@ func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) {
|
||||
HTLCAttemptInfo: HTLCAttemptInfo{
|
||||
AttemptID: attempt.attemptID,
|
||||
Route: attempt.route,
|
||||
SessionKey: attempt.sessionKey,
|
||||
sessionKey: attempt.sessionKey,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+21
-2
@@ -21,8 +21,8 @@ type HTLCAttemptInfo struct {
|
||||
// AttemptID is the unique ID used for this attempt.
|
||||
AttemptID uint64
|
||||
|
||||
// SessionKey is the ephemeral key used for this attempt.
|
||||
SessionKey *btcec.PrivateKey
|
||||
// sessionKey is the ephemeral key used for this attempt.
|
||||
sessionKey *btcec.PrivateKey
|
||||
|
||||
// Route is the route attempted to send the HTLC.
|
||||
Route route.Route
|
||||
@@ -38,6 +38,25 @@ type HTLCAttemptInfo struct {
|
||||
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
|
||||
// payment. It contains the HTLCAttemptInfo used to send the HTLC, as well
|
||||
// as a timestamp and any known outcome of the attempt.
|
||||
|
||||
@@ -45,7 +45,7 @@ func genInfo() (*PaymentCreationInfo, *HTLCAttemptInfo,
|
||||
},
|
||||
&HTLCAttemptInfo{
|
||||
AttemptID: 0,
|
||||
SessionKey: priv,
|
||||
sessionKey: priv,
|
||||
Route: *testRoute.Copy(),
|
||||
}, preimage, nil
|
||||
}
|
||||
|
||||
@@ -919,7 +919,7 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, 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
|
||||
}
|
||||
|
||||
@@ -945,7 +945,7 @@ func serializeHTLCAttemptInfo(w io.Writer, a *HTLCAttemptInfo) error {
|
||||
|
||||
func deserializeHTLCAttemptInfo(r io.Reader) (*HTLCAttemptInfo, error) {
|
||||
a := &HTLCAttemptInfo{}
|
||||
err := ReadElements(r, &a.SessionKey)
|
||||
err := ReadElements(r, &a.sessionKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func makeFakeInfo() (*PaymentCreationInfo, *HTLCAttemptInfo) {
|
||||
|
||||
a := &HTLCAttemptInfo{
|
||||
AttemptID: 44,
|
||||
SessionKey: priv,
|
||||
sessionKey: priv,
|
||||
Route: testRoute,
|
||||
AttemptTime: time.Unix(100, 0),
|
||||
Hash: &hash,
|
||||
@@ -124,8 +124,6 @@ func TestSentPaymentSerialization(t *testing.T) {
|
||||
s.Route = route.Route{}
|
||||
|
||||
if !reflect.DeepEqual(s, newWireInfo) {
|
||||
s.SessionKey.Curve = nil
|
||||
newWireInfo.SessionKey.Curve = nil
|
||||
t.Fatalf("Payments do not match after "+
|
||||
"serialization/deserialization %v vs %v",
|
||||
spew.Sdump(s), spew.Sdump(newWireInfo),
|
||||
|
||||
Reference in new issue
Block a user