Esempio n. 1
0
        /// <summary>
        /// Creates a deep copy of the object.
        /// </summary>
        public static BeaconState Clone(BeaconState other)
        {
            var clone = new BeaconState(
                other.GenesisTime,
                other.Slot,
                other.Fork,
                BeaconBlockHeader.Clone(other.LatestBlockHeader),
                other.BlockRoots.ToArray(),
                other.StateRoots.ToArray(),
                other.HistoricalRoots.ToArray(),
                Eth1Data.Clone(other.Eth1Data),
                other.Eth1DataVotes.Select(x => Eth1Data.Clone(x)).ToList(),
                other.Eth1DepositIndex,
                other.Validators.Select(x => Validator.Clone(x)).ToList(),
                other.Balances.Select(x => x).ToList(),
                other.RandaoMixes.Select(x => x).ToArray(),
                other.Slashings.Select(x => x).ToArray(),
                other.PreviousEpochAttestations.Select(x => PendingAttestation.Clone(x)).ToList(),
                other.CurrentEpochAttestations.Select(x => PendingAttestation.Clone(x)).ToList(),
                new BitArray(other.JustificationBits),
                Checkpoint.Clone(other.PreviousJustifiedCheckpoint),
                Checkpoint.Clone(other.CurrentJustifiedCheckpoint),
                Checkpoint.Clone(other.FinalizedCheckpoint)
                );

            return(clone);
        }
Esempio n. 2
0
 public BeaconState(
     ulong genesisTime,
     Fork fork,
     Eth1Data eth1Data,
     BeaconBlockHeader latestBlockHeader,
     Bytes32[] randaoMixes,
     uint slotsPerHistoricalRoot,
     ulong epochsPerHistoricalVector,
     ulong epochsPerSlashingsVector,
     int justificationBitsLength)
 {
     GenesisTime       = genesisTime;
     Fork              = fork;
     Eth1DepositIndex  = 0;
     _eth1DataVotes    = new List <Eth1Data>();
     Eth1Data          = eth1Data;
     LatestBlockHeader = latestBlockHeader;
     _randaoMixes      = randaoMixes;
     // Default/empty values:
     _validators      = new List <Validator>();
     _balances        = new List <Gwei>();
     _blockRoots      = Enumerable.Repeat(Root.Zero, (int)slotsPerHistoricalRoot).ToArray();
     _stateRoots      = Enumerable.Repeat(Root.Zero, (int)slotsPerHistoricalRoot).ToArray();
     _historicalRoots = new List <Root>();
     //_randaoMixes = Enumerable.Repeat(Bytes32.Zero, (int)epochsPerHistoricalVector).ToArray();
     _slashings = Enumerable.Repeat(Gwei.Zero, (int)epochsPerSlashingsVector).ToArray();
     _previousEpochAttestations  = new List <PendingAttestation>();
     _currentEpochAttestations   = new List <PendingAttestation>();
     JustificationBits           = new BitArray(justificationBitsLength);
     CurrentJustifiedCheckpoint  = new Checkpoint(new Epoch(0), Root.Zero);
     PreviousJustifiedCheckpoint = new Checkpoint(new Epoch(0), Root.Zero);
     FinalizedCheckpoint         = new Checkpoint(new Epoch(0), Root.Zero);
 }
Esempio n. 3
0
 public BeaconState(ulong genesisTime, ulong eth1DepositIndex, Eth1Data eth1Data, BeaconBlockHeader latestBlockHeader,
                    uint slotsPerHistoricalRoot, ulong epochsPerHistoricalVector, ulong epochsPerSlashingsVector, int justificationBitsLength)
 {
     GenesisTime                = genesisTime;
     Eth1DepositIndex           = eth1DepositIndex;
     _eth1DataVotes             = new List <Eth1Data>();
     Eth1Data                   = eth1Data;
     LatestBlockHeader          = latestBlockHeader;
     _validators                = new List <Validator>();
     _balances                  = new List <Gwei>();
     _blockRoots                = Enumerable.Repeat(Hash32.Zero, (int)slotsPerHistoricalRoot).ToArray();
     _stateRoots                = Enumerable.Repeat(Hash32.Zero, (int)slotsPerHistoricalRoot).ToArray();
     _historicalRoots           = new List <Hash32>();
     _randaoMixes               = Enumerable.Repeat(Hash32.Zero, (int)epochsPerHistoricalVector).ToArray();
     _slashings                 = Enumerable.Repeat(Gwei.Zero, (int)epochsPerSlashingsVector).ToArray();
     _previousEpochAttestations = new List <PendingAttestation>();
     _currentEpochAttestations  = new List <PendingAttestation>();
     JustificationBits          = new BitArray(justificationBitsLength);
     Fork = new Fork(new ForkVersion(), new ForkVersion(), Epoch.Zero);
     CurrentJustifiedCheckpoint  = new Checkpoint(new Epoch(0), Hash32.Zero);
     PreviousJustifiedCheckpoint = new Checkpoint(new Epoch(0), Hash32.Zero);
     FinalizedCheckpoint         = new Checkpoint(new Epoch(0), Hash32.Zero);
     //_previousCrosslinks = Enumerable.Repeat(new Crosslink(Shard.Zero), (int)(ulong)shardCount).ToArray();
     //_currentCrosslinks = Enumerable.Repeat(new Crosslink(Shard.Zero), (int)(ulong)shardCount).ToArray();
     //_currentCrosslinks = Enumerable.Range(0, (int)(ulong)shardCount).Select(x => new Crosslink(new Shard((ulong)x))).ToArray();
 }
