bloxbean / yaci

A Cardano Mini Protocols implementation in Java
MIT License
25 stars 3 forks source link

Protocal Params Mapping #5

Closed dodinhvit23f closed 1 year ago

dodinhvit23f commented 1 year ago

How could we know that protocol parameters are mapping properly ?

List<DataItem> paramsDIList = ((Array) extractResultArray(di[0]).get(0)).getDataItems();

CurrentProtocolParamsQuery.class line 48 return an array of data items . But because the data items result is an array so it really hard for us to tracking the index that what was mapped and it would change if come to other era or not.

for example: with mainnet and Babbage era I don't see decentralization at index 12 instead of major version

//        itemDI = paramsDIList.get(12);
//        BigDecimal decentralizationParam = itemDI != null? toRationalNumber(itemDI): null;

itemDI = paramsDIList.get(12); //Removed
        Integer protocolMajorVersion = itemDI != null? toInt(itemDI): null;

So could you change some thing via Query.class that tell cardano node return a Map like the protocol_param_update describe below

protocol_param_update =
  { ? 0:  uint               ; minfee A
  , ? 1:  uint               ; minfee B
  , ? 2:  uint               ; max block body size
  , ? 3:  uint               ; max transaction size
  , ? 4:  uint               ; max block header size
  , ? 5:  coin               ; key deposit
  , ? 6:  coin               ; pool deposit
  , ? 7: epoch               ; maximum epoch
  , ? 8: uint                ; n_opt: desired number of stake pools
  , ? 9: rational            ; pool pledge influence
  , ? 10: unit_interval      ; expansion rate
  , ? 11: unit_interval      ; treasury growth rate
  , ? 12: unit_interval      ; d. decentralization constant
  , ? 13: $nonce             ; extra entropy
  , ? 14: [protocol_version] ; protocol version
  , ? 16: coin               ; min pool cost ; New
  , ? 17: coin               ; ada per utxo byte ; New
  , ? 18: costmdls           ; cost models for script languages ; New
  , ? 19: ex_unit_prices     ; execution costs ; New
  , ? 20: ex_units           ; max tx ex units ; New
  , ? 21: ex_units           ; max block ex units ; New
  , ? 22: uint               ; max value size ; New
  , ? 23: uint               ; collateral percentage ; New
  , ? 24: uint               ; max collateral inputs ; New
  }

It would be great if we have to query protocol parameters for each epoch starting from shelley

satran004 commented 1 year ago

@dodinhvit23f

Thanks. Please see my comments inline below.

  1. How could we know that protocol parameters are mapping properly ?

The CurrentProtocolParams local query returns an array. As it's about "current" protocol prams, the array content changes based on the era. So the deserialization logic in the CurrentProtocolParamsQuery.class is specific to Babbage era.

Unfortunately, there is no standard CDDL for this and it is only defined in Haskell code.

Fyi, here are the links to Haskell code for the same.

Alonzo protocol params Haskell code : https://github.com/input-output-hk/cardano-ledger/blob/da48c5ba96b72426a51f36507d49604505fc96a7/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs#L290

Babbage protocol params Haskell code: https://github.com/input-output-hk/cardano-ledger/blob/da48c5ba96b72426a51f36507d49604505fc96a7/eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs#L226

  1. So could you change some thing via Query.class that tell cardano node return a Map like the protocol_param_update describe below

As I mentioned above, node returns an array in case of current protocol params query. I don't think we can change the node behavior through query.

However, as you mentioned, protocol_param_update is a part of the transaction object and is defined as a map in CDDL.

  1. It would be great if we have to query protocol parameters for each epoch starting from shelley

While doing local query, you first need to acquire a snapshot at a particular point. If you provide a too old point, node returns "ACQUIRE_FAILURE_POINT_TOO_OLD". So I am not sure if you will be able to query protocol params from shelley era through node to client.

Creating different Query class like ShelleyProtocolParamsQuery or AlonzoProtocolParamsQuery is possible, but it may not work due to point too old error.

For historical protocol params, you may need to keep track of protocol_params_update map in the transactions. So start with protocol params defined in shelley or alonzo genesis files and track all protocol update transactions.