Skip to content

Commit 1da0b2b

Browse files
authored
Upgrade mvr-indexer to latest sui-indexer-alt-framework (#235)
1 parent cb0ebf1 commit 1da0b2b

11 files changed

Lines changed: 2100 additions & 1453 deletions

File tree

Cargo.lock

Lines changed: 1974 additions & 1311 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ futures = "0.3.31"
3333
tempfile = "3.20.0"
3434

3535
# Main Sui Mono-repo
36-
sui-indexer-alt-metrics = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
37-
mysten-metrics = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
38-
telemetry-subscribers = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
39-
sui-pg-db = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
40-
move-core-types = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
41-
sui-types = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
42-
sui-package-resolver = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
43-
sui-move-build = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
44-
move-binary-format = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
45-
sui-indexer-alt-framework = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
46-
sui-rpc-api = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
47-
sui-storage = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62" }
48-
sui-field-count = { git = "https://github.com/MystenLabs/sui.git", rev = "3b96ab72dd5db2fb800837d6067bf45839178b62"}
36+
sui-indexer-alt-metrics = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
37+
mysten-metrics = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
38+
telemetry-subscribers = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
39+
sui-pg-db = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
40+
move-core-types = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
41+
sui-types = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
42+
sui-package-resolver = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
43+
sui-move-build = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
44+
move-binary-format = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
45+
sui-indexer-alt-framework = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
46+
sui-rpc-api = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
47+
sui-storage = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb" }
48+
sui-field-count = { git = "https://github.com/MystenLabs/sui.git", rev = "211e22a5b0e08f8840f6a3e74120e1b4b04d5adb"}
4949

5050
# New Rust SDK
51-
sui-sdk-types = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-sdk-types", rev="048124e484f14b9bf2a402227c9bc255c7621bc1"}
51+
sui-sdk-types = { git = "https://github.com/MystenLabs/sui-rust-sdk", package = "sui-sdk-types", rev = "339c2272fd5b8fb4e1fa6662cfa9acdbb0d05704", features = ["hash", "serde"] }
52+
53+
# async-graphql (use same fork as sui to avoid version conflicts)
54+
async-graphql = { git = "https://github.com/amnn/async-graphql", branch = "v7.0.1-react-18-graphiql-4", features = ["dataloader"] }
5255

5356
insta = "1.43.2"

crates/mvr-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
sui-package-resolver.workspace = true
8-
async-graphql = { version = "=7.0.1", features = ["dataloader"] }
8+
async-graphql.workspace = true
99
axum = "0.8.1"
1010
tokio = { workspace = true, features = ["full"] }
1111
tower-http = { version = "0.6.2", features = ["cors"] }

crates/mvr-api/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ pub async fn run_server(
3434
let registry = Registry::new_custom(Some("mvr_api".into()), None)
3535
.expect("Failed to create Prometheus registry.");
3636

37-
let metrics = MetricsService::new(
38-
MetricsArgs { metrics_address },
39-
registry,
40-
cancellation_token.clone(),
41-
);
37+
let metrics = MetricsService::new(MetricsArgs { metrics_address }, registry);
4238

4339
let mvr_source_header = HeaderName::from_str(MVR_SOURCE_HEADER)?;
4440

crates/mvr-indexer/src/handlers/git_info_handler.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ use mvr_schema::models::GitInfo;
1616
use serde::de::DeserializeOwned;
1717
use std::marker::PhantomData;
1818
use std::sync::Arc;
19-
use sui_indexer_alt_framework::pipeline::concurrent::Handler;
2019
use sui_indexer_alt_framework::pipeline::Processor;
21-
use sui_pg_db::{Connection, Db};
20+
use sui_indexer_alt_framework::postgres::{handler::Handler, Connection};
21+
use sui_indexer_alt_framework::types::full_checkpoint_content::Checkpoint;
2222
use sui_types::base_types::MoveObjectType;
23-
use sui_types::full_checkpoint_content::CheckpointData;
2423
use sui_types::object::Object;
2524

2625
pub struct GitInfoHandler<T> {
@@ -92,12 +91,10 @@ impl MoveObjectProcessor<TestnetGitInfo, GitInfo> for GitInfoHandler<TestnetGitI
9291
}
9392

9493
#[async_trait]
95-
impl<T: MoveStructType + DeserializeOwned> Handler for GitInfoHandler<T>
94+
impl<T: MoveStructType + DeserializeOwned + Send + Sync + 'static> Handler for GitInfoHandler<T>
9695
where
9796
Self: MoveObjectProcessor<T, GitInfo>,
9897
{
99-
type Store = Db;
100-
10198
async fn commit<'a>(
10299
values: &[Self::Value],
103100
conn: &mut Connection<'a>,
@@ -127,30 +124,32 @@ where
127124
}
128125
}
129126

130-
impl<T: MoveStructType + DeserializeOwned> Processor for GitInfoHandler<T>
127+
#[async_trait]
128+
impl<T: MoveStructType + DeserializeOwned + Send + Sync + 'static> Processor for GitInfoHandler<T>
131129
where
132130
Self: MoveObjectProcessor<T, GitInfo>,
133131
{
134132
const NAME: &'static str = Self::PROC_NAME;
135133
type Value = GitInfo;
136134

137-
fn process(&self, checkpoint: &Arc<CheckpointData>) -> anyhow::Result<Vec<Self::Value>> {
135+
async fn process(&self, checkpoint: &Arc<Checkpoint>) -> anyhow::Result<Vec<Self::Value>> {
138136
checkpoint
139137
.transactions
140138
.iter()
141139
.try_fold(vec![], |result, tx| {
142-
tx.output_objects.iter().try_fold(result, |mut result, o| {
143-
if matches!(o.type_(), Some(t) if t == &self.type_) {
144-
if let Some(move_obj) = o.data.try_as_move() {
145-
result.push(Self::process_move_object(
146-
self.chain_id.clone(),
147-
bcs::from_bytes(move_obj.contents())?,
148-
o,
149-
)?)
140+
tx.output_objects(&checkpoint.object_set)
141+
.try_fold(result, |mut result, o| {
142+
if matches!(o.type_(), Some(t) if t == &self.type_) {
143+
if let Some(move_obj) = o.data.try_as_move() {
144+
result.push(Self::process_move_object(
145+
self.chain_id.clone(),
146+
bcs::from_bytes(move_obj.contents())?,
147+
o,
148+
)?)
149+
}
150150
}
151-
}
152-
Ok(result)
153-
})
151+
Ok(result)
152+
})
154153
})
155154
}
156155
}

crates/mvr-indexer/src/handlers/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ use move_core_types::language_storage::StructTag as MoveStructTag;
1515
use mvr_schema::models::Package;
1616
use std::str::FromStr;
1717
use std::sync::Arc;
18-
use sui_indexer_alt_framework::pipeline::concurrent::Handler;
1918
use sui_indexer_alt_framework::pipeline::Processor;
20-
use sui_pg_db::{Connection, Db};
19+
use sui_indexer_alt_framework::postgres::{handler::Handler, Connection};
20+
use sui_indexer_alt_framework::types::full_checkpoint_content::Checkpoint;
2121
use sui_sdk_types::StructTag;
22-
use sui_types::full_checkpoint_content::CheckpointData;
2322
use tracing::info;
2423

2524
// Convert rust sdk struct tag to move struct tag.
@@ -80,21 +79,20 @@ pub struct NoOpsHandler;
8079

8180
#[async_trait]
8281
impl Handler for NoOpsHandler {
83-
type Store = Db;
84-
8582
async fn commit<'a>(_: &[Self::Value], _: &mut Connection<'a>) -> anyhow::Result<usize> {
8683
Ok(0)
8784
}
8885
}
8986

87+
#[async_trait]
9088
impl Processor for NoOpsHandler {
9189
const NAME: &'static str = "No Ops Handler";
9290
type Value = Package;
9391

94-
fn process(&self, checkpoint: &Arc<CheckpointData>) -> anyhow::Result<Vec<Self::Value>> {
92+
async fn process(&self, checkpoint: &Arc<Checkpoint>) -> anyhow::Result<Vec<Self::Value>> {
9593
info!(
9694
"Processed checkpoint: {}",
97-
checkpoint.checkpoint_summary.sequence_number
95+
checkpoint.summary.sequence_number
9896
);
9997
Ok(vec![])
10098
}

crates/mvr-indexer/src/handlers/name_record_handler.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ use mvr_types::name::Name;
1212
use mvr_types::name_service::Domain;
1313
use std::str::FromStr;
1414
use std::sync::Arc;
15-
use sui_indexer_alt_framework::pipeline::concurrent::Handler;
1615
use sui_indexer_alt_framework::pipeline::Processor;
17-
use sui_pg_db::{Connection, Db};
16+
use sui_indexer_alt_framework::postgres::{handler::Handler, Connection};
17+
use sui_indexer_alt_framework::types::full_checkpoint_content::Checkpoint;
1818
use sui_sdk_types::StructTag;
1919
use sui_types::base_types::MoveObjectType;
2020
use sui_types::dynamic_field::Field;
21-
use sui_types::full_checkpoint_content::CheckpointData;
2221

2322
pub struct NameRecordHandler {
2423
type_: MoveObjectType,
@@ -53,8 +52,6 @@ impl NameRecordHandler {
5352
}
5453
#[async_trait]
5554
impl Handler for NameRecordHandler {
56-
type Store = Db;
57-
5855
async fn commit<'a>(
5956
values: &[Self::Value],
6057
conn: &mut Connection<'a>,
@@ -83,44 +80,46 @@ impl Handler for NameRecordHandler {
8380
}
8481
}
8582

83+
#[async_trait]
8684
impl Processor for NameRecordHandler {
8785
const NAME: &'static str = "NameRecord";
8886
type Value = NameRecord;
8987

90-
fn process(&self, checkpoint: &Arc<CheckpointData>) -> anyhow::Result<Vec<Self::Value>> {
88+
async fn process(&self, checkpoint: &Arc<Checkpoint>) -> anyhow::Result<Vec<Self::Value>> {
9189
checkpoint
9290
.transactions
9391
.iter()
9492
.try_fold(vec![], |result, tx| {
95-
tx.output_objects.iter().try_fold(result, |mut result, o| {
96-
// TODO: do we need to check if the parent of the DF table entry is the MVR registry?
97-
if matches!(o.type_(), Some(t) if t == &self.type_) {
98-
if let Some(move_obj) = o.data.try_as_move() {
99-
let data: Field<Name, AppRecord> =
100-
bcs::from_bytes(move_obj.contents())?;
101-
let Name { org, app } = data.name;
102-
let name = Name::new(Domain { labels: org.labels }, app);
103-
let AppRecord {
104-
app_info,
105-
networks,
106-
metadata,
107-
..
108-
} = data.value;
93+
tx.output_objects(&checkpoint.object_set)
94+
.try_fold(result, |mut result, o| {
95+
// TODO: do we need to check if the parent of the DF table entry is the MVR registry?
96+
if matches!(o.type_(), Some(t) if t == &self.type_) {
97+
if let Some(move_obj) = o.data.try_as_move() {
98+
let data: Field<Name, AppRecord> =
99+
bcs::from_bytes(move_obj.contents())?;
100+
let Name { org, app } = data.name;
101+
let name = Name::new(Domain { labels: org.labels }, app);
102+
let AppRecord {
103+
app_info,
104+
networks,
105+
metadata,
106+
..
107+
} = data.value;
109108

110-
result.push(NameRecord {
111-
name: name.to_string(),
112-
object_version: o.version().value() as i64,
113-
mainnet_id: app_info
114-
.and_then(|info| Some(info.package_info_id?.to_string())),
115-
testnet_id: networks
116-
.get(&TESTNET_CHAIN_ID.to_string())
117-
.and_then(|info| Some(info.package_info_id?.to_string())),
118-
metadata: serde_json::to_value(into_hash_map(metadata))?,
119-
})
109+
result.push(NameRecord {
110+
name: name.to_string(),
111+
object_version: o.version().value() as i64,
112+
mainnet_id: app_info
113+
.and_then(|info| Some(info.package_info_id?.to_string())),
114+
testnet_id: networks
115+
.get(&TESTNET_CHAIN_ID.to_string())
116+
.and_then(|info| Some(info.package_info_id?.to_string())),
117+
metadata: serde_json::to_value(into_hash_map(metadata))?,
118+
})
119+
}
120120
}
121-
}
122-
Ok(result)
123-
})
121+
Ok(result)
122+
})
124123
})
125124
}
126125
}

crates/mvr-indexer/src/handlers/package_handler.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use crate::{MAINNET_CHAIN_ID, TESTNET_CHAIN_ID};
2+
use async_trait::async_trait;
23
use chrono::DateTime;
34
use diesel_async::RunQueryDsl;
45
use itertools::Itertools;
56
use move_binary_format::CompiledModule;
67
use mvr_schema::models::{Package, PackageDependency};
78
use std::collections::HashSet;
89
use std::sync::Arc;
9-
use sui_indexer_alt_framework::pipeline::concurrent::Handler;
1010
use sui_indexer_alt_framework::pipeline::Processor;
11-
use sui_pg_db::{Connection, Db};
11+
use sui_indexer_alt_framework::postgres::{handler::Handler, Connection};
12+
use sui_indexer_alt_framework::types::full_checkpoint_content::Checkpoint;
1213
use sui_types::base_types::ObjectID;
13-
use sui_types::full_checkpoint_content::CheckpointData;
1414
use sui_types::move_package::MovePackage;
1515
use sui_types::object::Data;
16+
use sui_types::transaction::TransactionDataAPI;
1617

1718
pub struct PackageHandler<const MAINNET: bool>;
1819

@@ -24,10 +25,8 @@ impl<const MAINNET: bool> PackageHandler<MAINNET> {
2425
};
2526
}
2627

27-
#[async_trait::async_trait]
28+
#[async_trait]
2829
impl<const MAINNET: bool> Handler for PackageHandler<MAINNET> {
29-
type Store = Db;
30-
3130
async fn commit<'a>(
3231
values: &[Self::Value],
3332
conn: &mut Connection<'a>,
@@ -53,6 +52,7 @@ impl<const MAINNET: bool> Handler for PackageHandler<MAINNET> {
5352
}
5453
}
5554

55+
#[async_trait]
5656
impl<const MAINNET: bool> Processor for PackageHandler<MAINNET> {
5757
const NAME: &'static str = if MAINNET {
5858
"Package - Mainnet"
@@ -61,15 +61,14 @@ impl<const MAINNET: bool> Processor for PackageHandler<MAINNET> {
6161
};
6262
type Value = Package;
6363

64-
fn process(&self, checkpoint: &Arc<CheckpointData>) -> anyhow::Result<Vec<Self::Value>> {
65-
let timestamp =
66-
DateTime::from_timestamp_millis(checkpoint.checkpoint_summary.timestamp_ms as i64)
67-
.unwrap()
68-
.naive_utc();
64+
async fn process(&self, checkpoint: &Arc<Checkpoint>) -> anyhow::Result<Vec<Self::Value>> {
65+
let timestamp = DateTime::from_timestamp_millis(checkpoint.summary.timestamp_ms as i64)
66+
.unwrap()
67+
.naive_utc();
6968

7069
let mut results = vec![];
7170
for tx in &checkpoint.transactions {
72-
for o in &tx.output_objects {
71+
for o in tx.output_objects(&checkpoint.object_set) {
7372
if let Data::Package(p) = &o.data {
7473
let package_id = p.id().to_hex_uncompressed();
7574
let deps = package_dependencies(Self::CHAIN_ID.to_string(), p)?;
@@ -80,7 +79,7 @@ impl<const MAINNET: bool> Processor for PackageHandler<MAINNET> {
8079
move_package: bcs::to_bytes(p)?,
8180
chain_id: Self::CHAIN_ID.to_string(),
8281
tx_hash: tx.transaction.digest().base58_encode(),
83-
sender: tx.transaction.sender_address().to_string(),
82+
sender: tx.transaction.sender().to_string(),
8483
timestamp,
8584
deps,
8685
})

crates/mvr-indexer/src/handlers/package_info_handler.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ use mvr_schema::models::PackageInfo;
1212
use serde::de::DeserializeOwned;
1313
use std::marker::PhantomData;
1414
use std::sync::Arc;
15-
use sui_indexer_alt_framework::pipeline::concurrent::Handler;
1615
use sui_indexer_alt_framework::pipeline::Processor;
17-
use sui_pg_db::{Connection, Db};
16+
use sui_indexer_alt_framework::postgres::{handler::Handler, Connection};
17+
use sui_indexer_alt_framework::types::full_checkpoint_content::Checkpoint;
1818
use sui_sdk_types::Address;
1919
use sui_types::collection_types::VecMap;
20-
use sui_types::full_checkpoint_content::CheckpointData;
2120
use sui_types::object::Object;
2221

2322
const DEFAULT_NAME_KEY: &str = "default";
@@ -114,12 +113,10 @@ impl MoveObjectProcessor<TestnetPackageInfo, PackageInfo>
114113
}
115114

116115
#[async_trait]
117-
impl<T: MoveStructType + DeserializeOwned> Handler for PackageInfoHandler<T>
116+
impl<T: MoveStructType + DeserializeOwned + Send + Sync + 'static> Handler for PackageInfoHandler<T>
118117
where
119118
Self: MoveObjectProcessor<T, PackageInfo>,
120119
{
121-
type Store = Db;
122-
123120
async fn commit<'a>(
124121
values: &[Self::Value],
125122
conn: &mut Connection<'a>,
@@ -149,16 +146,18 @@ where
149146
}
150147
}
151148

152-
impl<T: MoveStructType + DeserializeOwned> Processor for PackageInfoHandler<T>
149+
#[async_trait]
150+
impl<T: MoveStructType + DeserializeOwned + Send + Sync + 'static> Processor
151+
for PackageInfoHandler<T>
153152
where
154153
Self: MoveObjectProcessor<T, PackageInfo>,
155154
{
156155
const NAME: &'static str = Self::PROC_NAME;
157156
type Value = PackageInfo;
158157

159-
fn process(&self, checkpoint: &Arc<CheckpointData>) -> anyhow::Result<Vec<Self::Value>> {
158+
async fn process(&self, checkpoint: &Arc<Checkpoint>) -> anyhow::Result<Vec<Self::Value>> {
160159
checkpoint.transactions.iter().try_fold(vec![], |result, tx| {
161-
tx.output_objects.iter().try_fold(result, |mut result, obj| {
160+
tx.output_objects(&checkpoint.object_set).try_fold(result, |mut result, obj| {
162161
if matches!(obj.type_(), Some(t) if matches!(t.other(), Some(s) if s == &convert_struct_tag(T::struct_type())) ) {
163162
if let Some(move_obj) = obj.data.try_as_move() {
164163
let move_obj: T = bcs::from_bytes(move_obj.contents())?;

0 commit comments

Comments
 (0)