Skip to content

Commit d302488

Browse files
authored
Suifix (#5368)
2 parents d572ebc + a72f1e1 commit d302488

File tree

3 files changed

+168
-124
lines changed

3 files changed

+168
-124
lines changed

voyager/modules/state/sui/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ pub struct Module {
6161

6262
pub ibc_store: ObjectID,
6363

64-
pub ibc_contract: ObjectID,
64+
pub initial_ibc_contract: ObjectID,
65+
66+
pub latest_ibc_contract: ObjectID,
6567

6668
pub ibc_store_initial_seq: SequenceNumber,
6769
}
@@ -174,7 +176,7 @@ impl Module {
174176
.expect("there must be some events exist")
175177
.into_iter()
176178
.find_map(|e| {
177-
if e.type_.address == self.ibc_contract.into()
179+
if e.type_.address == self.initial_ibc_contract.into()
178180
&& e.type_.module.as_str() == "events"
179181
&& e.type_.name.as_str() == "PacketSend"
180182
{
@@ -255,7 +257,8 @@ impl StateModule<IbcUnion> for Module {
255257
sui_client,
256258
rpc_url: config.rpc_url,
257259
ibc_store: config.ibc_store,
258-
ibc_contract,
260+
initial_ibc_contract: config.ibc_contract,
261+
latest_ibc_contract: ibc_contract,
259262
ibc_store_initial_seq,
260263
})
261264
}
@@ -306,7 +309,7 @@ impl StateModuleServer<IbcUnion> for Module {
306309
) -> RpcResult<Value> {
307310
let query = SuiQuery::new_with_store(
308311
&self.sui_client,
309-
self.ibc_contract,
312+
self.latest_ibc_contract,
310313
self.ibc_store,
311314
self.ibc_store_initial_seq,
312315
)

voyager/plugins/client-update/sui/src/main.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use sui_sdk::{
1212
base_types::ObjectID, committee::EpochId, full_checkpoint_content::CheckpointTransaction,
1313
},
1414
};
15-
use tracing::instrument;
15+
use tracing::{info, instrument};
1616
use unionlabs::ibc::core::client::height::Height;
1717
use voyager_sdk::{
1818
DefaultCmd, anyhow,
@@ -177,26 +177,36 @@ impl Module {
177177
let mut headers = vec![];
178178

179179
let mut is_first = true;
180-
for epoch in from..to {
181-
let query = json!({
182-
"query": "query ($epoch_id: UInt53) { epoch(epochId: $epoch_id) { checkpoints(last: 1) { edges { node { sequenceNumber } } } } }",
183-
"variables": { "epoch_id": epoch }
184-
});
185-
186-
let resp = client
187-
.try_clone()
188-
.expect("no body, so this will work")
189-
.body(query.to_string())
190-
.send()
191-
.await
192-
.unwrap()
193-
.text()
194-
.await
195-
.unwrap();
180+
let epoch_ids: Vec<u64> = (from..to).collect();
181+
let query = json!({
182+
"query": "query ($epoch_ids: [UInt53]) { multiGetEpochs(keys: $epoch_ids) { checkpoints(last: 1) { edges { node { sequenceNumber } } } } }",
183+
"variables": { "epoch_ids": epoch_ids}
184+
});
185+
186+
let resp = client
187+
.try_clone()
188+
.expect("no body, so this will work")
189+
.body(query.to_string())
190+
.send()
191+
.await
192+
.map_err(RpcError::retryable("error fetching epoch checkpoint"))?
193+
.error_for_status()
194+
.map_err(RpcError::retryable(
195+
"error fetching epoch checkpoint: error status",
196+
))?
197+
.text()
198+
.await
199+
.map_err(RpcError::retryable(
200+
"error fetching epoch checkpoint: error reading text from body",
201+
))?;
202+
203+
info!(%resp);
196204

197-
let v: serde_json::Value = serde_json::from_str(&resp).unwrap();
205+
let v: &serde_json::Value =
206+
&serde_json::from_str::<serde_json::Value>(&resp).unwrap()["data"]["multiGetEpochs"];
198207

199-
let update_to = v["data"]["epoch"]["checkpoints"]["edges"][0]["node"]["sequenceNumber"]
208+
for (i, _) in (from..to).enumerate() {
209+
let update_to = v[i]["checkpoints"]["edges"][0]["node"]["sequenceNumber"]
200210
.as_u64()
201211
.unwrap();
202212

0 commit comments

Comments
 (0)