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)!: contests on testnet/devnet/local should take less time #2115

Merged
merged 8 commits into from
Sep 15, 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 packages/rs-drive-abci/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ impl PlatformConfig {
quorum_rotation: true,
},
block_spacing_ms: 5000,
drive: Default::default(),
drive: DriveConfig::default_testnet(),
abci: Default::default(),
core: Default::default(),
execution: Default::default(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::platform_types::epoch_info::EpochInfo;
use crate::platform_types::platform::Platform;
use crate::platform_types::platform_state::PlatformState;
use crate::rpc::core::CoreRPCLike;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ impl DocumentCreateTransitionActionStateValidationV0 for DocumentCreateTransitio
// We need to make sure that if there is a contest, it is in its first week
// The week might be more or less, as it's a versioned parameter
let time_ms_since_start = block_info.time_ms.checked_sub(start_block.time_ms).ok_or(Error::Drive(drive::error::Error::Drive(DriveError::CorruptedDriveState(format!("it makes no sense that the start block time {} is before our current block time {}", start_block.time_ms, block_info.time_ms)))))?;
let join_time_allowed = platform_version.dpp.validation.voting.allow_other_contenders_time_ms;

let join_time_allowed = platform_version.dpp.validation.voting.allow_other_contenders_time_mainnet_ms;

if time_ms_since_start > join_time_allowed {
return Ok(SimpleConsensusValidationResult::new_with_error(ConsensusError::StateError(StateError::DocumentContestNotJoinableError(
DocumentContestNotJoinableError::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use dpp::consensus::state::document::document_contest_document_with_same_id_alre
use dpp::consensus::state::document::document_contest_identity_already_contestant::DocumentContestIdentityAlreadyContestantError;
use dpp::consensus::state::document::document_contest_not_joinable_error::DocumentContestNotJoinableError;
use dpp::consensus::state::state_error::StateError;
use dpp::dashcore::Network;
use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::prelude::{ConsensusValidationResult, Identifier};
Expand Down Expand Up @@ -161,7 +162,10 @@ impl DocumentCreateTransitionActionStateValidationV1 for DocumentCreateTransitio
// We need to make sure that if there is a contest, it is in its first week
// The week might be more or less, as it's a versioned parameter
let time_ms_since_start = block_info.time_ms.checked_sub(start_block.time_ms).ok_or(Error::Drive(drive::error::Error::Drive(DriveError::CorruptedDriveState(format!("it makes no sense that the start block time {} is before our current block time {}", start_block.time_ms, block_info.time_ms)))))?;
let join_time_allowed = platform_version.dpp.validation.voting.allow_other_contenders_time_ms;
let join_time_allowed = match platform.config.network {
Network::Dash => platform_version.dpp.validation.voting.allow_other_contenders_time_mainnet_ms,
_ => platform_version.dpp.validation.voting.allow_other_contenders_time_testing_ms
};
if time_ms_since_start > join_time_allowed {
return Ok(SimpleConsensusValidationResult::new_with_error(ConsensusError::StateError(StateError::DocumentContestNotJoinableError(
DocumentContestNotJoinableError::new(
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/rs-drive-abci/src/test/helpers/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ impl TestPlatformBuilder {
self
}

/// Add initial protocol version as latest
pub fn with_latest_protocol_version(mut self) -> Self {
self.initial_protocol_version = Some(PlatformVersion::latest().protocol_version);
self
}

/// Create a new temp platform with a mock core rpc
pub fn build_with_mock_rpc(self) -> TempPlatform<MockCoreRPCLike> {
let use_initial_protocol_version =
Expand Down
42 changes: 42 additions & 0 deletions packages/rs-drive/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Drive Configuration File
//!

use dpp::dashcore::Network;
use dpp::fee::epoch::DEFAULT_EPOCHS_PER_ERA;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::str::FromStr;

/// Boolean if GroveDB batching consistency verification is enabled by default
pub const DEFAULT_GROVE_BATCHING_CONSISTENCY_VERIFICATION_ENABLED: bool = false;
Expand Down Expand Up @@ -112,6 +114,31 @@ pub struct DriveConfig {
serde(default, deserialize_with = "from_str_to_bool")
)]
pub grovedb_visualizer_enabled: bool,

/// The network type
#[cfg_attr(
feature = "serde",
serde(
default = "DriveConfig::default_network",
deserialize_with = "from_str_to_network_with_aliases"
)
)]
pub network: Network,
}

#[cfg(feature = "serde")]
fn from_str_to_network_with_aliases<'de, D>(deserializer: D) -> Result<Network, D::Error>
where
D: serde::Deserializer<'de>,
{
let network_name = String::deserialize(deserializer)?;

match network_name.as_str() {
"mainnet" => Ok(Network::Dash),
"local" => Ok(Network::Regtest),
_ => Network::from_str(network_name.as_str())
.map_err(|e| serde::de::Error::custom(format!("can't parse network name: {e}"))),
}
}

// TODO: some weird envy behavior requries this to exist
Expand Down Expand Up @@ -197,6 +224,21 @@ impl Default for DriveConfig {
grovedb_visualizer_address: default_grovedb_visualizer_address(),
#[cfg(feature = "grovedbg")]
grovedb_visualizer_enabled: false,
network: Network::Dash,
}
}
}

impl DriveConfig {
fn default_network() -> Network {
Network::Dash
}

/// The default testnet configuration
pub fn default_testnet() -> Self {
Self {
network: Network::Testnet,
..Default::default()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::error::Error;
use crate::fees::op::LowLevelDriveOperation;
use crate::util::object_size_info::DocumentAndContractInfo;
use dpp::block::block_info::BlockInfo;
use dpp::dashcore::Network;
use dpp::version::PlatformVersion;
use dpp::voting::vote_info_storage::contested_document_vote_poll_stored_info::ContestedDocumentVotePollStoredInfo;
use dpp::voting::vote_polls::VotePoll;
Expand Down Expand Up @@ -50,12 +51,22 @@ impl Drive {
platform_version,
)?;

let end_date = block_info.time_ms.saturating_add(
platform_version
.dpp
.voting_versions
.default_vote_poll_time_duration_ms,
);
let poll_time = match self.config.network {
Network::Dash => {
platform_version
.dpp
.voting_versions
.default_vote_poll_time_duration_mainnet_ms
}
_ => {
platform_version
.dpp
.voting_versions
.default_vote_poll_time_duration_test_network_ms
}
};

let end_date = block_info.time_ms.saturating_add(poll_time);

let contest_already_existed = self.add_contested_indices_for_contract_operations(
&document_and_contract_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::drive::DriveError;
use crate::error::Error;
use derive_more::From;
use dpp::block::epoch::Epoch;
use dpp::version::{PlatformVersion, PlatformVersionCurrentVersion};
use dpp::version::PlatformVersion;
use dpp::voting::contender_structs::ContenderWithSerializedDocument;
use grovedb::TransactionArg;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::drive::votes::paths::{
VotePollPaths, RESOURCE_ABSTAIN_VOTE_TREE_KEY_U8_32, RESOURCE_STORED_INFO_KEY_U8_32,
};
use crate::drive::votes::paths::{VotePollPaths, RESOURCE_STORED_INFO_KEY_U8_32};
use crate::drive::votes::resolved::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePollWithContractInfo;
use crate::drive::votes::ResourceVoteChoiceToKeyTrait;
use crate::drive::Drive;
use crate::error::Error;
use crate::fees::op::LowLevelDriveOperation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::drive::votes::paths::VotePollPaths;
use crate::drive::votes::resolved::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePollWithContractInfo;
use crate::drive::votes::ResourceVoteChoiceToKeyTrait;
use crate::drive::Drive;
use crate::error::Error;
use crate::fees::op::LowLevelDriveOperation;
Expand Down
7 changes: 5 additions & 2 deletions packages/rs-platform-version/src/version/dpp_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ pub struct DataContractValidationVersions {
#[derive(Clone, Debug, Default)]
pub struct VotingValidationVersions {
/// How long do we allow other contenders to join a contest after the first contender
pub allow_other_contenders_time_ms: u64,
pub allow_other_contenders_time_mainnet_ms: u64,
/// How long do we allow other contenders to join a contest after the first contender in a testing environment
pub allow_other_contenders_time_testing_ms: u64,
/// How many votes do we allow from the same masternode?
pub votes_allowed_per_masternode: u16,
}
Expand Down Expand Up @@ -235,7 +237,8 @@ pub struct IdentityVersions {

#[derive(Clone, Debug, Default)]
pub struct VotingVersions {
pub default_vote_poll_time_duration_ms: u64,
pub default_vote_poll_time_duration_mainnet_ms: u64,
pub default_vote_poll_time_duration_test_network_ms: u64,
pub contested_document_vote_poll_stored_info_version: FeatureVersion,
}

Expand Down
6 changes: 4 additions & 2 deletions packages/rs-platform-version/src/version/mocks/v2_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,8 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion {
unique_index_limit: 10,
},
voting: VotingValidationVersions {
allow_other_contenders_time_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_mainnet_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_testing_ms: 2_700_000, //45 minutes
votes_allowed_per_masternode: 5,
},
},
Expand Down Expand Up @@ -1244,7 +1245,8 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion {
},
},
voting_versions: VotingVersions {
default_vote_poll_time_duration_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_mainnet_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_test_network_ms: 5_400_000, //90 minutes
contested_document_vote_poll_stored_info_version: 0,
},
asset_lock_versions: AssetLockVersions {
Expand Down
6 changes: 4 additions & 2 deletions packages/rs-platform-version/src/version/mocks/v3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,8 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion {
unique_index_limit: 10,
},
voting: VotingValidationVersions {
allow_other_contenders_time_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_mainnet_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_testing_ms: 2_700_000, //45 minutes
votes_allowed_per_masternode: 5,
},
},
Expand Down Expand Up @@ -1244,7 +1245,8 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion {
},
},
voting_versions: VotingVersions {
default_vote_poll_time_duration_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_mainnet_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_test_network_ms: 5_400_000, //90 minutes
contested_document_vote_poll_stored_info_version: 0,
},
asset_lock_versions: AssetLockVersions {
Expand Down
6 changes: 4 additions & 2 deletions packages/rs-platform-version/src/version/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion {
unique_index_limit: 10,
},
voting: VotingValidationVersions {
allow_other_contenders_time_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_mainnet_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_testing_ms: 604_800_000, // 1 week in ms for v1 (changes in v2)
votes_allowed_per_masternode: 5,
},
},
Expand Down Expand Up @@ -1243,7 +1244,8 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion {
},
},
voting_versions: VotingVersions {
default_vote_poll_time_duration_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_mainnet_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_test_network_ms: 1_209_600_000, //2 weeks
contested_document_vote_poll_stored_info_version: 0,
},
asset_lock_versions: AssetLockVersions {
Expand Down
6 changes: 4 additions & 2 deletions packages/rs-platform-version/src/version/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion {
unique_index_limit: 10,
},
voting: VotingValidationVersions {
allow_other_contenders_time_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_mainnet_ms: 604_800_000, // 1 week in ms
allow_other_contenders_time_testing_ms: 2_700_000, //45 minutes
votes_allowed_per_masternode: 5,
},
},
Expand Down Expand Up @@ -1243,7 +1244,8 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion {
},
},
voting_versions: VotingVersions {
default_vote_poll_time_duration_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_mainnet_ms: 1_209_600_000, //2 weeks
default_vote_poll_time_duration_test_network_ms: 5_400_000, //90 minutes
contested_document_vote_poll_stored_info_version: 0,
},
asset_lock_versions: AssetLockVersions {
Expand Down
Loading