-
Notifications
You must be signed in to change notification settings - Fork 86
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
LedgerSupportsPeerSelection: return peers registered in ledger state #2536
Conversation
$ shelleyState | ||
|
||
relayToDomainAddress :: SL.StakePoolRelay -> DomainAddress | ||
relayToDomainAddress = undefined |
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.
@coot @JaredCorduan This hole still needs to be filled in.
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.
@coot Don't forget about this hole.
@@ -24,6 +24,9 @@ module Ouroboros.Network.PeerSelection.RootPeersDNS ( | |||
DNS.Domain, | |||
DNS.TTL, | |||
IPv4, | |||
|
|||
-- * Socket type re-exports | |||
Socket.PortNumber, |
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.
@coot Thanks to this extra re-export and the re-exports in Ouroboros.Consensus.Ledger.SupportsPeerSelection
, it should not be necessary to import anything from the network layer or network-related packages in Ouroboros.Consensus.Shelley.Ledger.PeerSelection
.
5e96201
to
602c946
Compare
I changed the target of this branch to master as it doesn't rely on anything in https://github.com/input-output-hk/ouroboros-network/tree/coot/connection-manager and it being part of a feature branch that won't be merged quickly will just cause bigger conflicts in the end (I'm already creating conflicts with a PR I submitted to that branch 🙁). |
poolDomainAddresses :: Map (SL.KeyHash 'SL.StakePool c) [DomainAddress] | ||
poolDomainAddresses = | ||
Map.map (map relayToDomainAddress . toList . SL._poolRelays) | ||
. SL._pParams |
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.
FYI, if we change this from SL._pParams
to SL._fPParams
, we get the future pool parameters.
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.
Presumably that's the set that is updated when pools re-register (that we take snapshots from).
We should aim for:
- sampling pools from an appropriate stake distribution (e.g. the one used for block production in the current epoch)
- selecting the pool relays that are the most up to date, so that we can respond to changed relays more quickly than waiting 5 days
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.
About 1: I believe the current version of this PR uses that stake distribution. It "samples" it in that it returns all registered relays for each stake pool. So the list returned by getPeers
will look something like (with pool1
having the most stake, etc.):
[pool1_relay1, pool1_relay2, pool2_relay1, pool3_relay1, pool3_relay2, ..]
About 2: I suppose we can merge the relays from SL._pParams
with those of SL._fPParams
so we get the future relays as well. For example:
[pool1_relay1, pool1_relay2, pool1_future_relay3, ..]
Let me know what is wanted, I'm just the conduit between network and ledger.
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.
I think we need both current and future relays. The governor should try future relays first and if they are not yet accessible then resort to the current ones.
Another point is that it would be more useful to group relays for the same core node, would that be possible? e.g. [[pool1_relay1, pool1_relay2, pool1_future_relay3], ...]
. @dcoutts I think this would require some changes to the governor, but it's more useful to know in advance that which relays belong to the same stake pool, instead of relaying on tip-sample
to discover that through some heuristics.
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.
As mentioned, this PR already groups them per stake pool.
@coot Which order do you want for the relays? Future relays first, then the current ones? The other way around? You probably want the duplicates filtered out, right?
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.
I think it makes more sense to get future relays first, and we'd like to filter out duplicates.
602c946
to
225a16e
Compare
See discussion on slack, we might need an API of type getPeers :: LedgerState blk -> [(PoolStake, [DomainAddress])] |
This PR already provides getPeers :: LedgerState blk -> [(PoolStake, NonEmpty DomainAddress)] |
ff1e72a
to
0e6b061
Compare
@coot: I updated the PR to also include the relays registered in the future pool parameters. The only thing left to do, but not for me, is |
0e6b061
to
c8fb01c
Compare
Rebased against master |
c8fb01c
to
248d2de
Compare
ouroboros-consensus/src/Ouroboros/Consensus/Ledger/SupportsPeerSelection.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Ledger/SupportsPeerSelection.hs
Outdated
Show resolved
Hide resolved
-- | ||
-- If the slot is too far in the future w.r.t. the current ledger state, | ||
-- 'HF.PastHorizonException' will be returned. | ||
getSlotTime :: |
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.
WRONG: we can't use the current LedgerState
if we don't know anything about the header or block that has that SlotNo
. In particular, the safe zone that is appropriate for a header should extend from the intersection with our and their chain, not from our tip. Since we don't know the intersection point here, we might be incorrectly returning a UTCTime
while we should be returning a PastHorizonException
.
For example, if the SlotNo
is of a header on a chain that forked off before the transition to Shelley on mainnet and in that chain the transition to Shelley happened ten epochs later, this conversion is completely wrong.
Alternative: introduce a Timed a
which stores the header and the time corresponding to its slot (computed using the ledger state at the intersection!). It can also include the time at which the header was received by the ChainSyncClient.
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.
Who knew time was tricky? 🤔 😬
248d2de
to
076cdbd
Compare
09c32a3
to
1d7c50b
Compare
Rebased and squashed some commits. |
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/PeerSelection.hs
Show resolved
Hide resolved
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.
I already reviewed the network changes in the PR that where merged into this branch; I skimmed through consensus changes and they looked fine to me, but that was very rudimentary; I only analysed the LedgerSupportsPeerSelection (SheelyBlock era)
instance which I think is the core of what we need. @mrBliss should I look more closely into other parts?
Map (SL.KeyHash 'SL.StakePool (EraCrypto era)) (NonEmpty StakePoolRelay) | ||
poolRelayAddresses = | ||
Map.unionWith | ||
(\futureRelays currentRelays -> NE.nub (futureRelays <> currentRelays)) |
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.
Looks good, we want both future and current relays.
SL.PoolDistr (EraCrypto era) | ||
-> [(SL.KeyHash 'SL.StakePool (EraCrypto era), PoolStake)] | ||
orderByStake = | ||
sortOn (Down . snd) |
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.
👍
No need, I have reviewed this with @edsko already. So from the PoV of consensus, this is ready to merge. |
I'll fix the CI error (didn't compile after rebasing, oops) |
1d7c50b
to
181726d
Compare
Done. |
bors merge |
Merge conflict. |
A relay can either be a domain name or an IP address therefore `DomainAddress` isn't suitable. Co-authored-by: Karl Knutsson <karl.knutsson@iohk.io>
Support for randomly picking peers from the current ledger state. The peers are randomly choosen from the relays registered on chain, and the chance to pick a given stake pools relay is weighted by the amount of stake they control.
181726d
to
ce220f1
Compare
bors merge |
Build succeeded: |
Fixes #2535.
For Shelley, this returns the stake pool relays ordered by descending stake.