Esempio n. 4
0
 public BeaconBlockBody()
 {
     RandaoReveal       = BlsSignature.Empty;
     Eth1Data           = new Eth1Data(0, Hash32.Zero);
     Graffiti           = new Bytes32();
     _proposerSlashings = new List <ProposerSlashing>();
     _attesterSlashings = new List <AttesterSlashing>();
     _attestations      = new List <Attestation>();
     _deposits          = new List <Deposit>();
     _voluntaryExits    = new List <VoluntaryExit>();
 }
Esempio n. 5
0
 public BeaconState(
     // Versioning
     ulong genesisTime,
     Slot slot,
     Fork fork,
     // History
     BeaconBlockHeader latestBlockHeader,
     Root[] blockRoots,
     Root[] stateRoots,
     IList <Root> historicalRoots,
     // Eth1
     Eth1Data eth1Data,
     IList <Eth1Data> eth1DataVotes,
     ulong eth1DepositIndex,
     // Registry
     IList <Validator> validators,
     IList <Gwei> balances,
     // Randomness
     Bytes32[] randaoMixes,
     // Slashings
     Gwei[] slashings,
     // Attestations
     IList <PendingAttestation> previousEpochAttestations,
     IList <PendingAttestation> currentEpochAttestations,
     // Finality
     BitArray justificationBits,
     Checkpoint previousJustifiedCheckpoint,
     Checkpoint currentJustifiedCheckpoint,
     Checkpoint finalizedCheckpoint)
 {
     GenesisTime                 = genesisTime;
     Slot                        = slot;
     Fork                        = fork;
     LatestBlockHeader           = latestBlockHeader;
     _blockRoots                 = blockRoots;
     _stateRoots                 = stateRoots;
     _historicalRoots            = historicalRoots.ToList();
     Eth1Data                    = eth1Data;
     _eth1DataVotes              = eth1DataVotes.ToList();
     Eth1DepositIndex            = eth1DepositIndex;
     _validators                 = validators.ToList();
     _balances                   = balances.ToList();
     _randaoMixes                = randaoMixes;
     _slashings                  = slashings;
     _previousEpochAttestations  = previousEpochAttestations.ToList();
     _currentEpochAttestations   = currentEpochAttestations.ToList();
     JustificationBits           = justificationBits;
     PreviousJustifiedCheckpoint = previousJustifiedCheckpoint;
     CurrentJustifiedCheckpoint  = currentJustifiedCheckpoint;
     FinalizedCheckpoint         = finalizedCheckpoint;
 }
Esempio n. 6
0
 public BeaconBlockBody(
     BlsSignature randaoReveal,
     Eth1Data eth1Data,
     Bytes32 graffiti,
     IEnumerable <ProposerSlashing> proposerSlashings,
     IEnumerable <AttesterSlashing> attesterSlashings,
     IEnumerable <Attestation> attestations,
     IEnumerable <Deposit> deposits,
     IEnumerable <SignedVoluntaryExit> voluntaryExits)
 {
     RandaoReveal       = randaoReveal;
     Eth1Data           = eth1Data;
     Graffiti           = graffiti;
     _proposerSlashings = new List <ProposerSlashing>(proposerSlashings);
     _attesterSlashings = new List <AttesterSlashing>(attesterSlashings);
     _attestations      = new List <Attestation>(attestations);
     _deposits          = new List <Deposit>(deposits);
     _voluntaryExits    = new List <SignedVoluntaryExit>(voluntaryExits);
 }
Esempio n. 7
0
 public bool Equals(Eth1Data other)
 {
     return(Equals(DepositRoot, other.DepositRoot) && DepositCount == other.DepositCount && Equals(BlockHash, other.BlockHash));
 }
Esempio n. 8
0
 public void SetEth1Data(Eth1Data eth1Data) => Eth1Data = eth1Data;
Esempio n. 9
0
 public void AddEth1DataVote(Eth1Data eth1Data) => _eth1DataVotes.Add(eth1Data);