Files
pezkuwi-subxt/substrate/primitives/src/validator.rs
T
Tomasz Drwięga 55e74cd426 Update some types and interfaces to match the spec (#24)
* Update primitives.

* Fix validator interface.
2017-12-04 16:51:43 +01:00

91 lines
2.6 KiB
Rust

// Copyright 2017 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/>.
//! Validator primitives.
use bytes;
use parachain;
/// Parachain outgoing message.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct EgressPost(#[serde(with="bytes")] pub Vec<u8>);
/// Balance upload.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BalanceUpload(#[serde(with="bytes")] pub Vec<u8>);
/// Balance download.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BalanceDownload(#[serde(with="bytes")] pub Vec<u8>);
/// The result of parachain validation.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct ValidationResult {
/// New head data that should be included in the relay chain state.
pub head_data: parachain::HeadData,
/// Outgoing messages (a vec for each parachain).
pub egress_queues: Vec<Vec<EgressPost>>,
/// Balance uploads
pub balance_uploads: Vec<BalanceUpload>,
}
// TODO [ToDr] This shouldn't be here!
/// Validator logic.
pub trait Validator {
/// Validation error.
type Error: ::std::error::Error;
/// Validates if the provided proof holds given a current ingress queue.
///
/// In case of success produces egress posts.
fn validate(
&self,
code: &[u8],
// TODO [ToDr] actually consolidate
consolidated_ingress: &[(u64, Vec<parachain::Message>)],
balance_downloads: &[BalanceDownload],
block_data: &parachain::BlockData,
previous_head_data: &parachain::HeadData,
) -> Result<ValidationResult, Self::Error>;
}
#[cfg(test)]
mod tests {
use super::*;
use polkadot_serializer as ser;
#[test]
fn test_validation_result() {
assert_eq!(ser::to_string_pretty(&ValidationResult {
head_data: parachain::HeadData(vec![1]),
egress_queues: vec![vec![EgressPost(vec![1])]],
balance_uploads: vec![BalanceUpload(vec![2])],
}), r#"{
"headData": "0x01",
"egressQueues": [
[
"0x01"
]
],
"balanceUploads": [
"0x02"
]
}"#);
}
}