iron-fish / ironfish

A novel cryptocurrency focused on privacy and accessibility.
https://ironfish.network
Mozilla Public License 2.0
964 stars 577 forks source link

Change `initializeSapling` to avoid cloning #5054

Closed andiflabs closed 3 weeks ago

andiflabs commented 3 weeks ago

Summary

The Sapling parameters defined in ironfish::sapling_bls12::SAPLING are behind a lazy_static. As such, the parameters are not loaded until accessed fo the first time. The purpose of initializeSapling is to acccess the parameters to ensure that they get loaded early.

The current implementation of initializeSapling was calling .clone() on ironfish::sapling_bls12::SAPLING, causing large amounts of memory to be allocated and written, only to be discarded shortly afterwards. The implementation has been changed to just dereference SAPLING, without doing anything else. This is enough to trigger lazy_static to load the parameters.

Also:

Testing Plan

Add debug instrumentation to initializeSapling and Sapling::load. Verify that:

Documentation

N/A

Breaking Change

N/A