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

WIP: Add Database entries for every transfer failure #362

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

# most popular python virtual enviroment folder name
venv

# ctags files
rusty-tags.*
21 changes: 21 additions & 0 deletions glados-audit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use chrono::Utc;
use cli::Args;
use ethportal_api::types::query_trace::QueryTrace;
use ethportal_api::{utils::bytes::hex_encode, HistoryContentKey, OverlayContentKey};
use sea_orm::DatabaseConnection;
use serde_json::json;
Expand Down Expand Up @@ -424,6 +425,10 @@ async fn perform_single_audit(
return;
};

if let Some(trace) = trace {
create_entry_for_failures(task.content.clone(), client_info_id, node_id, trace, &conn).await;
}

// Display audit result.
match task.content.protocol_id {
SubProtocol::History => {
Expand All @@ -448,6 +453,22 @@ async fn perform_single_audit(
active_threads.fetch_sub(1, Ordering::Relaxed);
}

// For each transfer failure in the trace, create a new entry in the database.
async fn create_entry_for_failures(
task_content: content::Model,
client_info_id: i32,
node_id: i32,
trace: QueryTrace,
conn: &DatabaseConnection,
) {
// Create a list of the failures from the parsed trace json
for (sender_node_id, fail_type) in trace.failures.iter() {
// For now, just log out the failure, and related info.
// Later, write this data into a new table in the database.
info!("Found a new transfer failure: Sender: {sender_node_id}, FailureType: {fail_type:?}, ContentID: {}, recipient_client_info_id: {client_info_id}, recipient_node: {node_id}", task_content.id);
}
}

async fn display_history_audit_result(
content: content::Model,
audit_result: bool,
Expand Down
4 changes: 3 additions & 1 deletion migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ mod m20240814_121507_census_subnetwork;
mod m20240919_121611_census_subnetwork_index;
mod m20241010_151313_audit_stats_performance;
mod m20241206_154045_add_beacon_and_state_audit_stats;
mod m20250130_042751_create_audit_internal_failures;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20230508_111707_create_census_tables::Migration),
Box::new(m20230511_104804_create_node::Migration),
Box::new(m20230511_104811_create_record::Migration),
Box::new(m20230511_104814_create_content::Migration),
Box::new(m20230511_104823_create_client_info::Migration),
Box::new(m20230511_104830_create_content_audit::Migration),
Box::new(m20230511_104838_create_execution_metadata::Migration),
Box::new(m20230511_104937_create_key_value::Migration),
Box::new(m20230508_111707_create_census_tables::Migration),
Box::new(m20231107_004843_create_audit_stats::Migration),
Box::new(m20240213_190221_add_fourfours_stats::Migration),
Box::new(m20240322_205213_add_content_audit_index::Migration),
Expand All @@ -41,6 +42,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240919_121611_census_subnetwork_index::Migration),
Box::new(m20241010_151313_audit_stats_performance::Migration),
Box::new(m20241206_154045_add_beacon_and_state_audit_stats::Migration),
Box::new(m20250130_042751_create_audit_internal_failures::Migration),
]
}
}
112 changes: 112 additions & 0 deletions migration/src/m20250130_042751_create_audit_internal_failures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
todo!();

manager
.create_table(
Table::create()
.table(AuditInternalFailure::Table)
.if_not_exists()
.col(
ColumnDef::new(AuditInternalFailure::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(AuditInternalFailure::Audit)
.integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("FK_auditinternalfailure_audit")
.from(AuditInternalFailure::Table, AuditInternalFailure::Audit)
.to(Audit::Table, Audit::Id)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.col(
ColumnDef::new(AuditInternalFailure::SenderClientInfo)
.integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("FK_auditinternalfailure_sender_client_info")
.from(
AuditInternalFailure::Table,
AuditInternalFailure::SenderClientInfo,
)
.to(ClientInfo::Table, ClientInfo::Id),
)
.col(
ColumnDef::new(AuditInternalFailure::SenderNode)
.integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("FK_auditinternalfailure_sender_node")
.from(AuditInternalFailure::Table, AuditInternalFailure::SenderNode)
.to(Node::Table, Node::Id),
)
.col(
ColumnDef::new(AuditInternalFailure::FailureType)
.integer()
.not_null(),
)
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
todo!();

manager
.drop_table(Table::drop().table(Post::Table).to_owned())
.await
}
}

#[derive(Iden)]
enum AuditInternalFailure {
Table,
Id,
// Foreign key
Audit,
// Foreign key
SenderClientInfo,
// Foreign key
SenderNode,
// Custom enum
FailureType,
}

#[derive(Iden)]
enum Audit {
Table,
Id,
}

#[derive(Iden)]
enum ClientInfo {
Table,
Id,
}

#[derive(Iden)]
enum Content {
Table,
Id,
}