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

Add Cardano chain #43

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

Conversation

FilippoScaramuzza
Copy link

Description: added Cardano chain.

Ticket(s): #1 (closed but should be the actual one) and #16.

Contribution Details:
I used the Cexplorer APIs to get the list of pools and staked amount.

From Cexplorer, the Nakamoto coefficient is something like 36. In the PR, anyway, the value you will get is expected to be higher (the last time I tried was 112) as the single pools are used instead of the groups; that is what they used (confirmed by an admin on Discord).

@xenowits
Copy link
Owner

Hey @FilippoScaramuzza , thanks for submitting this PR!

The NC value comes out to be 112, while the cexplorer seems to report 36. These data look very different, so I'd say we should look into how the cexplorer guys calculate it.

Would this be something you could take up?

@FilippoScaramuzza
Copy link
Author

FilippoScaramuzza commented Nov 22, 2023

Hi!
I asked exactly this to the admins. This is what they said:
image

They're using groups of pools instead of single ones. I guess it's a different point of view, nonetheless still appropriate.
I like to focus on the single pools instead of referring to the groups. Also, group statistics aren't wholly automated yet and need to be updated manually periodically. Hence, it might not be a reliable source of information.

More information about groups here: https://cexplorer.io/link/donuts.

@alfredonodo
Copy link

Hello,
I used the data provided here. There are 178 staking pool operators, adding up the total stake of each staking pool and removing the single pool operators, the actual Nakamoto coefficient is 35. So the number shown here is correct.
In Cardano, a staking pool operator is a single entity and acts as a validator for other networks. The consensus protocol requires 50% of the stake.

@Straightpool
Copy link

Straightpool commented Dec 5, 2023

Hello, I used the data provided here. There are 178 staking pool operators, adding up the total stake of each staking pool and removing the single pool operators, the actual Nakamoto coefficient is 35.

The data source you use is good and often referenced in the Cardano community, however there are much more than 178 staking pool operators in Cardano. The largest group "Single Pool Operators" bundles up all single staking pools aka pools where the operator is believed to only operate one single pool. The other segments show so called "Multi Pool Operators" so a single operator or an organisation operating more than one pool, usually under the same brand or same marketing, a cluster of pools. How many pools are hidden behind each donut chart segment is shown in the tooltip, so if you hover on "Single Pool Operators", you can see there are currently 1815 operators in this group.
For the calculation of the MAV obviously the big clusters are counted or multi pool operators counting from the largest cluster until 50% of stake is reached.

Here at https://pooltool.io/ in the top navigation you can see the total number of pools with at least one LoveLace staked, currently 2871 pools. One ADA is 1M Lovelace.

@alfredonodo
Copy link

Hello, I used the data provided here. There are 178 staking pool operators, adding up the total stake of each staking pool and removing the single pool operators, the actual Nakamoto coefficient is 35.

The data source you use is good and often referenced in the Cardano community, however there are much more than 178 staking pool operators in Cardano. The largest group "Single Pool Operators" bundles up all single staking pools aka pools where the operator is believed to only operate one single pool. The other segments show so called "Multi Pool Operators" so a single operator or an organisation operating more than one pool, usually under the same brand or same marketing, a cluster of pools. How many pools are hidden behind each donut chart segment is shown in the tooltip, so if you hover on "Single Pool Operators", you can see there are currently 1815 operators in this group. For the calculation of the MAV obviously the big clusters are counted or multi pool operators counting from the largest cluster until 50% of stake is reached.

Here at https://pooltool.io/ in the top navigation you can see the total number of pools with at least one LoveLace staked, currently 2871 pools. One ADA is 1M Lovelace.

Thank you very much for the detailed explanation. As you know, what is important to determine the PoS consensus and thus the generation and validation of blocks is not the total number of nodes, but the minimum number that decides i.e. the so-called Nakamoto coefficient. For example, on Ethereum there are about 900k nodes, but only about 10 of them rule the network.

@thenic95
Copy link

thenic95 commented Jan 4, 2024

Hi @xenowits ,
Hope all is well!
How can I help to get this PR ready for merge?
Thanks for your help

@xenowits
Copy link
Owner

xenowits commented Jan 6, 2024

Yes, sure @thenic95 !

Please update the code as pointed by @alfredonodo to also include staking pool operators. I can review from there (a fresh PR also works)

@MokhFn
Copy link

MokhFn commented Jun 4, 2024

Is this still ongoing ? Can we move forward with this, happy to help.

@thenic95
Copy link

I was not able to update the code @MokhFn. Would you be able to help?

}
defer resp.Body.Close()
// This is the PUBLIC_BALANCE_API_TOKEN taken from https://www.balanceanalytics.io/chartboards/donut_shop
req.Header.Set("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoid2ViYXBwX3VzZXIifQ.eg3Zb9ZduibYJr1pgUrfqy4PFhkVU1uO_F9gFPBZnBI")
Copy link

