mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 23:48:06 -05:00
beacon: move beacon-chain to geth-sharding repo (#250)
Former-commit-id: 689de6935d724226eb9125d597831d7b274d79c1 [formerly 4e0c0d671c4e6284cd33300231cc0f7aba99d314] Former-commit-id: c3079b352bc938c12708b81cdc0130909456ea27
This commit is contained in:
8
beacon-chain/BUILD.bazel
Normal file
8
beacon-chain/BUILD.bazel
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["config.go"],
|
||||||
|
importpath = "github.com/prysmaticlabs/geth-sharding/beacon-chain",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
21
beacon-chain/LICENSE.md
Normal file
21
beacon-chain/LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Prysmatic Labs
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
9
beacon-chain/README.md
Normal file
9
beacon-chain/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Prysmatic Labs Beacon Chain Implementation
|
||||||
|
|
||||||
|
This is the main repository for the beacon chain implementation of Ethereum 2.0 in Golang by [Prysmatic Labs](https://prysmaticlabs.com). Before you begin, check out our [Contribution Guidelines](#contribution-guidelines) and join our active chat room on Gitter below:
|
||||||
|
|
||||||
|
[](https://gitter.im/prysmaticlabs/geth-sharding?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||||
|
|
||||||
|
Also, read the latest sharding + casper [design spec](https://ethresear.ch/t/convenience-link-to-full-casper-chain-v2-spec/2332), this design spec serves as a source of truth for the beacon chain implementation we follow at prysmatic labs.
|
||||||
|
Refer this page on [why](http://email.mg2.substack.com/c/eJwlj9GOhCAMRb9G3jRQQPGBh5mM8xsbhKrsDGIAM9m_X9xN2qZtbpt7rCm4xvSjj5gLOTOmL-809CMbKXFaOKakIl4DZYr2AGyQIGjHOnWH22OiYnoIxmDijaBhhS6fcy7GvjobA9m0mSXOcnZq5GBqLkilXBZhBsus5ZK89VbKkRt-a-BZI6DzZ7iur1lQ953KJ9bemnxgahuQU9XJu6pFPdu8meT8vragzEjpMCwMGLlgLo6h5z1JumQTu4IJd4v15xqMf_8ZLP_Y1bSLdbnrD-LL71i2Kj7DLxaWWF4)
|
||||||
|
we are comibing sharding and casper together.
|
||||||
20
beacon-chain/config.go
Normal file
20
beacon-chain/config.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package beacon
|
||||||
|
|
||||||
|
const (
|
||||||
|
// AttesterCount is the number of attesters per committee/
|
||||||
|
AttesterCount = 32
|
||||||
|
// AttesterReward determines how much ETH attesters get for performing their duty.
|
||||||
|
AttesterReward = 1
|
||||||
|
// EpochLength is the beacon chain epoch length in blocks.
|
||||||
|
EpochLength = 5
|
||||||
|
// ShardCount is a fixed number.
|
||||||
|
ShardCount = 20
|
||||||
|
// DefaultBalance of a validator.
|
||||||
|
DefaultBalance = 32000
|
||||||
|
// DefaultSwitchDynasty value.
|
||||||
|
DefaultSwitchDynasty = 9999999999999999999
|
||||||
|
// MaxValidators in the protocol.
|
||||||
|
MaxValidators = 2 ^ 24
|
||||||
|
// NotariesPerCrosslink fixed to 100.
|
||||||
|
NotariesPerCrosslink = 100
|
||||||
|
)
|
||||||
12
beacon-chain/types/BUILD.bazel
Normal file
12
beacon-chain/types/BUILD.bazel
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = [
|
||||||
|
"block.go",
|
||||||
|
"state.go",
|
||||||
|
],
|
||||||
|
importpath = "github.com/prysmaticlabs/geth-sharding/beacon-chain/types",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@com_github_ethereum_go_ethereum//common:go_default_library"],
|
||||||
|
)
|
||||||
24
beacon-chain/types/block.go
Normal file
24
beacon-chain/types/block.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
import "github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
|
// Header contains the block header fields in beacon chain.
|
||||||
|
type Header struct {
|
||||||
|
ParentHash common.Hash // ParentHash is the hash of the parent beacon block.
|
||||||
|
SkipCount uint64 // SkipCount is the number of skips, this is used for the full PoS mechanism.
|
||||||
|
RandaoReveal common.Hash // RandaoReveal is used for Randao commitment reveal.
|
||||||
|
AttestationBitmask []byte // AttestationBitmask is the bit field of who from the attestation committee participated.
|
||||||
|
AttestationAggregateSig []uint // AttestationAggregateSig is validator's aggregate sig.
|
||||||
|
ShardAggregateVotes []AggregateVote // ShardAggregateVotes is shard aggregate votes.
|
||||||
|
MainChainRef common.Hash // MainChainRef is the reference to main chain block.
|
||||||
|
StateHash []byte // StateHash is the concatenation of crystallized and active state.
|
||||||
|
Sig []uint // Sig is the signature of the proposer.
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateVote contains the fields of aggregate vote in individual shard.
|
||||||
|
type AggregateVote struct {
|
||||||
|
ShardID uint16 // Shard ID of the voted shard.
|
||||||
|
ShardBlockHash common.Hash // ShardBlockHash is the shard block hash of the voted shard.
|
||||||
|
SignerBitmask []byte // SignerBitmask is the bit mask of every validator that signed.
|
||||||
|
AggregateSig []uint // AggregateSig is the aggregated signatures of individual shard.
|
||||||
|
}
|
||||||
62
beacon-chain/types/state.go
Normal file
62
beacon-chain/types/state.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ActiveState contains fields of current state of beacon chain,
|
||||||
|
// it changes every block.
|
||||||
|
type ActiveState struct {
|
||||||
|
Height uint64 // Height of the current block.
|
||||||
|
Randao common.Hash // Randao beacon state from global's point of view.
|
||||||
|
FfgVoterBitmask []byte // FfgVoterBitmask records the validators that voted for this epoch as bitfield.
|
||||||
|
BalanceDeltas []uint // BalanceDeltas is the deltas to validator balances.
|
||||||
|
PartialCrosslinks []PartialCrosslinkRecord // PartialCrosslinks records data about crosslinks in progress.
|
||||||
|
TotalSkipCount uint64 // TotalSkipCount records total number of skips to determine minimal time stamp.
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartialCrosslinkRecord contains information about cross links
|
||||||
|
// that are being put together during this epoch.
|
||||||
|
type PartialCrosslinkRecord struct {
|
||||||
|
ShardID uint16 // ShardID is the shard crosslink being made for.
|
||||||
|
ShardBlockHash common.Hash // ShardBlockHash is the hash of the block.
|
||||||
|
VoterBitmask []byte // VoterBitmask determines which of the eligible voters are voting for it.
|
||||||
|
}
|
||||||
|
|
||||||
|
// CrystallizedState contains fields of every epoch state,
|
||||||
|
// it changes every epoch.
|
||||||
|
type CrystallizedState struct {
|
||||||
|
ActiveValidators []ValidatorRecord // ActiveValidators is the list of active validators.
|
||||||
|
QueuedValidators []ValidatorRecord // QueuedValidators is the list of joined but not yet inducted validators.
|
||||||
|
ExitedValidators []ValidatorRecord // ExitedValidators is the list of removed validators pending withdrawal.
|
||||||
|
CurrentShuffling []uint16 // CurrentShuffling is hhe permutation of validators used to determine who cross-links what shard in this epoch.
|
||||||
|
CurrentEpoch uint64 // CurrentEpoch is the current epoch.
|
||||||
|
LastJustifiedEpoch uint64 // LastJustifiedEpoch is the last justified epoch.
|
||||||
|
LastFinalizedEpoch uint64 // LastFinalizedEpoch is the last finalized epoch.
|
||||||
|
Dynasty uint64 // Dynasty is the current dynasty.
|
||||||
|
NextShard uint16 // NextShard is the next shard that cross-linking assignment will start from.
|
||||||
|
CurrentCheckpoint common.Hash // CurrentCheckpoint is the current FFG checkpoint.
|
||||||
|
CrosslinkRecords []CrosslinkRecord // CrosslinkRecords records about the most recent crosslink for each shard.
|
||||||
|
TotalDeposits uint // TotalDeposits is the Total balance of deposits.
|
||||||
|
CrosslinkSeed common.Hash // CrosslinkSeed is used to select the committees for each shard.
|
||||||
|
CrosslinkSeedLastReset uint64 // CrosslinkSeedLastReset is the last epoch the crosslink seed was reset.
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatorRecord contains information about a validator
|
||||||
|
type ValidatorRecord struct {
|
||||||
|
PubKey ecdsa.PublicKey // PubKey is the validator's public key.
|
||||||
|
ReturnShard uint16 // ReturnShard is the shard balance will be sent to after withdrawal.
|
||||||
|
ReturnAddress common.Address // ReturnAddress is the address balance will be sent to after withdrawal.
|
||||||
|
RandaoCommitment common.Hash // RandaoCommitment is validator's current RANDAO beacon commitment.
|
||||||
|
Balance uint64 // Balance is validator's current balance.
|
||||||
|
SwitchDynasty uint64 // SwitchDynasty is the dynasty where the validator can (be inducted | be removed | withdraw their balance).
|
||||||
|
}
|
||||||
|
|
||||||
|
// CrosslinkRecord contains the fields of last fully formed
|
||||||
|
// crosslink to be submitted into the chain.
|
||||||
|
type CrosslinkRecord struct {
|
||||||
|
Epoch uint64 // Epoch records the epoch the crosslink was submitted in.
|
||||||
|
Hash common.Hash // Hash is the block hash.
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user