mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2025-12-18 22:54:25 +01:00
fix: return sane values for channels without any average liquidity
This commit is contained in:
@@ -90,15 +90,20 @@ public class RatingService {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
Duration durationForAnalysis = getDurationForAnalysis();
|
Duration durationForAnalysis = getDurationForAnalysis();
|
||||||
FeeReport feeReport =
|
Optional<Coins> averageLocalBalanceOptional =
|
||||||
feeService.getFeeReportForChannel(channelId, durationForAnalysis);
|
balanceService.getLocalBalanceAverage(channelId, (int) durationForAnalysis.toDays());
|
||||||
RebalanceReport rebalanceReport =
|
if (averageLocalBalanceOptional.isEmpty()) {
|
||||||
rebalanceService.getReportForChannel(channelId, durationForAnalysis);
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
FeeReport feeReport = feeService.getFeeReportForChannel(channelId, durationForAnalysis);
|
||||||
|
RebalanceReport rebalanceReport = rebalanceService.getReportForChannel(channelId, durationForAnalysis);
|
||||||
long feeRate = policyService.getMinimumFeeRateTo(localChannel.getRemotePubkey()).orElse(0L);
|
long feeRate = policyService.getMinimumFeeRateTo(localChannel.getRemotePubkey()).orElse(0L);
|
||||||
long localAvailableMilliSat = getLocalAvailableMilliSat(localChannel);
|
long localAvailableMilliSat = getLocalAvailableMilliSat(localChannel);
|
||||||
double millionSat = 1.0 * localAvailableMilliSat / 1_000 / 1_000_000;
|
double millionSat = 1.0 * localAvailableMilliSat / 1_000 / 1_000_000;
|
||||||
long averageSat = balanceService.getLocalBalanceAverage(channelId, (int) durationForAnalysis.toDays())
|
long averageSat = averageLocalBalanceOptional.get().satoshis();
|
||||||
.orElse(Coins.NONE).satoshis();
|
if (averageSat == 0) {
|
||||||
|
averageSat = 1;
|
||||||
|
}
|
||||||
|
|
||||||
long rating = feeReport.earned().milliSatoshis();
|
long rating = feeReport.earned().milliSatoshis();
|
||||||
rating += feeReport.sourced().milliSatoshis();
|
rating += feeReport.sourced().milliSatoshis();
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import static de.cotto.lndmanagej.model.OpenInitiator.LOCAL;
|
|||||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
|
||||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
@@ -306,9 +305,8 @@ class RatingServiceTest {
|
|||||||
when(balanceService.getLocalBalanceAverage(CHANNEL_ID, ANALYSIS_DAYS))
|
when(balanceService.getLocalBalanceAverage(CHANNEL_ID, ANALYSIS_DAYS))
|
||||||
.thenReturn(Optional.of(Coins.NONE));
|
.thenReturn(Optional.of(Coins.NONE));
|
||||||
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
|
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
|
||||||
when(feeService.getFeeReportForChannel(CHANNEL_ID, DEFAULT_DURATION_FOR_ANALYSIS))
|
long averageSat = ratingService.getRatingForChannel(CHANNEL_ID).map(Rating::getRating).orElseThrow();
|
||||||
.thenReturn(new FeeReport(Coins.ofMilliSatoshis(100_000 * ANALYSIS_DAYS), Coins.NONE));
|
assertThat(averageSat).isLessThan(Integer.MAX_VALUE);
|
||||||
assertThatCode(() -> ratingService.getRatingForChannel(CHANNEL_ID)).doesNotThrowAnyException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -316,9 +314,7 @@ class RatingServiceTest {
|
|||||||
when(balanceService.getLocalBalanceAverage(CHANNEL_ID, ANALYSIS_DAYS))
|
when(balanceService.getLocalBalanceAverage(CHANNEL_ID, ANALYSIS_DAYS))
|
||||||
.thenReturn(Optional.empty());
|
.thenReturn(Optional.empty());
|
||||||
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
|
when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL));
|
||||||
when(feeService.getFeeReportForChannel(CHANNEL_ID, DEFAULT_DURATION_FOR_ANALYSIS))
|
assertThat(ratingService.getRatingForChannel(CHANNEL_ID)).isEmpty();
|
||||||
.thenReturn(new FeeReport(Coins.ofMilliSatoshis(200_000 * ANALYSIS_DAYS), Coins.NONE));
|
|
||||||
assertThatCode(() -> ratingService.getRatingForChannel(CHANNEL_ID)).doesNotThrowAnyException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user