Skip to content

Commit

Permalink
revert error handling, do not throw errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MBrozhko34 committed May 21, 2024
1 parent 3a41efd commit 9be69d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
60 changes: 29 additions & 31 deletions pallets/eth-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use sp_application_crypto::RuntimeAppPublic;
use sp_avn_common::{
bounds::MaximumValidatorsBound,
event_discovery::*,
event_types::{ValidEvents, Validator},
event_types::{Validator},
};
use sp_core::{ecdsa, ConstU32, H160, H256};
use sp_io::hashing::keccak_256;
Expand Down Expand Up @@ -582,7 +582,7 @@ pub mod pallet {
if votes.len() < AVN::<T>::quorum() as usize {
EthereumEvents::<T>::insert(&events_partition, votes);
} else {
process_ethereum_events_partition::<T>(&active_range, &events_partition)?;
process_ethereum_events_partition::<T>(&active_range, &events_partition);
advance_partition::<T>(&active_range, &events_partition);
}

Expand Down Expand Up @@ -806,14 +806,14 @@ pub mod pallet {
fn process_ethereum_events_partition<T: Config>(
active_range: &ActiveEthRange,
partition: &EthereumEventsPartition,
) -> Result<(), DispatchError> {
) {
// Remove entry from storage. Ignore votes.
let _ = EthereumEvents::<T>::take(partition);
for discovered_event in partition.events().iter() {
match ValidEvents::try_from(&discovered_event.event.event_id.signature) {
Some(valid_event) =>
if active_range.event_types_filter.contains(&valid_event) {
process_ethereum_event::<T>(&discovered_event.event)?;
process_ethereum_event::<T>(&discovered_event.event);
} else {
log::warn!("Ethereum event signature ({:?}) included in approved range ({:?}), but not part of the expected ones {:?}", &discovered_event.event.event_id.signature, active_range.range, active_range.event_types_filter);
},
Expand All @@ -831,37 +831,35 @@ pub mod pallet {
// TODO raise offences
log::info!("Collators with invalid votes on ethereum events (range: {:?}, partition: {}): {:?}", partition.range(), partition.partition(), votes);
}

Ok(())
}

fn process_ethereum_event<T: Config>(event: &EthEvent) -> Result<(), DispatchError> {
ensure!(
false == T::ProcessedEventsChecker::processed_event_exists(&event.event_id.clone()),
Error::<T>::EventAlreadyProcessed
);

let mut event_accepted = false;

match T::BridgeInterfaceNotification::on_incoming_event_processed(&event) {
Ok(_) => {
event_accepted = true;
<Pallet<T>>::deposit_event(Event::<T>::EventAccepted {
eth_event_id: event.event_id.clone(),
});
},
Err(err) => {
log::error!("💔 Processing ethereum event failed: {:?}", err);
<Pallet<T>>::deposit_event(Event::<T>::EventRejected {
eth_event_id: event.event_id.clone(),
});
},
};
fn process_ethereum_event<T: Config>(event: &EthEvent) {
if false == T::ProcessedEventsChecker::processed_event_exists(&event.event_id.clone()) {
let mut event_accepted = false;

// Add record of succesful processing via ProcessedEventsChecker
T::ProcessedEventsChecker::add_processed_event(&event.event_id.clone(), event_accepted);
match T::BridgeInterfaceNotification::on_incoming_event_processed(&event) {
Ok(_) => {
event_accepted = true;
<Pallet<T>>::deposit_event(Event::<T>::EventAccepted {
eth_event_id: event.event_id.clone(),
});
},
Err(err) => {
log::error!("💔 Processing ethereum event failed: {:?}", err);
<Pallet<T>>::deposit_event(Event::<T>::EventRejected {
eth_event_id: event.event_id.clone(),
});
},
};

Ok(())
// Add record of succesful processing via ProcessedEventsChecker
T::ProcessedEventsChecker::add_processed_event(&event.event_id.clone(), event_accepted);
} else {
log::error!("💔 Duplicate Event Submission");
<Pallet<T>>::deposit_event(Event::<T>::DuplicateEventSubmission {
eth_event_id: event.event_id.clone(),
});
}
}

#[pallet::validate_unsigned]
Expand Down
19 changes: 10 additions & 9 deletions pallets/eth-bridge/src/tests/incoming_events_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ mod process_events {
context.second_mock_event_partition.clone(),
context.test_signature.clone()
));
assert_noop!(
EthBridge::submit_ethereum_events(
RuntimeOrigin::none(),
context.author_two.clone(),
context.second_mock_event_partition.clone(),
context.test_signature_two.clone()
),
Error::<TestRuntime>::EventAlreadyProcessed
);
assert_ok!(EthBridge::submit_ethereum_events(
RuntimeOrigin::none(),
context.author_two.clone(),
context.second_mock_event_partition.clone(),
context.test_signature_two.clone()
));
assert!(System::events().iter().any(|record| record.event ==
mock::RuntimeEvent::EthBridge(Event::<TestRuntime>::DuplicateEventSubmission {
eth_event_id: context.eth_event_id.clone(),
})));
});
}
}

0 comments on commit 9be69d1

Please sign in to comment.