NoteAssets::add_asset recomputes the commitment every time. This currently results in re-hashing the assets whenever an asset is added to a note due to OutputNoteBuilder::add_asset forwarding to NoteAssets::add_asset in the tx host.
To make this a bit more efficient:
- Store assets in a
Vec in OutputNoteBuilder and delay NoteAssets creation until OutputNoteBuilder::build is called.
- In addition to the above, we can consider making
NoteAssets immutable by removing add_asset. It seems to only exist for the purpose of calling it in OutputNoteBuilder. This is more in line with most other types in protocol, which are immutable. If one wants to mutate an existing NoteAssets, it can be converted (into_vec(self) -> Vec<Asset>) and then rebuilt after one or multiple assets were added to the vec.
NoteAssets::add_assetrecomputes the commitment every time. This currently results in re-hashing the assets whenever an asset is added to a note due toOutputNoteBuilder::add_assetforwarding toNoteAssets::add_assetin the tx host.To make this a bit more efficient:
VecinOutputNoteBuilderand delayNoteAssetscreation untilOutputNoteBuilder::buildis called.NoteAssetsimmutable by removingadd_asset. It seems to only exist for the purpose of calling it inOutputNoteBuilder. This is more in line with most other types in protocol, which are immutable. If one wants to mutate an existingNoteAssets, it can be converted (into_vec(self) -> Vec<Asset>) and then rebuilt after one or multiple assets were added to the vec.