txpipe / pallas

Rust-native building blocks for the Cardano blockchain ecosystem
Apache License 2.0
150 stars 60 forks source link

feat: New performant Block and Tx structures with raw auxiliary data. #534

Open Mr-Leshiy opened 3 weeks ago

Mr-Leshiy commented 3 weeks ago

During implementation our https://github.com/input-output-hk/catalyst-libs/tree/main/rust/cardano-chain-follower we have faced a necessity to decode auxiliary data by our own and not for every transaction. Which means that if we will skip CBOR decoding for such transactions in which we are not interested in, we can increase a performance of the blockchain synchronisation.

This PR introduces a naive and a strait forward implementation and basically shows at least what we need on the cardano-chain-follower side. So we are open to any suggestions how to change/improve this approach.

Added a new MultiEraBlockWithRawAuxiliary and MultiEraTxWithRawAuxiliary structures which does not actually decode Auxiliary data and keeps a raw bytes (replaced the usage of KeepRaw<'b, T> with the new OnlyRaw<'b, T>). This allows in the cases where user do not want to use pallas specific encoding of the metadata and decode by ourselves avoid redundant decoding by pallas. With the added benchmarks OnlyRaw<'b, AuxiliaryData> 5x faster in decoding rather than KeepRaw<'b, AuxiliaryData >: https://github.com/input-output-hk/catalyst-pallas/blob/feff0ef1ffe458d4fb61036d2290307ec67388c1/pallas-primitives/benches/alonzo_decoding.rs#L7.

Alonzo Auxilary Data Decoding/KeepRaw<AuxiliaryData>
                        time:   [4.8648 µs 5.0116 µs 5.2403 µs]
                        change: [-2.6346% +3.1304% +8.9719%] (p = 0.31 > 0.05)
                        No change in performance detected.
Found 13 outliers among 100 measurements (13.00%)
  4 (4.00%) high mild
  9 (9.00%) high severe
Alonzo Auxilary Data Decoding/OnlyRaw<AuxiliaryData>
                        time:   [983.42 ns 988.56 ns 994.95 ns]
                        change: [+0.7429% +1.3247% +2.0350%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 12 outliers among 100 measurements (12.00%)
  3 (3.00%) high mild
  9 (9.00%) high severe

Changes