This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
Base weights can be zero due to a negative intercept value from the linear regression calculated during benchmarks #11804
Labels
I3-bug
The node fails to follow expected behavior.
By default min squares linear regression is used to calculate weights for extrinsics with components. The linear regression returns two values: a single intercept value (used as the base weight which represents the constant cost for a given extrinsic) and one or more slope values (which model the cost of the extrinsic as the values' of its components increase).
Now, depending on the exact numbers passed into the regression solver the intercept can actually be negative, for example consider this minimal reproduction: (the numbers here are the exact values I got running a benchmark for
pallet_contracts/seal_transfer
)This returns an intercept value of
-271299.7199134391
. And for this particular extrinsic this was essentially random; sometimes you get a negative intercept, sometimes you don't. In both cases the input data is reasonable.So what we do in the code is that we cast the intercept value into u128 which, due to Rust's saturating float casts, results in a base weight of zero, which, while not as bad as saying it has a negative cost, still doesn't really make sense because based on the data the extrinsic clearly has a non-zero constant cost.
For extrinsics where the range of components is bound so that their values cannot be zero this should be mostly harmless (since the component weight will pick up the slack), but imagine an extrinsic where the allowed minimum values of the components are zero, in which case we'd have (ignoring database weights) an extrinsic which wouldn't actually consume any weight but still consume resources.
cc @athei @ggwpez @shawntabrizi
The text was updated successfully, but these errors were encountered: