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

Feature/Fix: Add simulated transaction fee to calculations.csv and fix compute logic #549

Merged
merged 57 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
42b174e
Add transaction fee to report
vkresch Jan 29, 2022
cc5f9b7
Added regression test
vkresch Feb 2, 2022
44d5f52
Merge branch 'master' into feature/transaction_fee_report
jdsika Feb 8, 2022
f2f5ff7
Adjust fee computation logic
amzid Feb 20, 2022
fe26165
fix black
jdsika Feb 21, 2022
d5be022
Merge branch 'master' into feature/transaction_fee_report
jdsika Feb 24, 2022
4eff263
review completed for fixing payment logic
jdsika Feb 24, 2022
05bd8a7
Review 2
jdsika Feb 28, 2022
331baff
removed kt accounts as payment address
jdsika Feb 28, 2022
b7464ce
added correct payment amount calculation
jdsika Feb 28, 2022
e5f940c
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 1, 2022
337115a
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 3, 2022
40dced7
replaced XTZ with tez, fixed CSV writer
jdsika Mar 3, 2022
fa310db
stuff
jdsika Mar 3, 2022
a6cc651
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 3, 2022
e5adf45
fixed type error in transaction content
jdsika Mar 3, 2022
09afd35
fix black
jdsika Mar 3, 2022
8fe119c
add descriptions to payment report
jdsika Mar 3, 2022
406d6ca
black fix
jdsika Mar 4, 2022
552ed80
minor changes to descritpions and convertion fix
jdsika Mar 4, 2022
a3290ca
made the operation hash consistent
jdsika Mar 7, 2022
8fc2bc9
fixed pass by reference for mutable objects
jdsika Mar 10, 2022
a245b7c
Fix partial tests
vkresch Mar 13, 2022
b8634e4
Fix number future payable cycles
vkresch Mar 14, 2022
869f2f5
removed legacy transaction_fee and replaced it with delegator_transac…
jdsika Mar 14, 2022
e38e48c
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 14, 2022
b7fa463
added instructions for vs code, changed to tez to mutez for consitenc…
jdsika Mar 14, 2022
7c210bd
readded check again and added .DONE for simulations as well
jdsika Mar 14, 2022
ce29426
changed formatting for mutez, removed redundant MUTEZ definitions
jdsika Mar 14, 2022
22edd54
fix lintq
nicolasochem Mar 14, 2022
8d0a7f7
fixed loggings, fixed int( ) conversions
jdsika Mar 15, 2022
762219b
Merge branch 'feature/transaction_fee_report' of https://github.com/t…
jdsika Mar 15, 2022
1f3df99
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 16, 2022
829e32d
fix black
jdsika Mar 16, 2022
7c8eeaa
minior changes
jdsika Mar 16, 2022
d8932d4
fix black and test_attempt_single_batch_tz/kt
jdsika Mar 16, 2022
132cc37
fix typos and moved a TODO into an issue
jdsika Mar 16, 2022
e3b97e5
harmonized type casts in reports
jdsika Mar 17, 2022
3d0a7a0
< threshold payments now correctly set to DONE, Removed magic numbers…
jdsika Mar 17, 2022
f9b7630
added burn fee remark to docs. added logger.info at keyboard interrup…
jdsika Mar 18, 2022
7ff6aa8
added type cast
jdsika Mar 18, 2022
deab106
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 18, 2022
df544bc
moved transaction fees from payment report to calculations report
jdsika Mar 18, 2022
09a40da
Merge branch 'feature/transaction_fee_report' of https://github.com/t…
jdsika Mar 18, 2022
5885ad7
changed .desc from None to empty string in calculations report
jdsika Mar 18, 2022
5c82fdb
fixed test_retry_producer.py by adapting test.csv to new format
jdsika Mar 21, 2022
92489a5
disabled flaky test
jdsika Mar 21, 2022
5de02a8
Expect zero payout amount
vkresch Mar 22, 2022
f4cfc92
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 22, 2022
3b050cb
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 23, 2022
7337b07
fixed bug which resulted in wrong parsing of atphase
jdsika Mar 23, 2022
d7ffada
fixed type cast
jdsika Mar 23, 2022
b570c16
replaced amount with adjusted_amount in webhook plugin
jdsika Mar 23, 2022
65a2ddb
fix "not in payment log" status in calculation (#572)
nicolasochem Mar 25, 2022
ee535ef
Merge branch 'master' into feature/transaction_fee_report
jdsika Mar 25, 2022
48e14ad
fixed webhook test
jdsika Mar 25, 2022
0c5afa8
added error messages for failed operations in payments csv
jdsika Mar 25, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
logs/
reports/
.vscode/
.env
*/*/__pycache__/
*/__pycache__/
email.ini*
Expand Down
12 changes: 7 additions & 5 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ Available configuration parameters are:

Example::

Current Baker Balance: 17,400 XTZ
Total Delegations: 69,520 XTZ
Total Staked: 86,920 XTZ
Current Baker Balance: 17,400 tez
Total Delegations: 69,520 tez
Total Staked: 86,920 tez

service_fee: 9
owners_map:
{'tz1PV5g16m9hHMAVJ4Hx6NzzUHgksDnTLFcK' : 0.4,
'tz1PirboZKFVqkfE45hVLpkpXaZtLk3mqC17' : 0.4,
'tz1VxS7ff4YnZRs8b4mMP4WaMVpoQjuo1rjf' : 0.2}

Charlie, and Dave, have each transfered 6,960 Tez to the baker address. Edwin has transfered 3,480 Tez. They are each partial owners of the baking balance. When rewards are delivered at the end of each cycle, 9% is taken as the bakery fee (ie: *service_fee*). That 9% is dispersed to any *founders*. If there are no founders, that 9% remains in the baker's balance.
Charlie, and Dave, have each transfered 6,960 tez to the baker address. Edwin has transfered 3,480 tez. They are each partial owners of the baking balance. When rewards are delivered at the end of each cycle, 9% is taken as the bakery fee (ie: *service_fee*). That 9% is dispersed to any *founders*. If there are no founders, that 9% remains in the baker's balance.
The baker address is technically a delegator to itself. Its share of rewards are part of the overall cycle rewards. Charlie, Dave, and Edwin divide the "baker address rewards" as per the ratios in *owners_map*. Additionally, owners are *not* subject to the *service_fee*.

**specials_map**
Expand All @@ -119,7 +119,7 @@ Available configuration parameters are:
'tz1PirboZKFVqkfE45hVLpkpXaZtLk3mqC17'}

**min_delegation_amt**
A minimum delegation amount can be set here. If this value is set to 10, 10 XTZ are required as minimum. It is important to define what happens to the rewards of excluded delegates that are below the minimum delegation balance in rules_map.
A minimum delegation amount can be set here. If this value is set to 10, 10 tez are required as minimum. It is important to define what happens to the rewards of excluded delegates that are below the minimum delegation balance in rules_map.

Example::

Expand All @@ -146,6 +146,8 @@ Available configuration parameters are:

delegator_pays_ra_fee : False

Note: This option does also apply to the burn fee needed to payout to kt accounts.

**pay_denunciation_rewards**
True/False - Baker may get rewarded for denunciating another baker's equivocation (double baking or double endorsing). The protocol rewards the baker including the denunciation. When True, these rewards will be distributed. When False, they will remain in the baker's account, allowing the baker to reimburse the party at fault if they desire. Must be set to True when using RPC backend as RPC is not able to itemize rewards.

Expand Down
36 changes: 35 additions & 1 deletion docs/contributors.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
For Developers
=====================================================

General:
---------

If you are interested in improving our project, this is just great! Our community looks forward to your contribution. Please follow this process:

1. Start a bug/feature issue on GitHub about your proposed change. Continue discussion until a solution is decided.
Expand Down Expand Up @@ -40,4 +43,35 @@ Guidelines for rewarding PRs in the context of the TRD grant:
4. The PR can only be approved if an agreement about the work effort (in hrs) is made.
5. The PR should be merged using a squash merge, the work effort of the contributor and reviewer should be documented in the squash merge commit message.
6. The work efforts are paid out in a regular basis. The payments are documented in a dedicated file named `contributor_payments.csv`.
7. For each payment, the reason for payment should be documented (commit hash, review efforts, etc.). Additionally, the paid amount in USD, the VWAP XTZ-USD on the payment day, the payed amount in XTZ and the transaction hash are documented.
7. For each payment, the reason for payment should be documented (commit hash, review efforts, etc.). Additionally, the paid amount in USD, the VWAP XTZ-USD on the payment day, the payed amount in XTZ and the transaction hash are documented.

