-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Slashing mechanism - Epoch snapshot in a document-oriented DB - Reports are now independent from epoch snapshotting (and can be extended by working on `reporter/reporter.py`)
- Loading branch information
Showing
75 changed files
with
25,177 additions
and
12,069 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ __pycache__ | |
.hypothesis/ | ||
build/ | ||
.vscode/ | ||
node_modules/ | ||
node_modules/ | ||
env/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from enum import Enum | ||
from tinydb import Query | ||
|
||
Account = Query() | ||
|
||
|
||
class AccountState(Enum): | ||
ACTIVE = "active" | ||
INACTIVE = "inactive" | ||
SLASHED = "slashed" | ||
|
||
|
||
def to_staker(staker): | ||
return {"address": staker[0], "balance": int(staker[1])} | ||
|
||
|
||
def state(voted, inactive_windows): | ||
if voted: | ||
return AccountState.ACTIVE.value | ||
|
||
# check if inactive windows are consecutive | ||
|
||
end_slice = inactive_windows[-3:] | ||
|
||
slashed = len(end_slice) == 3 and sorted(end_slice) == list( | ||
range(min(end_slice), max(end_slice) + 1) | ||
) | ||
|
||
return AccountState.INACTIVE.value if not slashed else AccountState.SLASHED.value | ||
|
||
|
||
def init_account(staker, db, window_index, participation, claim_map): | ||
account_prev = db.table("accounts").get(Account.address == staker["address"]) | ||
voted = participation[staker["address"]] | ||
claimed = claim_map[staker["address"]] | ||
|
||
if account_prev == None: | ||
# new staker, need to init his account | ||
inactive_windows = [] if voted else [window_index] | ||
|
||
return { | ||
"address": staker["address"], | ||
"vedough_balance": int(staker["balance"]), | ||
"slice_amount": 0, | ||
"state": state(voted, inactive_windows), | ||
"inactive_windows": inactive_windows, | ||
} | ||
else: | ||
inactive_windows = ( | ||
account_prev["inactive_windows"] | ||
if voted | ||
else account_prev["inactive_windows"] + [window_index] | ||
) | ||
|
||
return { | ||
"address": staker["address"], | ||
"vedough_balance": int(staker["balance"]), | ||
"slice_amount": 0 if claimed else account_prev["slice_amount"], | ||
"state": state(voted, inactive_windows), | ||
"inactive_windows": inactive_windows, | ||
} | ||
|
||
|
||
def update_account_with_distribution(account, rewards): | ||
if account["state"] == AccountState.SLASHED.value: | ||
account["slice_amount"] = 0 | ||
else: | ||
account["slice_amount"] += rewards[account["address"]] | ||
|
||
return account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
from helpers import get_dates | ||
|
||
import json | ||
|
||
|
||
def gen(): | ||
(date, start_date, end_date) = get_dates() | ||
|
||
block_snapshot = int(input("🔗 What is snapshot block? ")) | ||
|
||
distribution_window = int(input("#️⃣ What is the distribution window? ")) | ||
|
||
slice_to_distribute = input("🤑 What is the number of SLICE units to distribute? ") | ||
|
||
conf = { | ||
"date": f"{date.year}-{date.month}", | ||
"start_timestamp": int(start_date.timestamp()), | ||
"end_timestamp": int(end_date.timestamp()), | ||
"block_snapshot": block_snapshot, | ||
"distribution_window": distribution_window, | ||
"slice_to_distribute": slice_to_distribute, | ||
} | ||
|
||
path = f"reports/{date.year}-{date.month}" | ||
|
||
Path(path).mkdir(parents=True, exist_ok=True) | ||
Path(f"{path}/csv/").mkdir(parents=True, exist_ok=True) | ||
Path(f"{path}/json/").mkdir(parents=True, exist_ok=True) | ||
|
||
conf_json_file = open(f"{path}/epoch-conf.json", "w+") | ||
conf_json_file.write(json.dumps(conf, indent=4)) |
Oops, something went wrong.