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
base: master
Are you sure you want to change the base?
Conversation
4c893c8
to
e3cf273
Compare
30b0651
to
bd190c2
Compare
e0f3ac8
to
c074f34
Compare
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.
accBigPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)] | ||
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))] | ||
accBigPoolStake = |
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.
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 = |
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 have some code duplication between accPoolStake
and accBigPoolStake
; could you create an issue to address this in the future?
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
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 |
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.
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)
when (codeTag /= 3) . fail $ "Unrecognized RelayAccessPoint encoding tag " | ||
<> show codeTag |
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.
it's an unrecognised list length rather than a tag.
ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/LedgerPeers.hs
Outdated
Show resolved
Hide resolved
-- | ||
accBigPoolStake :: [(PoolStake, NonEmpty RelayAccessPoint)] | ||
-> [(AccPoolStake, (PoolStake, NonEmpty RelayAccessPoint))] | ||
accBigPoolStake = |
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.
Do we have any properties for accBigPoolStake
and reRelativeState
; it's a good opportunity to add some if we don't.
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 had a test for the first one, and I've added a test for recomputeRelativeStake - the properties I've considered are that
- It should not add/remove/modify any relay access points
- Each relative stake should be non-negative
- Total normalized stake adds up to unity
9a27667
to
249edf8
Compare
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.
249edf8
to
8916d88
Compare
component. Added property tests to check whether ledger peer snapshot peers are provided in appropriate circumstances.
8916d88
to
062381a
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