Unverified Commit 1382e26d authored by Sergey Pepyakin's avatar Sergey Pepyakin Committed by GitHub
Browse files

pvf-precheck: Add `PvfCheckStatement` to polkadot-primitives (#4406)

* pvf-precheck: Add `sign` in subsystem-util

Right now, most of operations that sign stuff in polkadot protocol are
handled by a very convenient tool - `Signed`. However `Signed` assumes
that whatever is signed is anchored to some `parent_hash` which works
for most cases, but does not work for others.

One instance of such a case is pre-checking (#3211). There validators
submit signed votes on-chain. A vote is valid for the entire session. If
we were to use `Signed` we would have to root a vote in some block of
that session and during vote verification check that this block is
indeed within the session. This is especially annoying since we agreed
to use unsigned extrinsics to submit votes and we need to make the
unsigned extrinsic validation as slim as possible.

(FWIW, the definition of a pre-checking vote can be seen in the next
diff in the stack)

That's the reason why we opted-out from using `Signed` for pre-checking
and decided to go with the manual signing approach. Almost every piece
of machinery is in place except for signing which is presented in this
PR.

* pvf-precheck: Add `PvfCheckStatement` to polkadot-primitives

This is an insubstantial PR that just unlocks PRs down the line. This PR
is a part of #3211.

Regarding the `PvfCheckStatement` struct itself: this is a structure
that will be used to convert from/into the binary representation and
ultimately will be used to sign and submit votes onto chain.
parent e4580d09
Pipeline #168585 canceled with stages
in 19 minutes and 10 seconds
...@@ -1378,6 +1378,31 @@ pub struct InherentData<HDR: HeaderT = Header> { ...@@ -1378,6 +1378,31 @@ pub struct InherentData<HDR: HeaderT = Header> {
pub parent_header: HDR, pub parent_header: HDR,
} }
/// A statement from the specified validator whether the given validation code passes PVF
/// pre-checking or not anchored to the given session index.
#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug, TypeInfo)]
pub struct PvfCheckStatement {
/// `true` if the subject passed pre-checking and `false` otherwise.
pub accept: bool,
/// The validation code hash that was checked.
pub subject: ValidationCodeHash,
/// The index of a session during which this statement is considered valid.
pub session_index: SessionIndex,
/// The index of the validator from which this statement originates.
pub validator_index: ValidatorIndex,
}
impl PvfCheckStatement {
/// Produce the payload used for signing this type of statement.
///
/// It is expected that it will be signed by the validator at `validator_index` in the
/// `session_index`.
pub fn signing_payload(&self) -> Vec<u8> {
const MAGIC: [u8; 4] = *b"VCPC"; // for "validation code pre-checking"
(MAGIC, self.accept, self.subject, self.session_index, self.validator_index).encode()
}
}
/// The maximum number of validators `f` which may safely be faulty. /// The maximum number of validators `f` which may safely be faulty.
/// ///
/// The total number of validators is `n = 3f + e` where `e in { 1, 2, 3 }`. /// The total number of validators is `n = 3f + e` where `e in { 1, 2, 3 }`.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment