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

Greg/initial state && The Great Refactor #73

Merged
merged 21 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea/
node_modules/
test:ethereum
test:ethereum
35 changes: 24 additions & 11 deletions beaconChain/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
// Misc
export const SHARD_COUNT = 2 ** 10; // 1024 shards
export const TARGET_COMMITTEE_SIZE = 2 ** 8; // 256 validators
export const MIN_BALANCE = 2 ** 4; // 16 ETH
export const EJECTION_BALANCE = 2 ** 4; // 16 ETH
export const MAX_BALANCE_CHURN_QUOTIENT = 2 ** 5; // 32
export const GWEI_PER_ETH = 10 ** 9; // 1B Gwei/ETH
export const BEACON_CHAIN_SHARD_NUMBER = 2 ** 64 - 1;
export const BLS_WITHDRAWAL_PREFIX_BYTE = 0x00;
export const MAX_CASPER_VOTES = 2 ** 10; // 1024 votes
export const LATEST_BLOCK_ROOTS_LENGTH = 2 ** 13; // 8192 block roots
export const LATEST_RANDAO_MIXES_LENGTH = 2 ** 13; // 8192 randao mixes
export const LATEST_PENALIZED_EXIT_LENGTH = 2 ** 13; // 8192 epochs
export const MAX_WITHDRAWALS_PER_EPOCH = 2 ** 2; // 4 withdrawals

// Deposit contract
export const DEPOSIT_CONTRACT_ADDRESS = "TBD";
Expand All @@ -19,29 +22,39 @@ export const MIN_DEPOSIT = 2 ** 0; // 1 ETH
export const MAX_DEPOSIT = 2 ** 5; // 32 ETH

// Initial values
export const INITIAL_FORK_VERSION = 0;
export const INITIAL_SLOT_NUMBER = 0;
export const GENESIS_FORK_VERSION = 0;
export const GENESIS_SLOT = 0;
export const GENESIS_START_SHARD = 0;
export const FAR_FUTURE_SLOT = 2 ** 64 - 1;
export const ZERO_HASH = new Uint8Array(32);
export const EMPTY_SIGNATURE = [new Uint8Array(48), new Uint8Array(48)]; // [bytes48(0), bytes48(0)]
export const BLS_WITHDRAWAL_PREFIX_BYTE = new Uint8Array(1);

// Time parameters
export const SLOT_DURATION = 6; // 6 seconds
export const MIN_ATTESTATION_INCLUSION_DELAY = 2 ** 2; // 4 slots
export const EPOCH_LENGTH = 2 ** 6; // 64 slots
export const MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL = 2 ** 8; // 256 slots
export const POW_RECEIPT_ROOT_VOTING_PERIOD = 2 ** 10; // 1024 slots
export const SHARD_PERSISTENT_COMMITTEE_CHANGE_POERIOD = 2 ** 17; // 131,072 slots
export const COLLECTIVE_PENALTY_CALCULATION_PERIOD = 2 ** 20; // 1,048,576 slots
export const ZERO_BALANCE_VALIDATOR_TTL = 2 ** 22; // 4,194,304 slots
export const SEED_LOOKAHEAD = 2 ** 6; // 64 slots
export const ENTRY_EXIT_DELAY = 2 ** 8; // 256 slots
export const DEPOSIT_ROOT_VOTING_PERIOD = 2 ** 10; // 1024 slots
export const MIN_VALIDATOR_WITHDRAWAL_TIME = 2 ** 14; // 16,384 slots

// Reward and penalty quotients
export const BASE_REWARD_QUOTIENT = 2 ** 11; // 2048
export const BASE_REWARD_QUOTIENT = 2 ** 10; // 1024
export const WHISTLEBLOWER_REWARD_QUOTIENT = 2 ** 9; // 512
export const INCLUDER_REWARD_QUOTIENT = 2 ** 3; // 8
export const INACTIVITY_PENALTY_QUOTIENT = 2 ** 34; // 17,179,869,184
export const INACTIVITY_PENALTY_QUOTIENT = 2 ** 24; // 16,777,216

// Max operations per block
export const MAX_PROPOSER_SLASHINGS = 2 ** 4; // 16
export const MAX_CASPER_SLASHINGS = 2 ** 4; // 16
export const MAX_ATTESTATIONS = 2 ** 7; // 128
export const MAX_DEPOSITS = 2 ** 4; // 16
export const MAX_EXITS = 2 ** 4; // 16

// OLD
// export const MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL = 2 ** 8; // 256 slots
// export const POW_RECEIPT_ROOT_VOTING_PERIOD = 2 ** 10; // 1024 slots
// export const SHARD_PERSISTENT_COMMITTEE_CHANGE_POERIOD = 2 ** 17; // 131,072 slots
// export const COLLECTIVE_PENALTY_CALCULATION_PERIOD = 2 ** 20; // 1,048,576 slots
// export const ZERO_BALANCE_VALIDATOR_TTL = 2 ** 22; // 4,194,304 slots
11 changes: 4 additions & 7 deletions beaconChain/constants/enums.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#constants

enum ValidatorStatusCodes {
PENDING_ACTIVATION = 0,
ACTIVE = 1,
ACTIVE_PENDING_EXIT = 2,
EXITED_WITHOUT_PENALTY = 3,
EXITED_WITH_PENALTY = 4,
enum StatusFlags {
INTIATED_EXIT = 2 ** 0,
WITHDRAWABLE = 2 ** 1,
}

enum ValidatorRegistryDeltaFlags {
Expand All @@ -23,5 +20,5 @@ enum SignatureDomains {
export {
SignatureDomains,
ValidatorRegistryDeltaFlags,
ValidatorStatusCodes,
StatusFlags,
};
16 changes: 16 additions & 0 deletions beaconChain/helpers/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Takes two arrays and combines them, similar to the Array.zip() from Python.
* a = [1,2,3] b = [4,5,6]
* c = zip(a,b) // [[1,4], [2,5], [3,6]]
* NOTE: Lodash would be an alternative, although theres no need *YET* to import lodash for one function.
GregTheGreek marked this conversation as resolved.
Show resolved Hide resolved
* That being said there is one main caveat: if the arrays are not 1-1 in length it will return undefined
* but, this is fine for our use case since validatorBalances and validators must be 1-1 in length.
* @param {Array<T>} a
* @param {Array<X>} b
* @returns {(T | X)[][]}
*/
function zip<T, X>(a: T[], b: X[]): Array<Array<T|X>> {
return a.map((e, i) => [e, b[i]]);
}

export { zip };
Loading