Ejemplo n.º 1
0
        /// <summary>Produce a new block, without signature.</summary>
        /// <param name="slot">The slot for which the block should be proposed.</param>
        /// <param name="randao_reveal">The validator's randao reveal value.</param>
        /// <returns>Success response</returns>
        public async Task <BeaconBlock> BlockAsync(ulong slot, byte[] randao_reveal)
        {
            var data = await _blockProducer.NewBlockAsync(new Slot(slot), new BlsSignature(randao_reveal));

            var result = new BeaconBlock()
            {
                Slot = (ulong)data.Slot,
                Body = new BeaconBlockBody()
                {
                    Randao_reveal = data.Body !.RandaoReveal.AsSpan().ToArray()
                }
            };

            return(result);
        }
Ejemplo n.º 2
0
 public override string ToString()
 {
     return($"[rr={RandaoReveal.ToString().Substring(0, 10)} ac={Attestations.Count} asc={AttesterSlashings.Count} dc={Deposits.Count} psc={ProposerSlashings.Count}]");
 }
Ejemplo n.º 3
0
 public override string ToString()
 {
     return($"R:{RandaoReveal.ToString().Substring(0, 12)} A[{Attestations.Count}] AS[{AttesterSlashings.Count}] D[{Deposits.Count}] PS[{ProposerSlashings.Count}]");
 }
Ejemplo n.º 4
0
        /// <summary>Produce a new block, without signature.</summary>
        /// <param name="slot">The slot for which the block should be proposed.</param>
        /// <param name="randao_reveal">The validator's randao reveal value.</param>
        /// <returns>Success response</returns>
        public async Task <BeaconBlock> BlockAsync(ulong slot, byte[] randao_reveal)
        {
            Containers.BeaconBlock data =
                await _beaconNode.NewBlockAsync(new Slot(slot), new BlsSignature(randao_reveal));

            OApi.BeaconBlock result = new OApi.BeaconBlock()
            {
                Slot        = (ulong)data.Slot,
                Parent_root = data.ParentRoot.ToString(),
                State_root  = data.StateRoot.ToString(),
                Signature   = data.Signature.ToString(),
                Body        = new OApi.BeaconBlockBody()
                {
                    Randao_reveal = data.Body !.RandaoReveal.AsSpan().ToArray(),
                    Eth1_data     = new Eth1_data()
                    {
                        Block_hash    = data.Body.Eth1Data.BlockHash.Bytes,
                        Deposit_count = (int)data.Body.Eth1Data.DepositCount,
                        Deposit_root  = data.Body.Eth1Data.DepositRoot.Bytes
                    },
                    Graffiti           = data.Body.Graffiti.AsSpan().ToArray(),
                    Proposer_slashings = data.Body.ProposerSlashings.Select(x => new Proposer_slashings()
                    {
                        Header_1       = MapBeaconBlockHeader(x.Header1),
                        Header_2       = MapBeaconBlockHeader(x.Header2),
                        Proposer_index = (int)x.ProposerIndex
                    }).ToList(),
                    Attester_slashings = data.Body.AttesterSlashings.Select(x => new Attester_slashings()
                    {
                        Attestation_1 = MapIndexedAttestation(x.Attestation1),
                        Attestation_2 = MapIndexedAttestation(x.Attestation2)
                    }).ToList(),
                    Attestations = data.Body.Attestations.Select(x => new Attestations()
                    {
                        Signature        = x.Signature.Bytes,
                        Aggregation_bits = x.AggregationBits.Cast <byte>().ToArray(),
                        Custody_bits     = x.CustodyBits.Cast <byte>().ToArray(),
                        Data             = MapAttestationData(x.Data)
                    }).ToList(),
                    Voluntary_exits = data.Body.VoluntaryExits.Select(x => new Voluntary_exits()
                    {
                        Validator_index = (int)x.ValidatorIndex,
                        Epoch           = x.Epoch,
                        Signature       = x.Signature.Bytes
                    }).ToList(),
                    Deposits = data.Body.Deposits.Select((x, index) => new Deposits()
                    {
                        Index = index,
                        Proof = x.Proof.Select(y => y.Bytes).ToList(),
                        Data  = new Data()
                        {
                            Amount    = (int)(ulong)x.Data.Amount,
                            Pubkey    = x.Data.PublicKey.Bytes,
                            Signature = x.Data.Signature.Bytes,
                            Withdrawal_credentials = x.Data.WithdrawalCredentials.Bytes
                        }
                    }).ToList(),
                }
            };
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <bool> PublishBlockAsync(Core2.Containers.BeaconBlock block, CancellationToken cancellationToken)
        {
            BeaconNode.OApiClient.BeaconBlock data = new BeaconNode.OApiClient.BeaconBlock()
            {
                Slot        = block.Slot,
                Parent_root = block.ParentRoot.ToString(),
                State_root  = block.StateRoot.ToString(),
                Signature   = block.Signature.ToString(),
                Body        = new BeaconNode.OApiClient.BeaconBlockBody()
                {
                    Randao_reveal = block.Body !.RandaoReveal.AsSpan().ToArray(),
                    Eth1_data     = new Eth1_data()
                    {
                        Block_hash    = block.Body.Eth1Data.BlockHash.Bytes,
                        Deposit_count = block.Body.Eth1Data.DepositCount,
                        Deposit_root  = block.Body.Eth1Data.DepositRoot.Bytes
                    },
                    Graffiti           = block.Body.Graffiti.AsSpan().ToArray(),
                    Proposer_slashings = block.Body.ProposerSlashings.Select(x => new Proposer_slashings()
                    {
                        Header_1       = MapBeaconBlockHeader(x.Header1),
                        Header_2       = MapBeaconBlockHeader(x.Header2),
                        Proposer_index = x.ProposerIndex
                    }).ToList(),
                    Attester_slashings = block.Body.AttesterSlashings.Select(x => new Attester_slashings()
                    {
                        Attestation_1 = MapIndexedAttestation(x.Attestation1),
                        Attestation_2 = MapIndexedAttestation(x.Attestation2)
                    }).ToList(),
                    Attestations = block.Body.Attestations.Select(x => new Attestations()
                    {
                        Signature        = x.Signature.Bytes,
                        Aggregation_bits = x.AggregationBits.Cast <byte>().ToArray(),
                        Custody_bits     = new byte[0],
                        Data             = MapAttestationData(x.Data)
                    }).ToList(),
                    Voluntary_exits = block.Body.VoluntaryExits.Select(x => new Voluntary_exits()
                    {
                        Validator_index = x.ValidatorIndex,
                        Epoch           = x.Epoch,
                        Signature       = x.Signature.Bytes
                    }).ToList(),
                    Deposits = block.Body.Deposits.Select((x, index) => new Deposits()
                    {
                        Index = (ulong)index,
                        Proof = x.Proof.Select(y => y.Bytes).ToList(),
                        Data  = new Data()
                        {
                            Amount    = x.Data.Amount,
                            Pubkey    = x.Data.PublicKey.Bytes,
                            Signature = x.Data.Signature.Bytes,
                            Withdrawal_credentials = x.Data.WithdrawalCredentials.Bytes
                        }
                    }).ToList(),
                }
            };

            await ClientOperationWithRetry(async (oapiClient, innerCancellationToken) =>
            {
                await oapiClient.Block2Async(data, innerCancellationToken).ConfigureAwait(false);
            }, cancellationToken).ConfigureAwait(false);

            // TODO: Parse 202 result separate from 200 result

            return(true);
        }