lib.rs 3.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.

//! Primitive types used on the node-side.
//!
//! Unlike the `polkadot-primitives` crate, these primitives are only used on the node-side,
//! not shared between the node and the runtime. This crate builds on top of the primitives defined
//! there.

23
24
25
26
27
28
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::{Hash,
	parachain::{
		AbridgedCandidateReceipt, CandidateReceipt, CompactStatement,
		EncodeAs, Signed,
	}
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
};

/// A statement, where the candidate receipt is included in the `Seconded` variant.
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
pub enum Statement {
	/// A statement that a validator seconds a candidate.
	#[codec(index = "1")]
	Seconded(AbridgedCandidateReceipt),
	/// A statement that a validator has deemed a candidate valid.
	#[codec(index = "2")]
	Valid(Hash),
	/// A statement that a validator has deemed a candidate invalid.
	#[codec(index = "3")]
	Invalid(Hash),
}

45
46
impl EncodeAs<CompactStatement> for Statement {
	fn encode_as(&self) -> Vec<u8> {
47
		let statement = match *self {
48
49
50
51
52
			Statement::Seconded(ref c) => {
				polkadot_primitives::parachain::CompactStatement::Candidate(c.hash())
			}
			Statement::Valid(hash) => polkadot_primitives::parachain::CompactStatement::Valid(hash),
			Statement::Invalid(hash) => polkadot_primitives::parachain::CompactStatement::Invalid(hash),
53
		};
54
		statement.encode()
55
56
57
58
59
60
	}
}

/// A statement, the corresponding signature, and the index of the sender.
///
/// Signing context and validator set should be apparent from context.
61
62
63
64
///
/// This statement is "full" in the sense that the `Seconded` variant includes the candidate receipt.
/// Only the compact `SignedStatement` is suitable for submission to the chain.
pub type SignedFullStatement = Signed<Statement, CompactStatement>;
65
66

/// A misbehaviour report.
67
#[derive(Debug)]
68
69
70
71
72
73
74
75
76
pub enum MisbehaviorReport {
	/// These validator nodes disagree on this candidate's validity, please figure it out
	///
	/// Most likely, the list of statments all agree except for the final one. That's not
	/// guaranteed, though; if somehow we become aware of lots of
	/// statements disagreeing about the validity of a candidate before taking action,
	/// this message should be dispatched with all of them, in arbitrary order.
	///
	/// This variant is also used when our own validity checks disagree with others'.
77
	CandidateValidityDisagreement(CandidateReceipt, Vec<SignedFullStatement>),
78
	/// I've noticed a peer contradicting itself about a particular candidate
79
	SelfContradiction(CandidateReceipt, SignedFullStatement, SignedFullStatement),
80
	/// This peer has seconded more than one parachain candidate for this relay parent head
81
	DoubleVote(CandidateReceipt, SignedFullStatement, SignedFullStatement),
82
}
83
84
85
86
87
88
89
90
91

/// A unique identifier for a network protocol.
pub type ProtocolId = [u8; 4];

/// A succinct representation of a peer's view. This consists of a bounded amount of chain heads.
///
/// Up to `N` (5?) chain heads.
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct View(pub Vec<Hash>);