Skip to content
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
8 changes: 8 additions & 0 deletions book/src/fees/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ left when the contest ends is released as processing fees. The amounts are
| Contested document fund (DPNS and every other contest) | 0.2 Dash | 0.1 Dash | 0.1 Dash |
| Moderation election fund (an `electedCharter` application) | none exist | 0.5 Dash | 0.5 Dash |
| Decision proposal fund (a `proposal` on the decision proposals contract) | none exist | none exist | 0.5 Dash |
| Multiple choice proposal processing fee (a `multipleChoiceProposal` on the decision proposals contract; not a fund, see below) | none exist | none exist | 0.2 Dash |
| One vote | 0.0001 Dash | 0.00002 Dash | 0.00002 Dash |

`required_vote_resolution_fund` in `rs-dpp` picks between the two contest
Expand All @@ -168,6 +169,13 @@ vote poll rather than a contest, and its fund
protocol version 15) prefunds that poll's votes the same way. The schedules
before 15 carry 0 there, unread.

A multiple choice proposal opens no poll of its own: the first choice entered
for it opens a contest, and each choice pays the contested document fund. So
its create prefunds nothing, and pays a flat processing fee instead
(`multiple_choice_proposal_processing_fee`, also added in `FEE_VERSION4`): the
amount is added to the processing fee of the batch that creates it and goes
to the fee pools. The schedules before 15 carry 0 there.

## User Fee Increase

