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

go staking: three-way fee split #2794

Merged
merged 12 commits into from
Mar 30, 2020
Merged

go staking: three-way fee split #2794

merged 12 commits into from
Mar 30, 2020

Conversation

pro-wh
Copy link
Contributor

@pro-wh pro-wh commented Mar 30, 2020

We should give more to the previous block proposer, which is the block that first ran the transactions that paid the fees in the LastBlockFees. Currently they only get paid as a voter.

Proposed design

Summary

The fee for block $h$ is split into $k$ portions, where $k$ is the number of validators at block $h$, one for each of those validators.
Each portion is split by constant weights into a proposer share, a voter share, and a next proposer share.
At the end of block $h$, pay the proposer share of all portions to the proposer of block $h$.
At the beginning of block $h+1$, for each portion where its validator's vote is included in block $h+1$, pay the voter share to the validator and pay the next proposer share to the proposer of block $h+1$.

Changes to genesis document

In .staking.params:

  • Changed: fee_split_* is renamed to fee_split_weight_*
  • Added: fee_split_weight_next_propose, a quantity.Quantity
  • Changed: fee_split_weight_propose controls the proposer share (previously controlled the next proposer share)

Setting idea:

  • fee_split_weight_propose: 2
  • fee_split_weight_vote: 1
  • fee_split_weight_next_propose: 1

Changes to block context

  • Added: proposerEntityKey, the block proposer, with the entity of the proposer (needed to remember the proposer from BeginBlock for use in EndBlock)

Changes to ABCI state

  • Changed: lastBlockFeesKeyFmt, the last block fees, now stores only the voter shares and next proposer shares

Algorithms

In cases where resolving an entity ID from a node address fails, skip movements to its balance.

In BeginBlock:

  • Get the proposer address $A_p$ from the request
  • Get the last commit number $k$ of validators from the request
  • Get the address $V$ of nodes that voted from the request
  • Resolve entity ID $I_p$ from node address $A_p$
  • Get $f_{v,q}$ from the last block fees
  • Compute a portion size $s=f_{v,q}/k$ (rounds down) where $k$ is the number of validators
  • Compute a share size $s_q=s*w_q/(w_v+w_q)$ (rounds down)
  • Compute a share size $s_v=s-s_q$
  • For each voter address $v_i \in V$:
    • Resolve the entity ID $I_{v_i}$ from node address $v_i$
    • Move $s_v$ from the last block fees to $I_{v_i}$'s general balance
  • Move $s_q*|V|$ from the last block fees to $I_p$'s general balance
  • Move the remaining amount from the last block fees to the common pool
  • Store $I_p$ as the block proposer

In EndBlock:

  • Compute a portion of the fee $f_{v,q}=f*(w_v+w_q)/(w_p+w_v+w_q)$ (rounds down) where $f$ is the accumulated fee, $w_p$ is the proposer share, $w_v$ is the voter share, and $w_q$ is the next proposer share
  • Move $f_{v,q}$ from the fee accumulator to the last block fees
  • Get $I_p$ from the block proposer
  • Move the remaining amount from the fee accumulator to $I_p$'s general balance
  • Move the remaining amount from the fee accumulator to the common pool (in case resolving $I_p$ failed)

@pro-wh pro-wh added c:consensus/tendermint Category: Tendermint-based consensus c:staking Category: staking labels Mar 30, 2020
@codecov
Copy link

codecov bot commented Mar 30, 2020

Codecov Report

Merging #2794 into master will increase coverage by 0.06%.
The diff coverage is 44.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2794      +/-   ##
==========================================
+ Coverage   61.63%   61.70%   +0.06%     
==========================================
  Files         386      386              
  Lines       37095    37131      +36     
==========================================
+ Hits        22865    22912      +47     
+ Misses      11222    11213       -9     
+ Partials     3008     3006       -2     
Impacted Files Coverage Δ
go/oasis-node/cmd/genesis/genesis.go 52.38% <0.00%> (ø)
go/staking/api/api.go 71.42% <ø> (ø)
go/staking/tests/debug/debug_stake.go 60.00% <ø> (ø)
go/staking/api/sanity_check.go 50.00% <25.00%> (-0.88%) ⬇️
go/consensus/tendermint/apps/staking/staking.go 61.24% <33.33%> (-0.67%) ⬇️
go/consensus/tendermint/apps/staking/fees.go 49.49% <45.67%> (+9.76%) ⬆️
go/consensus/tendermint/apps/staking/state/gas.go 84.44% <66.66%> (-5.56%) ⬇️
...oasis-node/cmd/debug/txsource/workload/transfer.go 0.00% <0.00%> (-63.81%) ⬇️
.../oasis-node/cmd/debug/txsource/workload/runtime.go 1.77% <0.00%> (-55.63%) ⬇️
go/worker/common/host/protocol/protocol.go 65.67% <0.00%> (-3.74%) ⬇️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b27c1cf...8f4ba58. Read the comment docs.

@pro-wh pro-wh merged commit 327ce4b into master Mar 30, 2020
@pro-wh pro-wh deleted the pro-wh/feature/nextprop branch March 30, 2020 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:consensus/tendermint Category: Tendermint-based consensus c:staking Category: staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants