Skip to content
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

Closed
wants to merge 63 commits into from

Conversation

marijanp
Copy link
Contributor

@marijanp marijanp commented Jun 22, 2024

Things done:

  • Extended kairos-test-utils/cctl to deploy a given contract
    • added a basic test that checks that the contract was deployed successfully
    • adjusted the nixos module for cctl
  • Added a contract hash argument to the kairos-cli deposit command
  • Refactored the EventManager to be a DepositManager. This manager is part of the ServerState and is used to both fetch events every 30s or when a known deposit deploy event got triggered.
  • Added a known deposit deploys set that is used to keep track of deposit deploys routed through our L2
  • Updated the EventManager initialization to use retry and to initialize the next_deposit_index with the current on-chain state
  • Disabled cctl tests for kairos-test-utils, as the cctl-related tests should be tested once factored our in cctil-rs and it's implicitly tested in our kairos-cli integration test as well as the e2e test

marijanp added 30 commits May 29, 2024 16:46
@marijanp marijanp self-assigned this Jun 22, 2024
@marijanp marijanp changed the title Introduce a deposit manager, in favor of #110 Add casper-sse notification trigger for deposits, implement deposit-manager (in favor of #110) Jun 22, 2024
Copy link
Contributor

@koxu1996 koxu1996 left a 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.

kairos-test-utils/bin/cctld.rs Outdated Show resolved Hide resolved
use error::DepositManagerError;
use kairos_circuit_logic::transactions::{KairosTransaction, L1Deposit};

pub struct DepositManager {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?;
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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:

  1. First fetch_event() succeeds and deposit is added to batch_state_manager
  2. Second fetch_events() fails (for example transient network issue), so the whole function is finished with error. Counter is not updated!
  3. Next call to add_events_to will fetch the first event again, and add it to batch_state_manager again.

Copy link
Contributor Author

@marijanp marijanp Jun 24, 2024

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@marijanp marijanp force-pushed the deposit-manager branch 2 times, most recently from 9d341c2 to 4bde71d Compare July 4, 2024 08:51
@marijanp marijanp marked this pull request as draft July 30, 2024 15:25
@marijanp marijanp closed this Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants