Skip to content

Commit

Permalink
Merge pull request #952 from golemfactory/payment-status/edited
Browse files Browse the repository at this point in the history
Payment CLI changes
  • Loading branch information
Wiezzel authored Jan 21, 2021
2 parents b88aa7f + 53b2211 commit edcdf76
Show file tree
Hide file tree
Showing 25 changed files with 452 additions and 131 deletions.
40 changes: 38 additions & 2 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions agent/provider/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It is rather straightforward and minimal:
* requires `golem.srv.comp.expiration` to be set
* if provided (via env or CLI) sets also `golem.node.debug.subnet`
* properties:
* linear pricing (see sample below: 0.01 NGNT/sec + 1.2 NGNT/CPUsec + 1.5 NGNT const)
* linear pricing (see sample below: 0.01 GLM/sec + 1.2 GLM/CPUsec + 1.5 GLM const)
* hardware: memory and storage (sample below: 1 gib RAM and 10 gib disk)
* node name set via env or CLI
* runtime (sample below: wasmtime)
Expand Down Expand Up @@ -203,9 +203,9 @@ Name: default
ExeUnit: wasmtime
Pricing model: linear
Coefficients:
Duration 0.1 NGNT
CPU 0.2 NGNT
Init price 1 NGNT
Duration 0.1 GLM
CPU 0.2 GLM
Init price 1 GLM
```

Expand Down
2 changes: 1 addition & 1 deletion agent/provider/src/market/presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ impl fmt::Display for Preset {
for (name, coeff) in self.usage_coeffs.iter() {
write!(
f,
" {:width$}{} NGNT\n",
" {:width$}{} GLM\n",
name.to_readable(),
coeff,
width = align_coeff
Expand Down
2 changes: 1 addition & 1 deletion agent/provider/src/preset_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl PresetUpdater {
.cloned()
.unwrap_or(0.);
let price = Input::<f64>::new()
.with_prompt(&format!("{} (NGNT)", coefficient.to_readable()))
.with_prompt(&format!("{} (GLM)", coefficient.to_readable()))
.default(prev_price)
.show_default(true)
.interact()?;
Expand Down
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
7 changes: 6 additions & 1 deletion core/model/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ pub mod local {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GetStatus {
pub platform: String,
pub address: String,
pub driver: String,
pub network: Option<String>,
pub token: Option<String>,
}

impl RpcMessage for GetStatus {
Expand All @@ -248,6 +250,9 @@ pub mod local {
pub reserved: BigDecimal,
pub outgoing: StatusNotes,
pub incoming: StatusNotes,
pub driver: String,
pub network: String,
pub token: String,
}

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
Expand Down
8 changes: 4 additions & 4 deletions core/payment/examples/cancel_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn main() -> anyhow::Result<()> {
payment_due_date: Some(Utc::now()),
};
log::info!(
"Issuing debit note for activity 1 (total amount due: {} NGNT)...",
"Issuing debit note for activity 1 (total amount due: {} GLM)...",
&debit_note.total_amount_due
);
let debit_note = provider.issue_debit_note(&debit_note).await?;
Expand All @@ -84,7 +84,7 @@ async fn main() -> anyhow::Result<()> {
payment_due_date: Some(Utc::now()),
};
log::info!(
"Issuing debit note for activity 2 (total amount due: {} NGNT)...",
"Issuing debit note for activity 2 (total amount due: {} GLM)...",
debit_note2.total_amount_due
);
let debit_note2 = provider.issue_debit_note(&debit_note2).await?;
Expand All @@ -107,7 +107,7 @@ async fn main() -> anyhow::Result<()> {
amount: BigDecimal::from(3u64),
payment_due_date: Utc::now(),
};
log::info!("Issuing invoice (amount: {} NGNT)...", &invoice.amount);
log::info!("Issuing invoice (amount: {} GLM)...", &invoice.amount);
let invoice = provider.issue_invoice(&invoice).await?;
log::info!("Invoice issued.");

Expand Down Expand Up @@ -178,7 +178,7 @@ async fn main() -> anyhow::Result<()> {
amount: BigDecimal::from(3u64),
payment_due_date: Utc::now(),
};
log::info!("Issuing invoice (amount: {} NGNT)...", &invoice.amount);
log::info!("Issuing invoice (amount: {} GLM)...", &invoice.amount);
let invoice = provider.issue_invoice(&invoice).await?;
log::info!("Invoice issued.");

Expand Down
8 changes: 4 additions & 4 deletions core/payment/examples/debit_note_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn main() -> anyhow::Result<()> {
payment_due_date: Some(Utc::now()),
};
log::info!(
"Issuing debit note (total amount due: {} NGNT)...",
"Issuing debit note (total amount due: {} GLM)...",
&debit_note.total_amount_due
);
let debit_note = provider.issue_debit_note(&debit_note).await?;
Expand Down Expand Up @@ -109,7 +109,7 @@ async fn main() -> anyhow::Result<()> {
log::info!("Debit note accepted.");

log::info!("Waiting for payment...");
let timeout = Some(Duration::from_secs(300)); // Should be enough for GNT transfer
let timeout = Some(Duration::from_secs(300)); // Should be enough for GLM transfer
let mut payments = provider
.get_payments(Some(&now), timeout, None, None)
.await?;
Expand All @@ -130,7 +130,7 @@ async fn main() -> anyhow::Result<()> {
payment_due_date: Some(Utc::now()),
};
log::info!(
"Issuing debit note (total amount due: {} NGNT)...",
"Issuing debit note (total amount due: {} GLM)...",
debit_note2.total_amount_due
);
let debit_note2 = provider.issue_debit_note(&debit_note2).await?;
Expand All @@ -154,7 +154,7 @@ async fn main() -> anyhow::Result<()> {
log::info!("Debit note accepted.");

log::info!("Waiting for payment...");
let timeout = Some(Duration::from_secs(300)); // Should be enough for GNT transfer
let timeout = Some(Duration::from_secs(300)); // Should be enough for GLM transfer
let mut payments = provider
.get_payments(Some(&now), timeout, None, args.app_session_id.clone())
.await?;
Expand Down
2 changes: 1 addition & 1 deletion core/payment/examples/invoice_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn main() -> anyhow::Result<()> {
log::debug!("events 2: {:?}", &invoice_events_accepted);

log::info!("Waiting for payment...");
let timeout = Some(Duration::from_secs(300)); // Should be enough for GNT transfer
let timeout = Some(Duration::from_secs(300)); // Should be enough for GLM transfer
let mut payments = provider
.get_payments(Some(&now), timeout, None, args.app_session_id.clone())
.await?;
Expand Down
Loading

0 comments on commit edcdf76

Please sign in to comment.