Connection between cardano node and ledger specs

Hi there,

this might be obvious but since I’m not a real programmer I couldn’t find a satisfying answer on my own.
How are the github repos cardano ledger specs and cardano node connected? Does the node use code from the specs or is the sole purpose of the specs to verify the papers?
Take wallet.hs for example


Or rewards.hs

Is this code referenced in the node’s code? From my understanding the node kind of is the cardano protocol so it somehow needs to incorporate the functions from those files or are they implemented in a different way?
Could you for example point me to the point in the node’s code where the reward function is implemented?

Again, this question might not make much sense for a developer, but I hope you get what I’m asking.

cardano-node, cardano-wallet,cardano-db-sync , etc are user facing modules that do consume executable specs (from cardano-ledger-specs) as well as other libraries. Rewards function could be very vague depending on what you’re looking for - as it would be spread over multiple files and modules depending on what point of interval you’re trying to analyse

2 Likes

Thanks for the insight. Which of those repos or modules would be considered the ‘core protocol’ if that makes any sense?

Most of those functions are used only locally in the module despite the fact that they’re exposed (exported) to the public.

Daedalus’s cardano-wallet executable (as an example for ranking) is communicating /w cardano-node through socket by using node-to-client protocol implemented in ouroboros-network library (the library’s ouroboros-consensus-shelley module to be precise).

The core protocol, in the sense of ledger and consensus, based on the cardano-ledger-spec repo.

So, I am not sure what you’re interested in.

1 Like

Thanks _ilap, I’m not looking for anything specific. I’m just trying to get a high level understanding how these modules work together.
Is there an easier way to navigate between the modules and make the dependancies visible? For example I thought about cloning the repo and using atom.io to jump between files using the go to definition functionality.

I’m stuck trying to find the line of code in cardano-wallet where the function call for calculating the non myopic member rewards is made. I can’t find the connection between the API defined in https://t.co/qXtJJ89jH1 with its getNonMyopicMemberRewards function and cardano wallet.

How would you go about doing that?

The API call to list stake pools presents the measure against pool ID as shown in the example on the page
image

Btw if you’re asking at code level how these repositories use functions against each other that would be at build time using stack / cabal project definitions.

Thanks for your reply @rdlrt. Forgive me my maybe stupid/obvious questions, since I’m only a beginner programmer and haskell newbe. While I think I do understand the general concept of what your saying in your comment, I fail to apply it in practice. Let me give some context:

In Daedalus you can set the slider to set your intended amount of stake. Based on this, the non-myopic member rewards should be calculated. However it’s obvious that pool saturation is not taken into account. However in the code in the legder specs (rewards.hs and wallet.hs) the formulas/finctions are yonstructed in a way that do account for oversaturation for non.myopic member rewards.

So what I’m trying to do is follow the trail in the code from Daedalus or the cardano-wallet (since this is used as Daedalus’ backend) to the function definition in the rewards.hs file. But I fail, as I can’t find where the function getNonMyopicMemberRewards from wallet.hs in https://t.co/qXtJJ89jH1 is called further up in the chain.

It is accounted for, just not immediately taken out from availability - checkout this video.

Daedalus connects to cardano-wallet instance launched as part of wallet - which also will make use of functions from ledger specs to provide pool information (checkout code here ) .

1 Like

Awesome, I will check that out more thoroughly later, bit at a first glance it seems like this is the part in the cardano-wallet code I was looking for. Thanks alot! I’ll also check out the video.
I’m not sure I understand when you say it’s not immediatelly taken out from availability. Maybe the video can answer my question.

Either way, the expected behavior in Daedalus ranking (at least my expectation) would be that depending on my desired staking amount the wallet should rank the top k pools according to the expected non-myopic member rewards, which of course need to consider saturation. A fully saturated pool from the top k pools should drop in rank for me. Rank one should be the pool yielding the highest rewards if it was fully saturized, but it should actually not get oversaturized if I were to delegate my desired stake to that pool.
I hope you can get what I’m saying :slight_smile:

Hey, sorry I missed. Yes, that is how it should work, but it’s not been implemented in the latest cardano-node yet. So, I would say Daedalus 3.0 or the upcoming flight would consider that.
So, how Daedalus work

  1. When you click or select new stake in the slider it queries cardano-wallet /w the API as @rdlrt mentioned. example curls -s https://localhost:8090/v2/stake-pools?stake=1000000000 i.e. 1bn Lovelace = 1000 ADA
  2. The returning list is the ordered pools based on that stake you set in point 1. and they’re ordered by the non-myopic reward based on the intended stake (set by slider)
  3. When you change the slider it will ask again and will get a new list based on the intended stake.

So, how it is working in the background, that cardano-wallet communicate /w the cardano-node using N2C protocol.
Check here:

  1. https://github.com/input-output-hk/cardano-wallet/blob/eff3c57abc15bc76e3fee060393532f16310530c/lib/shelley/src/Cardano/Wallet/Shelley/Network.hs#L448
  2. https://github.com/input-output-hk/ouroboros-network/blob/c3f83914edfe92974ccb0a94e46ce4b91d96899f/ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs#L85

And some other places, but I would not recommend searching for it as you would be lost in a second as Haskell code is some kind of a spaghetti code mixed with a lot of dependencies i.e. dependency-hell (if I want to be very-very gentle). Yep, FP needs learn some solid design principles, but they would never-ever accept that.:slight_smile:

2 Likes

Thank you very much for your extensive reply, this helps a lot!!!
Getting a development set up for Haskell was already quite a hassle (especially for a newbe) and I already cought a glimpse of the dependency hell issue.

As you say, imports/dependencies are all over the place which makes it difficult to find which modules work together in a certain way. I really wonder how the developers are able to keep track of everthing. On the other hand I can’t really compare to other laguages than Python and I’m also only a beginner there.

Anyways, sorry for rambling, I just really enjoy this whole programming thing. Without much knowledge in that domain (although I’m quite computer literate and tech savy) there’s just so much to learn, which can be intimidating but also lots of fun. Really love using my brain again, since my current job really doesn’t require full brain capacity :smiley: