Improve nesting / recursive calls
ilionic opened this issue · 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
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.
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.