Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiate subgraphs #140

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions grafana.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
"datasource": "${DS_SUBGRAPHRADIOGRAPHQL}",
"endTimePath": "endTime",
"groupBy": "null",
"queryText": "query {\n data:comparisonRatio{\n deployment\n blockNumber\n senderRatio\n stakeRatio\n }\n}",
"queryText": "query {\n data:comparisonRatio{\n deployment\n blockNumber\n senderRatio\n stakeRatio\n allocated\n}\n}",
"refId": "A",
"timePath": "Time"
}
Expand All @@ -512,7 +512,8 @@
"_blockNumber": "Block Number",
"_deployment": "Deployment",
"_senderRatio": "Count Ratio",
"_stakeRatio": "Stake Ratio"
"_stakeRatio": "Stake Ratio",
"_allocated": "Allocated"
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion subgraph-radio/benches/attestations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod attestation {
use criterion::{black_box, criterion_group, Criterion};
use graphcast_sdk::graphcast_agent::message_typing::GraphcastMessage;
use sqlx::SqlitePool;
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use subgraph_radio::{
database::{insert_local_attestation, insert_remote_ppoi_message},
messages::poi::PublicPoiMessage,
Expand Down Expand Up @@ -75,6 +75,7 @@ mod attestation {
42,
black_box(&remote_attestations.clone()),
"my-awesome-hash",
HashSet::new(),
)
})
});
Expand All @@ -87,6 +88,7 @@ mod attestation {
.await
.expect("Failed to connect to the in-memory database"),
);

