Skip to content

Commit

Permalink
Add more logs to the relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Dec 20, 2024
1 parent be63421 commit acb60c1
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 12 deletions.
34 changes: 33 additions & 1 deletion packages/relayer/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub async fn handle_email(email: String) -> Result<EmailAuthEvent, EmailError> {
let padded_from_addr = PaddedEmailAddr::from_email_addr(&guardian_email_addr);
trace!(LOG, "From address: {}", guardian_email_addr);
let email_body = parsed_email.get_cleaned_body()?;
trace!(LOG, "Email body: {}", email_body);

let request_def_path =
PathBuf::from(REGEX_JSON_DIR_PATH.get().unwrap()).join("request_def.json");
Expand All @@ -53,6 +54,7 @@ pub async fn handle_email(email: String) -> Result<EmailAuthEvent, EmailError> {
}
info!(LOG, "Request idxes: {:?}", request_idxes);
let request_id = &email[request_idxes[0].0..request_idxes[0].1];
info!(LOG, "Request ID: {}", request_id);
let request_id_u32 = request_id
.parse::<u32>()
.map_err(|e| EmailError::Parse(format!("Failed to parse request_id to u64: {}", e)))?;
Expand All @@ -70,7 +72,14 @@ pub async fn handle_email(email: String) -> Result<EmailAuthEvent, EmailError> {
});
}
};
trace!(LOG, "Request: {:?}", request);
if request.guardian_email_addr != guardian_email_addr {
error!(
LOG,
"Guardian email address in the request {} is not equal to the one in the email {}",
request.guardian_email_addr,
guardian_email_addr
);
return Err(EmailError::EmailAddress(format!(
"Guardian email address in the request {} is not equal to the one in the email {}",
request.guardian_email_addr, guardian_email_addr
Expand All @@ -84,6 +93,7 @@ pub async fn handle_email(email: String) -> Result<EmailAuthEvent, EmailError> {
"The user of the wallet address {} and the email address {} is not registered.",
request.account_eth_addr, guardian_email_addr
)))?;
trace!(LOG, "Account code: {}", account_code_str);

check_and_update_dkim(
&email,
Expand All @@ -99,6 +109,7 @@ pub async fn handle_email(email: String) -> Result<EmailAuthEvent, EmailError> {
Ok(code) => Some(code),
Err(_) => None,
};
trace!(LOG, "Invitation code: {:?}", invitation_code);

let params = EmailRequestContext {
request,
Expand Down Expand Up @@ -128,6 +139,12 @@ async fn handle_email_request(
match (invitation_code, params.request.is_for_recovery) {
(Some(invitation_code), is_for_recovery) if !is_for_recovery => {
if params.account_code_str != invitation_code {
error!(
LOG,
"Stored account code is not equal to one in the email. Stored: {}, Email: {}",
params.account_code_str,
invitation_code
);
return Err(EmailError::Body(format!(
"Stored account code is not equal to one in the email. Stored: {}, Email: {}",
params.account_code_str, invitation_code
Expand Down Expand Up @@ -191,6 +208,7 @@ async fn accept(
params.request.template_idx,
)
.await?;
info!(LOG, "Is accepted: {}", is_accepted);

update_request(
&params,
Expand All @@ -209,6 +227,7 @@ async fn accept(
is_set: true,
};
DB.update_credentials_of_account_code(&creds).await?;
trace!(LOG, "Credentials updated: {:?}", creds);

Ok(EmailAuthEvent::AcceptanceSuccess {
account_eth_addr: params.request.account_eth_addr,
Expand All @@ -219,6 +238,12 @@ async fn accept(
})
} else {
let original_subject = params.parsed_email.get_subject_all()?;
error!(
LOG,
"Failed to handle acceptance for request_id: {}. Original subject: {}",
params.request.request_id,
original_subject
);
Ok(EmailAuthEvent::Error {
email_addr: params.request.guardian_email_addr.clone(),
error: "Failed to handle acceptance".to_string(),
Expand Down Expand Up @@ -255,7 +280,7 @@ async fn recover(params: EmailRequestContext) -> Result<EmailAuthEvent, EmailErr
params.request.template_idx,
)
.await?;

info!(LOG, "Is success: {}", is_success);
update_request(
&params,
is_success,
Expand All @@ -266,6 +291,7 @@ async fn recover(params: EmailRequestContext) -> Result<EmailAuthEvent, EmailErr

let original_subject = params.parsed_email.get_subject_all()?;
if is_success {
trace!(LOG, "Recovery success");
Ok(EmailAuthEvent::RecoverySuccess {
account_eth_addr: params.request.account_eth_addr,
guardian_email_addr: params.request.guardian_email_addr,
Expand All @@ -275,6 +301,12 @@ async fn recover(params: EmailRequestContext) -> Result<EmailAuthEvent, EmailErr
})
} else {
let original_subject = params.parsed_email.get_subject_all()?;
error!(
LOG,
"Failed to handle recovery for request_id: {}. Original subject: {}",
params.request.request_id,
original_subject
);
Ok(EmailAuthEvent::Error {
email_addr: params.request.guardian_email_addr.clone(),
error: "Failed to handle recovery".to_string(),
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/src/modules/dkim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub async fn check_and_update_dkim(
.get_email_auth_addr_from_wallet(controller_eth_addr, wallet_addr, account_salt)
.await?;
let email_auth_addr = format!("0x{:x}", email_auth_addr);
info!(LOG, "email_auth_addr {:?}", email_auth_addr);

// Get DKIM from controller or email auth
let mut dkim = CLIENT.get_dkim_from_controller(controller_eth_addr).await?;
Expand Down
Loading

0 comments on commit acb60c1

Please sign in to comment.