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

[mkt] proposal self reaction attempt check #914

Merged
merged 7 commits into from
Jan 21, 2021
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
23 changes: 9 additions & 14 deletions core/market/src/negotiation/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::db::{
TakeEventsError,
},
model::{
Agreement, AgreementEvent, AgreementId, AgreementState, AppSessionId, Issuer, MarketEvent,
Owner, Proposal, ProposalId, ProposalState, SubscriptionId,
Agreement, AgreementEvent, AgreementId, AgreementState, AppSessionId, MarketEvent, Owner,
Proposal, ProposalId, ProposalState, SubscriptionId,
},
};
use crate::matcher::{store::SubscriptionStore, RawProposal};
Expand Down Expand Up @@ -116,12 +116,6 @@ impl CommonBroker {
self.validate_proposal(&prev_proposal, caller_id, caller_role)
.await?;

if prev_proposal.body.issuer == Issuer::Us {
Err(ProposalValidationError::OwnProposal(
prev_proposal.body.id.clone(),
))?;
}

let is_first = prev_proposal.body.prev_proposal_id.is_none();
let new_proposal = prev_proposal.from_client(proposal)?;

Expand Down Expand Up @@ -153,12 +147,6 @@ impl CommonBroker {
self.validate_proposal(&proposal, caller_id, caller_role)
.await?;

if proposal.body.issuer == Issuer::Us && proposal_id.owner() == caller_role {
let e = ProposalValidationError::OwnProposal(proposal.body.id.clone());
log::warn!("{}", e);
Err(e)?;
}

self.db
.as_dao::<ProposalDao>()
.change_proposal_state(proposal_id, ProposalState::Rejected)
Expand Down Expand Up @@ -643,6 +631,13 @@ impl CommonBroker {
ProposalValidationError::Unauthorized(proposal.body.id.clone(), caller_id.clone());
}

if &proposal.issuer() == caller_id {
let e = ProposalValidationError::OwnProposal(proposal.body.id.clone());
log::warn!("{}", e);
counter!("market.proposals.self-reaction-attempt", 1);
Err(e)?;
}

// check Offer
self.store.get_offer(&proposal.negotiation.offer_id).await?;

Expand Down
1 change: 1 addition & 0 deletions core/market/src/negotiation/requestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl RequestorBroker {
counter!("market.proposals.requestor.received", 0);
counter!("market.proposals.requestor.rejected.by-them", 0);
counter!("market.proposals.requestor.rejected.by-us", 0);
counter!("market.proposals.self-reaction-attempt", 0);

tokio::spawn(proposal_receiver_thread(broker, proposal_receiver));
Ok(engine)
Expand Down