/// <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); }
public async Task BasicNewBlock() { // Arrange int numberOfValidators = 64; int genesisTime = 1578009600; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = $"{numberOfValidators}", ["QuickStart:GenesisTime"] = $"{genesisTime}" }) .Build(); testServiceCollection.AddBeaconNodeQuickStart(configuration); testServiceCollection.AddBeaconNodeEth1Bridge(configuration); testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>()); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); IBeaconNodeApi beaconNode = testServiceProvider.GetService <IBeaconNodeApi>(); ApiResponse <Fork> forkResponse = await beaconNode.GetNodeForkAsync(CancellationToken.None); Fork fork = forkResponse.Content; fork.CurrentVersion.ShouldBe(new ForkVersion(new byte[4] { 0x00, 0x00, 0x00, 0x01 })); // Act BlockProducer blockProducer = testServiceProvider.GetService <BlockProducer>(); Slot targetSlot = new Slot(1); // With QuickStart64, proposer for Slot 1 is validator index 29, 0xa98ed496... QuickStartMockEth1GenesisProvider quickStartMockEth1GenesisProvider = (QuickStartMockEth1GenesisProvider)testServiceProvider.GetService <IEth1GenesisProvider>(); byte[] privateKey = quickStartMockEth1GenesisProvider.GeneratePrivateKey(29); BlsSignature randaoReveal = GetEpochSignature(testServiceProvider, privateKey, fork.CurrentVersion, targetSlot); // value for quickstart 20/64, fork 0, slot 1 randaoReveal.ToString().StartsWith("0x932f8730"); BeaconBlock newBlock = await blockProducer.NewBlockAsync(targetSlot, randaoReveal, CancellationToken.None); // Assert newBlock.Slot.ShouldBe(targetSlot); newBlock.Body.RandaoReveal.ShouldBe(randaoReveal); newBlock.ParentRoot.ToString().ShouldStartWith("0x4d4e9a16"); newBlock.Body.Eth1Data.DepositCount.ShouldBe((ulong)numberOfValidators); newBlock.Body.Eth1Data.DepositRoot.ToString().ShouldStartWith("0x66687aad"); newBlock.StateRoot.ToString().ShouldStartWith("0x0138b69f"); newBlock.Body.Attestations.Count.ShouldBe(0); newBlock.Body.Deposits.Count.ShouldBe(0); }
public async Task BasicNewBlock() { // Arrange int numberOfValidators = 64; int genesisTime = 1578009600; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = $"{numberOfValidators}", ["QuickStart:GenesisTime"] = $"{genesisTime}" }) .Build(); testServiceCollection.AddBeaconNodeQuickStart(configuration); testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>()); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); QuickStart quickStart = (QuickStart)testServiceProvider.GetService <INodeStart>(); await quickStart.InitializeNodeAsync(); IBeaconNodeApi beaconNode = testServiceProvider.GetService <IBeaconNodeApi>(); Core2.Containers.Fork fork = await beaconNode.GetNodeForkAsync(CancellationToken.None); fork.CurrentVersion.ShouldBe(new ForkVersion()); // Act BlockProducer blockProducer = testServiceProvider.GetService <BlockProducer>(); Slot targetSlot = new Slot(1); // With QuickStart64, proposer for Slot 1 is validator index 20, 0xa1c76af1... byte[] privateKey = quickStart.GeneratePrivateKey(20); BlsSignature randaoReveal = GetEpochSignature(testServiceProvider, privateKey, fork.CurrentVersion, targetSlot); // value for quickstart 20/64, fork 0, slot 1 randaoReveal.ToString().ShouldBe("0xa3426b6391a29c88f2280428d5fdae9e20f4c75a8d38d0714e3aa5b9e55594dbd555c4bc685191e83d39158c3be9744d06adc34b21d2885998a206e3b3fd435eab424cf1c01b8fd562deb411348a601e83d7332d8774d1fd3bf8b88d7a33c67c"); BeaconBlock newBlock = await blockProducer.NewBlockAsync(targetSlot, randaoReveal); // Assert newBlock.Slot.ShouldBe(targetSlot); newBlock.Body.RandaoReveal.ShouldBe(randaoReveal); Hash32 expectedParentRoot = new Hash32("0x91b06cbcd6dc97b89dc8b95e0b01a497932683b182e6c722ddfa10cd005b2180"); newBlock.ParentRoot.ShouldBe(expectedParentRoot); newBlock.Body.Eth1Data.DepositCount.ShouldBe((ulong)numberOfValidators); Hash32 expectedEth1DataDepositRoot = new Hash32("0x66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925"); newBlock.Body.Eth1Data.DepositRoot.ShouldBe(expectedEth1DataDepositRoot); Hash32 expectedStateRoot = new Hash32("0xe05ccf6347cac0b0dab0ad0d5c941fe7c7e2ed4c69550ed9a628bc9d62914242"); newBlock.StateRoot.ShouldBe(expectedStateRoot); newBlock.Signature.ShouldBe(new BlsSignature(new byte[96])); // signature should be empty newBlock.Body.Attestations.Count.ShouldBe(0); newBlock.Body.Deposits.Count.ShouldBe(0); }
public async Task BasicNewBlock() { // Arrange int numberOfValidators = 64; int genesisTime = 1578009600; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = $"{numberOfValidators}", ["QuickStart:GenesisTime"] = $"{genesisTime}" }) .Build(); testServiceCollection.AddQuickStart(configuration); testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>()); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); QuickStart quickStart = (QuickStart)testServiceProvider.GetService <INodeStart>(); await quickStart.InitializeNodeAsync(); IBeaconNodeApi beaconNode = testServiceProvider.GetService <IBeaconNodeApi>(); Core2.Containers.Fork fork = await beaconNode.GetNodeForkAsync(); fork.CurrentVersion.ShouldBe(new ForkVersion()); // Act BlockProducer blockProducer = testServiceProvider.GetService <BlockProducer>(); Slot targetSlot = new Slot(1); // With QuickStart64, proposer for Slot 1 is validator index 20, 0xa1c76af1... byte[] privateKey = quickStart.GeneratePrivateKey(20); BlsSignature randaoReveal = GetEpochSignature(testServiceProvider, privateKey, fork.CurrentVersion, targetSlot); // value for quickstart 20/64, fork 0, slot 1 randaoReveal.ToString().ShouldBe("0xa3426b6391a29c88f2280428d5fdae9e20f4c75a8d38d0714e3aa5b9e55594dbd555c4bc685191e83d39158c3be9744d06adc34b21d2885998a206e3b3fd435eab424cf1c01b8fd562deb411348a601e83d7332d8774d1fd3bf8b88d7a33c67c"); BeaconBlock newBlock = await blockProducer.NewBlockAsync(targetSlot, randaoReveal); // Assert newBlock.Slot.ShouldBe(targetSlot); newBlock.Body.RandaoReveal.ShouldBe(randaoReveal); Hash32 expectedParentRoot = new Hash32(Bytes.FromHexString("0x3111350140726cc0501223143ae5c7baad7f5a06764fcc7d444a657016e7d616")); newBlock.ParentRoot.ShouldBe(expectedParentRoot); newBlock.Body.Eth1Data.DepositCount.ShouldBe((ulong)numberOfValidators); Hash32 expectedEth1DataDepositRoot = new Hash32(Bytes.FromHexString("0x66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925")); newBlock.Body.Eth1Data.DepositRoot.ShouldBe(expectedEth1DataDepositRoot); Hash32 expectedStateRoot = new Hash32(Bytes.FromHexString("0x9c7d3e5180f95175691511fd56f8a610299f0b5a682b6fe178230493d74f6d13")); newBlock.StateRoot.ShouldBe(expectedStateRoot); newBlock.Signature.ShouldBe(new BlsSignature(new byte[96])); // signature should be empty newBlock.Body.Attestations.Count.ShouldBe(0); newBlock.Body.Deposits.Count.ShouldBe(0); }