Comments (4)
definition of chain quality in CSL: https://github.com/input-output-hk/cardano-sl/blob/develop/db/src/Pos/DB/Block/Logic/Util.hs#L93
(?)
from cardano-node.
Some pointers on how to implement this:
The traced event to watch for is ChainDB.SwitchedToChain
, which is part of ChainDB.TraceAddBlockEvent
You can use this snippet to calculate the chain density (not quality, which is a different concept in the Ouroboros paper, which we can't measure):
import Ouroboros.Network.Point (fromWithOrigin)
chainDensity :: HasHeader blk
=> AnchoredFragment (Header blk) -> Maybe Rational
chainDensity frag
| slots == 0
= Nothing
| otherwise
= Just $ toRational blocks / toRational slots
where
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis
slots = unSlotNo (fromWithOrigin 0 (AF.headSlot frag))
- unSlotNo (fromWithOrigin 0 (pointSlot (AF.anchorPoint frag)))
-- Includes EBBs
blocks = AF.length frag
from cardano-node.
Update:
import Ouroboros.Network.Point (fromWithOrigin)
chainDensity :: HasHeader blk
=> AnchoredFragment (Header blk) -> Maybe Rational
chainDensity frag
| slots == 0
= Nothing
| otherwise
= Just $ toRational blocks / toRational slots
where
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis
slots = unSlotNo (fromWithOrigin 0 (AF.headSlot frag))
- unSlotNo (fromWithOrigin 0 (AF.lastSlot frag))
blocks = unBlockNo (fromMaybe 0 (AF.headBlockNo frag))
- unBlockNo (either (const 0) blockNo (AF.last frag))
(I did not typecheck this)
from cardano-node.
My findings:
After three blocks we have the following fragment:
block: E R R
slot number: 0 0 1
block number: 0 1 2
where E
= EBB and R
= Regular block.
So using the code snippet above: slots = 1 - 0 = 1
, blocks = 2 - 0 = 2
, hence chain density = 2 / 1 = 2.0 😕
The reason for this is the genesis EBB with block number 0, which should not contribute to the total number of blocks. Looking at the next EBBs, we see:
blocks: E R R ... R | E R R ... R | E R R
slot number: 0 0 1 ... 21599 | 21600 21600 21601 ... 43199 | 43200 43200 43201
block number: 0 1 2 ... 21586 | 21586 21587 21588 ... 43175 | 43175 43176 43177
So EBBs have the block number of their predecessor, or 0 in case of the genesis EBB, but the slot number of their successor 😖. Fortunately, the chain density is only confused by the genesis EBB. So we can special case the genesis EBB:
... -- unchanged
-- Block numbers start at 1. We ignore the genesis EBB, which has block number 0.
blocks = unBlockNo (fromMaybe 1 (AF.headBlockNo frag))
- case unBlockNo . blockNo <$> AF.last frag of
-- Empty fragment, no blocks. We have that @blocks = 1 - 1 = 0@
Left _ -> 1
-- The oldest block is the genesis EBB with block number 0,
-- don't let it contribute to the number of blocks
Right 0 -> 1
Right b -> b
(not typechecked)
from cardano-node.
Related Issues (20)
- [BUG] - cardano-testnet sometimes hangs indefinitely HOT 2
- [BUG] - Error when running the node on windows 11 HOT 7
- [BUG] - Possible deserialization problems in cardano-submit-api v8.8.0 HOT 4
- Ouroboros Network default configuration should be used by `cardano-node` HOT 1
- Release: `cardano-node` 8.11.0
- [BUG] - cardano-testnet - genesis.json: renameFile:renamePath:rename: does not exist (No such file or directory) HOT 8
- [BUG] - Link to building from source is broken HOT 2
- [BUG] - Leadership not detected, but leaderlogs reported
- [BUG] - Connection Handshake Error and Promotion Failure of Cold Big Ledger Peers in Cardano Node v8.9.2 Docker Image HOT 5
- 8.10.1-pre not compatible with preview/conway-genesis referred to in the release notes. HOT 2
- [BUG] - query utxos by address performance varies vastly HOT 10
- [BUG] - Broken Link to Building Instructions
- [BUG] - Exception HeaderError while run sanchonet network HOT 2
- [FR] - cardano-testnet: DevX improvements HOT 4
- [BUG] - Missing prometheus metrics in cardano-node:8.11.0-sancho HOT 4
- [BUG] - Node Process Killed When Calculating Next Epoch's Leadership Schedule HOT 3
- Release v8.12.0-pre
- Missing Doc Required by OSC Governance HOT 1
- [BUG] - ValueNotConservedUTxO HOT 2
- [BUG] - InvalidBlock error on Cardano node v8.10.1 (sanchonet environment) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cardano-node.