Skip to content

Commit 88bf776

Browse files
Merge pull request #4850 from IntersectMBO/mwojtowicz/provide-peers-from-snapshot
Feed peer selection governor with big ledger peers obtained from a snapshot
2 parents 2c70d04 + 748fcf7 commit 88bf776

File tree

9 files changed

+393
-79
lines changed

9 files changed

+393
-79
lines changed

ouroboros-network-api/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* New type supports CBOR & JSON for serialisation purposes.
1515
* Ledger peer snapshot is versioned in case changes need to be made to the
1616
encoding format in the future.
17+
* Renamed:
18+
* `accBigPoolStake` -> `accumulateBigLedgerStake`
19+
and `reRelativeStake` -> `recomputeRelativeStake`
1720

1821
* Added `Measure` and `BoundedMeasure` instances for `SizeInBytes`.
1922

ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Utils.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
module Ouroboros.Network.PeerSelection.LedgerPeers.Utils
55
( bigLedgerPeerQuota
6-
, accBigPoolStake
7-
, reRelativeStake
6+
, accumulateBigLedgerStake
7+
, recomputeRelativeStake
88
, AccPoolStake (..)
99
, PoolStake (..)
1010
, RelayAccessPoint (..)
@@ -29,13 +29,13 @@ bigLedgerPeerQuota = 0.9
2929
-- and tag each one with cumulative stake, with a cutoff
3030
-- at 'bigLedgerPeerQuota'
3131
--
32-
accBigPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)]
33-
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))]
34-
accBigPoolStake =
32+
accumulateBigLedgerStake :: [(PoolStake, NonEmpty RelayAccessPoint)]
33+
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))]
34+
accumulateBigLedgerStake =
3535
takeWhilePrev (\(acc, _) -> acc <= bigLedgerPeerQuota)
3636
. go 0
3737
. sortOn (Down . fst)
38-
. reRelativeStake BigLedgerPeers
38+
. recomputeRelativeStake BigLedgerPeers
3939
where
4040
takeWhilePrev :: (a -> Bool) -> [a] -> [a]
4141
takeWhilePrev f as =
@@ -55,10 +55,10 @@ accBigPoolStake =
5555
-- | Not all stake pools have valid \/ usable relay information. This means that
5656
-- we need to recalculate the relative stake for each pool.
5757
--
58-
reRelativeStake :: LedgerPeersKind
58+
recomputeRelativeStake :: LedgerPeersKind
5959
-> [(PoolStake, NonEmpty RelayAccessPoint)]
6060
-> [(PoolStake, NonEmpty RelayAccessPoint)]
61-
reRelativeStake ledgerPeersKind pl =
61+
recomputeRelativeStake ledgerPeersKind pl =
6262
let pl' = first adjustment <$> pl
6363
total = List.foldl' (+) 0 (fst <$> pl')
6464
pl'' = first (/ total) <$> pl'

ouroboros-network/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
* moved `accBigPoolStake` and `reRelativeStake` to ouroboros-networking-api
88
in order to expose functionality of creating snapshots of big ledger peers,
99
eg. for Genesis consensus mode.
10+
* Introduced `daReadLedgerPeerSnapshot` to `P2P.ArgumentsExtra` which holds
11+
a `Maybe LedgerPeerSnapshot` from a node's configuration. If present, it
12+
may be used to pick big ledger peers by the peer selection governor when
13+
bootstrapping a node in Genesis consensus mode, or in general when
14+
LedgerStateJudgement = TooOld, subject to conditions in
15+
`LedgerPeers.ledgerPeersThread`.
1016

1117
### Non-Breaking changes
1218

@@ -15,6 +21,12 @@
1521
- Refactored Testnet suite according to changed Signal API.
1622
- Fixed block fetch client assertion failure
1723
* Make it build with ghc-9.10
24+
* Implemented provision of big ledger peers from the snapshot by `ledgerPeersThread`
25+
* Added property test checking if `ledgerPeersThread` is providing big ledger peers
26+
from the snapshot when appropriate conditions are met
27+
* Added property tests checking if `LedgerPeerSnapshot` CBOR encoding is valid,
28+
and decode/encode = id, as well as some property tests for calculating big ledger
29+
peers
1830

1931
## 0.16.1.1 -- 2024-06-28
2032

ouroboros-network/ouroboros-network.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ library sim-tests-lib
168168
quickcheck-monoids,
169169
aeson,
170170
array,
171+
cardano-binary,
171172
cborg,
172173
containers,
173174
deepseq,

ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Diffusion/Node.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,17 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
390390
mkArgsExtra :: StrictTVar m (Script UseBootstrapPeers)
391391
-> Diff.P2P.ArgumentsExtra m
392392
mkArgsExtra ubpVar = Diff.P2P.ArgumentsExtra
393-
{ Diff.P2P.daPeerSelectionTargets = aPeerSelectionTargets na
394-
, Diff.P2P.daReadLocalRootPeers = aReadLocalRootPeers na
395-
, Diff.P2P.daReadPublicRootPeers = aReadPublicRootPeers na
396-
, Diff.P2P.daReadUseBootstrapPeers = stepScriptSTM' ubpVar
397-
, Diff.P2P.daOwnPeerSharing = aOwnPeerSharing na
398-
, Diff.P2P.daReadUseLedgerPeers = aReadUseLedgerPeers na
399-
, Diff.P2P.daProtocolIdleTimeout = aProtocolIdleTimeout na
400-
, Diff.P2P.daTimeWaitTimeout = aTimeWaitTimeout na
401-
, Diff.P2P.daDeadlineChurnInterval = 3300
402-
, Diff.P2P.daBulkChurnInterval = 300
393+
{ Diff.P2P.daPeerSelectionTargets = aPeerSelectionTargets na
394+
, Diff.P2P.daReadLocalRootPeers = aReadLocalRootPeers na
395+
, Diff.P2P.daReadPublicRootPeers = aReadPublicRootPeers na
396+
, Diff.P2P.daReadUseBootstrapPeers = stepScriptSTM' ubpVar
397+
, Diff.P2P.daOwnPeerSharing = aOwnPeerSharing na
398+
, Diff.P2P.daReadUseLedgerPeers = aReadUseLedgerPeers na
399+
, Diff.P2P.daProtocolIdleTimeout = aProtocolIdleTimeout na
400+
, Diff.P2P.daTimeWaitTimeout = aTimeWaitTimeout na
401+
, Diff.P2P.daDeadlineChurnInterval = 3300
402+
, Diff.P2P.daBulkChurnInterval = 300
403+
, Diff.P2P.daReadLedgerPeerSnapshot = pure Nothing -- ^ tested independently
403404
}
404405

405406
appArgs :: Node.AppArgs BlockHeader Block m

0 commit comments

Comments
 (0)