Skip to content

Commit

Permalink
fix(diri): try to handle all events of a block even in case of handle…
Browse files Browse the repository at this point in the history
…r failure (#509)

## Description
1. Process all events of a block even in case of handler failure
2. 
<!--
Please do not leave this blank.
Describe the changes in this PR. What does it [add/remove/fix/replace]?

For crafting a good description, consider using ChatGPT to help
articulate your changes.
-->

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature (`feat:`)
- [x] 🐛 Bug Fix (`fix:`)
- [ ] 📝 Documentation Update (`docs:`)
- [ ] 🎨 Style (`style:`)
- [ ] 🧑‍💻 Code Refactor (`refactor:`)
- [ ] 🔥 Performance Improvements (`perf:`)
- [ ] ✅ Test (`test:`)
- [ ] 🤖 Build (`build:`)
- [ ] 🔁 CI (`ci:`)
- [ ] 📦 Chore (`chore:`)
- [ ] ⏩ Revert (`revert:`)
- [ ] 🚀 Breaking Changes (`BREAKING CHANGE:`)

## Related Tickets & Documents

<!--
Please use this format to link related issues: Fixes #<issue_number>
More info:
https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help

## Added to documentation?

- [ ] 📜 README.md
- [ ] 📓 Documentation
- [ ] 🙅 no documentation needed

## [optional] Are there any post-deployment tasks we need to perform?

<!-- Describe any additional tasks, if any, and provide steps. -->

## [optional] What gif best describes this PR or how it makes you feel?

<!-- Share a fun gif related to your PR! -->

### PR Title and Description Guidelines:

- Ensure your PR title follows semantic versioning standards. This helps
automate releases and changelogs.
- Use types like `feat:`, `fix:`, `chore:`, `BREAKING CHANGE:` etc. in
your PR title.
- Your PR title will be used as a commit message when merging. Make sure
it adheres to [Conventional Commits
standards](https://www.conventionalcommits.org/).

## Closing Issues

<!--
Use keywords to close related issues. This ensures that the associated
issues will automatically close when the PR is merged.

- `Fixes #123` will close issue 123 when the PR is merged.
- `Closes #123` will also close issue 123 when the PR is merged.
- `Resolves #123` will also close issue 123 when the PR is merged.

You can also use multiple keywords in one comment:
- `Fixes #123, Resolves #456`

More info:
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->
  • Loading branch information
ptisserand authored Dec 9, 2024
1 parent 1d5c4ea commit e134bb1
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions crates/diri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,58 @@ impl<S: Storage, E: EventHandler> Diri<S, E> {
match orderbook_event {
Event::OrderPlaced(ev) => {
trace!("OrderPlaced found: {:?}", ev);
self.storage
match self
.storage
.register_placed(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderPlaced event handler failed: {e}"),
}
}
Event::OrderCancelled(ev) => {
trace!("OrderCancelled found: {:?}", ev);
self.storage
match self
.storage
.register_cancelled(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderCancelled event handler failed: {e}"),
}
}
Event::OrderFulfilled(ev) => {
trace!("OrderFulfilled found: {:?}", ev);
self.storage
match self
.storage
.register_fulfilled(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderFulfilled event handler failed: {e}"),
}
}
Event::OrderExecuted(ev) => {
trace!("OrderExecuted found: {:?}", ev);
self.storage
match self
.storage
.register_executed(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderExecuted event handler failed: {e}"),
}
}
Event::RollbackStatus(ev) => {
trace!("RollbackStatus found: {:?}", ev);
self.storage
match self
.storage
.status_back_to_open(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("RollbackStatus event handler failed: {e}"),
}
}
_ => warn!("Orderbook event not handled: {:?}", orderbook_event),
};
Expand Down

0 comments on commit e134bb1

Please sign in to comment.