Setup:
-------

you can contribute to TRD using your the developer tool of your choice. The follwing setup helps with VS Code.

1. Creat a `.env` file in the workspace directory with the following content:

Windows: PYTHONPATH=${PYTHONPATH};./src
Mac/Linux: PYTHONPATH=${PYTHONPATH}:./src

2. Create a `settings.json` file in the folder `.vscode` with the following content:

.. code-block:: JSON

{
"terminal.integrated.env.osx": {
"PYTHONPATH": "${env:PYTHONPATH}:${workspaceFolder}/src",
},
"terminal.integrated.env.linux": {
"PYTHONPATH": "${env:PYTHONPATH}:${workspaceFolder}/src",
},
"terminal.integrated.env.windows": {
"PYTHONPATH": "${env:PYTHONPATH};${workspaceFolder}/src",
},
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
8 changes: 4 additions & 4 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ plugins:
- 827384777
bot_api_key: 988877766:SKDJFLSJDFJLJSKDFJLKSDJFLKJDF
telegram_text: >
&#x2728; Reward for cycle %CYCLE% <b>complete</b>! We had %NDELEGATORS% <i>delegators</i> in the cycle and paid out %TREWARDS% XTZ in rewards!
&#x2728; Reward for cycle %CYCLE% <b>complete</b>! We had %NDELEGATORS% <i>delegators</i> in the cycle and paid out %TREWARDS% tez in rewards!
```

### Example Result
Expand Down Expand Up @@ -166,14 +166,14 @@ plugins:
access_token: YYYYYYYY
access_secret: WWWWWWWW
tweet_text: >
Reward for cycle %CYCLE% complete! We had %NDELEGATORS% delegators in the cycle and paid out %TREWARDS% XTZ in rewards. #ourbakery #rewards #tezos
Reward for cycle %CYCLE% complete! We had %NDELEGATORS% delegators in the cycle and paid out %TREWARDS% tez in rewards. #ourbakery #rewards #tezos
```

The above example configuration will produce a tweet that looks like this:

```
Reward for cycle 290 complete! We had 133 delegators
in the cycle and paid out 1234.98 XTZ in rewards.
in the cycle and paid out 1234.98 tez in rewards.
#ourbakery #rewards #tezos
```

Expand All @@ -200,7 +200,7 @@ plugins:
send_admin: False
discord_text: >
Rewards for cycle %CYCLE% are completed.
We paid out %TREWARDS% XTZ in rewards to %NDELEGATORS% delegators.
We paid out %TREWARDS% tez in rewards to %NDELEGATORS% delegators.
```

### Example Result
Expand Down
4 changes: 2 additions & 2 deletions examples/tz1boot1pK9h2BVGXdyvfQSv8kd1LQM6H889.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ plugins:
bot_api_key: 988877766:SKDJFLSJDFJLJSKDFJLKSDJFLKJDF
telegram_text: >
Rewards for cycle %CYCLE% are completed.
We paid out %TREWARDS% XTZ in rewards to %NDELEGATORS% delegators.
We paid out %TREWARDS% tez in rewards to %NDELEGATORS% delegators.
twitter:
api_key: XXXXXXXX
api_secret: ZZZZZZZZ
Expand All @@ -67,4 +67,4 @@ plugins:
send_admin: False
discord_text: >
Rewards for cycle %CYCLE% are completed.
We paid out %TREWARDS% XTZ in rewards to %NDELEGATORS% delegators.
We paid out %TREWARDS% tez in rewards to %NDELEGATORS% delegators.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ fysom==2.1.6
parse
transitions
tweepy
# developer
parameterized
Pygments
graphviz
4 changes: 3 additions & 1 deletion src/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
}


MUTEZ = 1e6
MUTEZ_PER_TEZ = 1e6
MAXIMUM_ROUNDING_ERROR = 10 # mutez
ALMOST_ZERO = 1e-6

VERSION = 10.0

Expand Down
10 changes: 4 additions & 6 deletions src/calc/calculate_phase1.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ def calculate(self, reward_data0, total_amount):

# total reward amount needs to be diminished at the same rate total balance diminishes
new_total_amnt_multiplier = new_total_balance / total_balance
new_total_amount = int(
Decimal(total_amount * new_total_amnt_multiplier).to_integral_value(
rounding=ROUND_HALF_DOWN
)
)
new_total_amount = Decimal(
total_amount * new_total_amnt_multiplier
).to_integral_value(rounding=ROUND_HALF_DOWN)

return rewards, new_total_amount
return rewards, int(new_total_amount)
2 changes: 1 addition & 1 deletion src/calc/calculate_phase2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def calculate(self, reward_data1, total_amount):
rl2.ratio2 = rl2.ratio

# total reward amount remains the same
return rewards, total_amount
return rewards, int(total_amount)
5 changes: 3 additions & 2 deletions src/calc/calculate_phase3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)
from model.baking_conf import MIN_DELEGATION_KEY
from model.reward_log import RewardLog, TYPE_FOUNDERS_PARENT
from Constants import ALMOST_ZERO


class CalculatePhase3(CalculatePhaseBase):
Expand Down Expand Up @@ -63,7 +64,7 @@ def calculate(self, reward_data2, total_amount):
total_service_fee_ratio += rl.service_fee_ratio

# create founders parent record
if total_service_fee_ratio > 1e-6: # >0
if total_service_fee_ratio > ALMOST_ZERO:
rl = RewardLog(
address=TYPE_FOUNDERS_PARENT,
type=TYPE_FOUNDERS_PARENT,
Expand All @@ -77,4 +78,4 @@ def calculate(self, reward_data2, total_amount):

new_rewards.append(rl)

return new_rewards, total_amount
return new_rewards, int(total_amount)
2 changes: 1 addition & 1 deletion src/calc/calculate_phase4.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def calculate(self, reward_data3, total_amount):
rl3.ratio4 = rl3.ratio
new_rewards.append(rl3)

return new_rewards, total_amount
return new_rewards, int(total_amount)
6 changes: 3 additions & 3 deletions src/calc/calculate_phase_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import itertools

BY_CONFIGURATION = "Excluded by configuration"
BY_MIN_DELEGATION = "Excluded by min delegation"
BY_ZERO_BALANCE = "Excluded by zero balance"
BY_CONFIGURATION = "Excluded by configuration. "
BY_MIN_DELEGATION = "Excluded by min delegation. "
BY_ZERO_BALANCE = "Excluded by zero balance. "


class CalculatePhaseBase(ABC):
Expand Down
5 changes: 1 addition & 4 deletions src/calc/calculate_phase_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def calculate(self, reward_data5, total_amount, adjustments={}):
rounding=ROUND_HALF_DOWN
)
)
rl.payable = (
rl.type in [TYPE_FOUNDER, TYPE_OWNER, TYPE_DELEGATOR]
and rl.adjusted_amount > 0
)
rl.payable = rl.type in [TYPE_FOUNDER, TYPE_OWNER, TYPE_DELEGATOR]
rl.service_fee_amount = int(
Decimal(rl.service_fee_ratio * total_amount).to_integral_value(
rounding=ROUND_HALF_DOWN
Expand Down
39 changes: 20 additions & 19 deletions src/calc/phased_payment_calculator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools

from Constants import MAXIMUM_ROUNDING_ERROR, ALMOST_ZERO
from calc.calculate_phase0 import CalculatePhase0
from calc.calculate_phase1 import CalculatePhase1
from calc.calculate_phase2 import CalculatePhase2
Expand All @@ -15,9 +16,6 @@

logger = main_logger.getChild("phased_calculator")

MINOR_DIFF = 10
MINOR_RATIO_DIFF = 1e-6


class PhasedPaymentCalculator:
"""
Expand Down Expand Up @@ -58,9 +56,9 @@ def calculate(self, reward_provider_model, adjustments=None):
phase0 = CalculatePhase0(reward_provider_model)
rwrd_logs = phase0.calculate()

total_rwrd_amnt = reward_provider_model.computed_reward_amount
total_rwrd_amnt = int(reward_provider_model.computed_reward_amount)
logger.info(
"Total rewards before processing is {:,} mutez.".format(total_rwrd_amnt)
"Total rewards before processing is {:<,d} mutez.".format(total_rwrd_amnt)
)
if total_rwrd_amnt == 0:
logger.debug("NO REWARDS to process!")
Expand Down Expand Up @@ -133,41 +131,44 @@ def calculate(self, reward_provider_model, adjustments=None):
rwrd_logs.sort(key=functools.cmp_to_key(cmp_by_type_balance))

# check if there is difference between sum of calculated amounts and total_rewards
total_delegator_amounts = sum(
[rl.adjusted_amount for rl in rwrd_logs if not rl.skipped]
total_delegator_amounts = int(
sum([rl.adjusted_amount for rl in rwrd_logs if not rl.skipped])
)
total_adjustments = int(
sum([rl.adjustment for rl in rwrd_logs if not rl.skipped])
)
total_adjustments = sum([rl.adjustment for rl in rwrd_logs if not rl.skipped])
amnt_pay_diff = abs(
total_rwrd_amnt + total_adjustments - total_delegator_amounts
amnt_pay_diff = int(
abs(total_rwrd_amnt + total_adjustments - total_delegator_amounts)
)

logger.info(
"Total rewards after processing is {:,} mutez.".format(total_rwrd_amnt)
"Total rewards after processing is {:<,d} mutez.".format(total_rwrd_amnt)
)

if total_adjustments < 0:
logger.info(
"Total adjustment for past early payout is {:,} mutez.".format(
"Total adjustment for past early payout is {:<,d} mutez.".format(
total_adjustments
)
)
logger.info(
"Adjusted total rewards is {:,} mutez.".format(
"Adjusted total rewards is {:<,d} mutez.".format(
total_rwrd_amnt + total_adjustments
)
)
logger.info(
"Sum of amounts allocated to delegators is {:,} mutez".format(
"Sum of amounts allocated to delegators is {:<,d} mutez".format(
total_delegator_amounts
)
)
logger.info(
"Difference between total rewards and sum of amounts allocated to delegators is {:,} mutez. "
"This is due to floating point arithmetic. (max allowed diff is {:,})".format(
amnt_pay_diff, MINOR_DIFF
"Difference between total rewards and sum of amounts allocated to delegators is {:<,d} mutez. "
"This is due to floating point arithmetic. (max allowed diff is {:<,d} mutez)".format(
amnt_pay_diff, int(MAXIMUM_ROUNDING_ERROR)
)
)

return rwrd_logs, total_rwrd_amnt
return rwrd_logs, int(total_rwrd_amnt)

def almost_equal(self, double1, double2):
return abs(double1 - double2) < MINOR_RATIO_DIFF
return abs(double1 - double2) < ALMOST_ZERO
10 changes: 6 additions & 4 deletions src/config/yaml_baking_conf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from config.addr_type import AddrType
from config.yaml_conf_parser import YamlConfParser
from Constants import RewardsType
from Constants import RewardsType, ALMOST_ZERO
from exception.configuration import ConfigurationException
from log_config import main_logger
from model.baking_conf import (
Expand Down Expand Up @@ -147,7 +147,9 @@ def validate_share_map(self, conf_obj, map_name):

if len(share_map) > 0:
try:
if abs(1 - sum(share_map.values()) > 1e-4): # a zero check actually
if abs(
1 - sum(share_map.values()) > ALMOST_ZERO
): # a zero check actually
raise ConfigurationException(
"Map '{}' shares does not sum up to 1!".format(map_name)
)
Expand Down Expand Up @@ -312,13 +314,13 @@ def validate_plugins(self, conf_obj):
def validate_rewards_type(self, conf_obj):

if REWARDS_TYPE not in conf_obj or conf_obj[REWARDS_TYPE] is None:
conf_obj[REWARDS_TYPE] = "actual"
conf_obj[REWARDS_TYPE] = RewardsType.ACTUAL
logger.warning(
"[config_parser] Parameter '{:s}' is missing or incorrectly configured. "
"Defaults to 'actual' rewards payout type.".format(REWARDS_TYPE)
)

if conf_obj[REWARDS_TYPE] == "estimated":
if conf_obj[REWARDS_TYPE] == RewardsType.ESTIMATED:
raise ConfigurationException(
"Setting 'rewards_type' to 'estimated' is no longer supported.\n"
"Please see https://tezos-reward-distributor-organization.github.io/tezos-reward-distributor/payouttiming.html\n"
Expand Down
Loading