Approve multiple candidates with a single signature (#1191)

Initial implementation for the plan discussed here: https://github.com/paritytech/polkadot-sdk/issues/701
Built on top of https://github.com/paritytech/polkadot-sdk/pull/1178
v0: https://github.com/paritytech/polkadot/pull/7554,

## Overall idea

When approval-voting checks a candidate and is ready to advertise the
approval, defer it in a per-relay chain block until we either have
MAX_APPROVAL_COALESCE_COUNT candidates to sign or a candidate has stayed
MAX_APPROVALS_COALESCE_TICKS in the queue, in both cases we sign what
candidates we have available.

This should allow us to reduce the number of approvals messages we have
to create/send/verify. The parameters are configurable, so we should
find some values that balance:

- Security of the network: Delaying broadcasting of an approval
shouldn't but the finality at risk and to make sure that never happens
we won't delay sending a vote if we are past 2/3 from the no-show time.
- Scalability of the network: MAX_APPROVAL_COALESCE_COUNT = 1 &
MAX_APPROVALS_COALESCE_TICKS =0, is what we have now and we know from
the measurements we did on versi, it bottlenecks
approval-distribution/approval-voting when increase significantly the
number of validators and parachains
- Block storage: In case of disputes we have to import this votes on
chain and that increase the necessary storage with
MAX_APPROVAL_COALESCE_COUNT * CandidateHash per vote. Given that
disputes are not the normal way of the network functioning and we will
limit MAX_APPROVAL_COALESCE_COUNT in the single digits numbers, this
should be good enough. Alternatively, we could try to create a better
way to store this on-chain through indirection, if that's needed.

## Other fixes:
- Fixed the fact that we were sending random assignments to
non-validators, that was wrong because those won't do anything with it
and they won't gossip it either because they do not have a grid topology
set, so we would waste the random assignments.
- Added metrics to be able to debug potential no-shows and
mis-processing of approvals/assignments.

## TODO:
- [x] Get feedback, that this is moving in the right direction. @ordian
@sandreim @eskimor @burdges, let me know what you think.
- [x] More and more testing.
- [x]  Test in versi.
- [x] Make MAX_APPROVAL_COALESCE_COUNT &
MAX_APPROVAL_COALESCE_WAIT_MILLIS a parachain host configuration.
- [x] Make sure the backwards compatibility works correctly
- [x] Make sure this direction is compatible with other streams of work:
https://github.com/paritytech/polkadot-sdk/issues/635 &
https://github.com/paritytech/polkadot-sdk/issues/742
- [x] Final versi burn-in before merging

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
This commit is contained in:
Alexandru Gheorghe
2023-12-13 08:43:15 +02:00
committed by GitHub
parent d18a682bf7
commit a84dd0dba5
82 changed files with 5883 additions and 1483 deletions
@@ -26,8 +26,9 @@ use polkadot_parachain_primitives::primitives::{
MAX_HORIZONTAL_MESSAGE_NUM, MAX_UPWARD_MESSAGE_NUM,
};
use primitives::{
vstaging::NodeFeatures, AsyncBackingParams, Balance, ExecutorParamError, ExecutorParams,
SessionIndex, LEGACY_MIN_BACKING_VOTES, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE,
vstaging::{ApprovalVotingParams, NodeFeatures},
AsyncBackingParams, Balance, ExecutorParamError, ExecutorParams, SessionIndex,
LEGACY_MIN_BACKING_VOTES, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE,
ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
};
use sp_runtime::{traits::Zero, Perbill};
@@ -263,6 +264,8 @@ pub struct HostConfiguration<BlockNumber> {
pub minimum_backing_votes: u32,
/// Node features enablement.
pub node_features: NodeFeatures,
/// Params used by approval-voting
pub approval_voting_params: ApprovalVotingParams,
}
impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber> {
@@ -308,6 +311,7 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
pvf_voting_ttl: 2u32.into(),
minimum_validation_upgrade_delay: 2.into(),
executor_params: Default::default(),
approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 },
on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
on_demand_base_fee: 10_000_000u128,
on_demand_fee_variability: Perbill::from_percent(3),
@@ -515,7 +519,8 @@ pub mod pallet {
/// v7-v8: <https://github.com/paritytech/polkadot/pull/6969>
/// v8-v9: <https://github.com/paritytech/polkadot/pull/7577>
/// v9-v10: <https://github.com/paritytech/polkadot-sdk/pull/2177>
const STORAGE_VERSION: StorageVersion = StorageVersion::new(10);
/// v10-11: <https://github.com/paritytech/polkadot-sdk/pull/1191>
const STORAGE_VERSION: StorageVersion = StorageVersion::new(11);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
@@ -1191,6 +1196,7 @@ pub mod pallet {
config.on_demand_ttl = new;
})
}
/// Set the minimum backing votes threshold.
#[pallet::call_index(52)]
#[pallet::weight((
@@ -1203,6 +1209,7 @@ pub mod pallet {
config.minimum_backing_votes = new;
})
}
/// Set/Unset a node feature.
#[pallet::call_index(53)]
#[pallet::weight((
@@ -1220,6 +1227,22 @@ pub mod pallet {
config.node_features.set(index, value);
})
}
/// Set approval-voting-params.
#[pallet::call_index(54)]
#[pallet::weight((
T::WeightInfo::set_config_with_executor_params(),
DispatchClass::Operational,
))]
pub fn set_approval_voting_params(
origin: OriginFor<T>,
new: ApprovalVotingParams,
) -> DispatchResult {
ensure_root(origin)?;
Self::schedule_config_update(|config| {
config.approval_voting_params = new;
})
}
}
#[pallet::hooks]