@MokhFn MokhFn Jul 2, 2024

Choose a reason for hiding this comment

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

Is it possible to make this bearer value a param within a params file ? and import it from there ?
Is there and expiration date on the token ?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe we can add it as a parameter:

docker run --rm \
-e "SOLANA_API_KEY=<YOUR_SOLANA_API_KEY_HERE>" \
-e "CARDANO_API_KEY=<YOUR_CARDANO_API_KEY_HERE>" \
-e "RATED_API_KEY=<YOUR_RATED_API_KEY_HERE>" \
-p 8080:8080 xenowits/nc-calc:v0.1.4

Anyway, I'm not completely sure about the validity.
While searching for another data source to close this PR, I came across another PR. Here, @ccgarant, suggested to use https://www.balanceanalytics.io/chartboards/donut_shop. I searched the data source in the networking tab and noticed the API call to https://api.balanceanalytics.io/rpc/pool_group_stake_donut, where the bearer token to get authenticated can be found in the page's source code as PUBLIC_BALANCE_API_TOKEN:

__sveltekit_12bou38 = {
  base: new URL("..",location).pathname.slice(0, -1),
  env: {
      "PUBLIC_BALANCE_API_TOKEN": "...",
      "PUBLIC_SUPABASE_ANON_KEY": "...",
  ...
  }
};

So they're apparently loading it from the environment and then using it. Anyway, I'm not really sure if this is intentional or not. I'll try to contact @ccgarant and see if he can help.

@FilippoScaramuzza
Copy link
Author

I've got some time to work on this.
After the discussion with @alfredonodo in this thread and after reading the thread in PR #47, I searched for another data source taking into account pool groups.
The website mentioned in #47 is pretty well done https://www.balanceanalytics.io/chartboards/donut_shop and there is an API https://api.balanceanalytics.io/rpc/pool_group_stake_donut that returns the list of groups and associated stakes. (I'm not so sure if we are actually allowed to use that API as it is not listed and requires a token that I had to read directly from the page's source code, see comment above).

Anyway, as mentioned by @alfredonodo, the threshold for Cardano is not 0.33, but 0.50.
Therefore, I created another function

func CalcNakamotoCoefficientBigNums51(totalVotingPower *big.Int, votingPowers []big.Int) int {
	thresholdPercent := big.NewFloat(0.51)
	thresholdVal := new(big.Float).Mul(new(big.Float).SetInt(totalVotingPower), thresholdPercent)
	cumulativeVal := big.NewFloat(0.00)
	nakamotoCoefficient := 0

	for _, vp := range votingPowers {
		z := new(big.Float).Add(cumulativeVal, new(big.Float).SetInt(&vp))
		cumulativeVal = z
		nakamotoCoefficient += 1
		if cumulativeVal.Cmp(thresholdVal) == +1 {
			break
		}
	}

	return nakamotoCoefficient
}

where the logic is exactly the same as CalcNakamotoCoefficientBigNums. The idea (I think we can do it in another PR) is to have a parameter called threshold that we can adjust and modify based on the specific network we are dealing with to make it more elegant and scalable.

@GilbertStClr
Copy link

Hello and thank you for your patience here. I have created the API endpoint per your requirements. It can be called using the following URL: https://www.balanceanalytics.io/api/mavdata.json

@GilbertStClr
Copy link

GilbertStClr commented Jul 8, 2024

Please do test the data provided via the API mentioned above. If any changes are required, please let me know and I will be sure to update. The API data will be updated within the 24 hours following the start of each epoch.

@FilippoScaramuzza
Copy link
Author

Thank you @GilbertStClr! The API works perfectly, I just pushed the updated code! 😄

I noticed a typo in the new function CalcNakamotoCoefficientBigNums51 where the threshold was mistakenly set to 0.51 instead of 0.50. However, I believe that the name with the 51 is still appropriate.

Let me know if other changes are needed. Thanks!!

@MokhFn
Copy link

MokhFn commented Jul 9, 2024

@FilippoScaramuzza I'd update this doc by adding the cardano foundation's website to the list of supported chains. Other than that LGTM.
Nice work ! It's left to the maintainers to approve i guess.

@FilippoScaramuzza
Copy link
Author

Nice, thank you. I'll wait for @xenowits for the final review and how to update the doc (Cardano has a different threshold, so we should change or generalize the README).

@GilbertStClr
Copy link

Just as an FYI, I have updated the endpoint to include a new field called "class" which identifies the pool as MPO or sSPO per BALANCE pool group data set.

Copy link

@MokhFn MokhFn left a comment

Choose a reason for hiding this comment

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

To confirm with @xenowits for the threshold.

@FilippoScaramuzza
Copy link
Author

FilippoScaramuzza commented Jul 24, 2024

I've updated the code by modifying the data structure to reflect the changes outlined by @GilbertStClr. Then I also modified the README.md including Cardano and its website. Let me know if any other changes are needed.

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.

7 participants