Skip to content

Commit

Permalink
fix(dispatcher): check epoch before finishing
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Aug 15, 2024
1 parent 3e7438d commit cf63adf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions offchain/dispatcher/src/drivers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ impl Context {
broker: &impl BrokerSend,
) -> Result<(), BrokerFacadeError> {
let input_block_number = input.block_added.number.as_u64();
let input_epoch = self.calculate_epoch(input_block_number);
self.last_finished_epoch.map(|last_finished_epoch| {
// Asserting that the calculated epoch comes after the last finished epoch.
// (If last_finished_epoch == None then we don't need the assertion.)
assert!(input_epoch > last_finished_epoch)
});

self.finish_epoch_if_needed(input_block_number, broker)
.await?;

Expand All @@ -76,13 +83,6 @@ impl Context {
.inc();

self.inputs_sent += 1;

let input_epoch = self.calculate_epoch(input_block_number);
self.last_finished_epoch.map(|last_finished_epoch| {
// Asserting that the calculated epoch comes after the last finished epoch.
// (If last_finished_epoch == None then we don't need the assertion.)
assert!(input_epoch > last_finished_epoch)
});
self.last_input_epoch = Some(input_epoch);

Ok(())
Expand Down

0 comments on commit cf63adf

Please sign in to comment.