Skip to content

Commit

Permalink
Merge pull request #1003 from ethereum/master
Browse files Browse the repository at this point in the history
Backport (partial) v0.6.1 to dev
  • Loading branch information
djrtwo committed May 2, 2019
2 parents 3562264 + 715dc32 commit cdcb16d
Show file tree
Hide file tree
Showing 19 changed files with 352 additions and 338 deletions.
14 changes: 9 additions & 5 deletions configs/constant_presets/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ MAX_INDICES_PER_ATTESTATION: 4096
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536
# Normalizes base rewards
BASE_REWARDS_PER_EPOCH: 5
# See issue 563
SHUFFLE_ROUND_COUNT: 90

Expand All @@ -36,7 +38,7 @@ MAX_EFFECTIVE_BALANCE: 32000000000
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE: 16000000000
# 2**0 * 10**9 (= 1,000,000,000) Gwei
HIGH_BALANCE_INCREMENT: 1000000000
EFFECTIVE_BALANCE_INCREMENT: 1000000000


# Initial values
Expand Down Expand Up @@ -71,6 +73,8 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
PERSISTENT_COMMITTEE_PERIOD: 2048
# 2**6 (= 64) epochs ~7 hours
MAX_CROSSLINK_EPOCHS: 64
# 2**2 (= 4) epochs 25.6 minutes
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4


# State list lengths
Expand All @@ -91,14 +95,14 @@ BASE_REWARD_QUOTIENT: 32
WHISTLEBLOWING_REWARD_QUOTIENT: 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT: 8
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT: 16777216
# 2**25 (= 33,554,432)
INACTIVITY_PENALTY_QUOTIENT: 33554432
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT: 32


# Max operations per block
# ---------------------------------------------------------------
# 2**5 (= 32)
MIN_PENALTY_QUOTIENT: 32
# 2**4 (= 16)
MAX_PROPOSER_SLASHINGS: 16
# 2**0 (= 1)
Expand Down
15 changes: 9 additions & 6 deletions configs/constant_presets/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# [customized] Just 8 shards for testing purposes
SHARD_COUNT: 8

# [customized] unsecure, but fast
TARGET_COMMITTEE_SIZE: 4
# 2**12 (= 4,096)
Expand All @@ -15,6 +14,8 @@ MAX_INDICES_PER_ATTESTATION: 4096
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536
# Normalizes base rewards
BASE_REWARDS_PER_EPOCH: 5
# [customized] Faster, but unsecure.
SHUFFLE_ROUND_COUNT: 10

Expand All @@ -36,7 +37,7 @@ MAX_EFFECTIVE_BALANCE: 32000000000
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE: 16000000000
# 2**0 * 10**9 (= 1,000,000,000) Gwei
HIGH_BALANCE_INCREMENT: 1000000000
EFFECTIVE_BALANCE_INCREMENT: 1000000000


# Initial values
Expand Down Expand Up @@ -71,6 +72,8 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
PERSISTENT_COMMITTEE_PERIOD: 2048
# 2**6 (= 64) epochs ~7 hours
MAX_CROSSLINK_EPOCHS: 64
# 2**2 (= 4) epochs 25.6 minutes
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4


# State list lengths
Expand All @@ -91,14 +94,14 @@ BASE_REWARD_QUOTIENT: 32
WHISTLEBLOWING_REWARD_QUOTIENT: 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT: 8
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT: 16777216
# 2**25 (= 33,554,432)
INACTIVITY_PENALTY_QUOTIENT: 33554432
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT: 32


# Max operations per block
# ---------------------------------------------------------------
# 2**5 (= 32)
MIN_PENALTY_QUOTIENT: 32
# 2**4 (= 16)
MAX_PROPOSER_SLASHINGS: 16
# 2**0 (= 1)
Expand Down
30 changes: 10 additions & 20 deletions scripts/phase0/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
def build_phase0_spec(sourcefile, outfile):
code_lines = []
code_lines.append("""
from typing import (
Any,
Callable,
Dict,
List,
NewType,
Expand All @@ -17,19 +15,16 @@ def build_phase0_spec(sourcefile, outfile):
from eth2spec.utils.minimal_ssz import *
from eth2spec.utils.bls_stub import *
""")
""")
for i in (1, 2, 3, 4, 8, 32, 48, 96):
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))

code_lines.append("""
# stub, will get overwritten by real var
SLOTS_PER_EPOCH = 64
def slot_to_epoch(x): return x // SLOTS_PER_EPOCH
Slot = NewType('Slot', int) # uint64
Epoch = NewType('Epoch', int) # uint64
Shard = NewType('Shard', int) # uint64
Expand All @@ -38,31 +33,26 @@ def slot_to_epoch(x): return x // SLOTS_PER_EPOCH
Bytes32 = NewType('Bytes32', bytes) # bytes32
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48
BLSSignature = NewType('BLSSignature', bytes) # bytes96
Any = None
Store = None
""")
""")

code_lines += function_puller.get_spec(sourcefile)

code_lines.append("""
# Monkey patch validator get committee code
# Monkey patch validator compute committee code
_compute_committee = compute_committee
committee_cache = {}
def compute_committee(validator_indices: List[ValidatorIndex],
seed: Bytes32,
index: int,
total_committees: int) -> List[ValidatorIndex]:
param_hash = (hash_tree_root(validator_indices), seed, index, total_committees)
def compute_committee(indices: List[ValidatorIndex], seed: Bytes32, index: int, count: int) -> List[ValidatorIndex]:
param_hash = (hash_tree_root(indices), seed, index, count)
if param_hash in committee_cache:
# print("Cache hit, epoch={0}".format(epoch))
print("Cache hit, param_hash: ", param_hash)
return committee_cache[param_hash]
else:
# print("Cache miss, epoch={0}".format(epoch))
ret = _compute_committee(validator_indices, seed, index, total_committees)
print("Cache miss, param_hash: ", param_hash)
ret = _compute_committee(indices, seed, index, count)
committee_cache[param_hash] = ret
return ret
Expand All @@ -88,7 +78,7 @@ def apply_constants_preset(preset: Dict[str, Any]):
# Deal with derived constants
global_vars['GENESIS_EPOCH'] = slot_to_epoch(GENESIS_SLOT)
# Initialize SSZ types again, to account for changed lengths
init_SSZ_types()
""")
Expand Down
7 changes: 4 additions & 3 deletions scripts/phase0/function_puller.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def get_spec(file_name: str) -> List[str]:
code_lines.append('')
for type_line in ssz_type:
code_lines.append(' ' + type_line)
code_lines.append('')
code_lines.append('\n')
code_lines.append('ssz_types = [' + ', '.join([f'\'{ssz_type_name}\'' for (ssz_type_name, _) in type_defs]) + ']')
code_lines.append('')
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType: return globals()[name]')
code_lines.append('\n')
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType:')
code_lines.append(' return globals()[name]')
code_lines.append('')
return code_lines
Loading

0 comments on commit cdcb16d

Please sign in to comment.