use crate::hash::CryptoHash;
use crate::merkle::MerklePath;
use crate::sharding::{EncodedShardChunk, ShardChunk, ShardChunkHeader};
use crate::state::PartialState;
use crate::types::AccountId;
use borsh::{BorshDeserialize, BorshSerialize};
use near_crypto::Signature;
use near_primitives_core::types::BlockHeight;
use near_schema_checker_lib::ProtocolSchema;
use std::fmt::Debug;
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
pub struct BlockDoubleSign {
pub left_block_header: Vec<u8>,
pub right_block_header: Vec<u8>,
}
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
pub struct ChunkProofs {
pub block_header: Vec<u8>,
pub merkle_proof: MerklePath,
pub chunk: Box<MaybeEncodedShardChunk>,
}
#[allow(clippy::large_enum_variant)] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum MaybeEncodedShardChunk {
Encoded(EncodedShardChunk) = 0,
Decoded(ShardChunk) = 1,
}
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
pub struct ChunkState {
pub prev_block_header: Vec<u8>,
pub block_height: BlockHeight,
pub prev_merkle_proof: MerklePath,
pub prev_chunk: ShardChunk,
pub merkle_proof: MerklePath,
pub chunk_header: ShardChunkHeader,
pub partial_state: PartialState,
}
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
#[allow(clippy::large_enum_variant)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum ChallengeBody {
BlockDoubleSign(BlockDoubleSign) = 0,
ChunkProofs(ChunkProofs) = 1,
ChunkState(ChunkState) = 2,
}
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug, ProtocolSchema)]
#[borsh(init=init)]
pub struct Challenge {
pub body: ChallengeBody,
pub account_id: AccountId,
pub signature: Signature,
#[borsh(skip)]
pub hash: CryptoHash,
}
impl Challenge {
pub fn init(&mut self) {
self.hash = CryptoHash::hash_borsh(&self.body);
}
}
#[derive(
BorshSerialize,
BorshDeserialize,
PartialEq,
Eq,
Clone,
Debug,
serde::Serialize,
serde::Deserialize,
ProtocolSchema,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct SlashedValidator {
pub account_id: AccountId,
pub is_double_sign: bool,
}