Преглед изворни кода

DAO: switch to 4 hour windows instead of days

zero пре 2 година
родитељ
комит
603e917763

+ 1 - 1
doc/src/spec/contract/dao/concepts.md

@@ -41,7 +41,7 @@ There are currently two voting options:
 
 
 ### Voting Period
 ### Voting Period
 
 
-Once a proposal passes its duration, which is measured in days, participants can
+Once a proposal passes its duration, which is measured in 4 hour block windows, participants can
 no longer vote on the proposal, and it is considered *expired*.
 no longer vote on the proposal, and it is considered *expired*.
 
 
 ### Quorum
 ### Quorum

+ 4 - 4
doc/src/spec/contract/dao/model.md

@@ -90,18 +90,18 @@ Let $P$ be a proposal bulla as in the section [Proposal](#proposal).
 Define $\t{Nullifier}_\t{Vote} : 𝔽ₚ × 𝔽ₚ × 𝔽ₚ → 𝔽ₚ$ as follows:
 Define $\t{Nullifier}_\t{Vote} : 𝔽ₚ × 𝔽ₚ × 𝔽ₚ → 𝔽ₚ$ as follows:
 $$ \t{Nullifier}_\t{Vote}(\mathcal{C}.s, C, P) = \t{PoseidonHash}(\mathcal{C}.s, C, P) $$
 $$ \t{Nullifier}_\t{Vote}(\mathcal{C}.s, C, P) = \t{PoseidonHash}(\mathcal{C}.s, C, P) $$
 
 
-## Current Day
+## Blockwindow
 
 
-Time limits on proposals are expressed in terms of days. Since proofs cannot
+Time limits on proposals are expressed in 4 hour windows. Since proofs cannot
 guarantee which block they get into, we therefore must modulo the block height
 guarantee which block they get into, we therefore must modulo the block height
 a certain number which we use in the proofs.
 a certain number which we use in the proofs.
 
 
 ```rust
 ```rust
-{{#include ../../../../../src/contract/dao/src/lib.rs:dao-blockheight_to_day}}
+{{#include ../../../../../src/contract/dao/src/lib.rs:dao-blockwindow}}
 ```
 ```
 
 
 which can be used like this
 which can be used like this
 ```rust
 ```rust
-{{#include ../../../../../src/contract/dao/src/entrypoint/propose.rs:dao-blockheight_to_day-example-usage}}
+{{#include ../../../../../src/contract/dao/src/entrypoint/propose.rs:dao-blockwindow-example-usage}}
 ```
 ```
 
 

+ 3 - 1
doc/src/spec/contract/dao/scheme.md

@@ -121,7 +121,7 @@ $$ \begin{aligned}
 
 
 ### Contract Statement
 ### Contract Statement
 
 
-Let $t₀ = \t{CurrentDay} ∈ 𝔽ₚ$ be the current day as defined in [Current Day](model.md#current-day).
+Let $t₀ = \t{BlockWindow} ∈ 𝔽ₚ$ be the current blockwindow as defined in [Blockwindow](model.md#blockwindow).
 
 
 Let $\t{Attrs}_\t{Coin}$ be defined as in [Coin](../money/model.md#coin).
 Let $\t{Attrs}_\t{Coin}$ be defined as in [Coin](../money/model.md#coin).
 
 
@@ -260,6 +260,8 @@ This is then used in the Exec phase when we work on the sum of DAO votes.
 
 
 ### Contract Statement
 ### Contract Statement
 
 
+Let $t₀ = \t{BlockWindow} ∈ 𝔽ₚ$ be the current blockwindow as defined in [Blockwindow](model.md#blockwindow).
+
 **Proposal bulla exists**   check $𝒫 $ exists in the DAO contract proposal
 **Proposal bulla exists**   check $𝒫 $ exists in the DAO contract proposal
 bullas DB.
 bullas DB.
 
 

+ 4 - 4
src/contract/dao/src/entrypoint/propose.rs

@@ -33,7 +33,7 @@ use darkfi_sdk::{
 use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 
 
 use crate::{
 use crate::{
-    blockheight_to_day,
+    blockwindow,
     error::DaoError,
     error::DaoError,
     model::{DaoBlindAggregateVote, DaoProposalMetadata, DaoProposeParams, DaoProposeUpdate},
     model::{DaoBlindAggregateVote, DaoProposalMetadata, DaoProposeParams, DaoProposeUpdate},
     DaoFunction, DAO_CONTRACT_DB_DAO_MERKLE_ROOTS, DAO_CONTRACT_DB_PROPOSAL_BULLAS,
     DaoFunction, DAO_CONTRACT_DB_DAO_MERKLE_ROOTS, DAO_CONTRACT_DB_PROPOSAL_BULLAS,
@@ -84,9 +84,9 @@ pub(crate) fn dao_propose_get_metadata(
         ));
         ));
     }
     }
 
 
-    // ANCHOR: dao-blockheight_to_day-example-usage
-    let current_day = blockheight_to_day(get_verifying_block_height());
-    // ANCHOR_END: dao-blockheight_to_day-example-usage
+    // ANCHOR: dao-blockwindow-example-usage
+    let current_day = blockwindow(get_verifying_block_height());
+    // ANCHOR_END: dao-blockwindow-example-usage
 
 
     let total_funds_coords = total_funds_commit.to_affine().coordinates().unwrap();
     let total_funds_coords = total_funds_commit.to_affine().coordinates().unwrap();
     zk_public_inputs.push((
     zk_public_inputs.push((

+ 2 - 2
src/contract/dao/src/entrypoint/vote.rs

@@ -30,7 +30,7 @@ use darkfi_sdk::{
 use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 
 
 use crate::{
 use crate::{
-    blockheight_to_day,
+    blockwindow,
     error::DaoError,
     error::DaoError,
     model::{DaoProposalMetadata, DaoVoteParams, DaoVoteUpdate},
     model::{DaoProposalMetadata, DaoVoteParams, DaoVoteUpdate},
     DaoFunction, DAO_CONTRACT_DB_PROPOSAL_BULLAS, DAO_CONTRACT_DB_VOTE_NULLIFIERS,
     DaoFunction, DAO_CONTRACT_DB_PROPOSAL_BULLAS, DAO_CONTRACT_DB_VOTE_NULLIFIERS,
@@ -81,7 +81,7 @@ pub(crate) fn dao_vote_get_metadata(
         ));
         ));
     }
     }
 
 
-    let current_day = blockheight_to_day(get_verifying_block_height());
+    let current_day = blockwindow(get_verifying_block_height());
 
 
     let yes_vote_commit_coords = params.yes_vote_commit.to_affine().coordinates().unwrap();
     let yes_vote_commit_coords = params.yes_vote_commit.to_affine().coordinates().unwrap();
     let all_vote_commit_coords = all_vote_commit.to_affine().coordinates().unwrap();
     let all_vote_commit_coords = all_vote_commit.to_affine().coordinates().unwrap();

+ 7 - 6
src/contract/dao/src/lib.rs

@@ -90,13 +90,14 @@ pub const DAO_CONTRACT_ZKAS_DAO_AUTH_MONEY_TRANSFER_NS: &str = "DaoAuthMoneyTran
 pub const DAO_CONTRACT_ZKAS_DAO_AUTH_MONEY_TRANSFER_ENC_COIN_NS: &str =
 pub const DAO_CONTRACT_ZKAS_DAO_AUTH_MONEY_TRANSFER_ENC_COIN_NS: &str =
     "DaoAuthMoneyTransferEncCoin";
     "DaoAuthMoneyTransferEncCoin";
 
 
-// ANCHOR: dao-blockheight_to_day
+// ANCHOR: dao-blockwindow
 const BLOCK_TIME: u64 = 90;
 const BLOCK_TIME: u64 = 90;
-const SECS_IN_DAY: u64 = 24 * 60 * 60;
+const SECS_IN_HOUR: u64 = 60 * 60;
+const WINDOW_TIME_HR: u64 = 4;
 
 
-/// Days since genesis block. Used for time limit on DAO proposals.
-pub fn blockheight_to_day(height: u64) -> u64 {
+/// Blockwindow from blockheight. Used for time limit on DAO proposals.
+pub fn blockwindow(height: u64) -> u64 {
     let timestamp_secs = height * BLOCK_TIME;
     let timestamp_secs = height * BLOCK_TIME;
-    timestamp_secs / SECS_IN_DAY
+    timestamp_secs / (WINDOW_TIME_HR * SECS_IN_HOUR)
 }
 }
-// ANCHOR_END: dao-blockheight_to_day
+// ANCHOR_END: dao-blockwindow