CardanoSolutions / ogmios

❇️ A WebSocket JSON/RPC bridge for Cardano
https://ogmios.dev
Mozilla Public License 2.0
304 stars 90 forks source link

What is the oldest point, that can be aquired? #42

Closed MarcelKlammer closed 3 years ago

MarcelKlammer commented 3 years ago

The initial reason I started looking into cardano-ogmios was the retrieval of stake distribution at the last epoch boundary, since that isn't available in cardano-db-sync.

I now tried to aquire the last block of mainnet epoch 263, but it fails with pointTooOld.

So what's the max delta, that we can inspect/query?

KtorZ commented 3 years ago

The ledger has a "memory" of the past of about ~3k blocks if I recall correctly where k=2160 on mainnet. That is about ~6480 blocks, so ~36h in the past on mainnet from the network tip.

I'll add that to the user guide section about the state-query.

KtorZ commented 3 years ago

Note that the retrieval of stake distribution for past epochs is not something that is generally possible in Cardano. In order to do this, you would need to be able to run the actual ledger and "pause it" at each epoch to calculate this information. The ledger itself doesn't keep any form of history or more generally, it doesn't keep anything that isn't strictly necessary. The ledger doesn't even have an history of all past transactions; instead it maintain a UTxO set which is always evolving: old UTxOs are purged and only the current set is maintained.

MarcelKlammer commented 3 years ago

Then the results make more sense. So we would actually need some kind of db-sync addon, that can rewind tx until last block of last epoch to get the utxo set of that slot. So I will leave that out for now. Thanks for clarifying.

KtorZ commented 3 years ago

that can rewind tx until last block of last epoch to get the utxo set of that slot

That is relatively easy to achieve using the chain-sync mini-protocol. But it won't help you w.r.t to the stake distribution. The stake distribution is not only calculated from the UTxO, but also from rewards and some other factors that aren't part of the UTxO...

vlall commented 3 years ago

Hi, I'm posting this question here, since it's relevant to the current discussion. After reading through the issues, running the code, and using Ogmios, I'm wondering, is there a way to build an add-on to Ogmios in its current state and sync it up to write blockchain data into a database similar to what db-sync does? This could be useful for developers looking to customize the information we sync into the database, as well as sync to different database types (NoSQL), and remove some overhead for more advanced users.

I recognize a few hurdles as already mentioned in this issue and others:

The ledger has a "memory" of the past of about ~3k blocks if I recall correctly where k=2160 on mainnet. That is about ~6480 blocks, so ~36h in the past on mainnet from the network tip.

you would need to be able to run the actual ledger and "pause it" at each epoch to calculate this information.

Obtaining timestamps

However, I just wanted to know if this seems like a feasible idea. Thank you!

MarcelKlammer commented 3 years ago

cncli does exactly that.

It writes all blocks into a local db and helps SPOs to calculate the leader events.

So it should be achievable.

KtorZ commented 3 years ago

@vlall that is totally doable. You could actually reimplement most of db-sync using ogmios.

Ogmios really is an interface of the node; but translated to Json + Websocket.

vlall commented 3 years ago

cncli does exactly that.

@MarcelKlammer which tool is cncli?

@vlall that is totally doable. You could actually reimplement most of db-sync using ogmios.

@KtorZ Perfect thanks! Yes, one concern was how i'd get the full snapshot of the blockchain, but i believe you explained this with the stopping/pausing of the sync. In this case, i'd probably need to run the node separately and pause in-between to make requests in Ogmios. Then I can infer the time stamps like you've explained earlier using the slot numbers and genesis time stamp.

MarcelKlammer commented 3 years ago

https://github.com/AndrewWestberg/cncli