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

Provider - check debit notes acceptance #897

Merged
merged 38 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bfddea3
[Provider] refactor Negotiator - diretory structure
nieznanysprawiciel Dec 21, 2020
5e2fd21
Negotiator as actor
nieznanysprawiciel Dec 22, 2020
1499421
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Dec 23, 2020
f935201
Update actix to 0.10 due to bug in polling ResponseFuture
nieznanysprawiciel Dec 23, 2020
b698012
Introduced NegotiatorComponent trait; Implement Composite negotiator …
nieznanysprawiciel Dec 23, 2020
f94318c
Configurable Agreement expiration
nieznanysprawiciel Dec 23, 2020
5d1da8f
Introduce DeadlineChecker [+Tests]
nieznanysprawiciel Jan 12, 2021
7430e17
[Test] Check DeadlineChecker for multiple agreements
nieznanysprawiciel Jan 12, 2021
007e2c2
First working version of deadline notification; Hardcoded deadline; N…
nieznanysprawiciel Jan 13, 2021
25c5d2e
Reorganize code to get deadline from Agreement (but still hardcoded)
nieznanysprawiciel Jan 13, 2021
54b239a
Merge master and use app_session_id
nieznanysprawiciel Jan 13, 2021
5f92e19
Remove [] from AppSessionId and TODO comment
nieznanysprawiciel Jan 13, 2021
15e7401
Return unresolved constraints, when Proposals don't match
nieznanysprawiciel Jan 13, 2021
c7c4e50
Add deadline property on provider side
nieznanysprawiciel Jan 13, 2021
2c18ba6
Implement DebitNotes deadline negotiation logic
nieznanysprawiciel Jan 15, 2021
ece34e0
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Jan 15, 2021
3b9743f
Try to fix time dependent tests on CI
nieznanysprawiciel Jan 15, 2021
74a052b
Provider uses DebitNotes deadline from Agreement properties
nieznanysprawiciel Jan 15, 2021
cf2fcaa
Breaking Agreement if Requestor doesn't accept DebitNotes
nieznanysprawiciel Jan 15, 2021
0385d2f
Pretty display chrono::Duration in messages
nieznanysprawiciel Jan 18, 2021
56b32a5
Try to fix ordering of messages sent by DeadlineChecker
nieznanysprawiciel Jan 18, 2021
3da1433
Fix ugly Reason display; Fix negotiation deadline rejection sign
nieznanysprawiciel Jan 22, 2021
a22e48c
Merge branch 'master' of github.com:golemfactory/yagna into provider/…
nieznanysprawiciel Jan 22, 2021
6cb4484
Don't send new deadline events, when one was alreay sent
nieznanysprawiciel Jan 22, 2021
4abf4d5
[Test] Added tests for expiration negotiator
nieznanysprawiciel Jan 22, 2021
d5e156c
Update actix form 0.9 to 0.10
nieznanysprawiciel Jan 22, 2021
06a399f
Revert "Update actix form 0.9 to 0.10"
nieznanysprawiciel Jan 22, 2021
8d98376
Merge branch 'master' into provider/check-debit-notes-acceptance
tworec Jan 25, 2021
1b35ac7
Merge branch 'master' into provider/check-debit-notes-acceptance
tworec Jan 25, 2021
3b178a9
Fix binary_search on not sorted vector
nieznanysprawiciel Jan 25, 2021
b0b880c
Call if CompositeNegotiator accepts Agreement
nieznanysprawiciel Jan 25, 2021
876a60b
Don't set payment_due_date in DebitNote
nieznanysprawiciel Jan 25, 2021
a57214d
Remove LimitAgreement negotiator since we have CompositeNegotiator now
nieznanysprawiciel Jan 25, 2021
313e73d
Set minimal DebitNotes deadline limit; Change deadline property name
nieznanysprawiciel Jan 25, 2021
0078173
Merge branch 'master' into provider/check-debit-notes-acceptance
nieznanysprawiciel Jan 25, 2021
8266d88
[ya-version] fix REST api
tworec Jan 25, 2021
56b0d6a
Merge branch 'master' into provider/check-debit-notes-acceptance
tworec Jan 25, 2021
051ba63
acceptance-timeout instead accept-timeout
tworec Jan 26, 2021
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
40 changes: 32 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions agent/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ ya-utils-actix = "0.1"
ya-utils-path = "0.1"
ya-utils-process = { version = "0.1", features = ['lock'] }

