Uncle Stinky 2026-10-10 17:59:41 +03:00
parent d7ac7885b6
commit d940ede8ac
Signed by: st1nky
GPG Key ID: 016064BD97603B40
4 changed files with 31 additions and 18 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "ghost-weaver" name = "ghost-weaver"
version = "0.0.17" version = "0.0.18"
description = "Weaving a secure cryptographic tapestry across different external chains." description = "Weaving a secure cryptographic tapestry across different external chains."
license.workspace = true license.workspace = true
authors.workspace = true authors.workspace = true

View File

@ -35,6 +35,9 @@ fn prepare_pallet<T: Config>(
T::NetworkDataHandler::register(network_id, network_data) T::NetworkDataHandler::register(network_id, network_data)
.expect("network should be valid for insertion"); .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) (network_id, authority, 0)
} }

View File

@ -330,22 +330,13 @@ pub mod pallet {
let external_block = block_attestation.external_block; let external_block = block_attestation.external_block;
let current_authorities_count = Authorities::<T>::decode_len().
unwrap_or_default();
NetworkAttestations::<T>::try_mutate( NetworkAttestations::<T>::try_mutate(
&network_id, &network_id,
|attestations| -> DispatchResult { |attestations| -> DispatchResult {
if attestations.is_empty() { let index = authority_index as usize;
attestations.bounded_resize(current_authorities_count, None);
}
ensure!( ensure!(index < attestations.len(), Error::<T>::TooManyAttestations);
(authority_index as usize) < attestations.len(), attestations[index] = Some(external_block);
Error::<T>::TooManyAttestations,
);
attestations[authority_index as usize] = Some(external_block);
Ok(()) Ok(())
})?; })?;
@ -532,9 +523,11 @@ pub mod pallet {
weight.saturating_accrue(T::DbWeight::get().reads(1)); weight.saturating_accrue(T::DbWeight::get().reads(1));
let attestation_len = NetworkAttestations::<T>::decode_len(&network_id); let attestation_len = NetworkAttestations::<T>::decode_len(&network_id);
if attestation_len.unwrap_or(0) > len { if attestation_len.unwrap_or(0) != len {
weight.saturating_accrue(T::DbWeight::get().writes(1)); weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
NetworkAttestations::<T>::remove(&network_id); NetworkAttestations::<T>::mutate(&network_id, |attestations| {
attestations.bounded_resize(len, None);
});
return weight; return weight;
} }
@ -675,6 +668,13 @@ impl<T: Config> Pallet<T> {
let attestation_block = attestation.block(); let attestation_block = attestation.block();
let network_id = attestation.network_id(); 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) { if DisabledAuthorities::<T>::get().contains(authority_index) {
return Err(InvalidTransaction::BadSigner); return Err(InvalidTransaction::BadSigner);
} }

View File

@ -76,6 +76,7 @@ fn should_successfully_compute_median_and_start_weaving_round() {
let networks = vec![(network_id, network_data, Default::default())]; let networks = vec![(network_id, network_data, Default::default())];
new_test_ext(authorities, networks).execute_with(|| { new_test_ext(authorities, networks).execute_with(|| {
GhostWeaver::on_initialize(1);
System::set_block_number(2); System::set_block_number(2);
let context = AttestationContext::default() 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())]; let networks = vec![(network_id, network_data, Default::default())];
new_test_ext(authorities, networks).execute_with(|| { new_test_ext(authorities, networks).execute_with(|| {
GhostWeaver::on_initialize(9);
System::set_block_number(10); System::set_block_number(10);
let context = AttestationContext::default() 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())]; let networks = vec![(network_id, network_data, Default::default())];
new_test_ext(authorities, networks).execute_with(|| { new_test_ext(authorities, networks).execute_with(|| {
GhostWeaver::on_initialize(1);
System::set_block_number(2); System::set_block_number(2);
let att = AttestationContext::default() 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.register_extension(TransactionPoolExt::new(pool));
ext.execute_with(|| { ext.execute_with(|| {
GhostWeaver::on_initialize(1);
GhostWeaver::on_initialize(2);
let network_id_encoded = evm_network_id.encode(); let network_id_encoded = evm_network_id.encode();
let mut endpoint_key = b"ghost-weaver::".to_vec(); 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.register_extension(TransactionPoolExt::new(pool));
ext.execute_with(|| { ext.execute_with(|| {
GhostWeaver::on_initialize(1);
GhostWeaver::on_initialize(2);
let tapestry_draft = TapestryDraftBuilder::<crate::ExternalBlockNumber, u32>::default(); let tapestry_draft = TapestryDraftBuilder::<crate::ExternalBlockNumber, u32>::default();
let evm_tapestry_draft = tapestry_draft.with_median_external(25639556).build(); let evm_tapestry_draft = tapestry_draft.with_median_external(25639556).build();
let utxo_tapestry_draft = tapestry_draft.with_median_external(960129).build(); let utxo_tapestry_draft = tapestry_draft.with_median_external(960129).build();
CurrentWeavingSession::<TestRuntime>::insert(&evm_network_id, evm_session); 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(|| { new_test_ext(authorities, networks).execute_with(|| {
GhostWeaver::on_initialize(1);
// https://sepolia.etherscan.io/address/0x7fec11e652f4d54e8cf11c4b52c360380332f2bd#readContract // https://sepolia.etherscan.io/address/0x7fec11e652f4d54e8cf11c4b52c360380332f2bd#readContract
// getRoot: session 0, atBlock 11716130 // getRoot: session 0, atBlock 11716130
let session = 0; let session = 0;
@ -928,6 +937,7 @@ fn on_initialize_should_finalize_session_when_timeout_is_reached() {
new_test_ext(authorities, networks).execute_with(|| { new_test_ext(authorities, networks).execute_with(|| {
let current_substrate_block = 10; let current_substrate_block = 10;
GhostWeaver::on_initialize(current_substrate_block);
System::set_block_number(current_substrate_block + 1); System::set_block_number(current_substrate_block + 1);
let tapestry_draft = TapestryDraftBuilder::default() let tapestry_draft = TapestryDraftBuilder::default()