Skip to content

Commit

Permalink
Merge pull request #100 from dusk-network/79-update-provisioner-defin…
Browse files Browse the repository at this point in the history
…ition-to-only-include-one-stake

Update Provisioner to single stake
  • Loading branch information
fed-franz authored Jan 12, 2024
2 parents e3ca312 + 9ee85d4 commit 7f68c66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
8 changes: 4 additions & 4 deletions consensus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ A candidate block that reaches an agreement is called a *winning* block.
A provisioner is a user that locks a certain amount of their Dusk coins as *stake* (see [*Stake Contract*][c-stake]).
Formally, we define a *Provisioner* $\mathcal{P}$ as:

$$\mathcal{P}=(pk_\mathcal{P},\boldsymbol{Stakes}_\mathcal{P}),$$
$$\mathcal{P}=(pk_\mathcal{P}, S_\mathcal{P}),$$

where $pk_\mathcal{P}$ is the BLS public key of the provisioner, and $\boldsymbol{Stakes}_\mathcal{P} = [S_0,\dots,S_n]$, where $S_i$ is a stake amount belonging to $\mathcal{P}$.
where $pk_\mathcal{P}$ is the BLS public key of the provisioner and $S_\mathcal{P}$ is the stake belonging to $\mathcal{P}$.

In turn, a *stake* is defined as:
$$S^\mathcal{P}=(Amount, Height),$$
In turn, a *Stake* is defined as:
$$S_\mathcal{P}=(Amount, Height),$$
where $\mathcal{P}$ is the provisioner that owns the stake, $Amount$ is the quantity of locked Dusks, and $Height$ is the height of the block where the lock action took place (i.e., when the *stake* transaction was included). The minimum value for a stake is defined by the [global parameter][cp] $MinStake$, and is currently equivalent to 1000 Dusk.

The stake amount of each provisioner directly influences the probability of being extracted by the [Deterministic Sortition][dsa] algorithm: the higher the stake, the more the provisioner will be extracted on average.
Expand Down
54 changes: 26 additions & 28 deletions consensus/sortition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ Note that $Seed_0$ is a randomly-generated value contained in the genesis block
## Algorithm
We describe the *Deterministic Sortition* algorithm through the $DS$ procedure, which creates a *Voting Committee* by pseudo-randomly assigning *credits* to eligible provisioners. In turn, $DS$ uses the *Deterministic Extraction* algorithm, described through the $DE$ procedure.

In the following, we describe both $DS$ and $DE$ first as natural-language algorithm and then as formal procedure.

### Deterministic Sortition (DS)

***Parameters***
Expand All @@ -122,37 +120,37 @@ In the following, we describe both $DS$ and $DE$ first as natural-language algor
***Algorithm***

1. Start with empty committee
2. Set each provisioner's weight equal to the sum of its (mature) stakes
3. Set total weight to the sum of all provisioner's weights
2. Set each provisioner's weight equal to the amount of its stake
3. Set total weight $W$ to the sum of all provisioner's weights
4. Assign credit $i$ as follows:
1. Compute $Score$
2. Order provisioners by ascending public key
3. Extract provisioner $P$ with [*DE*][de]
4. Add $P$ to committee, if necessary
5. Assign credit to $P$
6. Compute $d$ as the minimum between $1$ Dusk and $P$'s weight
7. Subtract $d$ from $P$'s weight
8. Subtract $d$ from total weight
3. Extract provisioner $\mathcal{P}$ with [*DE*][de]
4. Add $\mathcal{P}$ to committee, if necessary
5. Assign credit to $\mathcal{P}$
6. Compute $d$ as the minimum between $1$ Dusk and $\mathcal{P}$'s weight
7. Subtract $d$ from $\mathcal{P}$'s weight
8. Subtract $d$ from total weight $W$
9. If total weight reaches 0, output the partial committee
5. Output committee

***Procedure***

