@@ -6,20 +6,40 @@ use bitcoin::secp256k1::SecretKey;
6
6
7
7
use crate :: { cryptography, UserId } ;
8
8
9
- #[ derive( Serialize , Debug ) ]
9
+ /// Proof that a user has registered with a tower. This serves two purposes:
10
+ ///
11
+ /// - First, the user is able to prove that the tower agreed on providing a service. If a tower refuses to accept appointments
12
+ /// from a user (claiming the subscription has expired) but the expiry time has still not passed and the tower cannot
13
+ /// provide the relevant appointments signed by the user, it means it is cheating.
14
+ /// - Second, it serves as proof, alongside an appointment receipt, that an appointment was not fulfilled. A registration receipt
15
+ /// specifies a subscription period (`subscription_start` - `subscription_expiry`) and the appointment a `start_block` so inclusion
16
+ /// can be proved.
17
+ ///
18
+ /// TODO: / DISCUSS: In order to minimize the amount of receipts the user has to store, the tower could batch subscription receipts
19
+ /// as long as the user info is still known. That is, if a user has a subscription with range (S, E) and the user renews the subscription
20
+ /// before the tower wipes their data, then the tower can create a new receipt with (S, E') for E' > E instead of a second receipt (E, E').
21
+ // Notice this only applies as long as there is no gap between the two subscriptions.
22
+ #[ derive( Serialize , Debug , Eq , PartialEq , Clone ) ]
10
23
pub struct RegistrationReceipt {
11
24
user_id : UserId ,
12
25
available_slots : u32 ,
26
+ subscription_start : u32 ,
13
27
subscription_expiry : u32 ,
14
28
#[ serde( skip) ]
15
29
signature : Option < String > ,
16
30
}
17
31
18
32
impl RegistrationReceipt {
19
- pub fn new ( user_id : UserId , available_slots : u32 , subscription_expiry : u32 ) -> Self {
33
+ pub fn new (
34
+ user_id : UserId ,
35
+ available_slots : u32 ,
36
+ subscription_start : u32 ,
37
+ subscription_expiry : u32 ,
38
+ ) -> Self {
20
39
RegistrationReceipt {
21
40
user_id,
22
41
available_slots,
42
+ subscription_start,
23
43
subscription_expiry,
24
44
signature : None ,
25
45
}
@@ -28,12 +48,14 @@ impl RegistrationReceipt {
28
48
pub fn with_signature (
29
49
user_id : UserId ,
30
50
available_slots : u32 ,
51
+ subscription_start : u32 ,
31
52
subscription_expiry : u32 ,
32
53
signature : String ,
33
54
) -> Self {
34
55
RegistrationReceipt {
35
56
user_id,
36
57
available_slots,
58
+ subscription_start,
37
59
subscription_expiry,
38
60
signature : Some ( signature) ,
39
61
}
@@ -47,6 +69,10 @@ impl RegistrationReceipt {
47
69
self . available_slots
48
70
}
49
71
72
+ pub fn subscription_start ( & self ) -> u32 {
73
+ self . subscription_start
74
+ }
75
+
50
76
pub fn subscription_expiry ( & self ) -> u32 {
51
77
self . subscription_expiry
52
78
}
@@ -59,6 +85,7 @@ impl RegistrationReceipt {
59
85
let mut ser = Vec :: new ( ) ;
60
86
ser. extend_from_slice ( & self . user_id . to_vec ( ) ) ;
61
87
ser. extend_from_slice ( & self . available_slots . to_be_bytes ( ) ) ;
88
+ ser. extend_from_slice ( & self . subscription_start . to_be_bytes ( ) ) ;
62
89
ser. extend_from_slice ( & self . subscription_expiry . to_be_bytes ( ) ) ;
63
90
64
91
ser
@@ -78,6 +105,9 @@ impl RegistrationReceipt {
78
105
}
79
106
}
80
107
108
+ /// Proof that a certain state was backed up with the tower.
109
+ ///
110
+ /// Appointment receipts can be used alongside a registration receipt that covers it, and on chain data (a breach not being reacted with a penalty), to prove a tower has not reacted to a channel breach.
81
111
#[ derive( Debug , Clone , PartialEq , Eq , Serialize ) ]
82
112
pub struct AppointmentReceipt {
83
113
user_signature : String ,
0 commit comments