-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add casper-sse notification trigger for deposits, implement deposit-manager (in favor of #110) #133
Conversation
…tegrate-deploy-notifier-2
226b0fa
to
5e7cbfa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like most changes, however this PR must be split into few smaller ones. I would expect that adding SSE notification, will just add SSE notification. Here I see that the main processing events logic was refactored (changed and broken), and too many new things were introduced.
use error::DepositManagerError; | ||
use kairos_circuit_logic::transactions::{KairosTransaction, L1Deposit}; | ||
|
||
pub struct DepositManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be EventManager
, as contract will emit more event types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EventManager
as it was/ is implemented now is currently only dealing with Deposit
's and it is initialized with a specific contract hash, our current expectation is that the corresponding contract emits deposit events. A EventManager
suggests a more generic use case, in that case the EventManager
should be capable to handle any kind of events which it isn't doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no batch logic in the smart contract yet, so there was no additional event to handle. I designed L1 synchronization mechanism and it should be EventManager
.
&self, | ||
batch_state_manager: &BatchStateManager, | ||
) -> Result<(), DepositManagerError> { | ||
let last_unprocessed_deposit_index = self.fetcher.fetch_events_count().await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer last_unprocessed_event_index
and similar naming in the whole function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deposit index is different to the event index. If we decide to emit other events later this deposit counter must not increase. We could add a separate counter and name it last_unprocessed_event_index, but we should not rename this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you always want to match all events before adding Deposits to the batch, then it makes sense.
} | ||
} | ||
} | ||
self.last_deposit_added_to_batch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internal logic of updating processed events (currently deposits) is broken. Example scenario where there are 3 new events:
- First
fetch_event()
succeeds and deposit is added to batch_state_manager - Second
fetch_events()
fails (for example transient network issue), so the whole function is finished with error. Counter is not updated! - Next call to
add_events_to
will fetch the first event again, and add it to batch_state_manager again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding events to the batch state manager should be/ is invariant according to @Avi-D-coder. I may understood him wrong. If it's not, I think the better API is to make adding deposits to the batch_state_manager invariant in the batch_state_manager instead of making the hosekeeping of deposits a concern of the user of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate deposits added to a batch are not currently handled by the batch state manager. I could de-duplicate them easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, instead trying to deduplicate deposits, we should not approve "refactor" code that introduces them.
…last_unprocessed_deposit_index
74227a3
to
006ab59
Compare
006ab59
to
548157f
Compare
9d341c2
to
4bde71d
Compare
Things done:
kairos-test-utils/cctl
to deploy a given contractEventManager
to be aDepositManager
. This manager is part of theServerState
and is used to both fetch events every 30s or when a known deposit deploy event got triggered.cctil-rs
and it's implicitly tested in ourkairos-cli
integration test as well as the e2e test