$DS(r, s, credits)$:
1. $C = \emptyset$
2. $\texttt{for } P \texttt{ in } \boldsymbol{P}_r :$
- $w_P = \sum_{i=0}^{|\boldsymbol{Stakes}_P|-1} \boldsymbol{Stakes}_P[i]$
3. $`W = \sum_{i=0}^{|\boldsymbol{P}_r|-1} w_{P_i} : P_i \in \boldsymbol{P}_r`$
2. $\texttt{for } \mathcal{P} \texttt{ in } \boldsymbol{P}_r :$
- $w_\mathcal{P} = S_\mathcal{P}.Amount$
3. $`W = \sum_{i=0}^{|\boldsymbol{P}_r|-1} w_{\mathcal{P}_i} : \mathcal{P}_i \in \boldsymbol{P}_r`$
4. $\texttt{for } c = 0\text{ }\dots\text{ }credits{-}1$:
1. $Score_c^{r,s} = Int(Hash_{SHA3}( Seed_{r-1}||r||s||c)) \mod W$
2. $\boldsymbol{P}_r' = SortByPK(\boldsymbol{P}_r)$
3. $P_c = \text{ }$[*DE*][de]$(Score_c^{r,s}, \boldsymbol{P}_r')$
4. $\texttt{if } P_c \notin C$ :
- $m_{P_c}^C = (P_c,0)$
- $C = C \cup m_{P_c}^C$
5. $m_{P_c}^C.influence = m_{P_c}^C.influence+1$
3. $\mathcal{P}_c = \text{ }$[*DE*][de]$(Score_c^{r,s}, \boldsymbol{P}_r')$
4. $\texttt{if } \mathcal{P}_c \notin C$ :
- $m_{\mathcal{P}_c}^C = (\mathcal{P}_c,0)$
- $C = C \cup m_{\mathcal{P}_c}^C$
5. $m_{\mathcal{P}_c}^C.influence = m_{\mathcal{P}_c}^C.influence+1$
6. $d = min(w_{P},1)$
7. $w_{P_c} = w_{P_c} - d$
7. $w_{\mathcal{P}_c} = w_{\mathcal{P}_c} - d$
8. $W = W - d$
9. $\texttt{if } W \le 0$
- $\texttt{output } C$
Expand All @@ -164,23 +162,23 @@ $DS(r, s, credits)$:

***Parameters***
- $Score$: score for current credit assignation
- $\boldsymbol{P} = [P_0,\dots,P_n]$: array of provisioners ordered by public key
- $\boldsymbol{P} = [\mathcal{P}_0,\dots,\mathcal{P}_n]$: array of provisioners ordered by public key

***Algorithm***
1. For each provisioner $P$ in $\boldsymbol{P}$
1. if $P$'s weight is higher than $Score$,
1. output $P$
1. For each provisioner $\mathcal{P}$ in $\boldsymbol{P}$
1. if $\mathcal{P}$'s weight is higher than $Score$,
1. output $\mathcal{P}$
2. otherwise,
1. subtract $P$'s weight from $Score$
1. subtract $\mathcal{P}$'s weight from $Score$

***Procedure***

$`DE(Score_i^{r,s}, \boldsymbol{P})`$:
1. $\texttt{for } P = \boldsymbol{P}[0] \dots \boldsymbol{P}[|\boldsymbol{P}|-1]$ :
1. $\texttt{if } w_{P} \ge Score$
1. $\texttt{output } P$
1. $\texttt{for } \mathcal{P} = \boldsymbol{P}[0] \dots \boldsymbol{P}[|\boldsymbol{P}|-1]$ :
1. $\texttt{if } w_\mathcal{P} \ge Score$
1. $\texttt{output } \mathcal{P}$
2. $\texttt{\texttt{else}}:$
1. $Score = Score - w_{P}$
1. $Score = Score - w_\mathcal{P}$

<!-- Note that the outer $loop$ means that if the $for$ loop ends (i.e. no provisioner was extracted), it starts over with $j=0$. -->

Expand Down

0 comments on commit 7f68c66

Please sign in to comment.