actix = { version = "0.9", default-features = false }
actix-rt = "1.0"
actix = { version = "0.10", default-features = false }
actix-rt = "1.1.1"
actix_derive = "0.5.0"
anyhow = "1.0"
backoff = "0.2.1"
Expand Down
24 changes: 24 additions & 0 deletions agent/provider/src/display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use humantime::format_duration;
use std::fmt::{Error, Formatter};

pub struct DisplayEnabler<'a, Type>(pub &'a Type);

pub trait EnableDisplay<Type> {
fn display(&self) -> DisplayEnabler<Type>;
}

impl<Type> EnableDisplay<Type> for Type {
fn display(&self) -> DisplayEnabler<Type> {
DisplayEnabler(self)
}
}

impl<'a> std::fmt::Display for DisplayEnabler<'a, chrono::Duration> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
match self.0.clone().to_std() {
Ok(duration) => write!(f, "{}", format_duration(duration)),
// If we can't convert, we will display ugly version, which we wanted to avoid.
Err(_) => write!(f, "{}", self.0),
}
}
}
33 changes: 4 additions & 29 deletions agent/provider/src/execution/task_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use ya_client_model::activity::{ActivityState, ProviderEvent, State};
use ya_core_model::activity;
use ya_utils_actix::actix_handler::ResultTypeGetter;
use ya_utils_actix::actix_signal::{SignalSlot, Subscribe};
use ya_utils_actix::forward_actix_handler;
use ya_utils_actix::{actix_signal_handler, forward_actix_handler};
use ya_utils_path::SecurePath;
use ya_utils_process::ExeUnitExitStatus;

Expand Down Expand Up @@ -364,7 +364,7 @@ impl TaskRunner {
_ctx: &mut Context<Self>,
) -> Result<()> {
// Agreement waits for first create activity event.
let agreement_id = msg.agreement.agreement_id.clone();
let agreement_id = msg.agreement.id.clone();
self.active_agreements.insert(agreement_id, msg.agreement);
Ok(())
}
Expand Down Expand Up @@ -462,22 +462,6 @@ impl TaskRunner {
Ok(())
}

pub fn on_subscribe_activity_created(
&mut self,
msg: Subscribe<ActivityCreated>,
_ctx: &mut Context<Self>,
) -> Result<()> {
Ok(self.activity_created.on_subscribe(msg))
}

pub fn on_subscribe_activity_destroyed(
&mut self,
msg: Subscribe<ActivityDestroyed>,
_ctx: &mut Context<Self>,
) -> Result<()> {
Ok(self.activity_destroyed.on_subscribe(msg))
}

