@@ -40,7 +40,7 @@ use sp_runtime::{
40
40
use sp_std:: collections:: btree_set:: BTreeSet ;
41
41
use sp_std:: prelude:: * ;
42
42
use thea_primitives:: {
43
- types:: { Message , NetworkType , PayloadType } ,
43
+ types:: { Message , PayloadType } ,
44
44
Network , ValidatorSet , GENESIS_AUTHORITY_SET_ID ,
45
45
} ;
46
46
@@ -382,6 +382,7 @@ pub mod pallet {
382
382
stake : Balance ,
383
383
) -> DispatchResult {
384
384
let signer = ensure_signed ( origin) ?;
385
+ // Testing relayer must be removed after final audit
385
386
let expected_signer = <AllowListTestingRelayers < T > >:: get ( payload. network )
386
387
. ok_or ( Error :: < T > :: NoRelayersFound ) ?;
387
388
ensure ! ( signer == expected_signer, Error :: <T >:: NotAnAllowlistedRelayer ) ;
@@ -758,103 +759,112 @@ impl<T: Config> Pallet<T> {
758
759
759
760
fn change_authorities (
760
761
incoming : BoundedVec < T :: TheaId , T :: MaxAuthorities > , // n+1th set
761
- queued : BoundedVec < T :: TheaId , T :: MaxAuthorities > , // n+ 2th set
762
+ _queued : BoundedVec < T :: TheaId , T :: MaxAuthorities > , // n+ 2th set
762
763
) {
763
764
// ( outgoing) -> (validators/incoming) -> (queued)
764
765
// nth epoch -> n+1th epoch -> n+2nd epoch
765
766
let id = Self :: validator_set_id ( ) ;
766
767
let outgoing = <Authorities < T > >:: get ( id) ; // nth set ( active ,current )
767
768
let new_id = id + 1u64 ;
768
769
let active_networks = <ActiveNetworks < T > >:: get ( ) ;
769
- // We need to issue a new message if the validator set is changing,
770
- // that is, the incoming set is has different session keys from outgoing set.
771
- // This last message should be signed by the outgoing set
772
- // Similar to how Grandpa's session change works.
770
+ // // We need to issue a new message if the validator set is changing,
771
+ // // that is, the incoming set is has different session keys from outgoing set.
772
+ // // This last message should be signed by the outgoing set
773
+ // // Similar to how Grandpa's session change works.
773
774
let incoming_set = BTreeSet :: from_iter ( incoming. to_vec ( ) ) ;
774
- if incoming_set != BTreeSet :: from_iter ( queued. to_vec ( ) ) {
775
- let uncompressed_keys: Vec < [ u8 ; 20 ] > = vec ! [ ] ;
776
- // TODO: Uncomment the following when parsing is fixed for ethereum keys.
777
- // for public_key in queued.clone().into_iter() {
778
- // let public_key: sp_core::ecdsa::Public = public_key.into();
779
- // if public_key.0 == [0u8; 33] {
780
- // uncompressed_keys.push([0u8; 20]);
781
- // continue;
782
- // }
783
- // if let Ok(compressed_key) = libsecp256k1::PublicKey::parse_compressed(&public_key.0)
784
- // {
785
- // let uncompressed_key = compressed_key.serialize();
786
- // let uncompressed_key: [u8; 64] =
787
- // if let Ok(uncompressed_key) = uncompressed_key[1..65].try_into() {
788
- // uncompressed_key
789
- // } else {
790
- // log::error!(target: "thea", "Unable to slice last 64 bytes of uncompressed_key for Evm");
791
- // Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
792
- // public_key.into(),
793
- // ));
794
- // return;
795
- // };
796
- // let hash: [u8; 32] = sp_io::hashing::keccak_256(&uncompressed_key);
797
- // if let Ok(address) = hash[12..32].try_into() {
798
- // uncompressed_keys.push(address);
799
- // } else {
800
- // log::error!(target: "thea", "Unable to slice last 20 bytes of hash for Evm");
801
- // Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
802
- // public_key.into(),
803
- // ));
804
- // return;
805
- // }
806
- // } else {
807
- // log::error!(target: "thea", "Unable to parse compressed key");
808
- // Self::deposit_event(Event::<T>::UnableToParsePublicKey(public_key.into()));
809
- // return;
810
- // }
811
- // }
812
- for network in & active_networks {
813
- let network_config = <NetworkConfig < T > >:: get ( * network) ;
814
- let message = match network_config. network_type {
815
- NetworkType :: Evm => {
816
- if let Some ( payload) = ValidatorSet :: new ( uncompressed_keys. clone ( ) , new_id)
817
- {
818
- Self :: generate_payload (
819
- PayloadType :: ScheduledRotateValidators ,
820
- * network,
821
- payload. encode ( ) ,
822
- )
823
- } else {
824
- log:: error!( target: "thea" , "Unable to generate rotate validators payload" ) ;
825
- Self :: deposit_event ( Event :: < T > :: UnableToGenerateValidatorSet ( * network) ) ;
826
- continue ;
827
- }
828
- } ,
829
- NetworkType :: Parachain => {
830
- if let Some ( payload) = ValidatorSet :: new ( queued. clone ( ) , new_id) {
831
- Self :: generate_payload (
832
- PayloadType :: ScheduledRotateValidators ,
833
- * network,
834
- payload. encode ( ) ,
835
- )
836
- } else {
837
- log:: error!( target: "thea" , "Unable to generate rotate validators payload" ) ;
838
- Self :: deposit_event ( Event :: < T > :: UnableToGenerateValidatorSet ( * network) ) ;
839
- continue ;
840
- }
841
- } ,
842
- } ;
843
- <OutgoingNonce < T > >:: insert ( message. network , message. nonce ) ;
844
- <OutgoingMessages < T > >:: insert ( message. network , message. nonce , message) ;
845
- }
846
- <NextAuthorities < T > >:: put ( queued) ;
847
- }
775
+ // if incoming_set != BTreeSet::from_iter(queued.to_vec()) {
776
+ // let uncompressed_keys: Vec<[u8; 20]> = vec![];
777
+ // // TODO: Uncomment the following when parsing is fixed for ethereum keys.
778
+ // // for public_key in queued.clone().into_iter() {
779
+ // // let public_key: sp_core::ecdsa::Public = public_key.into();
780
+ // // if public_key.0 == [0u8; 33] {
781
+ // // uncompressed_keys.push([0u8; 20]);
782
+ // // continue;
783
+ // // }
784
+ // // if let Ok(compressed_key) = libsecp256k1::PublicKey::parse_compressed(&public_key.0)
785
+ // // {
786
+ // // let uncompressed_key = compressed_key.serialize();
787
+ // // let uncompressed_key: [u8; 64] =
788
+ // // if let Ok(uncompressed_key) = uncompressed_key[1..65].try_into() {
789
+ // // uncompressed_key
790
+ // // } else {
791
+ // // log::error!(target: "thea", "Unable to slice last 64 bytes of uncompressed_key for Evm");
792
+ // // Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
793
+ // // public_key.into(),
794
+ // // ));
795
+ // // return;
796
+ // // };
797
+ // // let hash: [u8; 32] = sp_io::hashing::keccak_256(&uncompressed_key);
798
+ // // if let Ok(address) = hash[12..32].try_into() {
799
+ // // uncompressed_keys.push(address);
800
+ // // } else {
801
+ // // log::error!(target: "thea", "Unable to slice last 20 bytes of hash for Evm");
802
+ // // Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
803
+ // // public_key.into(),
804
+ // // ));
805
+ // // return;
806
+ // // }
807
+ // // } else {
808
+ // // log::error!(target: "thea", "Unable to parse compressed key");
809
+ // // Self::deposit_event(Event::<T>::UnableToParsePublicKey(public_key.into()));
810
+ // // return;
811
+ // // }
812
+ // // }
813
+ // for network in &active_networks {
814
+ // let network_config = <NetworkConfig<T>>::get(*network);
815
+ // let message = match network_config.network_type {
816
+ // NetworkType::Evm => {
817
+ // if let Some(payload) = ValidatorSet::new(uncompressed_keys.clone(), new_id)
818
+ // {
819
+ // Self::generate_payload(
820
+ // PayloadType::ScheduledRotateValidators,
821
+ // *network,
822
+ // payload.encode(),
823
+ // )
824
+ // } else {
825
+ // log::error!(target: "thea", "Unable to generate rotate validators payload");
826
+ // Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(*network));
827
+ // continue;
828
+ // }
829
+ // },
830
+ // NetworkType::Parachain => {
831
+ // if let Some(payload) = ValidatorSet::new(queued.clone(), new_id) {
832
+ // Self::generate_payload(
833
+ // PayloadType::ScheduledRotateValidators,
834
+ // *network,
835
+ // payload.encode(),
836
+ // )
837
+ // } else {
838
+ // log::error!(target: "thea", "Unable to generate rotate validators payload");
839
+ // Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(*network));
840
+ // continue;
841
+ // }
842
+ // },
843
+ // };
844
+ // <OutgoingNonce<T>>::insert(message.network, message.nonce);
845
+ // <OutgoingMessages<T>>::insert(message.network, message.nonce, message);
846
+ // }
847
+ // <NextAuthorities<T>>::put(queued);
848
+ // }
848
849
if incoming_set != BTreeSet :: from_iter ( outgoing. to_vec ( ) ) {
849
850
// This will happen when new era starts, or end of the last epoch
850
- <Authorities < T > >:: insert ( new_id, incoming) ;
851
- <ValidatorSetId < T > >:: put ( new_id) ;
852
851
for network in active_networks {
853
- let message =
854
- Self :: generate_payload ( PayloadType :: ValidatorsRotated , network, Vec :: new ( ) ) ; //Empty data means activate the next set_id
855
- <OutgoingNonce < T > >:: insert ( network, message. nonce ) ;
856
- <OutgoingMessages < T > >:: insert ( network, message. nonce , message) ;
852
+ if let Some ( payload) = ValidatorSet :: new ( incoming. clone ( ) , new_id) {
853
+ let message = Self :: generate_payload (
854
+ PayloadType :: ValidatorsRotated ,
855
+ network,
856
+ payload. encode ( ) ,
857
+ ) ;
858
+ <OutgoingNonce < T > >:: insert ( network, message. nonce ) ;
859
+ <OutgoingMessages < T > >:: insert ( network, message. nonce , message) ;
860
+ } else {
861
+ log:: error!( target: "thea" , "Unable to generate rotate validators payload" ) ;
862
+ Self :: deposit_event ( Event :: < T > :: UnableToGenerateValidatorSet ( network) ) ;
863
+ continue ;
864
+ }
857
865
}
866
+ <Authorities < T > >:: insert ( new_id, incoming) ;
867
+ <ValidatorSetId < T > >:: put ( new_id) ;
858
868
}
859
869
}
860
870
0 commit comments