use amount of received payments for rating

This commit is contained in:
Carsten Otto
2022-08-28 15:55:42 +02:00
parent 2c17a0f714
commit 3fcd71924b
3 changed files with 40 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.ClosedChannel;
import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.FeeReport;
import de.cotto.lndmanagej.model.FlowReport;
import de.cotto.lndmanagej.model.LocalChannel;
import de.cotto.lndmanagej.model.LocalOpenChannel;
import de.cotto.lndmanagej.model.Pubkey;
@@ -42,6 +43,7 @@ public class RatingService {
private final PolicyService policyService;
private final ConfigurationService configurationService;
private final BalanceService balanceService;
private final FlowService flowService;
private final LoadingCache<Pubkey, Rating> peerCache = new CacheBuilder()
.withExpiry(EXPIRY)
.withRefresh(REFRESH)
@@ -62,7 +64,8 @@ public class RatingService {
RebalanceService rebalanceService,
PolicyService policyService,
ConfigurationService configurationService,
BalanceService balanceService
BalanceService balanceService,
FlowService flowService
) {
this.channelService = channelService;
this.ownNodeService = ownNodeService;
@@ -71,6 +74,7 @@ public class RatingService {
this.policyService = policyService;
this.configurationService = configurationService;
this.balanceService = balanceService;
this.flowService = flowService;
}
public Rating getRatingForPeer(Pubkey peer) {
@@ -97,6 +101,7 @@ public class RatingService {
}
FeeReport feeReport = feeService.getFeeReportForChannel(channelId, durationForAnalysis);
RebalanceReport rebalanceReport = rebalanceService.getReportForChannel(channelId, durationForAnalysis);
FlowReport flowReport = flowService.getFlowReportForChannel(channelId, durationForAnalysis);
long feeRate = policyService.getMinimumFeeRateTo(localChannel.getRemotePubkey()).orElse(0L);
long localAvailableMilliSat = getLocalAvailableMilliSat(localChannel);
double millionSat = 1.0 * localAvailableMilliSat / 1_000 / 1_000_000;
@@ -107,6 +112,7 @@ public class RatingService {
long rating = feeReport.earned().milliSatoshis();
rating += feeReport.sourced().milliSatoshis();
rating += flowReport.receivedViaPayments().milliSatoshis();
rating += rebalanceReport.supportAsSourceAmount().milliSatoshis() / 10_000;
rating += rebalanceReport.supportAsTargetAmount().milliSatoshis() / 10_000;
rating += (long) (1.0 * feeRate * millionSat / 10);

View File

@@ -10,6 +10,7 @@ import de.cotto.lndmanagej.model.Coins;
import de.cotto.lndmanagej.model.CoopClosedChannel;
import de.cotto.lndmanagej.model.CoopClosedChannelBuilder;
import de.cotto.lndmanagej.model.FeeReport;
import de.cotto.lndmanagej.model.FlowReport;
import de.cotto.lndmanagej.model.LocalChannel;
import de.cotto.lndmanagej.model.LocalOpenChannel;
import de.cotto.lndmanagej.model.LocalOpenChannelFixtures;
@@ -81,6 +82,9 @@ class RatingServiceTest {
@Mock
private BalanceService balanceService;
@Mock
private FlowService flowService;
@BeforeEach
void setUp() {
int daysAhead = LOCAL_OPEN_CHANNEL_2.getId().getBlockHeight() + 100 * 24 * 60 / 10;
@@ -91,6 +95,7 @@ class RatingServiceTest {
lenient().when(configurationService.getIntegerValue(any())).thenReturn(Optional.empty());
lenient().when(balanceService.getLocalBalanceAverage(any(), anyInt()))
.thenReturn(Optional.of(Coins.ofSatoshis(1_000_000)));
lenient().when(flowService.getFlowReportForChannel(any(), any())).thenReturn(FlowReport.EMPTY);
}
@Test
@@ -293,6 +298,25 @@ class RatingServiceTest {
.contains(new Rating(maxEarnings / 10 / ANALYSIS_DAYS));
}
@Test
void received_via_payments() {
Coins receivedViaPayments = Coins.ofMilliSatoshis(123_456 * ANALYSIS_DAYS);
FlowReport flowReport = new FlowReport(
Coins.NONE,
Coins.NONE,
Coins.NONE,
Coins.NONE,
Coins.NONE,
Coins.NONE,
Coins.NONE,
Coins.NONE,
Coins.NONE,
receivedViaPayments
);
when(flowService.getFlowReportForChannel(CHANNEL_ID, DEFAULT_DURATION_FOR_ANALYSIS)).thenReturn(flowReport);
assertThat(ratingService.getRatingForChannel(CHANNEL_ID)).contains(new Rating(123_456));
}
@Test
void divided_by_average_million_sats_local() {
Coins localAvailableAverage = Coins.ofSatoshis(2_500_000);

View File

@@ -7,19 +7,22 @@ other channels/nodes on your peer.
The higher the rating, the better the channel/peer. The following values are taken into account to compute the final
rating:
1. Earned fees
1. Received Payments
For each mSAT received via a (non-self) payment via the channel/peer, the rating is increased by 1.
2. Earned fees
For each mSAT earned by routing out via the channel/peer, the rating is increased by 1.
2. Sourced fees
3. Sourced fees
For each mSAT earned by sats coming in from the channel/peer, but going out via some OTHER peer, the rating is increased by 1.
3. Rebalance Support (source)
4. Rebalance Support (source)
For each 10,000 mSAT taken from the local balance as part of a rebalance transaction (increasing the local balance to some other peer), the rating is increased by 1.
4. Rebalance Support (target)
5. Rebalance Support (target)
For each 10,000 mSAT received as part of a rebalance transaction (increasing the remote balance of some other peer), the rating is increased by 1.
5. Potential earnings
6. Potential earnings
For each 10 mSAT that could be earned by routing the local balance at the current fee rate, the rating is increased by 1.
@@ -31,6 +34,7 @@ divided by 10 for an average local balance of 10M satoshis, and the value is mul
As such, when considering 30 days for the analysis, a rating of 1,000 could mean:
- the channel/peer earned 30 satoshis with an average local balance of 1M sat, and currently no local balance
- you received a payment worth 30 satoshis via the channel/peer with an average local balance of 1M sat, and currently no local balance
- the channel/peer earned 30 satoshis with an average local balance of 1M sat, a current local balance of 10M sat, and a fee rate of 0pm
- the channel/peer earned 0 satoshis with an average local balance of 1M sat, a current local balance of 10M sat, and a fee rate of 30pm
- the channel/peer earned 0 satoshis with an average local balance of 1M sat, a current local balance of 5M sat, and a fee rate of 60pm