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

feat: Configurable sync_notifs backoff #3278

Merged
merged 9 commits into from
Jul 29, 2024

Conversation

mwalkiewicz
Copy link
Collaborator

@mwalkiewicz mwalkiewicz commented Jul 23, 2024

@mwalkiewicz mwalkiewicz requested a review from a team as a code owner July 23, 2024 14:24
@CLAassistant
Copy link

CLAassistant commented Jul 23, 2024

CLA assistant check
All committers have signed the CLA.

core/payment/src/lib.rs Show resolved Hide resolved
@mwalkiewicz mwalkiewicz force-pushed the mw/configurable-sync-notifs-backoff branch 4 times, most recently from 8e0fc8f to 22ad437 Compare July 25, 2024 20:38
@mwalkiewicz mwalkiewicz force-pushed the mw/configurable-sync-notifs-backoff branch 2 times, most recently from 1c0d514 to 1f8008c Compare July 25, 2024 21:34
@mwalkiewicz mwalkiewicz force-pushed the mw/configurable-sync-notifs-backoff branch from 1f8008c to 962c28f Compare July 25, 2024 21:37
Comment on lines 162 to 170
pub async fn mark_sent(&self, payment_id: String, owner_id: NodeId) -> DbResult<()> {
do_with_transaction(self.pool, "payment_dao_mark_sent", move |conn| {
diesel::update(dsl::pay_payment.filter(dsl::id.eq(payment_id)))
.filter(dsl::role.eq(Role::Requestor))
.set(dsl::send_payment.eq(false))
.execute(conn)?;
diesel::update(
dsl::pay_payment.filter(dsl::id.eq(payment_id).and(dsl::owner_id.eq(owner_id))),
)
.filter(dsl::role.eq(Role::Requestor))
.set(dsl::send_payment.eq(false))
.execute(conn)?;
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous version was correct, since payment_id and role should be unique. Your version should be correct as well, but I would restore previous, for 2 reasons:

  • To keep function signature more pleasant
  • To avoid risk of breaking something

Comment on lines 34 to 47
fn remove_allocation_ids_from_payment(payment: &Payment) -> Payment {
// We remove allocation ID from syncs because allocations are not transferred to peers and
// their IDs would be unknown to the recipient.
let mut payment = payment.clone();
for agreement_payment in &mut payment.agreement_payments.iter_mut() {
agreement_payment.allocation_id = None;
}

for activity_payment in &mut payment.activity_payments.iter_mut() {
activity_payment.allocation_id = None;
}

payment
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same functionality as

// Allocation IDs are requestor's private matter and should not be sent to provider
for agreement_payment in payment.agreement_payments.iter_mut() {
agreement_payment.allocation_id = None;
}
for activity_payment in payment.activity_payments.iter_mut() {
activity_payment.allocation_id = None;
}

so should be handled by the same code.

Payment struct is defined in ya-client, so I wouldn't modify it there, but probably you could define trait with function remove_private_info or something like that and implement this trait for Payment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, I'll reuse the code. However I'd refrain from creating a trait (an abstraction) for a single use case and stick with a free function in core/payment/utils.rs if this is OK for you.

@@ -45,6 +62,8 @@ async fn payment_sync(
let platform_components = payment.payment_platform.split('-').collect::<Vec<_>>();
let driver = &platform_components[0];

let payment = remove_allocation_ids_from_payment(&payment);

let signature = typed::service(driver_bus_id(driver))
Copy link
Contributor

Choose a reason for hiding this comment

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

We could query signature from database probably and sign only if we need to rely on fallback.
But this code was already implemented this way, so let's leave it as is

let mut result = ya_net::from(default_identity)
.to(peer)
.service(ya_core_model::payment::public::BUS_ID)
.call(msg_with_bytes.clone())
.await;

if matches!(&result, Err(Error::GsbBadRequest(_))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You comment made me realize, that those mechanisms broke because of transition to central net.
We shouldn't remove previous version, because we will break hybrid net this way

secs
};
capped
};
let cutoff = Utc::now();

let default_identity = typed::service(identity::BUS_ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can list identities instead of taking default. Check identity::List

async fn payment_sync(
db: &DbExecutor,
current_node_id: NodeId,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would call it current. Not sure what it means in this context. Maybe just node_id or owner_id`

@nieznanysprawiciel nieznanysprawiciel merged commit 83d4600 into master Jul 29, 2024
35 checks passed
@nieznanysprawiciel nieznanysprawiciel deleted the mw/configurable-sync-notifs-backoff branch July 29, 2024 11:29
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.

Jobs finishing in InvoiceSent status
3 participants