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

Refactor fork data #1028

Merged
merged 8 commits into from
Dec 2, 2018
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
8 changes: 5 additions & 3 deletions beacon-chain/core/state/validity_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ func isBlockAttestationValid(
return fmt.Errorf("unable to match attester bitfield with shard and committee bitfield")
}

forkVersion := beaconState.PostForkVersion()
if attestation.Slot < beaconState.ForkSlotNumber() {
forkVersion = beaconState.PreForkVersion()
// TODO(#258): Add coverage for determining fork version for an attestation.
forkData := beaconState.ForkData()
forkVersion := forkData.PostForkVersion
if attestation.Slot < forkData.ForkSlot {
forkVersion = forkData.PreForkVersion
}

// TODO(#258): Generate validators aggregated pub key.
Expand Down
24 changes: 5 additions & 19 deletions beacon-chain/core/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ func NewGenesisBeaconState(genesisValidators []*pb.ValidatorRecord) (*BeaconStat
LastJustifiedSlot: 0,
LastFinalizedSlot: 0,
ValidatorSetChangeSlot: 0,
ForkSlotNumber: 0,
Crosslinks: crosslinks,
Validators: genesisValidators,
ShardAndCommitteesForSlots: shardAndCommitteesForSlots,
PreForkVersion: uint64(params.BeaconConfig().InitialForkVersion),
PostForkVersion: uint64(params.BeaconConfig().InitialForkVersion),
PendingAttestations: []*pb.AggregatedAttestation{},
RecentBlockHashes: recentBlockHashes,
RandaoMix: make([]byte, 0, 32),
ForkData: &pb.ForkData{},
},
}, nil
}
Expand Down Expand Up @@ -119,9 +117,7 @@ func (b *BeaconState) CopyState() *BeaconState {
Validators: validators,
ShardAndCommitteesForSlots: shardAndCommitteesForSlots,
DepositsPenalizedInPeriod: b.DepositsPenalizedInPeriod(),
PreForkVersion: b.data.PreForkVersion,
PostForkVersion: b.data.PostForkVersion,
ForkSlotNumber: b.data.ForkSlotNumber,
ForkData: b.ForkData(),
}}

return &newState
Expand Down Expand Up @@ -224,19 +220,9 @@ func (b *BeaconState) DepositsPenalizedInPeriod() []uint64 {
return b.data.DepositsPenalizedInPeriod
}

// ForkSlotNumber returns the slot of last fork.
func (b *BeaconState) ForkSlotNumber() uint64 {
return b.data.ForkSlotNumber
}

// PreForkVersion returns the last pre fork version.
func (b *BeaconState) PreForkVersion() uint64 {
return b.data.PreForkVersion
}

// PostForkVersion returns the last post fork version.
func (b *BeaconState) PostForkVersion() uint64 {
return b.data.PostForkVersion
// ForkData returns the relevant fork data for this beacon state.
func (b *BeaconState) ForkData() *pb.ForkData {
return b.data.ForkData
}

// RecentBlockHashes returns the most recent 2*EPOCH_LENGTH block hashes.
Expand Down
Loading