Skip to content

Commit ee9c0ca

Browse files
authored
Refactor sui light client so it can used from other crates (MystenLabs#19604)
## Description This PR refactors sui light client so it can be used outside form other crates and libraries. And it does two other things: 1. Allow using an archive store url to sync the list of end of epoch checkpoint sequence numbers. This makes it easier to use because archive store for mainnet/testnet are freely and publicly available 2. Adds a function `get_verified_checkpoint` which returns the checkpoint for a given object. The intention is to use it for finding the checkpoint sequence number in which a particular package was published ## Test plan Existing tests
1 parent 9105b68 commit ee9c0ca

File tree

13 files changed

+1180
-648
lines changed

13 files changed

+1180
-648
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sui-archival/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,34 @@ impl Manifest {
192192
}
193193
}
194194
}
195+
196+
pub fn get_all_end_of_epoch_checkpoint_seq_numbers(&self) -> Result<Vec<u64>> {
197+
match self {
198+
Manifest::V1(manifest) => {
199+
let mut summary_files: Vec<_> = manifest
200+
.file_metadata
201+
.clone()
202+
.into_iter()
203+
.filter(|f| f.file_type == FileType::CheckpointSummary)
204+
.collect();
205+
summary_files.sort_by_key(|f| f.checkpoint_seq_range.start);
206+
assert!(summary_files
207+
.windows(2)
208+
.all(|w| w[1].checkpoint_seq_range.start == w[0].checkpoint_seq_range.end));
209+
assert_eq!(summary_files.first().unwrap().checkpoint_seq_range.start, 0);
210+
// get last checkpoint seq num per epoch
211+
let res = summary_files.windows(2).filter_map(|w| {
212+
if w[1].epoch_num == w[0].epoch_num + 1 {
213+
Some(w[0].checkpoint_seq_range.end - 1)
214+
} else {
215+
None
216+
}
217+
});
218+
Ok(res.collect())
219+
}
220+
}
221+
}
222+
195223
pub fn update(
196224
&mut self,
197225
epoch_num: u64,

crates/sui-light-client/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,27 @@ bcs.workspace = true
2020
bytes.workspace = true
2121
clap.workspace = true
2222
move-core-types.workspace = true
23+
roaring.workspace = true
2324
serde.workspace = true
2425
tokio = { workspace = true, features = ["full"] }
2526
serde_yaml.workspace = true
2627
serde_json.workspace = true
28+
sui-archival.workspace = true
2729
sui-types.workspace = true
2830
sui-config.workspace = true
2931
sui-rpc-api.workspace = true
3032
sui-sdk.workspace = true
3133
move-binary-format.workspace = true
3234
sui-json-rpc-types.workspace = true
3335
sui-package-resolver.workspace = true
36+
sui-storage.workspace = true
3437
url.workspace = true
3538
reqwest.workspace = true
39+
tracing.workspace = true
3640
object_store.workspace = true
3741
env_logger = "0.11.5"
3842
log = "0.4.22"
43+
tempfile = "3.8.0"
44+
45+
[dev-dependencies]
46+
tempfile.workspace = true

0 commit comments

Comments
 (0)