Skip to content

Commit

Permalink
[json rpc] remove kv queries for checkpoint content by checkpoint con…
Browse files Browse the repository at this point in the history
…tents digest (#20370)

## Description 

Allows not to maintain extra table in Bigtable (i.e. checkpoint contents
digest => checkpoint_sequence_number)

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
phoenix-o authored Nov 22, 2024
1 parent c7b108d commit 59be774
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 164 deletions.
11 changes: 1 addition & 10 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5335,12 +5335,10 @@ impl TransactionKeyValueStoreTrait for AuthorityState {
checkpoint_summaries: &[CheckpointSequenceNumber],
checkpoint_contents: &[CheckpointSequenceNumber],
checkpoint_summaries_by_digest: &[CheckpointDigest],
checkpoint_contents_by_digest: &[CheckpointContentsDigest],
) -> SuiResult<(
Vec<Option<CertifiedCheckpointSummary>>,
Vec<Option<CheckpointContents>>,
Vec<Option<CertifiedCheckpointSummary>>,
Vec<Option<CheckpointContents>>,
)> {
// TODO: use multi-get methods if it ever becomes important (unlikely)
let mut summaries = Vec::with_capacity(checkpoint_summaries.len());
Expand Down Expand Up @@ -5372,14 +5370,7 @@ impl TransactionKeyValueStoreTrait for AuthorityState {
.map(|c| c.into_inner());
summaries_by_digest.push(checkpoint);
}

let mut contents_by_digest = Vec::with_capacity(checkpoint_contents_by_digest.len());
for digest in checkpoint_contents_by_digest {
let checkpoint = store.get_checkpoint_contents(digest)?;
contents_by_digest.push(checkpoint);
}

Ok((summaries, contents, summaries_by_digest, contents_by_digest))
Ok((summaries, contents, summaries_by_digest))
}

#[instrument(skip(self))]
Expand Down
30 changes: 1 addition & 29 deletions crates/sui-json-rpc/src/authority_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use sui_json_rpc_types::{
SuiObjectDataFilter, TransactionFilter,
};
use sui_storage::key_value_store::{
KVStoreCheckpointData, KVStoreTransactionData, TransactionKeyValueStore,
TransactionKeyValueStoreTrait,
KVStoreTransactionData, TransactionKeyValueStore, TransactionKeyValueStoreTrait,
};
use sui_types::base_types::{
MoveObjectType, ObjectID, ObjectInfo, ObjectRef, SequenceNumber, SuiAddress,
Expand Down Expand Up @@ -61,14 +60,6 @@ pub trait StateRead: Send + Sync {
events: &[TransactionEventsDigest],
) -> StateReadResult<KVStoreTransactionData>;

async fn multi_get_checkpoints(
&self,
checkpoint_summaries: &[CheckpointSequenceNumber],
checkpoint_contents: &[CheckpointSequenceNumber],
checkpoint_summaries_by_digest: &[CheckpointDigest],
checkpoint_contents_by_digest: &[CheckpointContentsDigest],
) -> StateReadResult<KVStoreCheckpointData>;

fn get_object_read(&self, object_id: &ObjectID) -> StateReadResult<ObjectRead>;

fn get_past_object_read(
Expand Down Expand Up @@ -257,25 +248,6 @@ impl StateRead for AuthorityState {
)
}

async fn multi_get_checkpoints(
&self,
checkpoint_summaries: &[CheckpointSequenceNumber],
checkpoint_contents: &[CheckpointSequenceNumber],
checkpoint_summaries_by_digest: &[CheckpointDigest],
checkpoint_contents_by_digest: &[CheckpointContentsDigest],
) -> StateReadResult<KVStoreCheckpointData> {
Ok(
<AuthorityState as TransactionKeyValueStoreTrait>::multi_get_checkpoints(
self,
checkpoint_summaries,
checkpoint_contents,
checkpoint_summaries_by_digest,
checkpoint_contents_by_digest,
)
.await?,
)
}

fn get_object_read(&self, object_id: &ObjectID) -> StateReadResult<ObjectRead> {
Ok(self.get_object_read(object_id)?)
}
Expand Down
5 changes: 1 addition & 4 deletions crates/sui-json-rpc/src/coin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ mod tests {
use sui_types::error::{SuiError, SuiResult};
use sui_types::gas_coin::GAS;
use sui_types::id::UID;
use sui_types::messages_checkpoint::{
CheckpointContentsDigest, CheckpointDigest, CheckpointSequenceNumber,
};
use sui_types::messages_checkpoint::{CheckpointDigest, CheckpointSequenceNumber};
use sui_types::object::MoveObject;
use sui_types::object::Object;
use sui_types::object::Owner;
Expand All @@ -465,7 +463,6 @@ mod tests {
checkpoint_summaries: &[CheckpointSequenceNumber],
checkpoint_contents: &[CheckpointSequenceNumber],
checkpoint_summaries_by_digest: &[CheckpointDigest],
checkpoint_contents_by_digest: &[CheckpointContentsDigest],
) -> SuiResult<KVStoreCheckpointData>;

async fn deprecated_get_transaction_checkpoint(
Expand Down
14 changes: 4 additions & 10 deletions crates/sui-json-rpc/src/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ use sui_types::display::DisplayVersionUpdatedEvent;
use sui_types::effects::{TransactionEffects, TransactionEffectsAPI, TransactionEvents};
use sui_types::error::{SuiError, SuiObjectResponseError};
use sui_types::messages_checkpoint::{
CheckpointContents, CheckpointContentsDigest, CheckpointSequenceNumber, CheckpointSummary,
CheckpointTimestamp,
CheckpointContents, CheckpointSequenceNumber, CheckpointSummary, CheckpointTimestamp,
};
use sui_types::object::{Object, ObjectRead, PastObjectRead};
use sui_types::sui_serde::BigInt;
Expand Down Expand Up @@ -122,7 +121,7 @@ impl ReadApi {
.await?;
let content = self
.transaction_kv_store
.get_checkpoint_contents_by_digest(verified_summary.content_digest)
.get_checkpoint_contents(verified_summary.sequence_number)
.await?;
let signature = verified_summary.auth_sig().signature.clone();
(verified_summary.into_data(), content, signature).into()
Expand All @@ -134,7 +133,7 @@ impl ReadApi {
.await?;
let content = self
.transaction_kv_store
.get_checkpoint_contents_by_digest(verified_summary.content_digest)
.get_checkpoint_contents(verified_summary.sequence_number)
.await?;
let signature = verified_summary.auth_sig().signature.clone();
(verified_summary.into_data(), content, signature).into()
Expand Down Expand Up @@ -172,13 +171,8 @@ impl ReadApi {
})
.collect();

let checkpoint_contents_digest: Vec<CheckpointContentsDigest> =
checkpoint_summaries_and_signatures
.iter()
.map(|summary| summary.0.content_digest)
.collect();
let checkpoint_contents = transaction_kv_store
.multi_get_checkpoints_contents_by_digest(checkpoint_contents_digest.as_slice())
.multi_get_checkpoints_contents(&checkpoint_numbers)
.await?;
let contents: Vec<CheckpointContents> = checkpoint_contents.into_iter().flatten().collect();

Expand Down
24 changes: 3 additions & 21 deletions crates/sui-storage/src/bin/http_kv_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use sui_storage::http_key_value_store::*;
use sui_storage::key_value_store::TransactionKeyValueStore;
use sui_storage::key_value_store_metrics::KeyValueStoreMetrics;
use sui_types::base_types::ObjectID;
use sui_types::digests::{
CheckpointContentsDigest, CheckpointDigest, TransactionDigest, TransactionEventsDigest,
};
use sui_types::digests::{CheckpointDigest, TransactionDigest, TransactionEventsDigest};
use sui_types::messages_checkpoint::CheckpointSequenceNumber;

#[derive(Parser)]
Expand Down Expand Up @@ -104,29 +102,13 @@ impl Command {
}

"ckpt_contents" => {
let digests: Vec<_> = digest
.into_iter()
.map(|s| {
CheckpointContentsDigest::from_str(&s)
.expect("invalid checkpoint digest")
})
.collect();

let ckpts = kv
.multi_get_checkpoints(&[], &seqs, &[], &digests)
.await
.unwrap();
let ckpts = kv.multi_get_checkpoints(&[], &seqs, &[]).await.unwrap();

for (seq, ckpt) in seqs.iter().zip(ckpts.1.iter()) {
// populate digest before printing
ckpt.as_ref().map(|c| c.digest());
println!("fetched ckpt contents: {:?} {:?}", seq, ckpt);
}
for (digest, ckpt) in digests.iter().zip(ckpts.3.iter()) {
// populate digest before printing
ckpt.as_ref().map(|c| c.digest());
println!("fetched ckpt contents: {:?} {:?}", digest, ckpt);
}
}

"ckpt_summary" => {
Expand All @@ -138,7 +120,7 @@ impl Command {
.collect();

let ckpts = kv
.multi_get_checkpoints(&seqs, &[], &digests, &[])
.multi_get_checkpoints(&seqs, &[], &digests)
.await
.unwrap();

Expand Down
28 changes: 1 addition & 27 deletions crates/sui-storage/src/http_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,10 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
checkpoint_summaries: &[CheckpointSequenceNumber],
checkpoint_contents: &[CheckpointSequenceNumber],
checkpoint_summaries_by_digest: &[CheckpointDigest],
checkpoint_contents_by_digest: &[CheckpointContentsDigest],
) -> SuiResult<(
Vec<Option<CertifiedCheckpointSummary>>,
Vec<Option<CheckpointContents>>,
Vec<Option<CertifiedCheckpointSummary>>,
Vec<Option<CheckpointContents>>,
)> {
let keys = checkpoint_summaries
.iter()
Expand All @@ -437,26 +435,15 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
.iter()
.map(|cp| Key::CheckpointSummaryByDigest(*cp)),
)
.chain(
checkpoint_contents_by_digest
.iter()
.map(|cp| Key::CheckpointContentsByDigest(*cp)),
)
.collect::<Vec<_>>();

let summaries_len = checkpoint_summaries.len();
let contents_len = checkpoint_contents.len();
let summaries_by_digest_len = checkpoint_summaries_by_digest.len();
let contents_by_digest_len = checkpoint_contents_by_digest.len();

let fetches = self.multi_fetch(keys).await;

let input_slices = [
summaries_len,
contents_len,
summaries_by_digest_len,
contents_by_digest_len,
];
let input_slices = [summaries_len, contents_len, summaries_by_digest_len];

let result_slices = multi_split_slice(&fetches, &input_slices);

Expand Down Expand Up @@ -489,23 +476,10 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
})
})
.collect::<Vec<_>>();

let contents_by_digest_results = result_slices[3]
.iter()
.zip(checkpoint_contents_by_digest.iter())
.map(map_fetch)
.map(|maybe_bytes| {
maybe_bytes.and_then(|(bytes, digest)| {
deser_check_digest(digest, bytes, |c: &CheckpointContents| *c.digest())
})
})
.collect::<Vec<_>>();

Ok((
summaries_results,
contents_results,
summaries_by_digest_results,
contents_by_digest_results,
))
}

Expand Down
Loading

0 comments on commit 59be774

Please sign in to comment.