Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(platform)!: max field size and some clean up of versioning #1970

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-rs-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
test:
name: Tests
runs-on: ${{ fromJSON(inputs.test-runner) }}
timeout-minutes: 20
timeout-minutes: 25
steps:
- name: Check out repo
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::data_contract::accessors::v0::DataContractV0Getters;
use crate::data_contract::document_type::accessors::DocumentTypeV0Getters;
use crate::data_contract::document_type::{DocumentType, DocumentTypeRef};

use crate::consensus::basic::document::{InvalidDocumentTypeError, MissingDocumentTypeError};
use crate::consensus::basic::document::{
DocumentFieldMaxSizeExceededError, InvalidDocumentTypeError, MissingDocumentTypeError,
};
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::data_contract::schema::DataContractSchemaMethodsV0;
Expand Down Expand Up @@ -48,6 +50,24 @@ impl DataContract {
DocumentTypeRef::V0(v0) => v0.json_schema_validator.deref(),
};

if let Some((key, size)) =
value.has_data_larger_than(platform_version.system_limits.max_field_value_size)
{
let field = match key {
Some(Value::Text(field)) => field,
_ => "".to_string(),
};
return Ok(SimpleConsensusValidationResult::new_with_error(
ConsensusError::BasicError(BasicError::DocumentFieldMaxSizeExceededError(
DocumentFieldMaxSizeExceededError::new(
field,
size as u64,
platform_version.system_limits.max_field_value_size as u64,
),
)),
));
}

