@@ -150,8 +150,8 @@ pub enum Field {
150150 AuthenticityProof ( Proof ) = 0 ,
151151 /// An identifier for the key that `Data` field may be decrypted with.
152152 DecryptionKey ( DecryptionKey ) = 1 ,
153- /// Priority when competing with other messages from the same sender .
154- Priority ( u32 ) = 2 ,
153+ /// Expiry of the statement .
154+ Expiry ( u64 ) = 2 ,
155155 /// Account channel to use. Only one message per `(account, channel)` pair is allowed.
156156 Channel ( Channel ) = 3 ,
157157 /// First statement topic.
@@ -180,6 +180,7 @@ pub struct Statement {
180180 /// Proof used for authorizing the statement.
181181 proof : Option < Proof > ,
182182 /// An identifier for the key that `Data` field may be decrypted with.
183+ #[ deprecated( note = "Experimental feature, may be removed in future releases" ) ]
183184 decryption_key : Option < DecryptionKey > ,
184185 /// Used for identifying a distinct communication channel, only a message per channel is
185186 /// stored.
@@ -192,16 +193,25 @@ pub struct Statement {
192193 /// in the account quota. In that case, other statements from the same account with the lowest
193194 /// priority might be removed.
194195 channel : Option < Channel > ,
195- /// Message priority, if any, used for determining which statements to keep when over quota.
196- /// Statements with higher priority are kept over those with lower priority.
197- priority : Option < u32 > ,
196+ /// Message priority, used for determining which statements to keep.
197+ ///
198+ /// The the most significant 32 bits represents the expiration timestamp (in seconds since
199+ /// UNIX epoch) after which the statement gets removed. These ensure that statements with a
200+ /// higher expiration time have a higher priority.
201+ /// The lower 32 bits represents an arbitrary sequence number used to order statements with the
202+ /// same expiration time.
203+ ///
204+ /// Higher values indicate a higher priority.
205+ /// This is used in two case:
206+ /// 1) When an account exceeds its quota and some statements need to be removed. Statements
207+ /// with the lowest priority are removed first.
208+ /// 2) When multiple statements are submitted on the same channel, the one with the highest
209+ /// priority replaces the one with the same channel.
210+ expiry : u64 ,
198211 /// Number of topics present.
199212 num_topics : u8 ,
200213 /// Topics, used for querying and filtering statements.
201214 topics : [ Topic ; MAX_TOPICS ] ,
202- /// A Unix timestamp (in milliseconds) after which the statement is considered expired and it
203- /// will be cleaned up from the store.
204- expires_at_ms : u64 ,
205215 /// Statement data.
206216 data : Option < Vec < u8 > > ,
207217}
@@ -222,7 +232,7 @@ impl Decode for Statement {
222232 match field {
223233 Field :: AuthenticityProof ( p) => statement. set_proof ( p) ,
224234 Field :: DecryptionKey ( key) => statement. set_decryption_key ( key) ,
225- Field :: Priority ( p) => statement. set_priority ( p) ,
235+ Field :: Expiry ( p) => statement. set_expiry ( p) ,
226236 Field :: Channel ( c) => statement. set_channel ( c) ,
227237 Field :: Topic1 ( t) => statement. set_topic ( 0 , t) ,
228238 Field :: Topic2 ( t) => statement. set_topic ( 1 , t) ,
@@ -445,8 +455,8 @@ impl Statement {
445455 }
446456
447457 /// Get priority, if any.
448- pub fn priority ( & self ) -> Option < u32 > {
449- self . priority
458+ pub fn expiry ( & self ) -> u64 {
459+ self . expiry
450460 }
451461
452462 /// Return encoded fields that can be signed to construct or verify a proof
@@ -464,9 +474,9 @@ impl Statement {
464474 self . proof = Some ( proof)
465475 }
466476
467- /// Set statement priority .
468- pub fn set_priority ( & mut self , priority : u32 ) {
469- self . priority = Some ( priority )
477+ /// Set statement expiry .
478+ pub fn set_expiry ( & mut self , expiry : u64 ) {
479+ self . expiry = expiry ;
470480 }
471481
472482 /// Set statement channel.
@@ -495,9 +505,9 @@ impl Statement {
495505 fn encoded ( & self , for_signing : bool ) -> Vec < u8 > {
496506 // Encoding matches that of Vec<Field>. Basically this just means accepting that there
497507 // will be a prefix of vector length.
498- let num_fields = if !for_signing && self . proof . is_some ( ) { 1 } else { 0 } +
508+ // Expiry field is always present.
509+ let num_fields = if !for_signing && self . proof . is_some ( ) { 2 } else { 1 } +
499510 if self . decryption_key . is_some ( ) { 1 } else { 0 } +
500- if self . priority . is_some ( ) { 1 } else { 0 } +
501511 if self . channel . is_some ( ) { 1 } else { 0 } +
502512 if self . data . is_some ( ) { 1 } else { 0 } +
503513 self . num_topics as u32 ;
@@ -519,10 +529,10 @@ impl Statement {
519529 1u8 . encode_to ( & mut output) ;
520530 decryption_key. encode_to ( & mut output) ;
521531 }
522- if let Some ( priority ) = & self . priority {
523- 2u8 . encode_to ( & mut output) ;
524- priority . encode_to ( & mut output) ;
525- }
532+
533+ 2u8 . encode_to ( & mut output) ;
534+ self . expiry ( ) . encode_to ( & mut output) ;
535+
526536 if let Some ( channel) = & self . channel {
527537 3u8 . encode_to ( & mut output) ;
528538 channel. encode_to ( & mut output) ;
@@ -594,7 +604,7 @@ mod test {
594604 let fields = vec ! [
595605 Field :: AuthenticityProof ( proof. clone( ) ) ,
596606 Field :: DecryptionKey ( decryption_key) ,
597- Field :: Priority ( priority) ,
607+ Field :: Expiry ( priority) ,
598608 Field :: Channel ( channel) ,
599609 Field :: Topic1 ( topic1) ,
600610 Field :: Topic2 ( topic2) ,
@@ -616,7 +626,7 @@ mod test {
616626 let priority = 999 ;
617627
618628 let fields = vec ! [
619- Field :: Priority ( priority) ,
629+ Field :: Expiry ( priority) ,
620630 Field :: Topic1 ( topic1) ,
621631 Field :: Topic1 ( topic1) ,
622632 Field :: Topic2 ( topic2) ,
@@ -626,7 +636,7 @@ mod test {
626636 assert ! ( Statement :: decode( & mut fields. as_slice( ) ) . is_err( ) ) ;
627637
628638 let fields =
629- vec ! [ Field :: Topic1 ( topic1) , Field :: Priority ( priority) , Field :: Topic2 ( topic2) ] . encode ( ) ;
639+ vec ! [ Field :: Topic1 ( topic1) , Field :: Expiry ( priority) , Field :: Topic2 ( topic2) ] . encode ( ) ;
630640
631641 assert ! ( Statement :: decode( & mut fields. as_slice( ) ) . is_err( ) ) ;
632642 }
0 commit comments