black_box(
sqlx::migrate!("../migrations")
.run(&pool)
Expand Down
75 changes: 54 additions & 21 deletions subgraph-radio/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ pub async fn get_local_attestation(

let attestation = Attestation {
identifier: data.identifier,
block_number: data.block_number as u64,
block_number: data
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
hopeyen marked this conversation as resolved.
Show resolved Hide resolved
ppoi: data.ppoi,
stake_weight: data.stake_weight as u64,
stake_weight: data
.stake_weight
.parse::<u64>()
.expect("Failed to parse as u64"),
senders,
sender_group_hash: data.sender_group_hash,
timestamp: timestamps,
Expand Down Expand Up @@ -119,9 +125,15 @@ pub async fn get_local_attestations_by_identifier(

full_attestations.push(Attestation {
identifier: att.identifier,
block_number: att.block_number as u64,
block_number: att
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
ppoi: att.ppoi,
stake_weight: att.stake_weight as u64,
stake_weight: att
.stake_weight
.parse::<u64>()
.expect("Failed to parse as u64"),
senders,
sender_group_hash: att.sender_group_hash,
timestamp: timestamps,
Expand Down Expand Up @@ -158,9 +170,15 @@ pub async fn get_local_attestations(pool: &SqlitePool) -> Result<Vec<Attestation

full_attestations.push(Attestation {
identifier: record.identifier,
block_number: record.block_number as u64,
block_number: record
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
ppoi: record.ppoi,
stake_weight: record.stake_weight as u64,
stake_weight: record
.stake_weight
.parse::<u64>()
.expect("Failed to parse as u64"),
sender_group_hash: record.sender_group_hash,
senders,
timestamp: timestamps,
Expand Down Expand Up @@ -251,15 +269,18 @@ pub async fn get_remote_ppoi_messages(
.into_iter()
.map(|row| GraphcastMessage {
identifier: row.identifier.clone(),
nonce: row.nonce as u64,
nonce: row.nonce.parse::<u64>().expect("Failed to parse as u64"),
graph_account: row.graph_account.clone(),
signature: row.signature,
payload: PublicPoiMessage {
identifier: row.identifier,
content: row.content,
nonce: row.nonce as u64,
nonce: row.nonce.parse::<u64>().expect("Failed to parse as u64"),
network: row.network,
block_number: row.block_number as u64,
block_number: row
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
block_hash: row.block_hash,
graph_account: row.graph_account,
},
Expand Down Expand Up @@ -288,15 +309,18 @@ pub async fn get_remote_ppoi_messages_by_identifier(
.into_iter()
.map(|row| GraphcastMessage {
identifier: row.identifier.clone(),
nonce: row.nonce as u64,
nonce: row.nonce.parse::<u64>().expect("Failed to parse as u64"),
graph_account: row.graph_account.clone(),
signature: row.signature,
payload: PublicPoiMessage {
identifier: row.identifier,
content: row.content,
nonce: row.nonce as u64,
nonce: row.nonce.parse::<u64>().expect("Failed to parse as u64"),
network: row.network,
block_number: row.block_number as u64,
block_number: row
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
block_hash: row.block_hash,
graph_account: row.graph_account,
},
Expand Down Expand Up @@ -381,13 +405,13 @@ pub async fn get_upgrade_intent_message(
deployment: msg.deployment.clone(),
subgraph_id: msg.subgraph_id,
new_hash: msg.new_hash,
nonce: msg.nonce as u64,
nonce: msg.nonce.parse::<u64>().expect("Failed to parse as u64"),
graph_account: msg.graph_account.clone(),
};

let graphcast_message = GraphcastMessage::new(
msg.deployment,
msg.nonce as u64,
msg.nonce.parse::<u64>().expect("Failed to parse as u64"),
msg.graph_account,
payload,
msg.signature,
Expand Down Expand Up @@ -420,13 +444,13 @@ pub async fn get_upgrade_intent_message_by_id(
deployment: msg.deployment.clone(),
subgraph_id: msg.subgraph_id,
new_hash: msg.new_hash,
nonce: msg.nonce as u64,
nonce: msg.nonce.parse::<u64>().expect("Failed to parse as u64"),
graph_account: msg.graph_account.clone(),
};

let graphcast_message = GraphcastMessage::new(
msg.deployment,
msg.nonce as u64,
msg.nonce.parse::<u64>().expect("Failed to parse as u64"),
msg.graph_account,
payload,
msg.signature,
Expand Down Expand Up @@ -456,13 +480,13 @@ pub async fn get_upgrade_intent_messages(
deployment: msg.deployment.clone(),
subgraph_id: msg.subgraph_id,
new_hash: msg.new_hash,
nonce: msg.nonce as u64,
nonce: msg.nonce.parse::<u64>().expect("Failed to parse as u64"),
graph_account: msg.graph_account.clone(),
};

let graphcast_message = GraphcastMessage::new(
msg.deployment,
msg.nonce as u64,
msg.nonce.parse::<u64>().expect("Failed to parse as u64"),
msg.graph_account,
payload,
msg.signature,
Expand Down Expand Up @@ -622,7 +646,10 @@ pub async fn get_comparison_results(

results.push(ComparisonResult {
deployment: row.deployment,
block_number: row.block_number as u64,
block_number: row
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
result_type: ComparisonResultType::from_str(&row.result_type)?,
local_attestation,
attestations,
Expand Down Expand Up @@ -659,7 +686,10 @@ pub async fn get_comparison_results_by_type(
.map_err(DatabaseError::ParseError)
.map(|result_type| ComparisonResult {
deployment: row.deployment,
block_number: row.block_number as u64,
block_number: row
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
result_type,
local_attestation,
attestations,
Expand Down Expand Up @@ -692,7 +722,10 @@ pub async fn get_comparison_results_by_deployment(

Ok(ComparisonResult {
deployment: row.deployment,
block_number: row.block_number as u64,
block_number: row
.block_number
.parse::<u64>()
.expect("Failed to parse as u64"),
result_type: ComparisonResultType::from_str(&row.result_type)?,
local_attestation,
attestations,
Expand Down
6 changes: 4 additions & 2 deletions subgraph-radio/src/database/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(test)]
mod tests {
use std::collections::HashSet;

use graphcast_sdk::{graphcast_agent::message_typing::GraphcastMessage, networks::NetworkName};
use sqlx::SqlitePool;

Expand Down Expand Up @@ -189,7 +191,7 @@ mod tests {
attestations: Vec::new(),
};

let _ = handle_comparison_result(&pool, &new_result).await;
let _ = handle_comparison_result(&pool, &new_result, HashSet::new()).await;
let comparison_results = get_comparison_results(&pool).await.unwrap();
let result = comparison_results.first().unwrap();

Expand Down Expand Up @@ -223,7 +225,7 @@ mod tests {
};

let _ = save_comparison_result(&pool, &old_result).await;
let _ = handle_comparison_result(&pool, &new_result).await;
let _ = handle_comparison_result(&pool, &new_result, HashSet::new()).await;

let comparison_results = get_comparison_results(&pool).await.unwrap();
assert_eq!(
Expand Down
Loading
Loading