@@ -21,8 +21,15 @@ type HTLCAttemptInfo struct {
21
21
// AttemptID is the unique ID used for this attempt.
22
22
AttemptID uint64
23
23
24
- // SessionKey is the ephemeral key used for this attempt.
25
- SessionKey * btcec.PrivateKey
24
+ // sessionKey is the raw bytes ephemeral key used for this attempt.
25
+ // These bytes are lazily read off disk to save ourselves the expensive
26
+ // EC operations used by btcec.PrivKeyFromBytes.
27
+ sessionKey [btcec .PrivKeyBytesLen ]byte
28
+
29
+ // cachedSessionKey is our fully deserialized sesionKey. This value
30
+ // may be nil if the attempt has just been read from disk and its
31
+ // session key has not been used yet.
32
+ cachedSessionKey * btcec.PrivateKey
26
33
27
34
// Route is the route attempted to send the HTLC.
28
35
Route route.Route
@@ -38,6 +45,36 @@ type HTLCAttemptInfo struct {
38
45
Hash * lntypes.Hash
39
46
}
40
47
48
+ // NewHtlcAttemptInfo creates a htlc attempt.
49
+ func NewHtlcAttemptInfo (attemptID uint64 , sessionKey * btcec.PrivateKey ,
50
+ route route.Route , attemptTime time.Time ,
51
+ hash * lntypes.Hash ) * HTLCAttemptInfo {
52
+
53
+ var scratch [btcec .PrivKeyBytesLen ]byte
54
+ copy (scratch [:], sessionKey .Serialize ())
55
+
56
+ return & HTLCAttemptInfo {
57
+ AttemptID : attemptID ,
58
+ sessionKey : scratch ,
59
+ cachedSessionKey : sessionKey ,
60
+ Route : route ,
61
+ AttemptTime : attemptTime ,
62
+ Hash : hash ,
63
+ }
64
+ }
65
+
66
+ // SessionKey returns the ephemeral key used for a htlc attempt. This function
67
+ // performs expensive ec-ops to obtain the session key if it is not cached.
68
+ func (h * HTLCAttemptInfo ) SessionKey () * btcec.PrivateKey {
69
+ if h .cachedSessionKey == nil {
70
+ h .cachedSessionKey , _ = btcec .PrivKeyFromBytes (
71
+ btcec .S256 (), h .sessionKey [:],
72
+ )
73
+ }
74
+
75
+ return h .cachedSessionKey
76
+ }
77
+
41
78
// HTLCAttempt contains information about a specific HTLC attempt for a given
42
79
// payment. It contains the HTLCAttemptInfo used to send the HTLC, as well
43
80
// as a timestamp and any known outcome of the attempt.
0 commit comments