near_primitives/
challenge.rs1use crate::hash::CryptoHash;
2use crate::merkle::MerklePath;
3use crate::sharding::{EncodedShardChunk, ShardChunk, ShardChunkHeader};
4use crate::state::PartialState;
5use crate::types::AccountId;
6use borsh::{BorshDeserialize, BorshSerialize};
7use near_crypto::Signature;
8use near_primitives_core::types::BlockHeight;
9use near_schema_checker_lib::ProtocolSchema;
10use std::fmt::Debug;
11
12#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
14pub struct BlockDoubleSign {
15 pub left_block_header: Vec<u8>,
16 pub right_block_header: Vec<u8>,
17}
18
19#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
21pub struct ChunkProofs {
22 pub block_header: Vec<u8>,
24 pub merkle_proof: MerklePath,
26 pub chunk: Box<MaybeEncodedShardChunk>,
28}
29
30#[allow(clippy::large_enum_variant)] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
36pub enum MaybeEncodedShardChunk {
37 Encoded(EncodedShardChunk),
38 Decoded(ShardChunk),
39}
40
41#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
43pub struct ChunkState {
44 pub prev_block_header: Vec<u8>,
46 pub block_height: BlockHeight,
50 pub prev_merkle_proof: MerklePath,
52 pub prev_chunk: ShardChunk,
54 pub merkle_proof: MerklePath,
56 pub chunk_header: ShardChunkHeader,
58 pub partial_state: PartialState,
60}
61
62#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
63#[allow(clippy::large_enum_variant)]
65pub enum ChallengeBody {
66 BlockDoubleSign(BlockDoubleSign),
67 ChunkProofs(ChunkProofs),
68 ChunkState(ChunkState),
69}
70
71#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
72#[borsh(init=init)]
73pub struct Challenge {
74 pub body: ChallengeBody,
75 pub account_id: AccountId,
76 pub signature: Signature,
77
78 #[borsh(skip)]
79 pub hash: CryptoHash,
80}
81
82impl Challenge {
83 pub fn init(&mut self) {
84 self.hash = CryptoHash::hash_borsh(&self.body);
85 }
86}
87
88#[derive(
89 BorshSerialize,
90 BorshDeserialize,
91 PartialEq,
92 Eq,
93 Clone,
94 Debug,
95 serde::Serialize,
96 serde::Deserialize,
97 ProtocolSchema,
98)]
99#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
100pub struct SlashedValidator {
101 pub account_id: AccountId,
102 pub is_double_sign: bool,
103}