This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
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.
* started ghost implementation * rename * fixed
- Loading branch information
Dean Eigenmann
authored
Mar 18, 2019
1 parent
171d21d
commit d6e6418
Showing
15 changed files
with
87 additions
and
12 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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Blocks/BeaconBlockBody.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Blocks/ProposalSignedData.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/Attestations/Attestation.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/AttesterSlashings/AttesterSlashing.swift
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import Foundation | ||
|
||
struct AttesterSlashing { | ||
struct AttesterSlashing: Equatable { | ||
let slashableAttestation1: SlashableAttestation | ||
let slashableAttestation2: SlashableAttestation | ||
} |
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/AttesterSlashings/SlashableAttestation.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/Deposits/Deposit.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/Deposits/DepositData.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/Deposits/DepositInput.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/ProposerSlashing.swift
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 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
2 changes: 1 addition & 1 deletion
2
Sources/BeaconChain/DataStructures/Transactions/VoluntaryExit.swift
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 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,7 @@ | ||
import Foundation | ||
|
||
protocol ForkChoice { | ||
|
||
func execute(store: Store, startState: BeaconState, startBlock: BeaconBlock) -> BeaconBlock | ||
|
||
} |
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,43 @@ | ||
import Foundation | ||
|
||
class LMDGhost: ForkChoice { | ||
|
||
func execute(store: Store, startState: BeaconState, startBlock: BeaconBlock) -> BeaconBlock { | ||
let attestationTargets = startState.validatorRegistry.activeIndices(epoch: startState.slot.toEpoch()).map { | ||
($0, store.latestAttestationTarget(validator: $0)) | ||
} | ||
|
||
var head = startBlock | ||
while true { | ||
let children = store.children(head) | ||
if children.count == 0 { | ||
return head | ||
} | ||
|
||
head = children.max { | ||
voteCount(store: store, state: startState, block: $0, attestationTargets: attestationTargets) < voteCount(store: store, state: startState, block: $1, attestationTargets: attestationTargets) | ||
}! | ||
} | ||
} | ||
|
||
private func voteCount( | ||
store: Store, | ||
state: BeaconState, | ||
block: BeaconBlock, | ||
attestationTargets: [(ValidatorIndex, BeaconBlock)] | ||
) -> UInt64 { | ||
return attestationTargets.compactMap { | ||
(index, target) in | ||
guard let ancestor = store.ancestor(block: target, slot: index) else { | ||
return nil | ||
} | ||
|
||
if ancestor == block { | ||
return BeaconChain.getEffectiveBalance(state: state, index: index) / FORK_CHOICE_BALANCE_INCREMENT | ||
} | ||
|
||
return nil | ||
} | ||
.reduce(0, +) | ||
} | ||
} |
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,25 @@ | ||
import Foundation | ||
|
||
protocol Store { | ||
|
||
func parent(_ block: BeaconBlock) -> BeaconBlock | ||
func children(_ block: BeaconBlock) -> [BeaconBlock] | ||
func latestAttestation(validator: ValidatorIndex) -> Attestation | ||
func latestAttestationTarget(validator: ValidatorIndex) -> BeaconBlock | ||
} | ||
|
||
extension Store { | ||
|
||
func ancestor(block: BeaconBlock, slot: Slot) -> BeaconBlock? { | ||
if block.slot == slot { | ||
return block | ||
} | ||
|
||
if block.slot < slot { | ||
return nil | ||
} | ||
|
||
return ancestor(block: parent(block), slot: slot) | ||
} | ||
} | ||
|