Expand description

Types and helpers to define and handle election bounds.

Overview

This module defines and implements types that help creating and handling election bounds. DataProviderBounds encapsulates the upper limits for the results provided by DataProvider implementors. Those limits can be defined over two axis: number of elements returned (count) and/or the size of the returned SCALE encoded structure (size).

ElectionBoundsBuilder is a helper to construct data election bounds and it aims at preventing the caller from mistake the order of size and count limits.

Examples

ElectionBoundsBuilder helps defining the size and count bounds for both voters and targets.

use frame_election_provider_support::bounds::*;

// unbounded limits are never exhausted.
let unbounded = ElectionBoundsBuilder::default().build();
assert!(!unbounded.targets.exhausted(SizeBound(1_000_000_000).into(), None));

let bounds = ElectionBoundsBuilder::default()
    .voters_count(100.into())
    .voters_size(1_000.into())
    .targets_count(200.into())
    .targets_size(2_000.into())
    .build();

assert!(!bounds.targets.exhausted(SizeBound(1).into(), CountBound(1).into()));
assert!(bounds.targets.exhausted(SizeBound(1).into(), CountBound(100_000).into()));

Implementation details

A default or None bound means that no bounds are enforced (i.e. unlimited result size). In general, be careful when using unbounded election bounds in production.

Structs