Skip to content

Commit e21c86a

Browse files
committed
chore(sui): do less calls to sui
Signed-off-by: aeryz <[email protected]> wip even more Signed-off-by: aeryz <[email protected]>
1 parent 2181ed0 commit e21c86a

File tree

1 file changed

+29
-19
lines changed
  • voyager/plugins/client-update/sui/src

1 file changed

+29
-19
lines changed

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)