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

Add ui test for send payment middle hops restarting #512

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

chenyukang
Copy link
Collaborator

@chenyukang chenyukang commented Feb 17, 2025

Fixes #464
Fixes #448
Fixes #334

If we stop a node, then send a payment with failed status, this will be recorded by payment history

The following payment will use this record to eval probability, because we have a time factor in eval_probability:

fiber/src/fiber/history.rs

Lines 508 to 531 in d661c73

// The factor approaches 0 for success_time a long time in the past,
// is 1 when the success_time is now.
fn time_factor(&self, time: u64) -> f64 {
let time_ago = now_timestamp_as_millis_u64() - time;
// if time_ago is less than 1 second, we treat it as 0, this makes the factor 1
// this is to avoid the factor is too small when the time is very close to now,
// this will make the probability calculation more stable
let time_ago = if time_ago < 1000 { 0 } else { time_ago };
let exponent = -(time_ago as f64) / (DEFAULT_BIMODAL_DECAY_TIME as f64);
exponent.exp()
}
pub(crate) fn cannot_send(&self, fail_amount: u128, time: u64, capacity: u128) -> u128 {
let mut fail_amount = fail_amount;
if fail_amount > capacity {
fail_amount = capacity;
}
let factor = self.time_factor(time);
capacity - (factor * (capacity - fail_amount) as f64) as u128
}

this means the available sending amount for a failed channel will increase with time passing, for the test case in #464, waiting about 2 minutes is needed.

I think this behavior is reasonable and we don't need to fix it, 2 test cases are added.

@chenyukang
Copy link
Collaborator Author

@gpBlockchain please verify it.

@chenyukang chenyukang force-pushed the yukang-fix-restart-node-issue branch from 21c1109 to 4744d2d Compare February 17, 2025 08:46
@chenyukang
Copy link
Collaborator Author

@gpBlockchain
Notice if we stop a node without a failed payment, and then start the node again, there will be no failed payment history, so the following payments with the normal amount will be ok.

This is the scenario for this test case:
https://github.com/nervosnetwork/fiber/pull/512/files#diff-3c736a0be383d7bbc0b80d370ee362e42e694dbf882a87d05be62da6f8618165R2222

@gpBlockchain
Copy link
Contributor

gpBlockchain commented Feb 17, 2025

@gpBlockchain please verify it.

@ gpBlockchain 请确认。

yes, send_payment will succeed without no failed, will waiting about 213 s with failed history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment