-
Notifications
You must be signed in to change notification settings - Fork 90
Feed peer selection governor with big ledger peers obtained from a snapshot #4850
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
Feed peer selection governor with big ledger peers obtained from a snapshot #4850
Conversation
4c893c8 to
e3cf273
Compare
30b0651 to
bd190c2
Compare
e0f3ac8 to
c074f34
Compare
coot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add some tests where the simulation nodes are using ledger snapshot rather as a source of big ledger peers. Network simulation tests are located here.
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Utils.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Utils.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/RelayAccessPoint.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/RelayAccessPoint.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/LedgerPeers.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Utils.hs
Outdated
Show resolved
Hide resolved
8916d88 to
062381a
Compare
062381a to
1d93e05
Compare
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/PeerSelection/LedgerPeers.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/PeerSelection/LedgerPeers.hs
Outdated
Show resolved
Hide resolved
1d93e05 to
ba520a7
Compare
9e0af35 to
bdae33f
Compare
d191be9 to
b3d24b1
Compare
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/RelayAccessPoint.hs
Outdated
Show resolved
Hide resolved
ouroboros-network-api/src/Ouroboros/Network/PeerSelection/LedgerPeers/Type.hs
Show resolved
Hide resolved
c2b80bf to
c63e4b6
Compare
304f889 to
dba4e75
Compare
dba4e75 to
149e98f
Compare
bolt12
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just stylistic comments!
| let (peersStakeMap, bigPeersStakeMap, lastSnapshotSlot'') = | ||
| stakeMapWithSlotOverSource StakeMapOverSource { | ||
| ledgerSlotNo, ledgerPools, peerSnapshot, | ||
| lastSnapshotSlot, peerMap, bigPeerMap, ula} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let (peersStakeMap, bigPeersStakeMap, lastSnapshotSlot'') = | |
| stakeMapWithSlotOverSource StakeMapOverSource { | |
| ledgerSlotNo, ledgerPools, peerSnapshot, | |
| lastSnapshotSlot, peerMap, bigPeerMap, ula} | |
| let (peersStakeMap, bigPeersStakeMap, lastSnapshotSlot'') = | |
| stakeMapWithSlotOverSource | |
| StakeMapOverSource { | |
| ledgerSlotNo | |
| , ledgerPools | |
| , peerSnapshot | |
| , lastSnapshotSlot | |
| , peerMap | |
| , bigPeerMap | |
| , ula | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
| let (peersStakeMap, bigPeersStakeMap, lastSnapshotSlot'') = | |
| stakeMapWithSlotOverSource StakeMapOverSource { | |
| ledgerSlotNo, ledgerPools, peerSnapshot, | |
| lastSnapshotSlot, peerMap, bigPeerMap, ula} | |
| let stakeMapOverSource = | |
| StakeMapOverSource { | |
| ledgerSlotNo | |
| , ledgerPools | |
| , peerSnapshot | |
| , lastSnapshotSlot | |
| , peerMap | |
| , bigPeerMap | |
| , ula | |
| } | |
| (peersStakeMap, bigPeersStakeMap, lastSnapshotSlot'') = | |
| stakeMapWithSlotOverSource stakeMapOverSource | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| case (ledgerWithOrigin, ledgerPeers, peerSnapshot) of | ||
| (At ledgerSlotNo, LedgerPeers _ ledgerRelays, Just (LedgerPeerSnapshot (At snapshotSlotNo, accSnapshotRelays))) | ||
| | snapshotSlotNo >= ledgerSlotNo -> -- we cache the peers from the snapshot to avoid unnecessary work | ||
| case cachedSlot of | ||
| Just thatSlot | thatSlot == snapshotSlotNo -> | ||
| (peerMap, bigPeerMap, cachedSlot) | ||
| _otherwise -> (accPoolStake (map snd accSnapshotRelays), Map.fromAscList accSnapshotRelays, Just snapshotSlotNo) | ||
| | otherwise -> (accPoolStake ledgerRelays, accBigPoolStakeMap ledgerRelays, Nothing) | ||
|
|
||
| (_, LedgerPeers _ ledgerRelays, Nothing) -> (accPoolStake ledgerRelays, accBigPoolStakeMap ledgerRelays, Nothing) | ||
|
|
||
| (_, _, Just (LedgerPeerSnapshot (At snapshotSlotNo, accSnapshotRelays))) | ||
| | After slot <- ula, snapshotSlotNo >= slot -> do | ||
| case cachedSlot of | ||
| Just thatSlot | thatSlot == snapshotSlotNo -> | ||
| (peerMap, bigPeerMap, cachedSlot) | ||
| _otherwise -> (accPoolStake (map snd accSnapshotRelays), Map.fromAscList accSnapshotRelays, Just snapshotSlotNo) | ||
|
|
||
| _otherwise -> (Map.empty, Map.empty, Nothing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to keep to 80 character width lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Depending on its topology configuration, a node may provide diffusion layer with a snapshot of big ledger peers from some slot. This value is provided as an argument when diffusion is initialized, and is provided to ledgerPeersThread function, which contains the logic when these peers, if any, can be provided to peer selection governor when it requests them. This is especially useful when consensus is ran in Genesis mode and when the node is bootstrapping so it may have opportunity to connect to these trustworthy peers when they may not be yet available on its own ledger.
149e98f to
170ae15
Compare
encoding, as well as checking that ToCBOR and FromCBOR are working together correctly.
Test is modified such that ledger peer pool relays are equal modulo fully qualified domain names to pool relays restored from snapshot. Also, since stake is serialised in floating point format, comparison to original Rational values is approximate.
Improved naming of functions related to calculating big ledger stake distribution which were to moved public ouroboros-network-api component.
170ae15 to
748fcf7
Compare
Description
Consensus Genesis syncing mode relies on having at least one honest peer to ensure a syncing node will finish on a good chain. Largest stake pools are a good proxy for honesty, and therefore these peers are the big ledger peers, which a syncing node may not be aware of when its ledger state may still be too stale. A snapshot file of these peers can be provided in a node's topology configuration, and this set will be provided to peer selection governor so it has an opportunity to make these connections.
This change modifies ledgerPeersThread to leverage this data, and appropriately randomly pick from this set and respond to peer selection governor when it makes a request for big ledger peers.
Checklist