Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
update/0.3.0 (#58)
Browse files Browse the repository at this point in the history
* renamed constants

* data structure updates

* typealias updates

* unnecessary self

* updated on genesis

* fixed if

* fixed tests

* started working on transfer

* finished transfer implementation

* spellcheck

* beacon chain up to date

* Update SlotTests.swift

* changes

* remove todo

* using append

* plus
  • Loading branch information
Dean Eigenmann authored Feb 25, 2019
1 parent 4425314 commit 393ea82
Show file tree
Hide file tree
Showing 33 changed files with 303 additions and 233 deletions.
143 changes: 80 additions & 63 deletions Sources/BeaconChain/BeaconChain.swift

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions Sources/BeaconChain/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let TARGET_COMMITTEE_SIZE = UInt64(2**7)
let MAX_BALANCE_CHURN_QUOTIENT = UInt64(2**5)
let BEACON_CHAIN_SHARD_NUMBER = UInt64.max
let MAX_INDICES_PER_SLASHABLE_VOTE = UInt64(2**12)
let MAX_WITHDRAWALS_PER_EPOCH = UInt64(2**2)
let MAX_EXIT_DEQUEUES_PER_EPOCH = UInt64(2**2)
let SHUFFLE_ROUND_COUNT = 90

// Deposit Contract
Expand All @@ -22,37 +22,39 @@ let EJECTION_BALANCE = UInt64(2**4 * UInt64(1e9))
// Initial Values
let GENESIS_FORK_VERSION = UInt64(0)
let GENESIS_SLOT = UInt64(2**19)
let GENESIS_EPOCH = SlotNumber(GENESIS_SLOT).toEpoch()
let GENESIS_EPOCH = Slot(GENESIS_SLOT).toEpoch()
let GENESIS_START_SHARD = UInt64(0)
let FAR_FUTURE_EPOCH = UInt64.max
let ZERO_HASH = Data(repeating: 0, count: 32) // @todo create type
let EMPTY_SIGNATURE = Data(repeating: 0, count: 96)
let BLS_WITHDRAWAL_PREFIX_BYTE = Data(repeating: 0, count: 1)

// Time parameters
let SLOT_DURATION = UInt64(6)
let SECONDS_PER_SLOT = UInt64(6)
let MIN_ATTESTATION_INCLUSION_DELAY = UInt64(2**2)
let EPOCH_LENGTH = UInt64(2**6)
let SEED_LOOKAHEAD = UInt64(2**0)
let ENTRY_EXIT_DELAY = UInt64(2**2)
let ETH1_DATA_VOTING_PERIOD = UInt64(2**4)
let MIN_VALIDATOR_WITHDRAWAL_EPOCHS = UInt64(2**8)
let SLOTS_PER_EPOCH = UInt64(2**6)
let MIN_SEED_LOOKAHEAD = UInt64(2**0)
let ACTIVATION_EXIT_DELAY = UInt64(2**2)
let EPOCHS_PER_ETH1_VOTING_PERIOD = UInt64(2**4)
let MIN_VALIDATOR_WITHDRAWABILITY_DELAY = UInt64(2**8)

// State list lengths
let LATEST_BLOCK_ROOTS_LENGTH = UInt64(2**13)
let LATEST_RANDAO_MIXES_LENGTH = UInt64(2**13)
let LATEST_INDEX_ROOTS_LENGTH = UInt64(2**13)
let LATEST_PENALIZED_EXIT_LENGTH = UInt64(2**13)
let LATEST_ACTIVE_INDEX_ROOTS_LENGTH = UInt64(2**13)
let LATEST_SLASHED_EXIT_LENGTH = UInt64(2**13)

// Reward and penalty quotients
let BASE_REWARD_QUOTIENT = UInt64(2**5)
let WHISTLEBLOWER_REWARD_QUOTIENT = UInt64(2**9)
let INCLUDER_REWARD_QUOTIENT = UInt64(2**3)
let ATTESTATION_INCLUSION_REWARD_QUOTIENT = UInt64(2**3)
let INACTIVITY_PENALTY_QUOTIENT = UInt64(2**24)
let MIN_PENALTY_QUOTIENT = UInt64(2**5)

// Max operations per block
// Max transactions per block
let MAX_PROPOSER_SLASHINGS = UInt64(2**4)
let MAX_ATTESTER_SLASHINGS = UInt64(2**0)
let MAX_ATTESTATIONS = UInt64(2**7)
let MAX_DEPOSITS = UInt64(2**4)
let MAX_EXITS = UInt64(2**4)
let MAX_VOLUNTARY_EXITS = UInt64(2**4)
let MAX_TRANSFERS = UInt64(2**4)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ struct BeaconBlockBody {
let attesterSlashings: [AttesterSlashing]
let attestations: [Attestation]
let deposits: [Deposit]
let exits: [Exit]
let voluntaryExits: [VoluntaryExit]
let transfers: [Transfer]
}
17 changes: 9 additions & 8 deletions Sources/BeaconChain/DataStructures/State/BeaconState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ struct BeaconState {
var validatorRegistryUpdateEpoch: UInt64

var latestRandaoMixes: [Data]
var previousEpochStartShard: UInt64
let currentEpochStartShard: UInt64
var previousCalculationEpoch: UInt64
var currentCalculationEpoch: UInt64
var previousEpochSeed: Data
var currentEpochSeed: Data
var previousShufflingStartShard: UInt64
let currentShufflingStartShard: UInt64
var previousShufflingEpoch: UInt64
var currentShufflingEpoch: UInt64
var previousShufflingSeed: Data
var currentShufflingSeed: Data

var previousJustifiedEpoch: UInt64
var justifiedEpoch: UInt64
Expand All @@ -24,11 +24,12 @@ struct BeaconState {

var latestCrosslinks: [Crosslink]
var latestBlockRoots: [Data]
var latestIndexRoots: [Data]
var latestPenalizedBalances: [UInt64]
var latestActiveIndexRoots: [Data]
var latestSlashedBalances: [UInt64]
var latestAttestations: [PendingAttestation]
var batchedBlockRoots: [Data]

var latestEth1Data: Eth1Data
var eth1DataVotes: [Eth1DataVote]
let depositIndex: UInt64
}
8 changes: 4 additions & 4 deletions Sources/BeaconChain/DataStructures/State/Validator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ struct Validator {
let withdrawalCredentials: Data
var activationEpoch: UInt64
var exitEpoch: UInt64
let withdrawalEpoch: UInt64
var penalizedEpoch: UInt64
var withdrawableEpoch: UInt64
var slashedEpoch: UInt64
var statusFlags: UInt64

func isActive(epoch: EpochNumber) -> Bool {
return self.activationEpoch <= epoch && epoch < self.exitEpoch
func isActive(epoch: Epoch) -> Bool {
return activationEpoch <= epoch && epoch < exitEpoch
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Foundation

struct AttestationData: Equatable {
let slot: SlotNumber
let slot: Slot
let shard: UInt64
let beaconBlockRoot: Data
let epochBoundaryRoot: Data
let shardBlockRoot: Data
let latestCrosslink: Crosslink
let justifiedEpoch: EpochNumber
let justifiedEpoch: Epoch
let justifiedBlockRoot: Data
}
11 changes: 11 additions & 0 deletions Sources/BeaconChain/DataStructures/Transactions/Transfer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

struct Transfer {
let from: UInt64
let to: UInt64
let amount: UInt64
let fee: UInt64
let slot: UInt64
let pubkey: Data
let signature: Data
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct Exit {
struct VoluntaryExit {
let epoch: UInt64
let validatorIndex: UInt64
let signature: Data
Expand Down
1 change: 1 addition & 0 deletions Sources/BeaconChain/Enums/Domain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ enum Domain: UInt64 {
case PROPOSAL
case EXIT
case RANDAO
case TRANSFER
}
2 changes: 1 addition & 1 deletion Sources/BeaconChain/Extensions/Array+Validator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

extension Array where Element == Validator {

func activeIndices(epoch: EpochNumber) -> [ValidatorIndex] {
func activeIndices(epoch: Epoch) -> [ValidatorIndex] {
return enumerated().compactMap {
(k, v) in
if v.isActive(epoch: epoch) {
Expand Down
12 changes: 12 additions & 0 deletions Sources/BeaconChain/Extensions/Epoch.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

extension Epoch {

func startSlot() -> Slot {
return self * SLOTS_PER_EPOCH
}

func entryExitEpoch() -> Epoch {
return self + 1 + ACTIVATION_EXIT_DELAY
}
}
12 changes: 0 additions & 12 deletions Sources/BeaconChain/Extensions/EpochNumber.swift

This file was deleted.

8 changes: 8 additions & 0 deletions Sources/BeaconChain/Extensions/Slot.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

extension Slot {

func toEpoch() -> Epoch {
return self / SLOTS_PER_EPOCH
}
}
8 changes: 0 additions & 8 deletions Sources/BeaconChain/Extensions/SlotNumber.swift

This file was deleted.

Loading

0 comments on commit 393ea82

Please sign in to comment.