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

Idea for fix issue #264 #277

Merged
merged 1 commit into from
May 2, 2024
Merged

Idea for fix issue #264 #277

merged 1 commit into from
May 2, 2024

Conversation

arkanoider
Copy link
Collaborator

@arkanoider arkanoider commented May 1, 2024

Hi @grunch ,

first idea for fix the issue #264 .

Modified a bit this function pubkey_event_can_solve

pub async fn pubkey_event_can_solve(
    pool: &Pool<Sqlite>,
    ev_pubkey: &PublicKey,
    status: Status,
) -> bool {
    if let Ok(my_keys) = crate::util::get_keys() {
        // Is mostro admin taking dispute?
        if ev_pubkey.to_string() == my_keys.public_key().to_string()
            && matches!(status, Status::InProgress | Status::Initiated)
        {
            return true;
        }
    }

    // Is a solver taking a dispute
    if let Ok(solver) = find_solver_pubkey(pool, ev_pubkey.to_string()).await {
        if solver.is_solver != 0_i64 && status == Status::Initiated {
            return true;
        }
    }

    false
}

In this way if a solver takes first a dispute we have to check that dispute is in Initiated state, which (imo) is the only one a solver can take.
While an admin can overtake also InProgress state, so now he will become the solver and other solvers cannot take the dispute again.

You will see that I removed also pubkey_event_can_solve from admin_cancel.rs and admin_settle.rs because ( still imo ) they are redundat because of is_assigned_solver that is responsible to check if the pubkey of message is the solver.
If, for example, an admin overtake a solver dispute he will be the new solver so the check below should be enough.

   match is_assigned_solver(pool, &event.pubkey.to_string(), order_id).await {
        Ok(false) => {
            send_cant_do_msg(
                None,
                Some("Dispute not taken by you".to_string()),
                &event.pubkey,
            )
            .await;

            return Ok(());
        }
        Err(e) => {
            error!("Error checking if solver is assigned to order: {:?}", e);
            return Ok(());
        }
        _ => {}
    }

Let me know!

Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grunch grunch merged commit 1092fbc into MostroP2P:main May 2, 2024
1 check passed
@arkanoider arkanoider deleted the fix-#264 branch May 2, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants