use ExternalBlockNumber type everywhere
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
4c79048b49
commit
6a5029017c
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.4.22"
|
version = "0.4.23"
|
||||||
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
|
||||||
|
|||||||
@ -8,7 +8,7 @@ where
|
|||||||
Ok(Some(s.as_bytes().to_vec()))
|
Ok(Some(s.as_bytes().to_vec()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn de_string_to_u64<'de, D>(de: D) -> Result<Option<u64>, D::Error>
|
pub fn de_string_to_block_number<'de, D>(de: D) -> Result<Option<u64>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
@ -17,7 +17,7 @@ where
|
|||||||
Ok(u64::from_str_radix(s, 16).ok())
|
Ok(u64::from_str_radix(s, 16).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn de_string_to_u64_pure<'de, D>(de: D) -> Result<u64, D::Error>
|
pub fn de_string_to_block_number_pure<'de, D>(de: D) -> Result<u64, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,13 +2,10 @@ use sp_runtime::{traits::UniqueSaturatedInto, SaturatedConversion, Saturating};
|
|||||||
use sp_staking::SessionIndex;
|
use sp_staking::SessionIndex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
deserialisations::{
|
AuthIndex, BLOCK_COMMITMENT_DELAY, BalanceOf, BlockCommitment, BlockCommitments, BlockNumberFor, Call, Clap, Config, Decode, Deserialize, Encode, ExternalBlockNumber, H256, LOG_TARGET, NetworkIdOf, RuntimeAppPublic, RuntimeDebug, SubmitTransaction, Vec, deserialisations::{
|
||||||
de_string_to_bytes, de_string_to_h256, de_string_to_u64, de_string_to_u64_pure,
|
de_string_to_bytes, de_string_to_h256, de_string_to_block_number, de_string_to_block_number_pure,
|
||||||
de_string_to_vec_of_bytes,
|
de_string_to_vec_of_bytes,
|
||||||
},
|
}
|
||||||
AuthIndex, BalanceOf, BlockCommitment, BlockCommitments, BlockNumberFor, Call, Clap, Config,
|
|
||||||
Decode, Deserialize, Encode, NetworkIdOf, RuntimeAppPublic, RuntimeDebug, SubmitTransaction,
|
|
||||||
Vec, BLOCK_COMMITMENT_DELAY, H256, LOG_TARGET,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const NUMBER_OF_TOPICS: usize = 3;
|
const NUMBER_OF_TOPICS: usize = 3;
|
||||||
@ -28,8 +25,8 @@ pub struct EvmResponse {
|
|||||||
#[derive(RuntimeDebug, Clone, PartialEq, Deserialize, Encode, Decode)]
|
#[derive(RuntimeDebug, Clone, PartialEq, Deserialize, Encode, Decode)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum EvmResponseType {
|
pub enum EvmResponseType {
|
||||||
#[serde(deserialize_with = "de_string_to_u64_pure")]
|
#[serde(deserialize_with = "de_string_to_block_number_pure")]
|
||||||
BlockNumber(u64),
|
BlockNumber(ExternalBlockNumber),
|
||||||
TransactionLogs(Vec<Log>),
|
TransactionLogs(Vec<Log>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +35,8 @@ pub enum EvmResponseType {
|
|||||||
pub struct Log {
|
pub struct Log {
|
||||||
#[serde(default, deserialize_with = "de_string_to_h256")]
|
#[serde(default, deserialize_with = "de_string_to_h256")]
|
||||||
pub transaction_hash: Option<H256>,
|
pub transaction_hash: Option<H256>,
|
||||||
#[serde(default, deserialize_with = "de_string_to_u64")]
|
#[serde(default, deserialize_with = "de_string_to_block_number")]
|
||||||
pub block_number: Option<u64>,
|
pub block_number: Option<ExternalBlockNumber>,
|
||||||
#[serde(default, deserialize_with = "de_string_to_vec_of_bytes")]
|
#[serde(default, deserialize_with = "de_string_to_vec_of_bytes")]
|
||||||
pub topics: Vec<Vec<u8>>,
|
pub topics: Vec<Vec<u8>>,
|
||||||
pub removed: bool,
|
pub removed: bool,
|
||||||
@ -145,7 +142,7 @@ impl EvmResponseType {
|
|||||||
fn sign_and_submit_block_commitment<T: Config>(
|
fn sign_and_submit_block_commitment<T: Config>(
|
||||||
&self,
|
&self,
|
||||||
block_now: BlockNumberFor<T>,
|
block_now: BlockNumberFor<T>,
|
||||||
from_block: u64,
|
from_block: ExternalBlockNumber,
|
||||||
authority_index: AuthIndex,
|
authority_index: AuthIndex,
|
||||||
authority_key: T::AuthorityId,
|
authority_key: T::AuthorityId,
|
||||||
session_index: SessionIndex,
|
session_index: SessionIndex,
|
||||||
@ -210,7 +207,7 @@ impl EvmResponseType {
|
|||||||
pub fn sign_and_submit<T: Config>(
|
pub fn sign_and_submit<T: Config>(
|
||||||
&self,
|
&self,
|
||||||
block_now: BlockNumberFor<T>,
|
block_now: BlockNumberFor<T>,
|
||||||
from_block: u64,
|
from_block: ExternalBlockNumber,
|
||||||
authority_index: AuthIndex,
|
authority_index: AuthIndex,
|
||||||
authority_key: T::AuthorityId,
|
authority_key: T::AuthorityId,
|
||||||
session_index: SessionIndex,
|
session_index: SessionIndex,
|
||||||
|
|||||||
@ -123,7 +123,7 @@ pub struct Clap<AccountId, NetworkId, Balance> {
|
|||||||
pub session_index: SessionIndex,
|
pub session_index: SessionIndex,
|
||||||
pub authority_index: AuthIndex,
|
pub authority_index: AuthIndex,
|
||||||
pub transaction_hash: H256,
|
pub transaction_hash: H256,
|
||||||
pub block_number: u64,
|
pub block_number: ExternalBlockNumber,
|
||||||
pub removed: bool,
|
pub removed: bool,
|
||||||
pub network_id: NetworkId,
|
pub network_id: NetworkId,
|
||||||
pub receiver: AccountId,
|
pub receiver: AccountId,
|
||||||
@ -135,12 +135,12 @@ pub struct ApplauseDetail<NetworkId, Balance> {
|
|||||||
pub network_id: NetworkId,
|
pub network_id: NetworkId,
|
||||||
pub authorities: BitMap,
|
pub authorities: BitMap,
|
||||||
pub clapped_amount: Balance,
|
pub clapped_amount: Balance,
|
||||||
pub block_number: u64,
|
pub block_number: ExternalBlockNumber,
|
||||||
pub finalized: bool,
|
pub finalized: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<NetworkId, Balance: Default> ApplauseDetail<NetworkId, Balance> {
|
impl<NetworkId, Balance: Default> ApplauseDetail<NetworkId, Balance> {
|
||||||
pub fn new(network_id: NetworkId, block_number: u64, max_authorities: usize) -> Self {
|
pub fn new(network_id: NetworkId, block_number: ExternalBlockNumber, max_authorities: usize) -> Self {
|
||||||
ApplauseDetail {
|
ApplauseDetail {
|
||||||
network_id,
|
network_id,
|
||||||
block_number,
|
block_number,
|
||||||
@ -156,7 +156,7 @@ pub struct PreparedApplause<AccountId, NetworkId, Balance> {
|
|||||||
pub network_id: NetworkId,
|
pub network_id: NetworkId,
|
||||||
pub receiver: AccountId,
|
pub receiver: AccountId,
|
||||||
pub amount: Balance,
|
pub amount: Balance,
|
||||||
pub block_number: u64,
|
pub block_number: ExternalBlockNumber,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq))]
|
||||||
@ -171,7 +171,7 @@ enum OffchainErr<NetworkId> {
|
|||||||
DifferentEvmResponseTypes,
|
DifferentEvmResponseTypes,
|
||||||
MissingBlockNumber(u32, u32),
|
MissingBlockNumber(u32, u32),
|
||||||
ContradictoryTransactionLogs(u32, u32),
|
ContradictoryTransactionLogs(u32, u32),
|
||||||
ContradictoryBlockMedian(u64, u64, u64),
|
ContradictoryBlockMedian(ExternalBlockNumber, ExternalBlockNumber, ExternalBlockNumber),
|
||||||
UnparsableRequestBody(Vec<u8>),
|
UnparsableRequestBody(Vec<u8>),
|
||||||
NoEndpointAvailable(NetworkId),
|
NoEndpointAvailable(NetworkId),
|
||||||
StorageRetrievalError(NetworkId),
|
StorageRetrievalError(NetworkId),
|
||||||
@ -347,7 +347,7 @@ pub mod pallet {
|
|||||||
network_id: NetworkIdOf<T>,
|
network_id: NetworkIdOf<T>,
|
||||||
receiver: T::AccountId,
|
receiver: T::AccountId,
|
||||||
received_amount: BalanceOf<T>,
|
received_amount: BalanceOf<T>,
|
||||||
block_number: u64,
|
block_number: ExternalBlockNumber,
|
||||||
},
|
},
|
||||||
BlockCommited {
|
BlockCommited {
|
||||||
authority_id: AuthIndex,
|
authority_id: AuthIndex,
|
||||||
@ -384,7 +384,7 @@ pub mod pallet {
|
|||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn latest_executed_block)]
|
#[pallet::getter(fn latest_executed_block)]
|
||||||
pub(super) type LatestExecutedBlock<T: Config> =
|
pub(super) type LatestExecutedBlock<T: Config> =
|
||||||
StorageMap<_, Twox64Concat, NetworkIdOf<T>, u64, ValueQuery>;
|
StorageMap<_, Twox64Concat, NetworkIdOf<T>, ExternalBlockNumber, ValueQuery>;
|
||||||
|
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn block_commitments)]
|
#[pallet::getter(fn block_commitments)]
|
||||||
@ -484,7 +484,7 @@ pub mod pallet {
|
|||||||
fn on_initialize(current_block: BlockNumberFor<T>) -> Weight {
|
fn on_initialize(current_block: BlockNumberFor<T>) -> Weight {
|
||||||
let mut weight = T::DbWeight::get().reads(1);
|
let mut weight = T::DbWeight::get().reads(1);
|
||||||
let networks_count = T::NetworkDataHandler::count();
|
let networks_count = T::NetworkDataHandler::count();
|
||||||
let current_block_number: u64 = current_block.unique_saturated_into();
|
let current_block_number: ExternalBlockNumber = current_block.unique_saturated_into();
|
||||||
|
|
||||||
let check_block_interval = T::EpochDuration::get().saturating_div(BLOCK_CHECK_CYCLES);
|
let check_block_interval = T::EpochDuration::get().saturating_div(BLOCK_CHECK_CYCLES);
|
||||||
if check_block_interval == 0 {
|
if check_block_interval == 0 {
|
||||||
@ -668,7 +668,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
H256::from_slice(&sp_io::hashing::keccak_256(&clap_args_str)[..])
|
H256::from_slice(&sp_io::hashing::keccak_256(&clap_args_str)[..])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn u64_to_hexadecimal_bytes(value: u64) -> Vec<u8> {
|
fn block_number_to_hexadecimal_bytes(value: ExternalBlockNumber) -> Vec<u8> {
|
||||||
let mut hex_str = Vec::new();
|
let mut hex_str = Vec::new();
|
||||||
hex_str.push(b'0');
|
hex_str.push(b'0');
|
||||||
hex_str.push(b'x');
|
hex_str.push(b'x');
|
||||||
@ -878,17 +878,9 @@ impl<T: Config> Pallet<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_slow_clapping(block_number: BlockNumberFor<T>) -> OffchainResult<T, ()> {
|
fn start_slow_clapping(block_number: BlockNumberFor<T>) -> OffchainResult<T, ()> {
|
||||||
|
let converted_block: usize = block_number.unique_saturated_into();
|
||||||
let session_index = T::ValidatorSet::session_index();
|
let session_index = T::ValidatorSet::session_index();
|
||||||
let networks = T::NetworkDataHandler::iter().collect::<Vec<_>>();
|
let network_in_use = T::NetworkDataHandler::network_for_block(converted_block)
|
||||||
let network_index = block_number
|
|
||||||
.into()
|
|
||||||
.as_usize()
|
|
||||||
.checked_rem(networks.len())
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let network_in_use = networks
|
|
||||||
.iter()
|
|
||||||
.nth(network_index)
|
|
||||||
.ok_or(OffchainErr::NoStoredNetworks)?;
|
.ok_or(OffchainErr::NoStoredNetworks)?;
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
@ -946,7 +938,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
return Err(OffchainErr::NoEndpointAvailable(network_id));
|
return Err(OffchainErr::NoEndpointAvailable(network_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (from_block, to_block): (u64, u64) = StorageValueRef::persistent(&block_number_key)
|
let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) = StorageValueRef::persistent(&block_number_key)
|
||||||
.get()
|
.get()
|
||||||
.map_err(|_| OffchainErr::StorageRetrievalError(network_id))?
|
.map_err(|_| OffchainErr::StorageRetrievalError(network_id))?
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
@ -1028,7 +1020,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
|
|
||||||
fn local_authorities(
|
fn local_authorities(
|
||||||
session_index: &SessionIndex,
|
session_index: &SessionIndex,
|
||||||
) -> impl Iterator<Item = (u32, T::AuthorityId)> {
|
) -> impl Iterator<Item = (AuthIndex, T::AuthorityId)> {
|
||||||
let authorities = Authorities::<T>::get(session_index);
|
let authorities = Authorities::<T>::get(session_index);
|
||||||
let mut local_authorities = T::AuthorityId::all();
|
let mut local_authorities = T::AuthorityId::all();
|
||||||
local_authorities.sort();
|
local_authorities.sort();
|
||||||
@ -1102,7 +1094,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
|
|
||||||
fn get_balanced_evm_response(
|
fn get_balanced_evm_response(
|
||||||
parsed_evm_responses: &Vec<EvmResponseType>,
|
parsed_evm_responses: &Vec<EvmResponseType>,
|
||||||
max_block_distance: u64,
|
max_block_distance: ExternalBlockNumber,
|
||||||
) -> OffchainResult<T, EvmResponseType> {
|
) -> OffchainResult<T, EvmResponseType> {
|
||||||
let first_evm_response = parsed_evm_responses
|
let first_evm_response = parsed_evm_responses
|
||||||
.first()
|
.first()
|
||||||
@ -1264,8 +1256,8 @@ impl<T: Config> Pallet<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_evm_request_body_for_latest_transfers(
|
fn prepare_evm_request_body_for_latest_transfers(
|
||||||
from_block: u64,
|
from_block: ExternalBlockNumber,
|
||||||
to_block: u64,
|
to_block: ExternalBlockNumber,
|
||||||
network_data: &NetworkData,
|
network_data: &NetworkData,
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
match network_data.network_type {
|
match network_data.network_type {
|
||||||
@ -1274,9 +1266,9 @@ impl<T: Config> Pallet<T> {
|
|||||||
b"{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\",\"params\":[{"
|
b"{\"id\":0,\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\",\"params\":[{"
|
||||||
.to_vec();
|
.to_vec();
|
||||||
body.extend(b"\"fromBlock\":\"".to_vec());
|
body.extend(b"\"fromBlock\":\"".to_vec());
|
||||||
body.extend(Self::u64_to_hexadecimal_bytes(from_block));
|
body.extend(Self::block_number_to_hexadecimal_bytes(from_block));
|
||||||
body.extend(b"\",\"toBlock\":\"".to_vec());
|
body.extend(b"\",\"toBlock\":\"".to_vec());
|
||||||
body.extend(Self::u64_to_hexadecimal_bytes(to_block));
|
body.extend(Self::block_number_to_hexadecimal_bytes(to_block));
|
||||||
body.extend(b"\",\"address\":\"".to_vec());
|
body.extend(b"\",\"address\":\"".to_vec());
|
||||||
body.extend(network_data.gatekeeper.to_vec());
|
body.extend(network_data.gatekeeper.to_vec());
|
||||||
body.extend(b"\",\"topics\":[\"".to_vec());
|
body.extend(b"\",\"topics\":[\"".to_vec());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user