@@ -9,9 +9,7 @@ use std::{
99
1010use anyhow:: Context ;
1111use c509_certificate:: c509:: C509 ;
12- use cardano_blockchain_types:: {
13- hashes:: TransactionId , pallas_addresses:: Address , Cip0134Uri , Point , StakeAddress , TxnIndex ,
14- } ;
12+ use cardano_blockchain_types:: { hashes:: TransactionId , Point , StakeAddress , TxnIndex } ;
1513use catalyst_types:: {
1614 catalyst_id:: { key_rotation:: KeyRotation , role_index:: RoleId , CatalystId } ,
1715 conversion:: zero_out_last_n_bytes,
@@ -26,8 +24,8 @@ use x509_cert::certificate::Certificate as X509Certificate;
2624
2725use crate :: {
2826 cardano:: cip509:: {
29- CertKeyHash , CertOrPk , Cip0134UriSet , Cip509 , PaymentHistory , PointData , RoleData ,
30- RoleDataRecord , ValidationSignature ,
27+ CertKeyHash , CertOrPk , Cip0134UriSet , Cip509 , PaymentHistory , PointData , PointTxnIdx ,
28+ RoleData , RoleDataRecord , ValidationSignature ,
3129 } ,
3230 providers:: RbacRegistrationProvider ,
3331} ;
@@ -349,26 +347,13 @@ impl RegistrationChain {
349347 /// Returns all stake addresses associated to this chain.
350348 #[ must_use]
351349 pub fn stake_addresses ( & self ) -> HashSet < StakeAddress > {
352- let stolen_stake_addresses = self
353- . inner
354- . stolen_uris
355- . iter ( )
356- . flat_map ( |v| {
357- v. data ( ) . iter ( ) . filter_map ( |uri| {
358- match uri. address ( ) {
359- Address :: Stake ( a) => Some ( a. clone ( ) . into ( ) ) ,
360- _ => None ,
361- }
362- } )
363- } )
364- . collect ( ) ;
350+ self . inner . certificate_uris . stake_addresses ( ) ;
351+ }
365352
366- self . inner
367- . certificate_uris
368- . stake_addresses ( )
369- . difference ( & stolen_stake_addresses)
370- . cloned ( )
371- . collect ( )
353+ /// Returns the latest know applied registration's `PointTxnIdx`.
354+ #[ must_use]
355+ pub fn latest_applied ( & self ) -> PointTxnIdx {
356+ self . inner . latest_applied ( )
372357 }
373358}
374359
@@ -379,6 +364,9 @@ struct RegistrationChainInner {
379364 catalyst_id : CatalystId ,
380365 /// The current transaction ID hash (32 bytes)
381366 current_tx_id_hash : PointData < TransactionId > ,
367+ /// The latest `PointTxnIdx` of the stolen taken URIs by another registration chains.
368+ latest_taken_uris_point : Option < PointTxnIdx > ,
369+
382370 /// List of purpose for this registration chain
383371 purpose : Vec < UuidV4 > ,
384372
@@ -397,9 +385,6 @@ struct RegistrationChainInner {
397385 /// List of point + transaction index, and certificate key hash.
398386 revocations : Vec < PointData < CertKeyHash > > ,
399387
400- /// URIs which are stolen by another registration chains.
401- stolen_uris : Vec < PointData < Box < [ Cip0134Uri ] > > > ,
402-
403388 // Role
404389 /// Map of role number to list point + transaction index, and role data.
405390 /// Record history of the whole role data in point in time.
@@ -516,9 +501,9 @@ impl RegistrationChainInner {
516501 x509_certs,
517502 c509_certs,
518503 certificate_uris,
504+ latest_taken_uris_point : None ,
519505 simple_keys,
520506 revocations,
521- stolen_uris : vec ! [ ] ,
522507 role_data_history,
523508 role_data_record,
524509 payment_history,
@@ -536,6 +521,18 @@ impl RegistrationChainInner {
536521 signing_pk : VerifyingKey ,
537522 ) -> Option < Self > {
538523 let context = "Registration Chain update" ;
524+ if self . latest_applied ( ) . point ( ) >= cip509. origin ( ) . point ( ) {
525+ cip509. report ( ) . functional_validation (
526+ & format ! (
527+ "The provided registration is earlier {} than the current one {}" ,
528+ cip509. origin( ) . point( ) ,
529+ self . current_tx_id_hash. point( )
530+ ) ,
531+ "Provided registrations must be applied in the correct order." ,
532+ ) ;
533+ return None ;
534+ }
535+
539536 let mut new_inner = self . clone ( ) ;
540537
541538 let Some ( prv_tx_id) = cip509. previous_transaction ( ) else {
@@ -654,19 +651,12 @@ impl RegistrationChainInner {
654651 fn update_cause_another_chain (
655652 mut self ,
656653 cip509 : & Cip509 ,
657- ) -> Option < Self > {
658- if let Some ( uri_set) = cip509. certificate_uris ( ) {
659- let origin = cip509. origin ( ) . clone ( ) ;
660- self . stolen_uris . push ( PointData :: new (
661- origin,
662- uri_set
663- . values ( )
664- . cloned ( )
665- . collect :: < Vec < _ > > ( )
666- . into_boxed_slice ( ) ,
667- ) ) ;
654+ ) -> Self {
655+ if let Some ( reg) = cip509. metadata ( ) {
656+ self . certificate_uris = self . certificate_uris . update_taken_uris ( reg) ;
668657 }
669- Some ( self )
658+ self . latest_taken_uris_point = Some ( cip509. origin ( ) . clone ( ) ) ;
659+ self
670660 }
671661
672662 /// Get the latest signing public key for a role.
@@ -700,6 +690,20 @@ impl RegistrationChainInner {
700690 } )
701691 } )
702692 }
693+
694+ /// Returns the latest know applied registration's `PointTxnIdx`.
695+ #[ must_use]
696+ fn latest_applied ( & self ) -> PointTxnIdx {
697+ if let Some ( latest_taken_uris_point) = & self . latest_taken_uris_point {
698+ if latest_taken_uris_point. point ( ) > self . current_tx_id_hash . point ( ) {
699+ return latest_taken_uris_point. clone ( ) ;
700+ }
701+ }
702+ PointTxnIdx :: new (
703+ self . current_tx_id_hash . point ( ) . clone ( ) ,
704+ self . current_tx_id_hash . txn_index ( ) ,
705+ )
706+ }
703707}
704708
705709/// Perform a check on the validation signature.
0 commit comments