Every state transition carries a `user_fee_increase` field (a `UserFeeIncrease`
Expand Down
28 changes: 23 additions & 5 deletions docs/protocol/decision-proposals.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ proposal's creation whether or not a choice has been entered, so a choice
entered in the first two hours may answer a text that is edited afterwards.
The type keeps its history (`documentsKeepHistory: true`), so every version
stays readable. `open` is listed under `immutable` by name and never changes.
Creating one opens no vote and states no fund. Additional properties are
rejected.
Creating one opens no vote and states no fund. It pays a flat processing fee
instead, 0.2 Dash on top of its gas (see [What it costs](#what-it-costs)).
Additional properties are rejected.

| Property | Type | Meaning |
| --- | --- | --- |
Expand All @@ -163,9 +164,9 @@ neither unique.

#### The description

A proposal costs its storage and nothing else, so text held in it would be
cheap to fill with anything and could never be taken down: the proposal is
undeletable. It therefore holds no description. What is being decided is said
Text held in a proposal could never be taken down: the proposal is
undeletable, and for the price of one proposal it would stay for good. It
therefore holds no description. What is being decided is said
in one of two places, or both:

- **A description document**, hosted on Platform where an elected team can
Expand Down Expand Up @@ -327,6 +328,23 @@ If the proposal is not open (a rule reads `false` as 0), the choice's owner
must be the proposal's owner; a choice anyone else enters is refused
(`DocumentPropertyConstraintViolatedError`, 10422) and opens no vote.

### What it costs

| Action | Pays | Where it goes |
| --- | --- | --- |
| Creating a multiple choice proposal | 0.2 Dash, added to the processing fee of the create (`multiple_choice_proposal_processing_fee` in `VoteResolutionFundFees`, set in `FEE_VERSION4`, protocol version 15), and its gas | The processing fee pools, like any processing fee |
| Entering a choice | The contest's fund, 0.1 Dash, doubling once the vote holds 250 choices and again for every 50 more, and its gas | The vote's prefunded balance: each masternode vote takes a fixed cost from it (0.00002 Dash), and what is left when the vote ends is released as processing fees |

The proposal's fee is not a fund. A multiple choice proposal opens no poll of
its own (the first choice does), so there are no votes for it to prefund. The
create does not state the fee: it is charged as processing, whoever pays the
gas pays it, and an identity whose balance does not cover it creates no
proposal (`IdentityInsufficientBalanceError`). A create that is refused pays
its gas alone. A batch pays the fee once for each proposal it creates.

A question with two answers therefore costs 0.4 Dash and its gas, against the
0.5 Dash fund of a yes/no proposal.

### The vote

- **Entering a choice.** The create states the contest's fund as its prefunded
Expand Down
4 changes: 3 additions & 1 deletion packages/decision-proposals-contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ and point it at another description, for two hours after creating it; after
that they freeze. Every version is kept (`documentsKeepHistory`), so a reader
can see the proposal as it was when a choice was entered. Whether it is `open`
never changes. Creating it opens no vote and states no fund: the first choice
does.
does. It pays a flat processing fee of 0.2 Dash instead, on top of its gas,
which goes to the processing fee pools; each choice then pays its contest's
fund (0.1 Dash at first).

The proposal holds no description of its own. What is being decided is said
in one of two places, or both: at its `url`, for a description hosted
Expand Down
23 changes: 23 additions & 0 deletions packages/rs-dpp/src/decision_proposal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub const PROPOSAL_DOCUMENT_TYPE_NAME: &str = "proposal";
/// proposal's own type. A contested create names its contested index there instead.
pub const DECISION_PROPOSAL_FUND_NAME: &str = PROPOSAL_DOCUMENT_TYPE_NAME;

/// The name of the multiple choice proposal document type: a question whose answers are the
/// choices entered for it, which contend in a masternode vote the first choice opens.
pub const MULTIPLE_CHOICE_PROPOSAL_DOCUMENT_TYPE_NAME: &str = "multipleChoiceProposal";

/// The properties of a proposal.
pub mod properties {
/// The question, in one line. Editable for a day after the proposal is created.
Expand Down Expand Up @@ -76,6 +80,25 @@ pub fn decision_proposal_required_fund(platform_version: &PlatformVersion) -> Cr
.decision_proposal_fund_required_amount
}

/// Whether a document of `document_type_name` in the contract `contract_id` is a multiple
/// choice proposal: a `multipleChoiceProposal` of the decision proposals contract. Its create
/// opens no poll and states no fund; it pays the multiple choice proposal processing fee.
pub fn is_multiple_choice_proposal(contract_id: &Identifier, document_type_name: &str) -> bool {
*contract_id == DECISION_PROPOSALS_CONTRACT_ID
&& document_type_name == MULTIPLE_CHOICE_PROPOSAL_DOCUMENT_TYPE_NAME
}

/// What creating one multiple choice proposal adds to the processing fee of its batch: the
/// fee version's `multiple_choice_proposal_processing_fee`. Unlike a yes/no proposal's fund
/// it prefunds no votes, since the proposal opens no poll: it goes to the processing fee
/// pools, and the create does not state it. 0 before protocol version 15.
pub fn multiple_choice_proposal_processing_fee(platform_version: &PlatformVersion) -> Credits {
platform_version
.fee_version
.vote_resolution_fund_fees
.multiple_choice_proposal_processing_fee
}

/// The id of the yes/no poll the proposal `document_id` opens: the id of the purpose
/// [`YesNoVotePollPurpose::DecisionProposal`], which a vote on the proposal names and the poll
/// queries take. Known from the proposal's id alone, before or after the poll opens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::error::Error;
use dpp::address_funds::{AddressFundsFeeStrategy, PlatformAddress};
use dpp::asset_lock::reduced_asset_lock_value::AssetLockValueGettersV0;
use dpp::block::epoch::Epoch;
use dpp::decision_proposal::multiple_choice_proposal_processing_fee;
use dpp::fee::Credits;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -314,6 +315,12 @@ impl ExecutionEvent<'_> {
// Read off the transitions as state validation left them: one it replaced with
// a nonce bump owes no action fee.
let action_fees = batch_action.resolved_action_fees()?;
// Each multiple choice proposal the batch creates (protocol version 15) pays a
// flat processing fee: it opens no poll, so it prefunds no votes. The fee
// schedules before that version carry 0, and no such proposal exists there.
let multiple_choice_proposal_fees = batch_action
.multiple_choice_proposals_created()
.saturating_mul(multiple_choice_proposal_processing_fee(platform_version));
let operations =
action.into_high_level_drive_operations(epoch, platform_version)?;
if let Some(identity) = identity {
Expand All @@ -323,7 +330,8 @@ impl ExecutionEvent<'_> {
added_to_balance_outputs: None,
operations,
execution_operations: execution_context.operations_consume(),
additional_fixed_fee_cost: None,
additional_fixed_fee_cost: (multiple_choice_proposal_fees > 0)
.then_some(multiple_choice_proposal_fees),
Comment thread
QuantumExplorer marked this conversation as resolved.
Resolved
user_fee_increase,
signing_key_limits,
gas_sponsor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ use dpp::data_contract::document_type::accessors::DocumentTypeV2Getters;
use dpp::data_contract::document_type::DocumentReferenceKind;
use dpp::data_contract::schema::DataContractSchemaMethodsV0;
use dpp::data_contract::DataContract;
use dpp::decision_proposal::DECISION_PROPOSALS_CONTRACT_ID;
use dpp::decision_proposal::{
multiple_choice_proposal_processing_fee, DECISION_PROPOSALS_CONTRACT_ID,
MULTIPLE_CHOICE_PROPOSAL_DOCUMENT_TYPE_NAME,
};
use dpp::document::document_methods::DocumentMethodsV0;
use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
use dpp::document::{Document, DocumentV0, DocumentV0Getters, DocumentV0Setters};
Expand Down Expand Up @@ -2342,3 +2345,227 @@ async fn should_take_the_description_from_a_document_a_url_or_both() {
}
}
}

/// The identity's balance now.
fn balance(
platform: &TempPlatform<MockCoreRPCLike>,
identity_id: Identifier,
platform_version: &PlatformVersion,
) -> Credits {
platform
.drive
.fetch_identity_balance(identity_id.to_buffer(), None, platform_version)
.expect("expected to read the balance")
.expect("expected the identity")
}

/// Creating a multiple choice proposal opens no poll and prefunds no votes, so it pays a
/// flat processing fee instead: 0.2 Dash on top of its gas. Nothing else of the contract
/// pays it, a create that is refused does not, and an identity that cannot cover it creates
/// no proposal.
#[tokio::test]
async fn should_charge_a_flat_processing_fee_for_a_multiple_choice_proposal() {
let (mut platform, platform_version, contract, mut rng) = setup();
let fee = multiple_choice_proposal_processing_fee(platform_version);
assert_eq!(fee, dash_to_credits!(0.2));
// No fee schedule before protocol version 15 charges it
assert_eq!(
multiple_choice_proposal_processing_fee(
PlatformVersion::get(14).expect("expected protocol version 14")
),
0
);
assert_eq!(
multiple_choice_proposal::NAME,
MULTIPLE_CHOICE_PROPOSAL_DOCUMENT_TYPE_NAME
);
// The gas of any transition here is far below the fee
let at_most_gas = fee / 10;

let mut proposer = writer(&mut platform, &mut rng);
let mut alice = writer(&mut platform, &mut rng);
let described_at_a_url = |question: &str| {
BTreeMap::from([
(
multiple_choice_proposal::properties::TITLE.to_string(),
Value::Text(question.to_string()),
),
(
multiple_choice_proposal::properties::URL.to_string(),
Value::Text("https://example.org/proposals/mascot".to_string()),
),
(
multiple_choice_proposal::properties::OPEN.to_string(),
Value::Bool(true),
),
])
};

// The proposal pays the fee as processing, whoever described it and wherever
let before = balance(&platform, proposer.id(), platform_version);
let (transition, proposal_id) = create_transition(
&contract,
&mut proposer,
multiple_choice_proposal::NAME,
described_at_a_url("Which mascot?"),
&mut rng,
platform_version,
)
.await;
let StateTransitionExecutionResult::SuccessfulExecution { fee_result, .. } =
process(&platform, transition, 20_000, platform_version)
else {
panic!("expected the proposal to be created");
};
assert!(
fee_result.processing_fee >= fee && fee_result.processing_fee < fee + at_most_gas,
"expected the gas and the proposal fee, got {}",
fee_result.processing_fee
);
let after = balance(&platform, proposer.id(), platform_version);
assert_eq!(
before - after,
fee_result.processing_fee + fee_result.storage_fee
);

// A choice pays its contest's fund, which prefunds the votes, and no proposal fee
let before = balance(&platform, alice.id(), platform_version);
let (transition, _) = choice_transition(
&contract,
&mut alice,
proposal_id,
"An owl",
&mut rng,
platform_version,
)
.await;
let StateTransitionExecutionResult::SuccessfulExecution { fee_result, .. } =
process(&platform, transition, 30_000, platform_version)
else {
panic!("expected the choice to be entered");
};
assert!(
fee_result.processing_fee < at_most_gas,
"{}",
fee_result.processing_fee
);
let fund = platform_version
.fee_version
.vote_resolution_fund_fees
.contested_document_vote_resolution_fund_required_amount;
assert_eq!(
before - balance(&platform, alice.id(), platform_version),
fund + fee_result.processing_fee + fee_result.storage_fee
);

// A proposal that is refused is not created, and pays its gas alone
let (transition, _) = create_transition(
&contract,
&mut proposer,
multiple_choice_proposal::NAME,
BTreeMap::from([
(
multiple_choice_proposal::properties::TITLE.to_string(),
Value::Text("Described nowhere".to_string()),
),
(
multiple_choice_proposal::properties::OPEN.to_string(),
Value::Bool(true),
),
]),
&mut rng,
platform_version,
)
.await;
let StateTransitionExecutionResult::PaidConsensusError { actual_fees, .. } =
process(&platform, transition, 40_000, platform_version)
else {
panic!("expected the proposal described nowhere to be refused");
};
assert!(
actual_fees.processing_fee < at_most_gas,
"{}",
actual_fees.processing_fee
Comment thread
QuantumExplorer marked this conversation as resolved.
Resolved
);

// Nor does one that state validation refuses: it passes every check on the transition
// itself, becomes an action of the batch, and is replaced there by a nonce bump when the
// description document it names turns out not to exist. A bump creates nothing
let host = description_host(true, platform_version);
let (transition, never_created_id) = create_transition(
&contract,
&mut proposer,
multiple_choice_proposal::NAME,
question_properties(
"Described by a document that is not there",
true,
host.id(),
TEXT,
Identifier::new([7; 32]),
),
&mut rng,
platform_version,
)
.await;
let StateTransitionExecutionResult::PaidConsensusError {
error, actual_fees, ..
} = process(&platform, transition, 45_000, platform_version)
else {
panic!("expected the proposal naming a missing description to be refused");
};
assert!(
matches!(
error,
ConsensusError::StateError(StateError::ReferencedEntityNotFoundError(_))
),
"{error:?}"
);
assert!(
actual_fees.processing_fee < at_most_gas,
"{}",
actual_fees.processing_fee
);
assert!(stored_document(
&platform,
&contract,
multiple_choice_proposal::NAME,
never_created_id
)
.is_none());

// An identity holding less than the fee creates no proposal and keeps its balance
let mut poor = Writer {
info: setup_identity(&mut platform, rng.gen(), dash_to_credits!(0.1)),
next_nonce: 1,
};
let (transition, unaffordable_id) = create_transition(
&contract,
&mut poor,
multiple_choice_proposal::NAME,
described_at_a_url("Which colour?"),
&mut rng,
platform_version,
)
.await;
let result = process(&platform, transition, 50_000, platform_version);
assert!(
matches!(
result,
StateTransitionExecutionResult::UnpaidConsensusError(ConsensusError::StateError(
StateError::IdentityInsufficientBalanceError(_)
))
),
"{result:?}"
);
assert!(stored_document(
&platform,
&contract,
multiple_choice_proposal::NAME,
unaffordable_id
)
.is_none());
assert_eq!(
balance(&platform, poor.id(), platform_version),
dash_to_credits!(0.1)
);
}
Loading
Loading