let json_value = match value.try_into_validating_json() {
Ok(json_value) => json_value,
Err(e) => {
Expand Down
17 changes: 10 additions & 7 deletions packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ use crate::consensus::basic::decode::{
};
use crate::consensus::basic::document::{
DataContractNotPresentError, DocumentCreationNotAllowedError,
DocumentTransitionsAreAbsentError, DuplicateDocumentTransitionsWithIdsError,
DuplicateDocumentTransitionsWithIndicesError, InconsistentCompoundIndexDataError,
InvalidDocumentTransitionActionError, InvalidDocumentTransitionIdError,
InvalidDocumentTypeError, MaxDocumentsTransitionsExceededError,
MissingDataContractIdBasicError, MissingDocumentTransitionActionError,
MissingDocumentTransitionTypeError, MissingDocumentTypeError,
MissingPositionsInDocumentTypePropertiesError, NonceOutOfBoundsError,
DocumentFieldMaxSizeExceededError, DocumentTransitionsAreAbsentError,
DuplicateDocumentTransitionsWithIdsError, DuplicateDocumentTransitionsWithIndicesError,
InconsistentCompoundIndexDataError, InvalidDocumentTransitionActionError,
InvalidDocumentTransitionIdError, InvalidDocumentTypeError,
MaxDocumentsTransitionsExceededError, MissingDataContractIdBasicError,
MissingDocumentTransitionActionError, MissingDocumentTransitionTypeError,
MissingDocumentTypeError, MissingPositionsInDocumentTypePropertiesError, NonceOutOfBoundsError,
};
use crate::consensus::basic::identity::{
DataContractBoundsNotPresentError, DisablingKeyIdAlsoBeingAddedInSameTransitionError,
Expand Down Expand Up @@ -364,6 +364,9 @@ pub enum BasicError {
#[error(transparent)]
MissingStateTransitionTypeError(MissingStateTransitionTypeError),

#[error(transparent)]
DocumentFieldMaxSizeExceededError(DocumentFieldMaxSizeExceededError),

#[error(transparent)]
StateTransitionMaxSizeExceededError(StateTransitionMaxSizeExceededError),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::errors::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

#[derive(
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error(
"Document field {field} size {actual_size_bytes} is more than system maximum {max_size_bytes}"
)]
#[platform_serialize(unversioned)]
pub struct DocumentFieldMaxSizeExceededError {
/*

DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION

*/
field: String,
actual_size_bytes: u64,
max_size_bytes: u64,
}

impl DocumentFieldMaxSizeExceededError {
pub fn new(field: String, actual_size_bytes: u64, max_size_bytes: u64) -> Self {
Self {
field,
actual_size_bytes,
max_size_bytes,
}
}

pub fn field(&self) -> &str {
self.field.as_str()
}

pub fn actual_size_bytes(&self) -> u64 {
self.actual_size_bytes
}
pub fn max_size_bytes(&self) -> u64 {
self.max_size_bytes
}
}

impl From<DocumentFieldMaxSizeExceededError> for ConsensusError {
fn from(err: DocumentFieldMaxSizeExceededError) -> Self {
Self::BasicError(BasicError::DocumentFieldMaxSizeExceededError(err))
}
}
2 changes: 2 additions & 0 deletions packages/rs-dpp/src/errors/consensus/basic/document/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod data_contract_not_present_error;
mod document_creation_not_allowed_error;
mod document_field_max_size_exceeded_error;
mod document_transitions_are_absent_error;
mod duplicate_document_transitions_with_ids_error;
mod duplicate_document_transitions_with_indices_error;
Expand All @@ -17,6 +18,7 @@ mod missing_positions_in_document_type_properties_error;

pub use data_contract_not_present_error::*;
pub use document_creation_not_allowed_error::*;
pub use document_field_max_size_exceeded_error::*;
pub use document_transitions_are_absent_error::*;
pub use duplicate_document_transitions_with_ids_error::*;
pub use duplicate_document_transitions_with_indices_error::*;
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl ErrorWithCode for BasicError {
Self::NonceOutOfBoundsError(_) => 10414,
Self::InvalidDocumentTypeNameError(_) => 10415,
Self::DocumentCreationNotAllowedError(_) => 10416,
Self::DocumentFieldMaxSizeExceededError(_) => 10417,

// Identity Errors: 10500-10599
Self::DuplicatedIdentityPublicKeyBasicError(_) => 10500,
Expand Down
1 change: 0 additions & 1 deletion packages/rs-dpp/src/fee/epoch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use crate::block::epoch::EpochIndex;
use crate::fee::{Credits, SignedCredits};

/// Genesis epoch index
//todo move to dpp
pub const GENESIS_EPOCH_INDEX: EpochIndex = 0;

/// Eras of fees charged for perpetual storage
Expand Down
1 change: 0 additions & 1 deletion packages/rs-dpp/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

pub mod core_script;
mod get_biggest_possible_identity;
mod identity;

Check warning on line 10 in packages/rs-dpp/src/identity/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dpp) / Linting

module has the same name as its containing module

warning: module has the same name as its containing module --> packages/rs-dpp/src/identity/mod.rs:10:1 | 10 | mod identity; | ^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception = note: `#[warn(clippy::module_inception)]` on by default
pub mod identity_public_key;

pub mod state_transition;
Expand All @@ -29,7 +29,6 @@
#[cfg(feature = "random-identities")]
pub mod random;
pub mod v0;
pub mod versions;

pub use fields::*;

Expand Down
33 changes: 0 additions & 33 deletions packages/rs-dpp/src/identity/versions.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl DataContractUpdateTransitionMethodsV0 for DataContractUpdateTransitionV0 {
signature_public_key_id: key_id,
signature: Default::default(),
});
//todo remove close
let mut state_transition: StateTransition = transition.clone().into();

let mut state_transition: StateTransition = transition.into();
let value = state_transition.signable_bytes()?;
let public_key =
identity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ impl DocumentsBatchTransition {
if transitions_len > u16::MAX as usize
|| transitions_len as u16
> platform_version
.dpp
.state_transitions
.system_limits
.max_transitions_in_documents_batch
{
return Ok(SimpleConsensusValidationResult::new_with_error(
MaxDocumentsTransitionsExceededError::new(
platform_version
.dpp
.state_transitions
.system_limits
.max_transitions_in_documents_batch,
)
.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ impl TryFrom<IdentityCreateTransitionV0Inner> for IdentityCreateTransitionV0 {
}
}

//todo: there shouldn't be a default

impl IdentityCreateTransitionV0 {
pub fn try_from_identity_v0(
identity: &Identity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::execution::types::block_state_info::v0::{
use crate::platform_types::block_execution_outcome;
use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult;
use crate::rpc::core::CoreRPCLike;
use dpp::version::PlatformVersion;
use dpp::version::TryIntoPlatformVersioned;
use tenderdash_abci::proto::abci as proto;
use tenderdash_abci::proto::abci::tx_record::TxAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,14 @@ where
.iter()
.map(|raw_state_transition| {
if raw_state_transition.as_ref().len() as u64
> platform_version
.dpp
.state_transitions
.max_state_transition_size
> platform_version.system_limits.max_state_transition_size
{
// The state transition is too big
let consensus_error = ConsensusError::BasicError(
BasicError::StateTransitionMaxSizeExceededError(
StateTransitionMaxSizeExceededError::new(
raw_state_transition.as_ref().len() as u64,
platform_version
.dpp
.state_transitions
.max_state_transition_size,
platform_version.system_limits.max_state_transition_size,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,6 @@ mod tests {
.build_with_mock_rpc()
.set_initial_state_structure();

let platform_state = platform.state.load();

let (identity, signer, key) = setup_identity(&mut platform, 958, dash_to_credits!(0.1));

let card_game_path = "tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-creation-restricted-to-owner.json";
Expand Down
Loading
Loading