@@ -6,20 +6,40 @@ use bitcoin::secp256k1::SecretKey;
66
77use crate :: { cryptography, UserId } ;
88
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 ) ]
1023pub struct RegistrationReceipt {
1124 user_id : UserId ,
1225 available_slots : u32 ,
26+ subscription_start : u32 ,
1327 subscription_expiry : u32 ,
1428 #[ serde( skip) ]
1529 signature : Option < String > ,
1630}
1731
1832impl 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 {
2039 RegistrationReceipt {
2140 user_id,
2241 available_slots,
42+ subscription_start,
2343 subscription_expiry,
2444 signature : None ,
2545 }
@@ -28,12 +48,14 @@ impl RegistrationReceipt {
2848 pub fn with_signature (
2949 user_id : UserId ,
3050 available_slots : u32 ,
51+ subscription_start : u32 ,
3152 subscription_expiry : u32 ,
3253 signature : String ,
3354 ) -> Self {
3455 RegistrationReceipt {
3556 user_id,
3657 available_slots,
58+ subscription_start,
3759 subscription_expiry,
3860 signature : Some ( signature) ,
3961 }
@@ -47,6 +69,10 @@ impl RegistrationReceipt {
4769 self . available_slots
4870 }
4971
72+ pub fn subscription_start ( & self ) -> u32 {
73+ self . subscription_start
74+ }
75+
5076 pub fn subscription_expiry ( & self ) -> u32 {
5177 self . subscription_expiry
5278 }
@@ -59,6 +85,7 @@ impl RegistrationReceipt {
5985 let mut ser = Vec :: new ( ) ;
6086 ser. extend_from_slice ( & self . user_id . to_vec ( ) ) ;
6187 ser. extend_from_slice ( & self . available_slots . to_be_bytes ( ) ) ;
88+ ser. extend_from_slice ( & self . subscription_start . to_be_bytes ( ) ) ;
6289 ser. extend_from_slice ( & self . subscription_expiry . to_be_bytes ( ) ) ;
6390
6491 ser
@@ -78,6 +105,9 @@ impl RegistrationReceipt {
78105 }
79106}
80107
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.
81111#[ derive( Debug , Clone , PartialEq , Eq , Serialize ) ]
82112pub struct AppointmentReceipt {
83113 user_signature : String ,
0 commit comments