mithril icon indicating copy to clipboard operation
mithril copied to clipboard

`ChainObserver` supports retrieving the Chain Point of the tip of the chain

Open jpraynaud opened this issue 11 months ago • 2 comments

Why

We need to retrieve the block number of the tip of the Cardano chain with the Chain observer to use it to create new types of beacons.

What

Add a new function in the ChainObserver trait:

async fn get_current_chain_point(&self) -> Result<Option<ChainPoint>, ChainObserverError>;

And a new entity type:

struct ChainPoint {
    slot_number: u64,
    block_number: u64,
    block_hash: String //hex encoded bytes Vec<u8>
}

And implement this function for the:

  • PallasChainObserver by using n2c mini-protocol to get access to it
  • CardanoCLIChainObserver by using the query tip command (already used for implementing get_current_epoch)

See

  • Cardano node code base: https://github.com/IntersectMBO/cardano-api/blob/14deccd3dd4e56bc4c1d8aaf4c2e87be4786af54/cardano-api/internal/Cardano/Api/Block.hs#L368
  • Pallas code base: https://docs.rs/pallas-network/0.24.0/src/pallas_network/miniprotocols/common.rs.html#68
  • Ouroboros abstract protocol: https://ouroboros-consensus.cardano.intersectmbo.org/docs/for-developers/AbstractProtocol

How

  • [x] Adapt ChainObserver trait (@jpraynaud)
  • [x] Implement trait function for FakeChainObserver (@jpraynaud)
  • [x] Implement trait function for CardanoCliChainObserver (@jpraynaud)
  • [ ] Implement trait function for PallasChainObserver (@falcucci )

jpraynaud avatar Mar 26 '24 08:03 jpraynaud

Hi @falcucci, the PR #1623 has been merged 👍 You can work on the implementation of the new function in the ChainObserver trait in the PallasChainObserver: https://github.com/input-output-hk/mithril/blob/f700c4692b26c4b78ed9c83515af8992461a3040/mithril-common/src/chain_observer/pallas_observer.rs#L387

jpraynaud avatar Apr 10 '24 16:04 jpraynaud

thank you! @jpraynaud

falcucci avatar Apr 12 '24 15:04 falcucci