Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
d7ac7885b6
commit
d940ede8ac
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-weaver"
|
||||
version = "0.0.17"
|
||||
version = "0.0.18"
|
||||
description = "Weaving a secure cryptographic tapestry across different external chains."
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -35,6 +35,9 @@ fn prepare_pallet<T: Config>(
|
||||
T::NetworkDataHandler::register(network_id, network_data)
|
||||
.expect("network should be valid for insertion");
|
||||
|
||||
let current_block = T::BlockNumberProvider::current_block_number();
|
||||
Pallet::<T>::on_initialize(current_block);
|
||||
|
||||
(network_id, authority, 0)
|
||||
}
|
||||
|
||||
|
||||
@ -330,22 +330,13 @@ pub mod pallet {
|
||||
|
||||
let external_block = block_attestation.external_block;
|
||||
|
||||
let current_authorities_count = Authorities::<T>::decode_len().
|
||||
unwrap_or_default();
|
||||
|
||||
NetworkAttestations::<T>::try_mutate(
|
||||
&network_id,
|
||||
|attestations| -> DispatchResult {
|
||||
if attestations.is_empty() {
|
||||
attestations.bounded_resize(current_authorities_count, None);
|
||||
}
|
||||
let index = authority_index as usize;
|
||||
|
||||
ensure!(
|
||||
(authority_index as usize) < attestations.len(),
|
||||
Error::<T>::TooManyAttestations,
|
||||
);
|
||||
|
||||
attestations[authority_index as usize] = Some(external_block);
|
||||
ensure!(index < attestations.len(), Error::<T>::TooManyAttestations);
|
||||
attestations[index] = Some(external_block);
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
@ -532,9 +523,11 @@ pub mod pallet {
|
||||
weight.saturating_accrue(T::DbWeight::get().reads(1));
|
||||
let attestation_len = NetworkAttestations::<T>::decode_len(&network_id);
|
||||
|
||||
if attestation_len.unwrap_or(0) > len {
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
NetworkAttestations::<T>::remove(&network_id);
|
||||
if attestation_len.unwrap_or(0) != len {
|
||||
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
|
||||
NetworkAttestations::<T>::mutate(&network_id, |attestations| {
|
||||
attestations.bounded_resize(len, None);
|
||||
});
|
||||
return weight;
|
||||
}
|
||||
|
||||
@ -675,6 +668,13 @@ impl<T: Config> Pallet<T> {
|
||||
let attestation_block = attestation.block();
|
||||
let network_id = attestation.network_id();
|
||||
|
||||
let current_attestation_len = NetworkAttestations::<T>::decode_len(&network_id)
|
||||
.unwrap_or(0);
|
||||
|
||||
if authority_index as usize >= current_attestation_len {
|
||||
return Err(InvalidTransaction::BadSigner.into());
|
||||
}
|
||||
|
||||
if DisabledAuthorities::<T>::get().contains(authority_index) {
|
||||
return Err(InvalidTransaction::BadSigner);
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ fn should_successfully_compute_median_and_start_weaving_round() {
|
||||
let networks = vec![(network_id, network_data, Default::default())];
|
||||
|
||||
new_test_ext(authorities, networks).execute_with(|| {
|
||||
GhostWeaver::on_initialize(1);
|
||||
System::set_block_number(2);
|
||||
|
||||
let context = AttestationContext::default()
|
||||
@ -120,6 +121,7 @@ fn should_apply_cooldown_delay_on_consensus_failure() {
|
||||
let networks = vec![(network_id, network_data, Default::default())];
|
||||
|
||||
new_test_ext(authorities, networks).execute_with(|| {
|
||||
GhostWeaver::on_initialize(9);
|
||||
System::set_block_number(10);
|
||||
|
||||
let context = AttestationContext::default()
|
||||
@ -168,6 +170,7 @@ fn validate_unsigned_should_prevent_mempool_dos_via_tags() {
|
||||
let networks = vec![(network_id, network_data, Default::default())];
|
||||
|
||||
new_test_ext(authorities, networks).execute_with(|| {
|
||||
GhostWeaver::on_initialize(1);
|
||||
System::set_block_number(2);
|
||||
|
||||
let att = AttestationContext::default()
|
||||
@ -240,6 +243,9 @@ fn offchain_worker_should_fetch_block_and_submit_unsigned_tx() {
|
||||
ext.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
ext.execute_with(|| {
|
||||
GhostWeaver::on_initialize(1);
|
||||
GhostWeaver::on_initialize(2);
|
||||
|
||||
let network_id_encoded = evm_network_id.encode();
|
||||
|
||||
let mut endpoint_key = b"ghost-weaver::".to_vec();
|
||||
@ -406,10 +412,11 @@ fn offchain_worker_should_fetch_hash_and_submit_unsigned_tx() {
|
||||
ext.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
ext.execute_with(|| {
|
||||
GhostWeaver::on_initialize(1);
|
||||
GhostWeaver::on_initialize(2);
|
||||
|
||||
let tapestry_draft = TapestryDraftBuilder::<crate::ExternalBlockNumber, u32>::default();
|
||||
|
||||
let evm_tapestry_draft = tapestry_draft.with_median_external(25639556).build();
|
||||
|
||||
let utxo_tapestry_draft = tapestry_draft.with_median_external(960129).build();
|
||||
|
||||
CurrentWeavingSession::<TestRuntime>::insert(&evm_network_id, evm_session);
|
||||
@ -635,6 +642,8 @@ fn should_successfully_pull_evm_thread_and_mint_currency() {
|
||||
];
|
||||
|
||||
new_test_ext(authorities, networks).execute_with(|| {
|
||||
GhostWeaver::on_initialize(1);
|
||||
|
||||
// https://sepolia.etherscan.io/address/0x7fec11e652f4d54e8cf11c4b52c360380332f2bd#readContract
|
||||
// getRoot: session 0, atBlock 11716130
|
||||
let session = 0;
|
||||
@ -928,6 +937,7 @@ fn on_initialize_should_finalize_session_when_timeout_is_reached() {
|
||||
|
||||
new_test_ext(authorities, networks).execute_with(|| {
|
||||
let current_substrate_block = 10;
|
||||
GhostWeaver::on_initialize(current_substrate_block);
|
||||
System::set_block_number(current_substrate_block + 1);
|
||||
|
||||
let tapestry_draft = TapestryDraftBuilder::default()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user