forked from ghostchain/ghost-node
		
	rotate endpoints on each offchain worker exection
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									0375bd1434
								
							
						
					
					
						commit
						1d826fbf7e
					
				@ -1,6 +1,6 @@
 | 
				
			|||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "ghost-slow-clap"
 | 
					name = "ghost-slow-clap"
 | 
				
			||||||
version = "0.3.33"
 | 
					version = "0.3.34"
 | 
				
			||||||
description = "Applause protocol for the EVM bridge"
 | 
					description = "Applause protocol for the EVM bridge"
 | 
				
			||||||
license.workspace = true
 | 
					license.workspace = true
 | 
				
			||||||
authors.workspace = true
 | 
					authors.workspace = true
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ use sp_runtime::{
 | 
				
			|||||||
        storage_lock::{StorageLock, Time},
 | 
					        storage_lock::{StorageLock, Time},
 | 
				
			||||||
        HttpError,
 | 
					        HttpError,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    traits::{BlockNumberProvider, Convert, Saturating},
 | 
					    traits::{BlockNumberProvider, Convert, Saturating, TrailingZeroInput},
 | 
				
			||||||
    Perbill, RuntimeAppPublic, RuntimeDebug, SaturatedConversion,
 | 
					    Perbill, RuntimeAppPublic, RuntimeDebug, SaturatedConversion,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use sp_staking::{
 | 
					use sp_staking::{
 | 
				
			||||||
@ -692,14 +692,35 @@ impl<T: Config> Pallet<T> {
 | 
				
			|||||||
        let block_distance_key = Self::create_storage_key(b"block-distance-", &network_id_encoded);
 | 
					        let block_distance_key = Self::create_storage_key(b"block-distance-", &network_id_encoded);
 | 
				
			||||||
        let endpoint_key = Self::create_storage_key(b"endpoint-", &network_id_encoded);
 | 
					        let endpoint_key = Self::create_storage_key(b"endpoint-", &network_id_encoded);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let rpc_endpoint = Self::read_persistent_offchain_storage(
 | 
					 | 
				
			||||||
            &endpoint_key,
 | 
					 | 
				
			||||||
            network_data.default_endpoint.clone(),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        let max_block_distance = Self::read_persistent_offchain_storage(
 | 
					        let max_block_distance = Self::read_persistent_offchain_storage(
 | 
				
			||||||
            &block_distance_key,
 | 
					            &block_distance_key,
 | 
				
			||||||
            network_data.block_distance,
 | 
					            network_data.block_distance,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					        let stored_endpoints = Self::read_persistent_offchain_storage(
 | 
				
			||||||
 | 
					            &endpoint_key,
 | 
				
			||||||
 | 
					            network_data.default_endpoints.clone(),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let random_seed = sp_io::offchain::random_seed();
 | 
				
			||||||
 | 
					        let random_number = <u32>::decode(
 | 
				
			||||||
 | 
					            &mut TrailingZeroInput::new(random_seed.as_ref())
 | 
				
			||||||
 | 
					        ).expect("input is padded with zeroes; qed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let rpc_endpoint = if stored_endpoints.len() > 0 {
 | 
				
			||||||
 | 
					            stored_endpoints
 | 
				
			||||||
 | 
					                .iter()
 | 
				
			||||||
 | 
					                .nth((random_number as usize)
 | 
				
			||||||
 | 
					                    .checked_rem(stored_endpoints.len())
 | 
				
			||||||
 | 
					                    .unwrap_or_default())
 | 
				
			||||||
 | 
					                .expect("stored endpoint should be non empty; qed")
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            network_data.default_endpoints
 | 
				
			||||||
 | 
					                .iter()
 | 
				
			||||||
 | 
					                .nth((random_number as usize)
 | 
				
			||||||
 | 
					                    .checked_rem(network_data.default_endpoints.len())
 | 
				
			||||||
 | 
					                    .unwrap_or_default())
 | 
				
			||||||
 | 
					                .expect("default endpoint should be non empty; qed")
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        StorageValueRef::persistent(&block_number_key)
 | 
					        StorageValueRef::persistent(&block_number_key)
 | 
				
			||||||
            .mutate(
 | 
					            .mutate(
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,7 @@ fn prepare_evm_network(
 | 
				
			|||||||
) -> NetworkData {
 | 
					) -> NetworkData {
 | 
				
			||||||
    let network_data = NetworkData {
 | 
					    let network_data = NetworkData {
 | 
				
			||||||
        chain_name: "Ethereum".into(),
 | 
					        chain_name: "Ethereum".into(),
 | 
				
			||||||
        default_endpoint: get_rpc_endpoint(),
 | 
					        default_endpoints: get_rpc_endpoints(),
 | 
				
			||||||
        finality_delay: 69,
 | 
					        finality_delay: 69,
 | 
				
			||||||
        rate_limit_delay: 69,
 | 
					        rate_limit_delay: 69,
 | 
				
			||||||
        block_distance: 69,
 | 
					        block_distance: 69,
 | 
				
			||||||
@ -1041,6 +1041,13 @@ fn get_rpc_endpoint() -> Vec<u8> {
 | 
				
			|||||||
    b"https://rpc.endpoint.network.com".to_vec()
 | 
					    b"https://rpc.endpoint.network.com".to_vec()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn get_rpc_endpoints() -> Vec<Vec<u8>> {
 | 
				
			||||||
 | 
					    vec![
 | 
				
			||||||
 | 
					        get_rpc_endpoint(),
 | 
				
			||||||
 | 
					        b"https://other.endpoint.network.com".to_vec(),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn get_gatekeeper() -> Vec<u8> {
 | 
					fn get_gatekeeper() -> Vec<u8> {
 | 
				
			||||||
    b"0x4d224452801ACEd8B2F0aebE155379bb5D594381".to_vec()
 | 
					    b"0x4d224452801ACEd8B2F0aebE155379bb5D594381".to_vec()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user