diff --git a/chanevents/analyzer.go b/chanevents/analyzer.go index e010d1b..abbd3dd 100644 --- a/chanevents/analyzer.go +++ b/chanevents/analyzer.go @@ -12,6 +12,7 @@ import ( "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btclog/v2" "github.com/lightninglabs/lndclient" + "github.com/lightningnetwork/lnd/lnwire" ) var ( @@ -75,8 +76,31 @@ type ForwardingAbility struct { EffectiveUptime time.Duration // ForwardedAmount is the total successfully forwarded amount over the - // window. + // window, at satoshi granularity. ForwardedAmount btcutil.Amount + + // FeeMsat is the total fee earned on the pair's forwards over the + // window. + FeeMsat lnwire.MilliSatoshi + + // Forwards is how many successful forwards the pair carried. It decides + // whether the pair forwarded at all, since both sums can be zero for + // one that did: sub-satoshi volume floors away and a zero-fee policy + // earns nothing. + Forwards int64 +} + +// pairForwards accumulates what one direction of a peer pair carried over the +// analysis window. +type pairForwards struct { + // amount is the total forwarded amount, at satoshi granularity. + amount btcutil.Amount + + // feeMsat is the total fee earned on those forwards. + feeMsat lnwire.MilliSatoshi + + // forwards is how many successful forwards were carried. + forwards int64 } // PeerPair identifies a unidirectional routing edge from PeerIn to PeerOut. @@ -166,10 +190,10 @@ func (a *ForwardingAnalyzer) EffectiveUptime(ctx context.Context, startTime, // getForwardingData queries lnd's forwarding history sequentially in paginated // batches to retrieve successful forwarding events within the specified time -// range, indexing the results by peer pair. +// range, accumulating the volume, fees and count of each peer pair's forwards. func (a *ForwardingAnalyzer) getForwardingData(ctx context.Context, startTime, endTime time.Time, scidToPeer map[uint64]string) ( - map[PeerPair][]btcutil.Amount, map[uint64]string, error) { + map[PeerPair]*pairForwards, map[uint64]string, error) { var events []lndclient.ForwardingEvent var offset uint32 @@ -214,7 +238,7 @@ func (a *ForwardingAnalyzer) getForwardingData(ctx context.Context, startTime, ) channelPeersConsidered := make(map[uint64]string) - successfulForwards := make(map[PeerPair][]btcutil.Amount) + successfulForwards := make(map[PeerPair]*pairForwards) for _, fwd := range events { inPeer, ok := scidToPeer[fwd.ChannelIn] if !ok { @@ -242,8 +266,15 @@ func (a *ForwardingAnalyzer) getForwardingData(ctx context.Context, startTime, PeerOut: outPeer, } - amt := fwd.AmountMsatOut.ToSatoshis() - successfulForwards[pair] = append(successfulForwards[pair], amt) + totals, ok := successfulForwards[pair] + if !ok { + totals = &pairForwards{} + successfulForwards[pair] = totals + } + + totals.amount += fwd.AmountMsatOut.ToSatoshis() + totals.feeMsat += fwd.FeeMsat + totals.forwards++ } return successfulForwards, channelPeersConsidered, nil @@ -427,7 +458,7 @@ func (a *ForwardingAnalyzer) getInitialChannelState(ctx context.Context, // computing both directions (A→B and B→A) in a single pass. func calculateAllPairsUptime(ctx context.Context, store EventsSource, startTime, endTime time.Time, liquidityFloor btcutil.Amount, - successfulForwards map[PeerPair][]btcutil.Amount, + successfulForwards map[PeerPair]*pairForwards, initialStates map[string]map[int64]*channelState, peerChannels map[string][]int64) ( map[PeerPair]ForwardingAbility, error) { @@ -506,10 +537,10 @@ func calculateAllPairsUptime(ctx context.Context, store EventsSource, startTime, statesB := initialStates[peerB] sumsB := initialSums[peerB] - forwardedAB := pairForwardedTotal( + totalsAB := pairForwardTotals( successfulForwards, peerA, peerB, ) - forwardedBA := pairForwardedTotal( + totalsBA := pairForwardTotals( successfulForwards, peerB, peerA, ) @@ -529,7 +560,7 @@ func calculateAllPairsUptime(ctx context.Context, store EventsSource, startTime, sumsA.remote, sumsA.local, sumsB.remote, sumsB.local, mergeEventSlices(sliceA, sliceB), - forwardedAB, forwardedBA, + totalsAB, totalsBA, ) if err != nil { return nil, err @@ -594,32 +625,34 @@ func loadPeerEvents(ctx context.Context, store EventsSource, startTime, return events, nil } -// pairForwardedTotal sums the successfully forwarded amounts for one direction -// of a peer pair over the analysis window. -func pairForwardedTotal(successfulForwards map[PeerPair][]btcutil.Amount, - peerIn, peerOut string) btcutil.Amount { +// pairForwardTotals returns the accumulated forwards for one direction of a +// peer pair over the analysis window. A pair with no recorded forwards yields +// the zero value, whose zero count marks it as having carried nothing. +func pairForwardTotals(successfulForwards map[PeerPair]*pairForwards, + peerIn, peerOut string) pairForwards { - var total btcutil.Amount - for _, amt := range successfulForwards[PeerPair{ + totals, ok := successfulForwards[PeerPair{ PeerIn: peerIn, PeerOut: peerOut, - }] { - total += amt + }] + if !ok { + return pairForwards{} } - return total + return *totals } // calculateBothDirectionsUptime computes the effective forwarding uptime for // both directions of a peer pair in a single chronological walk of the merged // event stream. Only the liquidity-direction roles differ between the two -// accumulators, as both share the same uniform liquidityFloor. forwardedAB and -// forwardedBA carry each direction's total forwarded volume through to the -// returned abilities. For self-pair calls both returned abilities are equal. +// accumulators, as both share the same uniform liquidityFloor. totalsAB and +// totalsBA carry each direction's forwarded volume, fees and count through to +// the returned abilities. For self-pair calls both returned abilities are +// equal. func calculateBothDirectionsUptime(ctx context.Context, startTime, endTime time.Time, liquidityFloor btcutil.Amount, statesA, statesB map[int64]*channelState, sumARemote, sumALocal, sumBRemote, sumBLocal btcutil.Amount, mergedEvents channelEventSeq, - forwardedAB, forwardedBA btcutil.Amount) ( + totalsAB, totalsBA pairForwards) ( *ForwardingAbility, *ForwardingAbility, error) { traceOn := log.Level() <= btclog.LevelTrace @@ -787,8 +820,8 @@ func calculateBothDirectionsUptime(ctx context.Context, startTime, ) } - abilityAB := makeAbility(uptimeAB, forwardedAB) - abilityBA := makeAbility(uptimeBA, forwardedBA) + abilityAB := makeAbility(uptimeAB, totalsAB) + abilityBA := makeAbility(uptimeBA, totalsBA) return abilityAB, abilityBA, nil } @@ -882,14 +915,16 @@ func applyEvent(state *channelState, event *ChannelEvent) error { return nil } -// makeAbility folds an accumulated uptime and successful-amount total into a -// ForwardingAbility carrying the raw facts. Derived rates and categories are +// makeAbility folds an accumulated uptime and a direction's forward totals into +// a ForwardingAbility carrying the raw facts. Derived rates and categories are // left to the consumer. func makeAbility(totalUptime time.Duration, - totalAmt btcutil.Amount) *ForwardingAbility { + totals pairForwards) *ForwardingAbility { return &ForwardingAbility{ EffectiveUptime: totalUptime, - ForwardedAmount: totalAmt, + ForwardedAmount: totals.amount, + FeeMsat: totals.feeMsat, + Forwards: totals.forwards, } } diff --git a/chanevents/analyzer_test.go b/chanevents/analyzer_test.go index ced5e5d..f95c9fb 100644 --- a/chanevents/analyzer_test.go +++ b/chanevents/analyzer_test.go @@ -9,6 +9,7 @@ import ( "github.com/lightninglabs/lndclient" "github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/fn/v2" + "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" "github.com/stretchr/testify/require" ) @@ -596,9 +597,20 @@ func TestCalculateBothDirectionsUptime(t *testing.T) { func(t *testing.T) { t.Parallel() - var totalSuccessfulAmount btcutil.Amount + forwards := pairForwards{ + forwards: int64(len(tc.successAmts)), + } for _, amt := range tc.successAmts { - totalSuccessfulAmount += amt + forwards.amount += amt + + // Two msat of fee per satoshi + // forwarded, so the fee total is + // distinct from the volume total and a + // crossed assignment fails the + // assertion below. + forwards.feeMsat += lnwire.MilliSatoshi( + amt, + ) * 2 } mergedEvents := mergeEventSlices( @@ -622,9 +634,9 @@ func TestCalculateBothDirectionsUptime(t *testing.T) { } } - // The (B→A) forwarded total is not asserted by - // this test; pass zero so the second ability is - // well-defined but ignored. + // The (B→A) forwarded totals are not asserted + // by this test; pass the zero value so the + // second ability is well-defined but ignored. abilityAB, _, err := calculateBothDirectionsUptime( context.Background(), @@ -634,12 +646,14 @@ func TestCalculateBothDirectionsUptime(t *testing.T) { sumARemote, sumALocal, sumBRemote, sumBLocal, mergedEvents, - totalSuccessfulAmount, 0, + forwards, pairForwards{}, ) require.NoError(t, err) require.Equal(t, &ForwardingAbility{ EffectiveUptime: tc.expectedUptime, - ForwardedAmount: totalSuccessfulAmount, + ForwardedAmount: forwards.amount, + FeeMsat: forwards.feeMsat, + Forwards: forwards.forwards, }, abilityAB) }, ) @@ -702,7 +716,8 @@ func TestCalculateBothDirectionsUptimeAsymmetric(t *testing.T) { liquidityFloor, statesA, statesB, sumARemote, sumALocal, sumBRemote, sumBLocal, mergeEventSlices(nil, nil), - 100, 50, + pairForwards{amount: 100, feeMsat: 200, forwards: 2}, + pairForwards{amount: 50, feeMsat: 100, forwards: 1}, ) require.NoError(t, err) @@ -710,14 +725,18 @@ func TestCalculateBothDirectionsUptimeAsymmetric(t *testing.T) { t, &ForwardingAbility{ EffectiveUptime: 100 * time.Second, ForwardedAmount: 100, + FeeMsat: 200, + Forwards: 2, }, abilityAB, ) require.Equal( t, &ForwardingAbility{ // Forwards landed but BA never crossed the floor: zero - // uptime, volume still reported. + // uptime, volume and fees still reported. EffectiveUptime: 0, ForwardedAmount: 50, + FeeMsat: 100, + Forwards: 1, }, abilityBA, ) } @@ -1003,11 +1022,13 @@ func TestEffectiveUptimeArgs(t *testing.T) { ChannelIn: testShortChanID1, ChannelOut: testShortChanID2, AmountMsatOut: 100_000_000, // 100k sat + FeeMsat: 100_000, }, { ChannelIn: testShortChanID1, ChannelOut: testShortChanID2, AmountMsatOut: 300_000_000, // 300k sat + FeeMsat: 300_000, }, }, }, @@ -1020,7 +1041,7 @@ func TestEffectiveUptimeArgs(t *testing.T) { // Case 1: liquidityFloor = 50k. Liquidity of 1M exceeds the floor for // the whole 60s window, so effective uptime is the full minute and the - // forwarded volume is the 400k sat total. + // forwarded volume is the 400k sat total, earning 400k msat. abilities, err := a.EffectiveUptime(ctx, startTime, endTime, 50_000) require.NoError(t, err) @@ -1028,14 +1049,22 @@ func TestEffectiveUptimeArgs(t *testing.T) { require.Contains(t, abilities, pair) require.Equal(t, time.Minute, abilities[pair].EffectiveUptime) require.Equal(t, btcutil.Amount(400_000), abilities[pair].ForwardedAmount) + require.Equal( + t, lnwire.MilliSatoshi(400_000), abilities[pair].FeeMsat, + ) + require.EqualValues(t, 2, abilities[pair].Forwards) // Case 2: liquidityFloor = 1.5M, above the 1M liquidity, so the floor is - // never crossed and effective uptime is zero. The forwarded volume is - // still reported so the consumer keeps the demand signal. + // never crossed and effective uptime is zero. The forwarded volume and + // fees are still reported so the consumer keeps the signal. abilities, err = a.EffectiveUptime(ctx, startTime, endTime, 1_500_000) require.NoError(t, err) require.Contains(t, abilities, pair) require.Zero(t, abilities[pair].EffectiveUptime) require.Equal(t, btcutil.Amount(400_000), abilities[pair].ForwardedAmount) + require.Equal( + t, lnwire.MilliSatoshi(400_000), abilities[pair].FeeMsat, + ) + require.EqualValues(t, 2, abilities[pair].Forwards) } diff --git a/cmd/frcli/forwarding_ability.go b/cmd/frcli/forwarding_ability.go index f956708..93c88af 100644 --- a/cmd/frcli/forwarding_ability.go +++ b/cmd/frcli/forwarding_ability.go @@ -46,8 +46,11 @@ type pairView struct { PeerOut string `json:"peer_out"` EffectiveUptimeS int64 `json:"effective_uptime_s"` ForwardedSat int64 `json:"forwarded_sat"` + FeeMsat int64 `json:"fee_msat"` + Forwards int64 `json:"forwards"` UptimeFraction float64 `json:"uptime_fraction"` Velocity float64 `json:"velocity"` + FeeRate float64 `json:"fee_rate"` } func queryForwardingAbility(ctx *cli.Context) error { @@ -72,8 +75,8 @@ func queryForwardingAbility(ctx *cli.Context) error { return err } - // The metrics are raw, so derive uptime fraction and velocity here from - // the window the server reported. + // The metrics are raw, so derive uptime fraction, velocity and fee rate + // here from the window the server reported. windowSeconds := resp.EndTime - resp.StartTime var views []pairView @@ -91,14 +94,26 @@ func queryForwardingAbility(ctx *cli.Context) error { float64(ability.EffectiveUptimeS) } + // Fees over volume. A pair with only sub-satoshi + // forwards has no volume to divide by, so it keeps a + // zero rate rather than an infinite one. + var feeRate float64 + if ability.ForwardedSat > 0 { + feeRate = float64(ability.FeeMsat) / + (float64(ability.ForwardedSat) * 1000) + } + views = append( views, pairView{ PeerIn: inPeer, PeerOut: outPeer, EffectiveUptimeS: ability.EffectiveUptimeS, ForwardedSat: ability.ForwardedSat, + FeeMsat: ability.FeeMsat, + Forwards: ability.Forwards, UptimeFraction: uptimeFraction, Velocity: velocity, + FeeRate: feeRate, }, ) } diff --git a/frdrpc/faraday.pb.go b/frdrpc/faraday.pb.go index e854008..2142bde 100644 --- a/frdrpc/faraday.pb.go +++ b/frdrpc/faraday.pb.go @@ -2303,10 +2303,10 @@ type ForwardingAbilityResponse struct { // Sorted list of unique compressed 33-byte public keys of the peers. Peers [][]byte `protobuf:"bytes,1,rep,name=peers,proto3" json:"peers,omitempty"` // Sparse list of forwarding ability entries. An entry is present only for a - // pair that forwarded volume, carrying its exact effective_uptime_s and - // forwarded_sat. Pairs that did not forward are never listed here; they are - // either flagged in quiet_uptime_bitmask or absent. Entries take precedence - // over the bitmask for the same pair. + // pair that carried at least one forward, with its exact facts. Pairs that + // carried none are never listed here; they are either flagged in + // up_but_idle_bitmask or absent. Entries take precedence over the bitmask + // for the same pair. Entries []*ForwardingAbilityEntry `protobuf:"bytes,2,rep,name=entries,proto3" json:"entries,omitempty"` // The start of the window the metrics cover, as unix seconds. StartTime int64 `protobuf:"varint,3,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"` @@ -2314,8 +2314,8 @@ type ForwardingAbilityResponse struct { EndTime int64 `protobuf:"varint,4,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"` // A packed bitmask over the n*n ordered peer pairs, where n is the length // of peers. The bit at index in*n+out is set when that pair held at least - // the uptime_threshold fraction of effective uptime over the window but did - // not forward: the dense "up but idle" population. A pair with a forwarded + // the uptime_threshold fraction of effective uptime over the window but + // carried no forward: the dense "up but idle" population. A pair with an // entry is never flagged here. A pair that is neither listed in entries nor // flagged here had sub-threshold uptime and no forwards: treat it as zero. UpButIdleBitmask []byte `protobuf:"bytes,5,opt,name=up_but_idle_bitmask,json=upButIdleBitmask,proto3" json:"up_but_idle_bitmask,omitempty"` @@ -2410,8 +2410,20 @@ type ForwardingAbilityEntry struct { // Seconds the peer pair held at least the requested liquidity floor of // directional forwardable liquidity over the window. EffectiveUptimeS int64 `protobuf:"varint,2,opt,name=effective_uptime_s,json=effectiveUptimeS,proto3" json:"effective_uptime_s,omitempty"` - // Total successfully forwarded amount over the window, in satoshis. + // Total successfully forwarded amount over the window, in satoshis. A + // pair whose forwards were all sub-satoshi reports zero here and still + // reports them in forwards. ForwardedSat int64 `protobuf:"varint,3,opt,name=forwarded_sat,json=forwardedSat,proto3" json:"forwarded_sat,omitempty"` + // Total fees earned on the pair's forwards over the window, in + // millisatoshis. Fees are reported at millisatoshi granularity because a + // single forward routinely earns less than one satoshi, and a satoshi + // granular sum would floor a low-fee pair's earnings to zero. + FeeMsat int64 `protobuf:"varint,4,opt,name=fee_msat,json=feeMsat,proto3" json:"fee_msat,omitempty"` + // The number of successful forwards the pair carried over the window. It + // decides whether the pair forwarded at all, since both sums can be zero + // for one that did: sub-satoshi volume floors away and a zero-fee policy + // earns nothing. With forwarded_sat it also gives the mean forward size. + Forwards int64 `protobuf:"varint,5,opt,name=forwards,proto3" json:"forwards,omitempty"` } func (x *ForwardingAbilityEntry) Reset() { @@ -2467,6 +2479,20 @@ func (x *ForwardingAbilityEntry) GetForwardedSat() int64 { return 0 } +func (x *ForwardingAbilityEntry) GetFeeMsat() int64 { + if x != nil { + return x.FeeMsat + } + return 0 +} + +func (x *ForwardingAbilityEntry) GetForwards() int64 { + if x != nil { + return x.Forwards + } + return 0 +} + var File_faraday_proto protoreflect.FileDescriptor var file_faraday_proto_rawDesc = []byte{ @@ -2756,7 +2782,7 @@ var file_faraday_proto_rawDesc = []byte{ 0x0c, 0x52, 0x10, 0x75, 0x70, 0x42, 0x75, 0x74, 0x49, 0x64, 0x6c, 0x65, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x73, 0x6b, 0x12, 0x29, 0x0a, 0x10, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0f, 0x75, - 0x70, 0x74, 0x69, 0x6d, 0x65, 0x54, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x22, 0x8a, + 0x70, 0x74, 0x69, 0x6d, 0x65, 0x54, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x22, 0xc1, 0x01, 0x0a, 0x16, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x41, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x70, @@ -2765,101 +2791,105 @@ var file_faraday_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x65, 0x64, 0x5f, 0x73, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x66, - 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x65, 0x64, 0x53, 0x61, 0x74, 0x2a, 0xa1, 0x01, 0x0a, 0x0b, - 0x47, 0x72, 0x61, 0x6e, 0x75, 0x6c, 0x61, 0x72, 0x69, 0x74, 0x79, 0x12, 0x17, 0x0a, 0x13, 0x55, - 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x47, 0x52, 0x41, 0x4e, 0x55, 0x4c, 0x41, 0x52, 0x49, - 0x54, 0x59, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4d, 0x49, 0x4e, 0x55, 0x54, 0x45, 0x10, 0x01, - 0x12, 0x10, 0x0a, 0x0c, 0x46, 0x49, 0x56, 0x45, 0x5f, 0x4d, 0x49, 0x4e, 0x55, 0x54, 0x45, 0x53, - 0x10, 0x02, 0x12, 0x13, 0x0a, 0x0f, 0x46, 0x49, 0x46, 0x54, 0x45, 0x45, 0x4e, 0x5f, 0x4d, 0x49, - 0x4e, 0x55, 0x54, 0x45, 0x53, 0x10, 0x03, 0x12, 0x12, 0x0a, 0x0e, 0x54, 0x48, 0x49, 0x52, 0x54, - 0x59, 0x5f, 0x4d, 0x49, 0x4e, 0x55, 0x54, 0x45, 0x53, 0x10, 0x04, 0x12, 0x08, 0x0a, 0x04, 0x48, - 0x4f, 0x55, 0x52, 0x10, 0x05, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x49, 0x58, 0x5f, 0x48, 0x4f, 0x55, - 0x52, 0x53, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x57, 0x45, 0x4c, 0x56, 0x45, 0x5f, 0x48, - 0x4f, 0x55, 0x52, 0x53, 0x10, 0x07, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x41, 0x59, 0x10, 0x08, 0x2a, - 0x6a, 0x0a, 0x0b, 0x46, 0x69, 0x61, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x17, - 0x0a, 0x13, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x46, 0x49, 0x41, 0x54, 0x42, 0x41, - 0x43, 0x4b, 0x45, 0x4e, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x4f, 0x49, 0x4e, 0x43, - 0x41, 0x50, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x4f, 0x49, 0x4e, 0x44, 0x45, 0x53, 0x4b, - 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x55, 0x53, 0x54, 0x4f, 0x4d, 0x10, 0x03, 0x12, 0x0d, - 0x0a, 0x09, 0x43, 0x4f, 0x49, 0x4e, 0x47, 0x45, 0x43, 0x4b, 0x4f, 0x10, 0x04, 0x12, 0x0c, 0x0a, - 0x08, 0x42, 0x49, 0x54, 0x46, 0x49, 0x4e, 0x45, 0x58, 0x10, 0x05, 0x2a, 0xa2, 0x02, 0x0a, 0x09, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, - 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x4c, 0x4f, 0x43, 0x41, 0x4c, 0x5f, - 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x4f, 0x50, 0x45, 0x4e, 0x10, 0x01, 0x12, 0x17, - 0x0a, 0x13, 0x52, 0x45, 0x4d, 0x4f, 0x54, 0x45, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, - 0x5f, 0x4f, 0x50, 0x45, 0x4e, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x43, 0x48, 0x41, 0x4e, 0x4e, - 0x45, 0x4c, 0x5f, 0x4f, 0x50, 0x45, 0x4e, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x03, 0x12, 0x11, 0x0a, - 0x0d, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x43, 0x4c, 0x4f, 0x53, 0x45, 0x10, 0x04, - 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x45, 0x43, 0x45, 0x49, 0x50, 0x54, 0x10, 0x05, 0x12, 0x0b, 0x0a, - 0x07, 0x50, 0x41, 0x59, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x06, 0x12, 0x07, 0x0a, 0x03, 0x46, 0x45, - 0x45, 0x10, 0x07, 0x12, 0x14, 0x0a, 0x10, 0x43, 0x49, 0x52, 0x43, 0x55, 0x4c, 0x41, 0x52, 0x5f, - 0x52, 0x45, 0x43, 0x45, 0x49, 0x50, 0x54, 0x10, 0x08, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x4f, 0x52, - 0x57, 0x41, 0x52, 0x44, 0x10, 0x09, 0x12, 0x0f, 0x0a, 0x0b, 0x46, 0x4f, 0x52, 0x57, 0x41, 0x52, - 0x44, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0a, 0x12, 0x14, 0x0a, 0x10, 0x43, 0x49, 0x52, 0x43, 0x55, - 0x4c, 0x41, 0x52, 0x5f, 0x50, 0x41, 0x59, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x0b, 0x12, 0x10, 0x0a, - 0x0c, 0x43, 0x49, 0x52, 0x43, 0x55, 0x4c, 0x41, 0x52, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0c, 0x12, - 0x09, 0x0a, 0x05, 0x53, 0x57, 0x45, 0x45, 0x50, 0x10, 0x0d, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x57, - 0x45, 0x45, 0x50, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0e, 0x12, 0x15, 0x0a, 0x11, 0x43, 0x48, 0x41, - 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x43, 0x4c, 0x4f, 0x53, 0x45, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0f, - 0x2a, 0x70, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, - 0x4e, 0x54, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x15, 0x0a, 0x11, - 0x43, 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x4f, 0x4e, 0x4c, 0x49, 0x4e, - 0x45, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, - 0x54, 0x5f, 0x4f, 0x46, 0x46, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x15, 0x0a, 0x11, 0x43, - 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, - 0x10, 0x03, 0x32, 0x83, 0x06, 0x0a, 0x0d, 0x46, 0x61, 0x72, 0x61, 0x64, 0x61, 0x79, 0x53, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x12, 0x65, 0x0a, 0x16, 0x4f, 0x75, 0x74, 0x6c, 0x69, 0x65, 0x72, 0x52, - 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x25, - 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x4f, 0x75, 0x74, 0x6c, 0x69, 0x65, 0x72, 0x52, - 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, - 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x69, 0x0a, 0x18, 0x54, - 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, - 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x27, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, - 0x2e, 0x54, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, - 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x24, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, - 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a, 0x0d, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x75, - 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1c, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, - 0x2e, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x75, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x52, - 0x65, 0x76, 0x65, 0x6e, 0x75, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x52, 0x0a, 0x0f, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, - 0x6e, 0x73, 0x69, 0x67, 0x68, 0x74, 0x73, 0x12, 0x1e, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, - 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x6e, 0x73, 0x69, 0x67, 0x68, 0x74, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, - 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x6e, 0x73, 0x69, 0x67, 0x68, 0x74, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x0c, 0x45, 0x78, 0x63, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x52, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, - 0x63, 0x2e, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x45, - 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x40, 0x0a, 0x09, 0x4e, 0x6f, 0x64, 0x65, 0x41, 0x75, 0x64, 0x69, 0x74, - 0x12, 0x18, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x41, 0x75, - 0x64, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x66, 0x72, 0x64, - 0x72, 0x70, 0x63, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x41, 0x75, 0x64, 0x69, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46, 0x0a, 0x0b, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, - 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1a, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6c, - 0x6f, 0x73, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1b, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, - 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4f, 0x0a, - 0x10, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, - 0x73, 0x12, 0x1c, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1d, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x58, - 0x0a, 0x11, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x41, 0x62, 0x69, 0x6c, - 0x69, 0x74, 0x79, 0x12, 0x20, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x46, 0x6f, 0x72, - 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x41, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x46, - 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x41, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, - 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x66, 0x61, 0x72, 0x61, 0x64, 0x61, 0x79, 0x2f, 0x66, 0x72, 0x64, - 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x65, 0x64, 0x53, 0x61, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x66, + 0x65, 0x65, 0x5f, 0x6d, 0x73, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x66, + 0x65, 0x65, 0x4d, 0x73, 0x61, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, + 0x64, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, + 0x64, 0x73, 0x2a, 0xa1, 0x01, 0x0a, 0x0b, 0x47, 0x72, 0x61, 0x6e, 0x75, 0x6c, 0x61, 0x72, 0x69, + 0x74, 0x79, 0x12, 0x17, 0x0a, 0x13, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x47, 0x52, + 0x41, 0x4e, 0x55, 0x4c, 0x41, 0x52, 0x49, 0x54, 0x59, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4d, + 0x49, 0x4e, 0x55, 0x54, 0x45, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x46, 0x49, 0x56, 0x45, 0x5f, + 0x4d, 0x49, 0x4e, 0x55, 0x54, 0x45, 0x53, 0x10, 0x02, 0x12, 0x13, 0x0a, 0x0f, 0x46, 0x49, 0x46, + 0x54, 0x45, 0x45, 0x4e, 0x5f, 0x4d, 0x49, 0x4e, 0x55, 0x54, 0x45, 0x53, 0x10, 0x03, 0x12, 0x12, + 0x0a, 0x0e, 0x54, 0x48, 0x49, 0x52, 0x54, 0x59, 0x5f, 0x4d, 0x49, 0x4e, 0x55, 0x54, 0x45, 0x53, + 0x10, 0x04, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x4f, 0x55, 0x52, 0x10, 0x05, 0x12, 0x0d, 0x0a, 0x09, + 0x53, 0x49, 0x58, 0x5f, 0x48, 0x4f, 0x55, 0x52, 0x53, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x54, + 0x57, 0x45, 0x4c, 0x56, 0x45, 0x5f, 0x48, 0x4f, 0x55, 0x52, 0x53, 0x10, 0x07, 0x12, 0x07, 0x0a, + 0x03, 0x44, 0x41, 0x59, 0x10, 0x08, 0x2a, 0x6a, 0x0a, 0x0b, 0x46, 0x69, 0x61, 0x74, 0x42, 0x61, + 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x17, 0x0a, 0x13, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, + 0x5f, 0x46, 0x49, 0x41, 0x54, 0x42, 0x41, 0x43, 0x4b, 0x45, 0x4e, 0x44, 0x10, 0x00, 0x12, 0x0b, + 0x0a, 0x07, 0x43, 0x4f, 0x49, 0x4e, 0x43, 0x41, 0x50, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x43, + 0x4f, 0x49, 0x4e, 0x44, 0x45, 0x53, 0x4b, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x55, 0x53, + 0x54, 0x4f, 0x4d, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x49, 0x4e, 0x47, 0x45, 0x43, + 0x4b, 0x4f, 0x10, 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x42, 0x49, 0x54, 0x46, 0x49, 0x4e, 0x45, 0x58, + 0x10, 0x05, 0x2a, 0xa2, 0x02, 0x0a, 0x09, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x16, 0x0a, + 0x12, 0x4c, 0x4f, 0x43, 0x41, 0x4c, 0x5f, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x4f, + 0x50, 0x45, 0x4e, 0x10, 0x01, 0x12, 0x17, 0x0a, 0x13, 0x52, 0x45, 0x4d, 0x4f, 0x54, 0x45, 0x5f, + 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x4f, 0x50, 0x45, 0x4e, 0x10, 0x02, 0x12, 0x14, + 0x0a, 0x10, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x4f, 0x50, 0x45, 0x4e, 0x5f, 0x46, + 0x45, 0x45, 0x10, 0x03, 0x12, 0x11, 0x0a, 0x0d, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, + 0x43, 0x4c, 0x4f, 0x53, 0x45, 0x10, 0x04, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x45, 0x43, 0x45, 0x49, + 0x50, 0x54, 0x10, 0x05, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x41, 0x59, 0x4d, 0x45, 0x4e, 0x54, 0x10, + 0x06, 0x12, 0x07, 0x0a, 0x03, 0x46, 0x45, 0x45, 0x10, 0x07, 0x12, 0x14, 0x0a, 0x10, 0x43, 0x49, + 0x52, 0x43, 0x55, 0x4c, 0x41, 0x52, 0x5f, 0x52, 0x45, 0x43, 0x45, 0x49, 0x50, 0x54, 0x10, 0x08, + 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x4f, 0x52, 0x57, 0x41, 0x52, 0x44, 0x10, 0x09, 0x12, 0x0f, 0x0a, + 0x0b, 0x46, 0x4f, 0x52, 0x57, 0x41, 0x52, 0x44, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0a, 0x12, 0x14, + 0x0a, 0x10, 0x43, 0x49, 0x52, 0x43, 0x55, 0x4c, 0x41, 0x52, 0x5f, 0x50, 0x41, 0x59, 0x4d, 0x45, + 0x4e, 0x54, 0x10, 0x0b, 0x12, 0x10, 0x0a, 0x0c, 0x43, 0x49, 0x52, 0x43, 0x55, 0x4c, 0x41, 0x52, + 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0c, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x57, 0x45, 0x45, 0x50, 0x10, + 0x0d, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x57, 0x45, 0x45, 0x50, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0e, + 0x12, 0x15, 0x0a, 0x11, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x5f, 0x43, 0x4c, 0x4f, 0x53, + 0x45, 0x5f, 0x46, 0x45, 0x45, 0x10, 0x0f, 0x2a, 0x70, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x6e, + 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x43, + 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, + 0x4e, 0x10, 0x00, 0x12, 0x15, 0x0a, 0x11, 0x43, 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, + 0x54, 0x5f, 0x4f, 0x4e, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x48, + 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x4f, 0x46, 0x46, 0x4c, 0x49, 0x4e, 0x45, + 0x10, 0x02, 0x12, 0x15, 0x0a, 0x11, 0x43, 0x48, 0x41, 0x4e, 0x5f, 0x45, 0x56, 0x45, 0x4e, 0x54, + 0x5f, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x03, 0x32, 0x83, 0x06, 0x0a, 0x0d, 0x46, 0x61, + 0x72, 0x61, 0x64, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x65, 0x0a, 0x16, 0x4f, + 0x75, 0x74, 0x6c, 0x69, 0x65, 0x72, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x25, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x4f, + 0x75, 0x74, 0x6c, 0x69, 0x65, 0x72, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x66, + 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x6d, + 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x69, 0x0a, 0x18, 0x54, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, 0x64, 0x52, + 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x27, + 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x54, 0x68, 0x72, 0x65, 0x73, 0x68, 0x6f, 0x6c, + 0x64, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, + 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a, + 0x0d, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x75, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1c, + 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x75, 0x65, 0x52, + 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x66, + 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x75, 0x65, 0x52, 0x65, 0x70, + 0x6f, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x52, 0x0a, 0x0f, 0x43, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x6e, 0x73, 0x69, 0x67, 0x68, 0x74, 0x73, 0x12, 0x1e, + 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, + 0x6e, 0x73, 0x69, 0x67, 0x68, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, + 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, + 0x6e, 0x73, 0x69, 0x67, 0x68, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x49, 0x0a, 0x0c, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x61, 0x74, 0x65, 0x12, + 0x1b, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x52, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x66, + 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x40, 0x0a, 0x09, 0x4e, 0x6f, + 0x64, 0x65, 0x41, 0x75, 0x64, 0x69, 0x74, 0x12, 0x18, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, + 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x41, 0x75, 0x64, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x19, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x41, + 0x75, 0x64, 0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46, 0x0a, 0x0b, + 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1a, 0x2e, 0x66, 0x72, + 0x64, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, + 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4f, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, + 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1c, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, + 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x58, 0x0a, 0x11, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, + 0x69, 0x6e, 0x67, 0x41, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x20, 0x2e, 0x66, 0x72, 0x64, + 0x72, 0x70, 0x63, 0x2e, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x41, 0x62, + 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x66, + 0x72, 0x64, 0x72, 0x70, 0x63, 0x2e, 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, + 0x41, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, + 0x67, 0x68, 0x74, 0x6e, 0x69, 0x6e, 0x67, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x66, 0x61, 0x72, 0x61, + 0x64, 0x61, 0x79, 0x2f, 0x66, 0x72, 0x64, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/frdrpc/faraday.proto b/frdrpc/faraday.proto index cd551d0..22dd372 100644 --- a/frdrpc/faraday.proto +++ b/frdrpc/faraday.proto @@ -711,10 +711,10 @@ message ForwardingAbilityResponse { repeated bytes peers = 1; // Sparse list of forwarding ability entries. An entry is present only for a - // pair that forwarded volume, carrying its exact effective_uptime_s and - // forwarded_sat. Pairs that did not forward are never listed here; they are - // either flagged in quiet_uptime_bitmask or absent. Entries take precedence - // over the bitmask for the same pair. + // pair that carried at least one forward, with its exact facts. Pairs that + // carried none are never listed here; they are either flagged in + // up_but_idle_bitmask or absent. Entries take precedence over the bitmask + // for the same pair. repeated ForwardingAbilityEntry entries = 2; // The start of the window the metrics cover, as unix seconds. @@ -725,8 +725,8 @@ message ForwardingAbilityResponse { // A packed bitmask over the n*n ordered peer pairs, where n is the length // of peers. The bit at index in*n+out is set when that pair held at least - // the uptime_threshold fraction of effective uptime over the window but did - // not forward: the dense "up but idle" population. A pair with a forwarded + // the uptime_threshold fraction of effective uptime over the window but + // carried no forward: the dense "up but idle" population. A pair with an // entry is never flagged here. A pair that is neither listed in entries nor // flagged here had sub-threshold uptime and no forwards: treat it as zero. bytes up_but_idle_bitmask = 5; @@ -746,6 +746,20 @@ message ForwardingAbilityEntry { // directional forwardable liquidity over the window. int64 effective_uptime_s = 2; - // Total successfully forwarded amount over the window, in satoshis. + // Total successfully forwarded amount over the window, in satoshis. A + // pair whose forwards were all sub-satoshi reports zero here and still + // reports them in forwards. int64 forwarded_sat = 3; + + // Total fees earned on the pair's forwards over the window, in + // millisatoshis. Fees are reported at millisatoshi granularity because a + // single forward routinely earns less than one satoshi, and a satoshi + // granular sum would floor a low-fee pair's earnings to zero. + int64 fee_msat = 4; + + // The number of successful forwards the pair carried over the window. It + // decides whether the pair forwarded at all, since both sums can be zero + // for one that did: sub-satoshi volume floors away and a zero-fee policy + // earns nothing. With forwarded_sat it also gives the mean forward size. + int64 forwards = 5; } diff --git a/frdrpc/faraday.swagger.json b/frdrpc/faraday.swagger.json index 2bcc0db..1e0262c 100644 --- a/frdrpc/faraday.swagger.json +++ b/frdrpc/faraday.swagger.json @@ -1041,7 +1041,17 @@ "forwarded_sat": { "type": "string", "format": "int64", - "description": "Total successfully forwarded amount over the window, in satoshis." + "description": "Total successfully forwarded amount over the window, in satoshis. A\npair whose forwards were all sub-satoshi reports zero here and still\nreports them in forwards." + }, + "fee_msat": { + "type": "string", + "format": "int64", + "description": "Total fees earned on the pair's forwards over the window, in\nmillisatoshis. Fees are reported at millisatoshi granularity because a\nsingle forward routinely earns less than one satoshi, and a satoshi\ngranular sum would floor a low-fee pair's earnings to zero." + }, + "forwards": { + "type": "string", + "format": "int64", + "description": "The number of successful forwards the pair carried over the window. It\ndecides whether the pair forwarded at all, since both sums can be zero\nfor one that did: sub-satoshi volume floors away and a zero-fee policy\nearns nothing. With forwarded_sat it also gives the mean forward size." } } }, @@ -1062,7 +1072,7 @@ "type": "object", "$ref": "#/definitions/frdrpcForwardingAbilityEntry" }, - "description": "Sparse list of forwarding ability entries. An entry is present only for a\npair that forwarded volume, carrying its exact effective_uptime_s and\nforwarded_sat. Pairs that did not forward are never listed here; they are\neither flagged in quiet_uptime_bitmask or absent. Entries take precedence\nover the bitmask for the same pair." + "description": "Sparse list of forwarding ability entries. An entry is present only for a\npair that carried at least one forward, with its exact facts. Pairs that\ncarried none are never listed here; they are either flagged in\nup_but_idle_bitmask or absent. Entries take precedence over the bitmask\nfor the same pair." }, "start_time": { "type": "string", @@ -1077,7 +1087,7 @@ "up_but_idle_bitmask": { "type": "string", "format": "byte", - "description": "A packed bitmask over the n*n ordered peer pairs, where n is the length\nof peers. The bit at index in*n+out is set when that pair held at least\nthe uptime_threshold fraction of effective uptime over the window but did\nnot forward: the dense \"up but idle\" population. A pair with a forwarded\nentry is never flagged here. A pair that is neither listed in entries nor\nflagged here had sub-threshold uptime and no forwards: treat it as zero." + "description": "A packed bitmask over the n*n ordered peer pairs, where n is the length\nof peers. The bit at index in*n+out is set when that pair held at least\nthe uptime_threshold fraction of effective uptime over the window but\ncarried no forward: the dense \"up but idle\" population. A pair with an\nentry is never flagged here. A pair that is neither listed in entries nor\nflagged here had sub-threshold uptime and no forwards: treat it as zero." }, "uptime_threshold": { "type": "number", diff --git a/frdrpc/forwarding_ability_codec.go b/frdrpc/forwarding_ability_codec.go index e105ac6..6821d24 100644 --- a/frdrpc/forwarding_ability_codec.go +++ b/frdrpc/forwarding_ability_codec.go @@ -27,8 +27,21 @@ type ForwardingAbility struct { EffectiveUptimeS int64 // ForwardedSat is the total successfully forwarded amount over the - // window, in satoshis. + // window, in satoshis. A pair whose forwards were all sub-satoshi + // reports zero here and still reports them in Forwards. ForwardedSat int64 + + // FeeMsat is the total fee earned on the pair's forwards over the + // window, in millisatoshis. A single forward routinely earns less than + // one satoshi, so a satoshi granular sum would floor a low-fee pair's + // earnings to zero. + FeeMsat int64 + + // Forwards is how many successful forwards the pair carried. It decides + // whether the pair forwarded at all, since both sums can be zero for + // one that did: sub-satoshi volume floors away and a zero-fee policy + // earns nothing. + Forwards int64 } // abilityTier classifies how a pair is encoded: a full entry, a single "up but @@ -36,16 +49,18 @@ type ForwardingAbility struct { type abilityTier int const ( - // tierAbsent omits the pair: it neither forwarded nor held enough - // uptime to clear the threshold. Consumers treat absence as zero. + // tierAbsent omits the pair: it carried no forward and did not hold + // enough uptime to clear the threshold. Consumers treat absence as + // zero. tierAbsent abilityTier = iota // tierBit flags the pair in the up-but-idle bitmask: it held at least - // the uptime threshold but did not forward. + // the uptime threshold but carried no forward. tierBit - // tierEntry emits a full entry carrying the pair's exact uptime and - // forwarded volume. Reserved for pairs that actually forwarded. + // tierEntry emits a full entry carrying the pair's exact uptime, + // forwarded volume, fees and forward count. Reserved for pairs that + // actually forwarded. tierEntry ) @@ -53,9 +68,12 @@ const ( // seconds. Forwarding always wins, so a pair that forwarded keeps its exact // facts even if its uptime is below the threshold; otherwise the pair is // compacted to a bit when it was up enough, and dropped when it was not. +// +// The count decides whether the pair forwarded, not the sums: both can be zero +// for a pair that did, and demoting it to a bit would record it as idle. func (a ForwardingAbility) tier(minUptimeS int64) abilityTier { switch { - case a.ForwardedSat > 0: + case a.Forwards > 0: return tierEntry case a.EffectiveUptimeS >= minUptimeS: @@ -102,11 +120,11 @@ func getBit(mask []byte, index int64) bool { // EncodeForwardingAbility serializes a nested map of peer forwarding abilities // into a memory-efficient sparse gRPC response over [startTime, endTime]. To -// optimize payload size it tiers each pair: pairs that forwarded keep a full -// entry, pairs that were up at least uptimeThreshold of the window but did not -// forward collapse to a single bit in the up-but-idle bitmask, and pairs below -// the threshold that did not forward are omitted entirely. Public keys are -// deduplicated and peer pairs packed into 32-bit indices. +// optimize payload size it tiers each pair: pairs that carried at least one +// forward keep a full entry, pairs that were up at least uptimeThreshold of the +// window but carried none collapse to a single bit in the up-but-idle bitmask, +// and pairs below the threshold that carried none are omitted entirely. Public +// keys are deduplicated and peer pairs packed into 32-bit indices. func EncodeForwardingAbility(abilities map[string]map[string]ForwardingAbility, startTime, endTime int64, uptimeThreshold float64) (*ForwardingAbilityResponse, error) { @@ -178,6 +196,8 @@ func EncodeForwardingAbility(abilities map[string]map[string]ForwardingAbility, PackedIdx: packed, EffectiveUptimeS: a.EffectiveUptimeS, ForwardedSat: a.ForwardedSat, + FeeMsat: a.FeeMsat, + Forwards: a.Forwards, }) } @@ -252,8 +272,9 @@ func EncodeForwardingAbility(abilities map[string]map[string]ForwardingAbility, // DecodeForwardingAbility reconstructs the nested map of peer forwarding // abilities from a sparse packed gRPC response. Forwarded pairs come back with // their exact facts; up-but-idle pairs flagged in the bitmask come back at full -// window uptime with zero forwarded volume. It validates packed indices and the -// bitmask length against the decoded peer list to prevent out-of-bounds errors. +// window uptime with no forwards, and therefore no volume and no fees. It +// validates packed indices and the bitmask length against the decoded peer list +// to prevent out-of-bounds errors. func DecodeForwardingAbility(resp *ForwardingAbilityResponse) ( map[string]map[string]ForwardingAbility, error) { @@ -300,6 +321,8 @@ func DecodeForwardingAbility(resp *ForwardingAbilityResponse) ( inIdx, outIdx, ForwardingAbility{ EffectiveUptimeS: entry.EffectiveUptimeS, ForwardedSat: entry.ForwardedSat, + FeeMsat: entry.FeeMsat, + Forwards: entry.Forwards, }, ) } @@ -321,10 +344,11 @@ func DecodeForwardingAbility(resp *ForwardingAbilityResponse) ( } // Up-but-idle pairs were up the whole window by definition of the - // threshold bucket, so reconstruct them at full window uptime with zero - // forwarded volume. Iterate over the bitmask bytes directly, skipping - // zero bytes, so cost scales with the number of set bits rather than - // the O(n*n) pair space; padding bits beyond n*n are ignored. + // threshold bucket, so reconstruct them at full window uptime with no + // forwards, and therefore no volume and no fees. Iterate over the + // bitmask bytes directly, skipping zero bytes, so cost scales with the + // number of set bits rather than the O(n*n) pair space; padding bits + // beyond n*n are ignored. windowSeconds := resp.EndTime - resp.StartTime for i, b := range bitmask { if b == 0 { diff --git a/frdrpc/forwarding_ability_codec_test.go b/frdrpc/forwarding_ability_codec_test.go index 7029138..f4e38d9 100644 --- a/frdrpc/forwarding_ability_codec_test.go +++ b/frdrpc/forwarding_ability_codec_test.go @@ -25,9 +25,9 @@ type pair struct { } // TestForwardingAbilityCodecRoundTrip verifies the three-tier encoding: pairs -// that forwarded keep exact facts as entries, pairs up at least the threshold -// but idle collapse to a bitmask bit (decoded at full window uptime), and -// sub-threshold idle pairs are dropped. The window is [0, 100) and the +// that carried a forward keep exact facts as entries, pairs up at least the +// threshold but idle collapse to a bitmask bit (decoded at full window uptime), +// and sub-threshold idle pairs are dropped. The window is [0, 100) and the // threshold 0.5, so the minimum qualifying uptime is 50 seconds. func TestForwardingAbilityCodecRoundTrip(t *testing.T) { const ( @@ -52,12 +52,16 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { fwdKey(2): { EffectiveUptimeS: 80, ForwardedSat: 1500, + FeeMsat: 1500, + Forwards: 3, }, }, fwdKey(2): { fwdKey(1): { EffectiveUptimeS: 0, ForwardedSat: 2500, + FeeMsat: 5000, + Forwards: 1, }, }, }, @@ -70,16 +74,20 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { fwdKey(1), fwdKey(2), ForwardingAbility{ - 80, - 1500, + EffectiveUptimeS: 80, + ForwardedSat: 1500, + FeeMsat: 1500, + Forwards: 3, }, }, { fwdKey(2), fwdKey(1), ForwardingAbility{ - 0, - 2500, + EffectiveUptimeS: 0, + ForwardedSat: 2500, + FeeMsat: 5000, + Forwards: 1, }, }, }, @@ -111,16 +119,14 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { fwdKey(1), fwdKey(2), ForwardingAbility{ - 100, - 0, + EffectiveUptimeS: 100, }, }, { fwdKey(3), fwdKey(1), ForwardingAbility{ - 100, - 0, + EffectiveUptimeS: 100, }, }, }, @@ -149,6 +155,8 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { fwdKey(2): { EffectiveUptimeS: 80, ForwardedSat: 1500, + FeeMsat: 750, + Forwards: 2, }, fwdKey(3): { EffectiveUptimeS: 60, @@ -162,6 +170,8 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { fwdKey(3): { fwdKey(1): { ForwardedSat: 500, + FeeMsat: 250, + Forwards: 1, }, }, }, @@ -175,24 +185,26 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { fwdKey(1), fwdKey(2), ForwardingAbility{ - 80, - 1500, + EffectiveUptimeS: 80, + ForwardedSat: 1500, + FeeMsat: 750, + Forwards: 2, }, }, { fwdKey(1), fwdKey(3), ForwardingAbility{ - 100, - 0, + EffectiveUptimeS: 100, }, }, { fwdKey(3), fwdKey(1), ForwardingAbility{ - 0, - 500, + ForwardedSat: 500, + FeeMsat: 250, + Forwards: 1, }, }, }, @@ -246,6 +258,54 @@ func TestForwardingAbilityCodecRoundTrip(t *testing.T) { } } +// TestForwardingAbilityCodecZeroValueForward verifies that a pair whose +// forwards summed to no volume and no fees still survives as a full entry +// rather than collapsing to an up-but-idle bit. Both sums can legitimately be +// zero for a pair that really did forward, so only the count can tell the two +// apart, and recording such a pair as idle would report traffic that happened +// as traffic that did not. +func TestForwardingAbilityCodecZeroValueForward(t *testing.T) { + const ( + startTime, endTime int64 = 0, 100 + threshold float64 = 0.5 + ) + + abilities := map[string]map[string]ForwardingAbility{ + fwdKey(1): { + // Sub-satoshi volume and a zero-fee policy: the pair + // forwarded, but both sums floor to zero. + fwdKey(2): { + EffectiveUptimeS: 80, + Forwards: 2, + }, + }, + } + + resp, err := EncodeForwardingAbility( + abilities, startTime, endTime, threshold, + ) + require.NoError(t, err) + + // The pair clears the uptime threshold, so a volume-driven tier would + // have demoted it to a bit. It must be an entry instead, and the + // bitmask must stay empty. + require.Len(t, resp.Entries, 1) + require.Empty(t, resp.UpButIdleBitmask) + + decoded, err := DecodeForwardingAbility(resp) + require.NoError(t, err) + + // The entry keeps its exact uptime rather than the full-window uptime a + // decoded bit would have synthesized. + require.Equal( + t, ForwardingAbility{ + EffectiveUptimeS: 80, + Forwards: 2, + }, + decoded[fwdKey(1)][fwdKey(2)], + ) +} + // TestMinQualifyingUptime verifies the threshold-to-seconds conversion shared // by the encoder and the server guard, including its boundary behavior. func TestMinQualifyingUptime(t *testing.T) { @@ -336,6 +396,8 @@ func TestForwardingAbilityDecodeEntryPrecedence(t *testing.T) { PackedIdx: (0 << 16) | 1, EffectiveUptimeS: 42, ForwardedSat: 7, + FeeMsat: 21, + Forwards: 2, }, }, UpButIdleBitmask: mask, @@ -344,7 +406,12 @@ func TestForwardingAbilityDecodeEntryPrecedence(t *testing.T) { decoded, err := DecodeForwardingAbility(resp) require.NoError(t, err) require.Equal( - t, ForwardingAbility{42, 7}, + t, ForwardingAbility{ + EffectiveUptimeS: 42, + ForwardedSat: 7, + FeeMsat: 21, + Forwards: 2, + }, decoded[hex.EncodeToString([]byte{1})][hex.EncodeToString( []byte{2}, )], @@ -406,8 +473,11 @@ func TestForwardingAbilityDecodeBadBitmaskLen(t *testing.T) { func TestForwardingAbilityEncodePeerCap(t *testing.T) { outMap := make(map[string]ForwardingAbility) for i := 1; i <= maxPackedPeers+1; i++ { - // Use forwarded volume so inclusion is threshold-independent. - outMap[fwdKey(i)] = ForwardingAbility{ForwardedSat: 1} + // Use a carried forward so inclusion is threshold-independent. + outMap[fwdKey(i)] = ForwardingAbility{ + ForwardedSat: 1, + Forwards: 1, + } } abilities := map[string]map[string]ForwardingAbility{ fwdKey(0): outMap, @@ -429,11 +499,13 @@ func TestForwardingAbilityEncodeNormalizesCase(t *testing.T) { strings.ToUpper(peer): { fwdKey(2): { ForwardedSat: 20, + Forwards: 1, }, }, peer: { fwdKey(3): { ForwardedSat: 40, + Forwards: 1, }, }, } @@ -450,12 +522,14 @@ func TestForwardingAbilityEncodeNormalizesCase(t *testing.T) { require.Equal( t, ForwardingAbility{ ForwardedSat: 20, + Forwards: 1, }, decoded[peer][fwdKey(2)], ) require.Equal( t, ForwardingAbility{ ForwardedSat: 40, + Forwards: 1, }, decoded[peer][fwdKey(3)], ) @@ -474,11 +548,13 @@ func TestForwardingAbilityEncodeRejectsCaseCollision(t *testing.T) { strings.ToUpper(inPeer): { outPeer: { ForwardedSat: 10, + Forwards: 1, }, }, inPeer: { outPeer: { ForwardedSat: 20, + Forwards: 1, }, }, } @@ -514,6 +590,8 @@ func TestForwardingAbilityCodecRoundTripHighIndices(t *testing.T) { enc = ForwardingAbility{ EffectiveUptimeS: 70, ForwardedSat: int64(i + 1), + FeeMsat: int64(i + 1), + Forwards: 1, } dec = enc } else { diff --git a/frdrpcserver/forwarding_ability.go b/frdrpcserver/forwarding_ability.go index 2d4088b..9cc8652 100644 --- a/frdrpcserver/forwarding_ability.go +++ b/frdrpcserver/forwarding_ability.go @@ -128,6 +128,8 @@ func (s *RPCServer) ForwardingAbility(ctx context.Context, ability.EffectiveUptime.Seconds(), ), ForwardedSat: int64(ability.ForwardedAmount), + FeeMsat: int64(ability.FeeMsat), + Forwards: ability.Forwards, } } diff --git a/frdrpcserver/forwarding_ability_test.go b/frdrpcserver/forwarding_ability_test.go index f842dc6..f9e905a 100644 --- a/frdrpcserver/forwarding_ability_test.go +++ b/frdrpcserver/forwarding_ability_test.go @@ -67,6 +67,8 @@ func TestForwardingAbility(t *testing.T) { }: { EffectiveUptime: 90 * time.Second, ForwardedAmount: 550, + FeeMsat: 1100, + Forwards: 2, }, }, nil }, @@ -92,6 +94,12 @@ func TestForwardingAbility(t *testing.T) { require.EqualValues( t, 550, resp.Entries[0].ForwardedSat, ) + require.EqualValues( + t, 1100, resp.Entries[0].FeeMsat, + ) + require.EqualValues( + t, 2, resp.Entries[0].Forwards, + ) // An unset threshold echoes the server default, // and a forwarded pair leaves the bitmask empty. diff --git a/itest/channel_events_test.go b/itest/channel_events_test.go index b1befbd..2178bb1 100644 --- a/itest/channel_events_test.go +++ b/itest/channel_events_test.go @@ -229,9 +229,11 @@ func TestForwardingAbility(t *testing.T) { // The bob self-pair was up but never forwarded through itself, so it // surfaces via the up-but-idle bitmask: non-zero effective uptime and - // zero forwarded volume. + // no forwards, hence neither volume nor fees. require.Greater(c.t, ability.EffectiveUptimeS, int64(0)) + require.Zero(c.t, ability.Forwards) require.Zero(c.t, ability.ForwardedSat) + require.Zero(c.t, ability.FeeMsat) } // TestForwardingDowntime exercises the offline/online plumbing end to end. It