Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pallets/indexing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ pub mod pallet {
error: e,
data: on_chain_table_bytes,
});
return Err(e);
} else {
Pallet::<T, I>::deposit_event(Event::SystemTableUpdate {
table: quorum.table.clone(),
Expand Down
73 changes: 36 additions & 37 deletions pallets/system_tables/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ pub mod pallet {

Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);
Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// Process a Nominate SystemRequest
Expand All @@ -272,9 +272,10 @@ pub mod pallet {
errors
);

errors
.into_iter()
.for_each(|e| emit_for_error::<T>(Result::<(), _>::Err(e)));
for error in errors.iter().copied() {
emit_error::<T>(error);
}
Err(*errors.first().expect("There is at least one error"))?;
}

if nominations.is_empty() {
Expand All @@ -289,12 +290,11 @@ pub mod pallet {
pallet_staking::Pallet::<T>::nominate(nominator_signer, nominations)?;
Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);

Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// Processes the actual withdrawal once the Unstaked event is emitted from the Ethereum
Expand Down Expand Up @@ -325,12 +325,11 @@ pub mod pallet {

Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);

Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// Processes an unstake claimed event and updates chain state appropriately
Expand Down Expand Up @@ -383,11 +382,11 @@ pub mod pallet {

Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);
Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// Parse a system request to initiate unstaking
Expand Down Expand Up @@ -420,12 +419,11 @@ pub mod pallet {

Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);

Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// Process a request to cancel unstakng
Expand All @@ -448,18 +446,21 @@ pub mod pallet {
.map_err(|e| e.error)?;
Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);
Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

fn emit_for_error<T: Config>(r: DispatchResult) {
if let Err(error) = r {
// Emit an event for any errors
Pallet::<T>::deposit_event(Event::<T>::MessageProcessingError { error });
}
fn emit_error<T: Config>(error: DispatchError) {
Pallet::<T>::deposit_event(Event::<T>::MessageProcessingError { error });
}

fn emit_missing_expected_field_error<T: Config>() -> DispatchResult {
let error = Error::<T>::MissingExpectedField.into();
emit_error::<T>(error);
Err(error)
}

#[pallet::storage]
Expand Down Expand Up @@ -502,12 +503,11 @@ pub mod pallet {
messages::handle_message::<T>(eth_sender, body.to_vec())?;
Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);

Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// Process a funded message received from our EVM contract
Expand Down Expand Up @@ -541,12 +541,11 @@ pub mod pallet {
)?;
Ok(())
}
_ => Err(Error::<T>::MissingExpectedField.into()),
_ => emit_missing_expected_field_error::<T>(),
}
})
.for_each(emit_for_error::<T>);

Ok(())
.collect::<Result<Vec<_>, _>>()
.map(|_| ())
}

/// A custom offence handler that chills validators when they offend
Expand Down
Loading