-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: do not allow contested documents for the first three epochs (#…
- Loading branch information
Showing
24 changed files
with
813 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../src/errors/consensus/basic/document/contested_documents_temporarily_not_allowed_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::consensus::basic::BasicError; | ||
use crate::consensus::ConsensusError; | ||
use crate::errors::ProtocolError; | ||
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize}; | ||
use thiserror::Error; | ||
|
||
use crate::block::epoch::EpochIndex; | ||
use bincode::{Decode, Encode}; | ||
|
||
#[derive( | ||
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize, | ||
)] | ||
#[error( | ||
"Contested documents are not allowed until epoch {target_epoch}. Current epoch is {current_epoch}" | ||
)] | ||
#[platform_serialize(unversioned)] | ||
pub struct ContestedDocumentsTemporarilyNotAllowedError { | ||
/* | ||
DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION | ||
*/ | ||
current_epoch: EpochIndex, | ||
target_epoch: EpochIndex, | ||
} | ||
|
||
impl ContestedDocumentsTemporarilyNotAllowedError { | ||
pub fn new(current_epoch: EpochIndex, target_epoch: EpochIndex) -> Self { | ||
Self { | ||
current_epoch, | ||
target_epoch, | ||
} | ||
} | ||
} | ||
|
||
impl From<ContestedDocumentsTemporarilyNotAllowedError> for ConsensusError { | ||
fn from(err: ContestedDocumentsTemporarilyNotAllowedError) -> Self { | ||
Self::BasicError(BasicError::ContestedDocumentsTemporarilyNotAllowedError( | ||
err, | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...execution/validation/state_transition/state_transitions/documents_batch/is_allowed/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::error::execution::ExecutionError; | ||
use crate::error::Error; | ||
use crate::execution::validation::state_transition::processor::v0::StateTransitionIsAllowedValidationV0; | ||
use crate::platform_types::platform::PlatformRef; | ||
use dpp::state_transition::documents_batch_transition::DocumentsBatchTransition; | ||
use dpp::validation::ConsensusValidationResult; | ||
use dpp::version::PlatformVersion; | ||
|
||
mod v0; | ||
|
||
impl StateTransitionIsAllowedValidationV0 for DocumentsBatchTransition { | ||
fn has_is_allowed_validation(&self, platform_version: &PlatformVersion) -> Result<bool, Error> { | ||
match platform_version | ||
.drive_abci | ||
.validation_and_processing | ||
.state_transitions | ||
.documents_batch_state_transition | ||
.is_allowed | ||
{ | ||
0 => Ok(true), | ||
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { | ||
method: "StateTransition::has_is_allowed_validation".to_string(), | ||
known_versions: vec![0], | ||
received: version, | ||
})), | ||
} | ||
} | ||
|
||
/// Disable contested document create transitions for the first 3 epochs | ||
fn validate_is_allowed<C>( | ||
&self, | ||
platform: &PlatformRef<C>, | ||
platform_version: &PlatformVersion, | ||
) -> Result<ConsensusValidationResult<()>, Error> { | ||
match platform_version | ||
.drive_abci | ||
.validation_and_processing | ||
.state_transitions | ||
.documents_batch_state_transition | ||
.is_allowed | ||
{ | ||
0 => Ok(v0::validate_is_allowed_v0(self, platform)), | ||
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { | ||
method: "StateTransition::validate_is_allowed".to_string(), | ||
known_versions: vec![0], | ||
received: version, | ||
})), | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...cution/validation/state_transition/state_transitions/documents_batch/is_allowed/v0/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::platform_types::platform::PlatformRef; | ||
use crate::platform_types::platform_state::v0::PlatformStateV0Methods; | ||
use dpp::block::epoch::EpochIndex; | ||
use dpp::consensus::basic::document::ContestedDocumentsTemporarilyNotAllowedError; | ||
use dpp::state_transition::documents_batch_transition::accessors::DocumentsBatchTransitionAccessorsV0; | ||
use dpp::state_transition::documents_batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods; | ||
use dpp::state_transition::documents_batch_transition::DocumentsBatchTransition; | ||
use dpp::validation::ConsensusValidationResult; | ||
|
||
pub const TARGET_EPOCH_INDEX: EpochIndex = 3; | ||
|
||
#[inline(always)] | ||
pub fn validate_is_allowed_v0<C>( | ||
state_transition: &DocumentsBatchTransition, | ||
platform: &PlatformRef<C>, | ||
) -> ConsensusValidationResult<()> { | ||
#[cfg(feature = "testing-config")] | ||
if platform | ||
.config | ||
.testing_configs | ||
.disable_contested_documents_is_allowed_validation | ||
{ | ||
return ConsensusValidationResult::new(); | ||
} | ||
|
||
let block_info = platform.state.last_block_info(); | ||
|
||
if block_info.epoch.index >= TARGET_EPOCH_INDEX { | ||
return ConsensusValidationResult::new(); | ||
} | ||
|
||
let is_contested = state_transition.transitions().iter().any(|transition| { | ||
transition | ||
.as_transition_create() | ||
.and_then(|create| create.prefunded_voting_balance().as_ref()) | ||
.is_some() | ||
}); | ||
|
||
if is_contested { | ||
return ConsensusValidationResult::new_with_errors(vec![ | ||
ContestedDocumentsTemporarilyNotAllowedError::new( | ||
block_info.epoch.index, | ||
TARGET_EPOCH_INDEX, | ||
) | ||
.into(), | ||
]); | ||
} | ||
|
||
ConsensusValidationResult::new() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.