-
Notifications
You must be signed in to change notification settings - Fork 57
feat: Refactor event processing code #2152
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
Open
sadhansood
wants to merge
1
commit into
main
Choose a base branch
from
sadhan/authenticated_events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Walrus Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Event related modules. | ||
|
||
pub mod event_blob; | ||
pub mod event_blob_downloader; | ||
pub mod event_processor; | ||
pub mod events; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Walrus Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Event processor for processing events from the Sui network. | ||
|
||
pub mod bootstrap; | ||
pub mod catchup; | ||
pub mod checkpoint; | ||
pub mod client; | ||
pub mod config; | ||
pub mod db; | ||
pub mod metrics; | ||
pub mod package_store; | ||
pub mod processor; | ||
pub mod runtime; |
67 changes: 67 additions & 0 deletions
67
crates/walrus-service/src/event/event_processor/bootstrap.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Walrus Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Bootstrap module for getting the initial committee and checkpoint information. | ||
use anyhow::{Result, anyhow}; | ||
use sui_sdk::rpc_types::{SuiObjectDataOptions, SuiTransactionBlockResponseOptions}; | ||
use sui_types::{ | ||
base_types::ObjectID, | ||
committee::Committee, | ||
messages_checkpoint::VerifiedCheckpoint, | ||
sui_serde::BigInt, | ||
}; | ||
use walrus_sui::client::retry_client::{RetriableRpcClient, RetriableSuiClient}; | ||
|
||
/// Gets the initial committee and checkpoint information by: | ||
/// 1. Fetching the system package object | ||
/// 2. Getting its previous transaction | ||
/// 3. Using that transaction's checkpoint to get the committee and checkpoint data | ||
/// | ||
/// Returns a tuple containing: | ||
/// - The committee for the current or next epoch | ||
/// - The verified checkpoint containing the system package deployment | ||
pub async fn get_bootstrap_committee_and_checkpoint( | ||
sui_client: RetriableSuiClient, | ||
rpc_client: RetriableRpcClient, | ||
system_pkg_id: ObjectID, | ||
) -> Result<(Committee, VerifiedCheckpoint)> { | ||
let object_options = SuiObjectDataOptions::new() | ||
.with_bcs() | ||
.with_type() | ||
.with_previous_transaction(); | ||
let object = sui_client | ||
.get_object_with_options(system_pkg_id, object_options) | ||
.await?; | ||
let txn_options = SuiTransactionBlockResponseOptions::new(); | ||
let txn_digest = object | ||
.data | ||
.ok_or(anyhow!("No object data"))? | ||
.previous_transaction | ||
.ok_or(anyhow!("No transaction data"))?; | ||
let txn = sui_client | ||
.get_transaction_with_options(txn_digest, txn_options) | ||
.await?; | ||
let checkpoint_data = rpc_client | ||
.get_full_checkpoint(txn.checkpoint.ok_or(anyhow!("No checkpoint data"))?) | ||
.await?; | ||
let epoch = checkpoint_data.checkpoint_summary.epoch; | ||
let checkpoint_summary = checkpoint_data.checkpoint_summary.clone(); | ||
let committee = if let Some(end_of_epoch_data) = &checkpoint_summary.end_of_epoch_data { | ||
let next_committee = end_of_epoch_data | ||
.next_epoch_committee | ||
.iter() | ||
.cloned() | ||
.collect(); | ||
Committee::new(epoch + 1, next_committee) | ||
} else { | ||
let committee_info = sui_client | ||
.get_committee_info(Some(BigInt::from(epoch))) | ||
.await?; | ||
Committee::new( | ||
committee_info.epoch, | ||
committee_info.validators.into_iter().collect(), | ||
) | ||
}; | ||
let verified_checkpoint = VerifiedCheckpoint::new_unchecked(checkpoint_summary); | ||
Ok((committee, verified_checkpoint)) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.