Skip to content

Commit b82e65b

Browse files
authoredJun 13, 2024··
[sui replay] migrate off using sui_getLoadedChildObjects json rpc api (#18213)
The PR removes usage of the sui_getLoadedChildObjects API for the remote mode of the replay tool. It's required to drop the corresponding index from index_db. The change is verified by deploying the dynamic field smart contract to devnet, modifying the underlying child object several times, and replaying the corresponding transactions.
1 parent 4592c09 commit b82e65b

File tree

6 files changed

+164
-68
lines changed

6 files changed

+164
-68
lines changed
 

‎crates/sui-replay/src/data_fetcher.rs

+40-23
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use sui_types::object::Object;
3030
use sui_types::transaction::SenderSignedData;
3131
use sui_types::transaction::TransactionDataAPI;
3232
use sui_types::transaction::{EndOfEpochTransactionKind, TransactionKind};
33-
use tracing::error;
3433

3534
/// This trait defines the interfaces for fetching data from some local or remote store
3635
#[async_trait]
@@ -85,6 +84,12 @@ pub(crate) trait DataFetcher {
8584
) -> Result<Vec<SuiEvent>, ReplayEngineError>;
8685

8786
async fn get_chain_id(&self) -> Result<String, ReplayEngineError>;
87+
88+
async fn get_child_object(
89+
&self,
90+
object_id: &ObjectID,
91+
version_upper_bound: VersionNumber,
92+
) -> Result<Object, ReplayEngineError>;
8893
}
8994

9095
#[derive(Clone)]
@@ -223,6 +228,16 @@ impl DataFetcher for Fetchers {
223228
Fetchers::NodeStateDump(q) => q.get_chain_id().await,
224229
}
225230
}
231+
async fn get_child_object(
232+
&self,
233+
object_id: &ObjectID,
234+
version_upper_bound: VersionNumber,
235+
) -> Result<Object, ReplayEngineError> {
236+
match self {
237+
Fetchers::Remote(q) => q.get_child_object(object_id, version_upper_bound).await,
238+
Fetchers::NodeStateDump(q) => q.get_child_object(object_id, version_upper_bound).await,
239+
}
240+
}
226241
}
227242

228243
const VERSIONED_OBJECT_CACHE_CAPACITY: Option<NonZeroUsize> = NonZeroUsize::new(1_000);
@@ -378,6 +393,20 @@ impl DataFetcher for RemoteFetcher {
378393
})
379394
}
380395

396+
async fn get_child_object(
397+
&self,
398+
object_id: &ObjectID,
399+
version_upper_bound: VersionNumber,
400+
) -> Result<Object, ReplayEngineError> {
401+
let response = self
402+
.rpc_client
403+
.read_api()
404+
.try_get_object_before_version(*object_id, version_upper_bound)
405+
.await
406+
.map_err(|q| ReplayEngineError::SuiRpcError { err: q.to_string() })?;
407+
convert_past_obj_response(response)
408+
}
409+
381410
async fn multi_get_latest(
382411
&self,
383412
objects: &[ObjectID],
@@ -441,29 +470,9 @@ impl DataFetcher for RemoteFetcher {
441470

442471
async fn get_loaded_child_objects(
443472
&self,
444-
tx_digest: &TransactionDigest,
473+
_: &TransactionDigest,
445474
) -> Result<Vec<(ObjectID, SequenceNumber)>, ReplayEngineError> {
446-
let loaded_child_objs = match self
447-
.rpc_client
448-
.read_api()
449-
.get_loaded_child_objects(*tx_digest)
450-
.await
451-
{
452-
Ok(objs) => objs,
453-
Err(e) => {
454-
error!("Error getting dynamic fields loaded objects: {}. This RPC server might not support this feature yet", e);
455-
return Err(ReplayEngineError::UnableToGetDynamicFieldLoadedObjects {
456-
rpc_err: e.to_string(),
457-
});
458-
}
459-
};
460-
461-
// Fetch the refs
462-
Ok(loaded_child_objs
463-
.loaded_child_objects
464-
.iter()
465-
.map(|obj| (obj.object_id(), obj.sequence_number()))
466-
.collect::<Vec<_>>())
475+
Ok(vec![])
467476
}
468477

469478
async fn get_latest_checkpoint_sequence_number(&self) -> Result<u64, ReplayEngineError> {
@@ -806,4 +815,12 @@ impl DataFetcher for NodeStateDumpFetcher {
806815
async fn get_chain_id(&self) -> Result<String, ReplayEngineError> {
807816
unimplemented!("get_chain_id for state dump is not implemented")
808817
}
818+
819+
async fn get_child_object(
820+
&self,
821+
_object_id: &ObjectID,
822+
_version_upper_bound: VersionNumber,
823+
) -> Result<Object, ReplayEngineError> {
824+
unimplemented!("get child object is not implemented for state dump");
825+
}
809826
}

‎crates/sui-replay/src/lib.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ pub enum ReplayToolCommand {
9090
tx_digest: String,
9191
#[arg(long, short)]
9292
show_effects: bool,
93-
#[arg(long, short)]
94-
diag: bool,
9593
/// Optional version of the executor to use, if not specified defaults to the one originally used for the transaction.
9694
#[arg(long, short, allow_hyphen_values = true)]
9795
executor_version: Option<i64>,
@@ -206,11 +204,8 @@ pub async fn execute_replay_command(
206204
let contents = std::fs::read_to_string(path)?;
207205
let sandbox_state: ExecutionSandboxState = serde_json::from_str(&contents)?;
208206
info!("Executing tx: {}", sandbox_state.transaction_info.tx_digest);
209-
let sandbox_state = LocalExec::certificate_execute_with_sandbox_state(
210-
&sandbox_state,
211-
&sandbox_state.pre_exec_diag,
212-
)
213-
.await?;
207+
let sandbox_state =
208+
LocalExec::certificate_execute_with_sandbox_state(&sandbox_state).await?;
214209
sandbox_state.check_effects()?;
215210
info!("Execution finished successfully. Local and on-chain effects match.");
216211
None
@@ -330,12 +325,10 @@ pub async fn execute_replay_command(
330325
let contents = std::fs::read_to_string(file).unwrap();
331326
let sandbox_state: ExecutionSandboxState =
332327
serde_json::from_str(&contents).unwrap();
333-
let sandbox_state = LocalExec::certificate_execute_with_sandbox_state(
334-
&sandbox_state,
335-
&sandbox_state.pre_exec_diag,
336-
)
337-
.await
338-
.unwrap();
328+
let sandbox_state =
329+
LocalExec::certificate_execute_with_sandbox_state(&sandbox_state)
330+
.await
331+
.unwrap();
339332
sandbox_state.check_effects().unwrap();
340333
}
341334
});
@@ -372,7 +365,6 @@ pub async fn execute_replay_command(
372365
ReplayToolCommand::ReplayTransaction {
373366
tx_digest,
374367
show_effects,
375-
diag,
376368
executor_version,
377369
protocol_version,
378370
} => {
@@ -389,9 +381,6 @@ pub async fn execute_replay_command(
389381
)
390382
.await?;
391383

392-
if diag {
393-
println!("{:#?}", sandbox_state.pre_exec_diag);
394-
}
395384
if show_effects {
396385
println!("{}", sandbox_state.local_exec_effects);
397386
}

0 commit comments

Comments
 (0)
Please sign in to comment.