fn list_activities(&self, agreement_id: &str) -> Vec<String> {
self.tasks
.iter()
Expand Down Expand Up @@ -557,6 +541,8 @@ impl Actor for TaskRunner {
forward_actix_handler!(TaskRunner, AgreementApproved, on_agreement_approved);
forward_actix_handler!(TaskRunner, ExeUnitProcessFinished, on_exeunit_exited);
forward_actix_handler!(TaskRunner, GetExeUnit, get_exeunit);
actix_signal_handler!(TaskRunner, ActivityCreated, activity_created);
actix_signal_handler!(TaskRunner, ActivityDestroyed, activity_destroyed);

impl Handler<GetOfferTemplates> for TaskRunner {
type Result = ResponseFuture<Result<HashMap<String, OfferTemplate>>>;
Expand All @@ -582,17 +568,6 @@ impl Handler<GetOfferTemplates> for TaskRunner {
}
}

forward_actix_handler!(
TaskRunner,
Subscribe<ActivityCreated>,
on_subscribe_activity_created
);
forward_actix_handler!(
TaskRunner,
Subscribe<ActivityDestroyed>,
on_subscribe_activity_destroyed
);

impl Handler<UpdateActivity> for TaskRunner {
type Result = ActorResponse<Self, (), Error>;

Expand Down
1 change: 1 addition & 0 deletions agent/provider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use structopt::{clap, StructOpt};

mod cli;
mod dir;
mod display;
mod events;
mod execution;
mod hardware;
Expand Down
6 changes: 5 additions & 1 deletion agent/provider/src/market/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use structopt::StructOpt;

use crate::market::negotiator::factory::NegotiatorsConfig;

/// Configuration for ProviderMarket actor.
#[derive(StructOpt, Clone, Debug)]
pub struct MarketConfig {
Expand All @@ -9,8 +11,10 @@ pub struct MarketConfig {
pub negotiation_events_interval: f32,
#[structopt(long, env, default_value = "10.0")]
pub agreement_approve_timeout: f32,
#[structopt(long, env, default_value = "LimitAgreements")]
#[structopt(long, env, default_value = "Composite")]
pub negotiator_type: String,
#[structopt(flatten)]
pub negotiator_config: NegotiatorsConfig,
#[structopt(skip = "you-forgot-to-set-session-id")]
pub session_id: String,
}
1 change: 0 additions & 1 deletion agent/provider/src/market/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod config;
mod mock_negotiator;
mod negotiator;
pub mod presets;
pub mod provider_market;
Expand Down
116 changes: 17 additions & 99 deletions agent/provider/src/market/negotiator.rs
Original file line number Diff line number Diff line change
@@ -1,99 +1,17 @@
use ya_agreement_utils::AgreementView;
use ya_agreement_utils::OfferDefinition;
use ya_client_model::market::{NewOffer, Proposal};

use anyhow::Result;
use derive_more::Display;

use crate::market::termination_reason::BreakReason;
use ya_client::model::market::Reason;

/// Response for requestor proposals.
#[derive(Debug, Display)]
#[allow(dead_code)]
pub enum ProposalResponse {
#[display(fmt = "CounterProposal")]
CounterProposal {
offer: NewOffer,
},
AcceptProposal,
#[display(
fmt = "RejectProposal{}",
"reason.as_ref().map(|r| format!(\" (reason: {})\", r)).unwrap_or(\"\".into())"
)]
RejectProposal {
reason: Option<Reason>,
},
///< Don't send any message to requestor. Could be useful to wait for other offers.
IgnoreProposal,
}

/// Response for requestor agreements.
#[derive(Debug, Display)]
#[allow(dead_code)]
pub enum AgreementResponse {
ApproveAgreement,
#[display(
fmt = "RejectAgreement{}",
"reason.as_ref().map(|r| format!(\" (reason: {})\", r)).unwrap_or(\"\".into())"
)]
RejectAgreement {
reason: Option<Reason>,
},
}

/// Result of agreement execution.
pub enum AgreementResult {
/// Failed to approve agreement. (Agreement even wasn't created)
ApprovalFailed,
/// Agreement was finished with success after first Activity.
ClosedByUs,
/// Agreement was finished with success by Requestor.
ClosedByRequestor,
/// Agreement was broken by us.
Broken { reason: BreakReason },
}

pub trait Negotiator {
/// Negotiator can modify offer, that was generated for him. He can save
/// information about this offer, that are necessary for negotiations.
fn create_offer(&mut self, node_info: &OfferDefinition) -> Result<NewOffer>;

/// Agreement notifications. Negotiator can adjust his strategy based on it.
fn agreement_finalized(&mut self, agreement_id: &str, result: &AgreementResult) -> Result<()>;

/// Reactions to events from market. These function make market decisions.
fn react_to_proposal(
&mut self,
offer: &NewOffer,
demand: &Proposal,
) -> Result<ProposalResponse>;
fn react_to_agreement(&mut self, agreement: &AgreementView) -> Result<AgreementResponse>;
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_proposal_response_display() {
let reason = ProposalResponse::RejectProposal {
reason: Some("zima".into()),
};
let no_reason = ProposalResponse::RejectProposal { reason: None };

assert_eq!(reason.to_string(), "RejectProposal (reason: 'zima')");
assert_eq!(no_reason.to_string(), "RejectProposal");
}

#[test]
fn test_agreement_response_display() {
let reason = AgreementResponse::RejectAgreement {
reason: Some("lato".into()),
};
let no_reason = AgreementResponse::RejectAgreement { reason: None };

assert_eq!(reason.to_string(), "RejectAgreement (reason: 'lato')");
assert_eq!(no_reason.to_string(), "RejectAgreement");
}
}
mod accept_all;
mod builtin;
mod common;
mod component;
mod composite;
pub mod factory;
mod limit_agreements;

pub use accept_all::AcceptAllNegotiator;
pub use composite::CompositeNegotiator;
pub use limit_agreements::LimitAgreementsNegotiator;

pub use common::{
AgreementResponse, AgreementResult, Negotiator, NegotiatorAddr, ProposalResponse,
};

pub use component::{NegotiationResult, NegotiatorComponent, NegotiatorsPack, ProposalView};
Loading