Skip to content

Commit

Permalink
Refactor SignatureDifferentiator
Browse files Browse the repository at this point in the history
  • Loading branch information
VanBarbascu committed Jan 20, 2025
1 parent 4291777 commit fc86073
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions core/primitives/src/optimistic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use near_crypto::Signature;

use crate::block::BlockHeader;
use crate::hash::{hash, CryptoHash};
use crate::stateless_validation::SignatureDifferentiator;
use crate::types::BlockHeight;
use crate::types::{BlockHeight, SignatureDifferentiator};

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct OptimisticBlockInner {
Expand Down
4 changes: 2 additions & 2 deletions core/primitives/src/stateless_validation/chunk_endorsement.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::fmt::Debug;

use crate::sharding::{ChunkHash, ShardChunkHeader};
use crate::types::EpochId;
use crate::types::{EpochId, SignatureDifferentiator};
use crate::validator_signer::ValidatorSigner;
use borsh::{BorshDeserialize, BorshSerialize};
use near_crypto::{PublicKey, Signature};
use near_primitives_core::types::{AccountId, BlockHeight, ShardId};
use near_schema_checker_lib::ProtocolSchema;

use super::{ChunkProductionKey, SignatureDifferentiator};
use super::ChunkProductionKey;

/// The endorsement of a chunk by a chunk validator. By providing this, a
/// chunk validator has verified that the chunk state witness is correct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use near_primitives_core::hash::{hash, CryptoHash};
use near_primitives_core::types::{AccountId, ShardId};
use near_schema_checker_lib::ProtocolSchema;

use super::ChunkProductionKey;
#[cfg(feature = "solomon")]
use crate::reed_solomon::{ReedSolomonEncoderDeserialize, ReedSolomonEncoderSerialize};
use crate::types::SignatureDifferentiator;
use crate::{utils::compression::CompressedData, validator_signer::ValidatorSigner};

use super::{ChunkProductionKey, SignatureDifferentiator};

// Data structures for chunk producers to send accessesed contracts to chunk validators.

/// Contains contracts (as code-hashes) accessed during the application of a chunk.
Expand Down
8 changes: 0 additions & 8 deletions core/primitives/src/stateless_validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ pub mod state_witness;
pub mod stored_chunk_state_transition_data;
pub mod validator_assignment;

/// An arbitrary static string to make sure that this struct cannot be
/// serialized to look identical to another serialized struct. For chunk
/// production we are signing a chunk hash, so we need to make sure that
/// this signature means something different.
///
/// This is a messy workaround until we know what to do with NEP 483.
pub type SignatureDifferentiator = String;

/// This struct contains combination of fields that uniquely identify chunk production.
/// It means that for a given instance only one chunk could be produced.
#[derive(Debug, Hash, PartialEq, Eq, Clone, BorshSerialize, BorshDeserialize, ProtocolSchema)]
Expand Down
4 changes: 2 additions & 2 deletions core/primitives/src/stateless_validation/partial_witness.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt::{Debug, Formatter};

use super::{ChunkProductionKey, SignatureDifferentiator};
use super::ChunkProductionKey;
use crate::sharding::ShardChunkHeader;
use crate::types::EpochId;
use crate::types::{EpochId, SignatureDifferentiator};
use crate::validator_signer::ValidatorSigner;
use borsh::{BorshDeserialize, BorshSerialize};
use bytesize::ByteSize;
Expand Down
4 changes: 2 additions & 2 deletions core/primitives/src/stateless_validation/state_witness.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::collections::HashMap;
use std::fmt::Debug;

use super::{ChunkProductionKey, SignatureDifferentiator};
use super::ChunkProductionKey;
use crate::bandwidth_scheduler::BandwidthRequests;
use crate::challenge::PartialState;
use crate::congestion_info::CongestionInfo;
#[cfg(feature = "solomon")]
use crate::reed_solomon::{ReedSolomonEncoderDeserialize, ReedSolomonEncoderSerialize};
use crate::sharding::{ChunkHash, ReceiptProof, ShardChunkHeader, ShardChunkHeaderV3};
use crate::transaction::SignedTransaction;
use crate::types::EpochId;
use crate::types::{EpochId, SignatureDifferentiator};
use crate::utils::compression::CompressedData;
use crate::validator_signer::EmptyValidatorSigner;
use borsh::{BorshDeserialize, BorshSerialize};
Expand Down
8 changes: 8 additions & 0 deletions core/primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ pub use chunk_validator_stats::ChunkStats;
/// Hash used by to store state root.
pub type StateRoot = CryptoHash;

/// An arbitrary static string to make sure that this struct cannot be
/// serialized to look identical to another serialized struct. For chunk
/// production we are signing a chunk hash, so we need to make sure that
/// this signature means something different.
///
/// This is a messy workaround until we know what to do with NEP 483.
pub(crate) type SignatureDifferentiator = String;

/// Different types of finality.
#[derive(
serde::Serialize, serde::Deserialize, Default, Clone, Debug, PartialEq, Eq, arbitrary::Arbitrary,
Expand Down

0 comments on commit fc86073

Please sign in to comment.