rmrk-substrate icon indicating copy to clipboard operation
rmrk-substrate copied to clipboard

Improve nesting / recursive calls

Open ilionic opened this issue 3 years ago • 1 comments

Currently there few places utilising unbound recursion ( ie lookup_root_owner ). In order to follow best practices and implement proper benchmarking we need to bound recursive calls ( ideally avoid them in favour of loops ).

Proposed improvement is to integrate concept of budgets, as seen in Unique Network example

ilionic avatar Sep 26 '22 14:09 ilionic

We can check the Budget trait defined here. This will allow for the caller to create a Budget for a call and define a Value for the number of calls allowed for an owner lookup.

Budget budget.rs

Example:

// NESTING_BUDGET could be a configurable runtime trait or a StorageValue
let budget = budget::Value::new(NESTING_BUDGET);
let nft_owner = <pallet_rmrk_core::Pallet<T>>::lookup_root_owner(collection_id, nft_id, &budget).map_err(|_| <Error<T>>::Error)?;			

Possible change to lookup_root_owner would move to a loop that calls consume on the Budget every iteration to ensure that the Budget throws an Error on a deeply nested NFT. This can work as a temporary workaround, but I'd be interested in other ideas on how to handle this.

HashWarlock avatar Oct 03 '22 21:10 HashWarlock