Skip to content
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

Merged
merged 4 commits into from
Dec 10, 2020

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Aug 24, 2020

Fixes #2535.

For Shelley, this returns the stake pool relays ordered by descending stake.

@mrBliss mrBliss added the consensus issues related to ouroboros-consensus label Aug 24, 2020
@mrBliss mrBliss requested a review from coot August 24, 2020 13:26
$ shelleyState

relayToDomainAddress :: SL.StakePoolRelay -> DomainAddress
relayToDomainAddress = undefined
Copy link
Contributor Author

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.

Copy link
Contributor Author

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,
Copy link
Contributor Author

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.

@mrBliss mrBliss linked an issue Aug 24, 2020 that may be closed by this pull request
@mrBliss mrBliss changed the base branch from coot/connection-manager to master August 25, 2020 06:53
@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 5e96201 to 602c946 Compare August 25, 2020 06:53
@mrBliss
Copy link
Contributor Author

mrBliss commented Aug 25, 2020

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
Copy link
Contributor Author

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.

Copy link
Contributor

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:

  1. sampling pools from an appropriate stake distribution (e.g. the one used for block production in the current epoch)
  2. 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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 602c946 to 225a16e Compare September 8, 2020 07:08
@edsko
Copy link
Contributor

edsko commented Sep 15, 2020

See discussion on slack, we might need an API of type

getPeers :: LedgerState blk -> [(PoolStake, [DomainAddress])]

@mrBliss
Copy link
Contributor Author

mrBliss commented Sep 28, 2020

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)]

@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from ff1e72a to 0e6b061 Compare September 29, 2020 14:18
@mrBliss
Copy link
Contributor Author

mrBliss commented Sep 29, 2020

@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 relayToDomainAddress. When somebody from the network team or ledger team fills that in, I can mark this PR ready for review.

@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 0e6b061 to c8fb01c Compare November 11, 2020 09:33
@mrBliss
Copy link
Contributor Author

mrBliss commented Nov 11, 2020

Rebased against master

@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from c8fb01c to 248d2de Compare November 20, 2020 11:00
--
-- If the slot is too far in the future w.r.t. the current ledger state,
-- 'HF.PastHorizonException' will be returned.
getSlotTime ::
Copy link
Contributor Author

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.

Copy link
Contributor

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? 🤔 😬

@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 248d2de to 076cdbd Compare November 20, 2020 13:55
@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 09c32a3 to 1d7c50b Compare December 9, 2020 16:34
@mrBliss
Copy link
Contributor Author

mrBliss commented Dec 9, 2020

Rebased and squashed some commits.

@mrBliss mrBliss marked this pull request as ready for review December 9, 2020 16:34
@mrBliss mrBliss requested a review from karknu December 9, 2020 16:40
Copy link
Contributor

@coot coot left a 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))
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mrBliss
Copy link
Contributor Author

mrBliss commented Dec 10, 2020

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?

No need, I have reviewed this with @edsko already. So from the PoV of consensus, this is ready to merge.

@mrBliss
Copy link
Contributor Author

mrBliss commented Dec 10, 2020

I'll fix the CI error (didn't compile after rebasing, oops)

@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 1d7c50b to 181726d Compare December 10, 2020 10:55
@mrBliss
Copy link
Contributor Author

mrBliss commented Dec 10, 2020

I'll fix the CI error (didn't compile after rebasing, oops)

Done.

@mrBliss
Copy link
Contributor Author

mrBliss commented Dec 10, 2020

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Dec 10, 2020

Merge conflict.

mrBliss and others added 4 commits December 10, 2020 14:01
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.
@mrBliss mrBliss force-pushed the mrBliss/ledger-supports-peer-selection branch from 181726d to ce220f1 Compare December 10, 2020 13:10
@mrBliss
Copy link
Contributor Author

mrBliss commented Dec 10, 2020

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Dec 10, 2020

@iohk-bors iohk-bors bot merged commit 02771ee into master Dec 10, 2020
@iohk-bors iohk-bors bot deleted the mrBliss/ledger-supports-peer-selection branch December 10, 2020 13:34
@karknu karknu mentioned this pull request Dec 11, 2020
@mrBliss mrBliss mentioned this pull request Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus issues related to ouroboros-consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On chain root peers
5 participants