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

Feed peer selection governor with big ledger peers obtained from a snapshot #4850

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

crocodile-dentist
Copy link
Contributor

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

  • Branch
    • Updated changelog files.
    • Commit sequence broadly makes sense
    • Commits have useful messages
    • The documentation has been properly updated
    • New tests are added if needed and existing tests are updated
    • If serialization changes, user-facing consequences (e.g. replay from genesis) are confirmed to be intentional.
  • Pull Request
    • Self-reviewed the diff
    • Useful pull request description at least containing the following information:
      • What does this PR change?
      • Why these changes were needed?
      • How does this affect downstream repositories and/or end-users?
      • Which ticket does this PR close (if any)? If it does, is it linked?
    • Reviewer requested

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.

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.

Comment on lines 32 to 34
accBigPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)]
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))]
accBigPoolStake =
Copy link
Contributor

Choose a reason for hiding this comment

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

Sine accBigPoolStake nand reRelativeState are now public API, it's better to give them better name, maybe:

  • accumulateBigLedgerState
  • recomputeRelativeStake

--
accBigPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)]
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))]
accBigPoolStake =
Copy link
Contributor

Choose a reason for hiding this comment

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

We have some code duplication between accPoolStake and accBigPoolStake; could you create an issue to address this in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 65 to 82
toCBOR = mconcat . (encodeListLen 3 :) . \case
RelayAccessDomain domain port ->
[encodeWord8 0, serialize' port, toCBOR domain]
RelayAccessAddress (IP.IPv4 ip4) port ->
[encodeWord8 1, serialize' port, toCBOR (IP.fromIPv4 ip4)]
RelayAccessAddress (IP.IPv6 ip6) port ->
[encodeWord8 2, serialize' port, toCBOR (IP.fromIPv6 ip6)]
where
serialize' = toCBOR . toInteger
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be cleaner to avoid mconcat;

toCBOR (RelayAccessDomain domain port) =
     encodeListLen 3
  <> encodeWord8 0
  <> serialize' port
  <> toCBOR domain
toCBOR (RelayAccessAddress (IP.IPv4 ipv4) port) =
     encodeListLen 3
  <> encodeWord8 1
  <> serialize' port
  <> toCBOR (IP.fromIPv4 ipv4)
toCBOR (RelayAccessAddress (IP.IPv6 ip6) port) =
     encodeListLen 3
  <> encodeWord8 2
  <> serialize' port
  <> toCBOR (IP.fromIPv4 ip6)

Comment on lines 78 to 79
when (codeTag /= 3) . fail $ "Unrecognized RelayAccessPoint encoding tag "
<> show codeTag
Copy link
Contributor

Choose a reason for hiding this comment

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

it's an unrecognised list length rather than a tag.

--
accBigPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)]
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))]
accBigPoolStake =
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any properties for accBigPoolStake and reRelativeState; it's a good opportunity to add some if we don't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had a test for the first one, and I've added a test for recomputeRelativeStake - the properties I've considered are that

  1. It should not add/remove/modify any relay access points
  2. Each relative stake should be non-negative
  3. Total normalized stake adds up to unity

@crocodile-dentist crocodile-dentist force-pushed the mwojtowicz/provide-peers-from-snapshot branch 6 times, most recently from 9a27667 to 249edf8 Compare May 1, 2024 14:25
This change tidies up a function signature to make use of records
that were created previously for use by other functions. They bundle
many common related values together to facilitate passing them around.
This change binds useLedgerPeers after unblocking due to a demand
for ledger peers by its clients. If this value has changed in the
configuration while the thread was dormant, ie. a race, it will be
picked up when the function unblocks.
Moved utility functions to ouroboros-network-api to support
calculating big ledger peer snapshots by upstream libraries,
for eg. Genesis consensus mode and bootstrapping a node with
a recent snapshot of these peers.
This change adds ToCBOR and FromCBOR instances that are necessary
to serialize a snapshot of ledger peers.
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.
encoding, as well as checking that ToCBOR and FromCBOR are working
together correctly.
@crocodile-dentist crocodile-dentist force-pushed the mwojtowicz/provide-peers-from-snapshot branch from 249edf8 to 8916d88 Compare May 1, 2024 14:39
component.
Added property tests to check whether ledger peer snapshot peers are
provided in appropriate circumstances.
@crocodile-dentist crocodile-dentist force-pushed the mwojtowicz/provide-peers-from-snapshot branch from 8916d88 to 062381a Compare May 2, 2024 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants