@@ -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
@@ -758,103 +758,112 @@ impl<T: Config> Pallet<T> {
758
758
759
759
fn change_authorities (
760
760
incoming : BoundedVec < T :: TheaId , T :: MaxAuthorities > , // n+1th set
761
- queued : BoundedVec < T :: TheaId , T :: MaxAuthorities > , // n+ 2th set
761
+ _queued : BoundedVec < T :: TheaId , T :: MaxAuthorities > , // n+ 2th set
762
762
) {
763
763
// ( outgoing) -> (validators/incoming) -> (queued)
764
764
// nth epoch -> n+1th epoch -> n+2nd epoch
765
765
let id = Self :: validator_set_id ( ) ;
766
766
let outgoing = <Authorities < T > >:: get ( id) ; // nth set ( active ,current )
767
767
let new_id = id + 1u64 ;
768
768
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.
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.
773
773
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
- }
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
+ // }
848
848
if incoming_set != BTreeSet :: from_iter ( outgoing. to_vec ( ) ) {
849
849
// 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
850
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) ;
851
+ if let Some ( payload) = ValidatorSet :: new ( incoming. clone ( ) , new_id) {
852
+ let message = Self :: generate_payload (
853
+ PayloadType :: ValidatorsRotated ,
854
+ network,
855
+ payload. encode ( ) ,
856
+ ) ;
857
+ <OutgoingNonce < T > >:: insert ( network, message. nonce ) ;
858
+ <OutgoingMessages < T > >:: insert ( network, message. nonce , message) ;
859
+ } else {
860
+ log:: error!( target: "thea" , "Unable to generate rotate validators payload" ) ;
861
+ Self :: deposit_event ( Event :: < T > :: UnableToGenerateValidatorSet ( network) ) ;
862
+ continue ;
863
+ }
857
864
}
865
+ <Authorities < T > >:: insert ( new_id, incoming) ;
866
+ <ValidatorSetId < T > >:: put ( new_id) ;
858
867
}
859
868
}
860
869
0 commit comments