Skip to content

Commit

Permalink
[kv store] json rpc: remove leftover call sites to old events API
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-o committed Dec 23, 2024
1 parent ad58cb9 commit f77eeaa
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 247 deletions.
28 changes: 10 additions & 18 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4114,24 +4114,27 @@ impl AuthorityState {
}

// get the unique set of digests from the event_keys
let event_digests = event_keys
let transaction_digests = event_keys
.iter()
.map(|(digest, _, _, _)| *digest)
.map(|(_, digest, _, _)| *digest)
.collect::<HashSet<_>>()
.into_iter()
.collect::<Vec<_>>();

let events = kv_store.multi_get_events(&event_digests).await?;
let events = kv_store
.multi_get_events_by_tx_digests(&transaction_digests)
.await?;

let events_map: HashMap<_, _> = event_digests.iter().zip(events.into_iter()).collect();
let events_map: HashMap<_, _> =
transaction_digests.iter().zip(events.into_iter()).collect();

let stored_events = event_keys
.into_iter()
.map(|k| {
(
k,
events_map
.get(&k.0)
.get(&k.1)
.expect("fetched digest is missing")
.clone()
.and_then(|e| e.data.get(k.2).cloned()),
Expand Down Expand Up @@ -5308,12 +5311,7 @@ impl TransactionKeyValueStoreTrait for AuthorityState {
&self,
transactions: &[TransactionDigest],
effects: &[TransactionDigest],
events: &[TransactionEventsDigest],
) -> SuiResult<(
Vec<Option<Transaction>>,
Vec<Option<TransactionEffects>>,
Vec<Option<TransactionEvents>>,
)> {
) -> SuiResult<(Vec<Option<Transaction>>, Vec<Option<TransactionEffects>>)> {
let txns = if !transactions.is_empty() {
self.get_transaction_cache_reader()
.multi_get_transaction_blocks(transactions)
Expand All @@ -5331,13 +5329,7 @@ impl TransactionKeyValueStoreTrait for AuthorityState {
vec![]
};

let evts = if !events.is_empty() {
self.get_transaction_cache_reader().multi_get_events(events)
} else {
vec![]
};

Ok((txns, fx, evts))
Ok((txns, fx))
}

#[instrument(skip(self))]
Expand Down
5 changes: 1 addition & 4 deletions crates/sui-json-rpc/src/authority_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sui_types::base_types::{
};
use sui_types::bridge::Bridge;
use sui_types::committee::{Committee, EpochId};
use sui_types::digests::{ChainIdentifier, TransactionDigest, TransactionEventsDigest};
use sui_types::digests::{ChainIdentifier, TransactionDigest};
use sui_types::dynamic_field::DynamicFieldInfo;
use sui_types::effects::TransactionEffects;
use sui_types::error::{SuiError, UserInputError};
Expand Down Expand Up @@ -57,7 +57,6 @@ pub trait StateRead: Send + Sync {
&self,
transactions: &[TransactionDigest],
effects: &[TransactionDigest],
events: &[TransactionEventsDigest],
) -> StateReadResult<KVStoreTransactionData>;

fn get_object_read(&self, object_id: &ObjectID) -> StateReadResult<ObjectRead>;
Expand Down Expand Up @@ -235,14 +234,12 @@ impl StateRead for AuthorityState {
&self,
transactions: &[TransactionDigest],
effects: &[TransactionDigest],
events: &[TransactionEventsDigest],
) -> StateReadResult<KVStoreTransactionData> {
Ok(
<AuthorityState as TransactionKeyValueStoreTrait>::multi_get(
self,
transactions,
effects,
events,
)
.await?,
)
Expand Down
5 changes: 2 additions & 3 deletions crates/sui-json-rpc/src/coin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ mod tests {
use sui_types::balance::Supply;
use sui_types::base_types::{ObjectID, SequenceNumber, SuiAddress};
use sui_types::coin::TreasuryCap;
use sui_types::digests::{ObjectDigest, TransactionDigest, TransactionEventsDigest};
use sui_types::digests::{ObjectDigest, TransactionDigest};
use sui_types::effects::{TransactionEffects, TransactionEvents};
use sui_types::error::{SuiError, SuiResult};
use sui_types::gas_coin::GAS;
Expand All @@ -455,7 +455,6 @@ mod tests {
&self,
transactions: &[TransactionDigest],
effects: &[TransactionDigest],
events: &[TransactionEventsDigest],
) -> SuiResult<KVStoreTransactionData>;

async fn multi_get_checkpoints(
Expand Down Expand Up @@ -1399,7 +1398,7 @@ mod tests {
.return_once(move |_| Ok(transaction_digest));
mock_state
.expect_multi_get()
.return_once(move |_, _, _| Ok((vec![], vec![Some(transaction_effects)], vec![])));
.return_once(move |_, _| Ok((vec![], vec![Some(transaction_effects)])));

let coin_read_api = CoinReadApi::new_for_tests(Arc::new(mock_state), None);
let response = coin_read_api.get_total_supply(coin_name.clone()).await;
Expand Down
17 changes: 1 addition & 16 deletions crates/sui-storage/src/bin/http_kv_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +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::{CheckpointDigest, TransactionDigest, TransactionEventsDigest};
use sui_types::digests::{CheckpointDigest, TransactionDigest};
use sui_types::messages_checkpoint::CheckpointSequenceNumber;

#[derive(Parser)]
Expand Down Expand Up @@ -86,21 +86,6 @@ impl Command {
}
}

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

let tx = kv.multi_get_events(&digests).await.unwrap();
for (digest, ev) in digests.iter().zip(tx.iter()) {
println!("fetched events: {:?} {:?}", digest, ev);
}
}

"ckpt_contents" => {
let ckpts = kv.multi_get_checkpoints(&[], &seqs, &[]).await.unwrap();

Expand Down
35 changes: 3 additions & 32 deletions crates/sui-storage/src/http_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ use sui_types::base_types::{ObjectID, SequenceNumber, VersionNumber};
use sui_types::object::Object;
use sui_types::storage::ObjectKey;
use sui_types::{
digests::{
CheckpointContentsDigest, CheckpointDigest, TransactionDigest, TransactionEventsDigest,
},
digests::{CheckpointContentsDigest, CheckpointDigest, TransactionDigest},
effects::{TransactionEffects, TransactionEffectsAPI, TransactionEvents},
error::{SuiError, SuiResult},
messages_checkpoint::{
Expand Down Expand Up @@ -77,7 +75,6 @@ where
pub enum Key {
Tx(TransactionDigest),
Fx(TransactionDigest),
Events(TransactionEventsDigest),
CheckpointContents(CheckpointSequenceNumber),
CheckpointSummary(CheckpointSequenceNumber),
CheckpointContentsByDigest(CheckpointContentsDigest),
Expand All @@ -93,7 +90,6 @@ impl Key {
match self {
Key::Tx(_) => "tx",
Key::Fx(_) => "fx",
Key::Events(_) => "ev",
Key::CheckpointContents(_) => "cc",
Key::CheckpointSummary(_) => "cs",
Key::CheckpointContentsByDigest(_) => "cc",
Expand All @@ -108,7 +104,6 @@ impl Key {
match self {
Key::Tx(digest) => encode_digest(digest),
Key::Fx(digest) => encode_digest(digest),
Key::Events(digest) => encode_digest(digest),
Key::CheckpointContents(seq) => {
encoded_tagged_key(&TaggedKey::CheckpointSequenceNumber(*seq))
}
Expand Down Expand Up @@ -144,9 +139,6 @@ pub fn path_elements_to_key(digest: &str, type_: &str) -> anyhow::Result<Key> {
match type_ {
"tx" => Ok(Key::Tx(TransactionDigest::try_from(decoded_digest)?)),
"fx" => Ok(Key::Fx(TransactionDigest::try_from(decoded_digest)?)),
"ev" => Ok(Key::Events(TransactionEventsDigest::try_from(
decoded_digest,
)?)),
"cc" => {
// first try to decode as digest, otherwise try to decode as tagged key
match CheckpointContentsDigest::try_from(decoded_digest.clone()) {
Expand Down Expand Up @@ -351,27 +343,19 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
&self,
transactions: &[TransactionDigest],
effects: &[TransactionDigest],
events: &[TransactionEventsDigest],
) -> SuiResult<(
Vec<Option<Transaction>>,
Vec<Option<TransactionEffects>>,
Vec<Option<TransactionEvents>>,
)> {
) -> SuiResult<(Vec<Option<Transaction>>, Vec<Option<TransactionEffects>>)> {
let num_txns = transactions.len();
let num_effects = effects.len();
let num_events = events.len();

let keys = transactions
.iter()
.map(|tx| Key::Tx(*tx))
.chain(effects.iter().map(|fx| Key::Fx(*fx)))
.chain(events.iter().map(|events| Key::Events(*events)))
.collect::<Vec<_>>();

let fetches = self.multi_fetch(keys).await;
let txn_slice = fetches[..num_txns].to_vec();
let fx_slice = fetches[num_txns..num_txns + num_effects].to_vec();
let events_slice = fetches[num_txns + num_effects..].to_vec();

let txn_results = txn_slice
.iter()
Expand All @@ -398,20 +382,7 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
})
})
.collect::<Vec<_>>();

let events_results = events_slice
.iter()
.take(num_events)
.zip(events.iter())
.map(map_fetch)
.map(|maybe_bytes| {
maybe_bytes.and_then(|(bytes, digest)| {
deser_check_digest(digest, bytes, |events: &TransactionEvents| events.digest())
})
})
.collect::<Vec<_>>();

Ok((txn_results, fx_results, events_results))
Ok((txn_results, fx_results))
}

#[instrument(level = "trace", skip_all)]
Expand Down
Loading

0 comments on commit f77eeaa

Please sign in to comment.