public void IsValidGenesisStateFalseNotEnoughValidators() { // Arrange IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(useStore: true); MiscellaneousParameters miscellaneousParameters = testServiceProvider.GetService <IOptions <MiscellaneousParameters> >().Value; GweiValues gweiValues = testServiceProvider.GetService <IOptions <GweiValues> >().Value; BeaconNode.GenesisChainStart beaconChain = testServiceProvider.GetService <BeaconNode.GenesisChainStart>(); int depositCount = miscellaneousParameters.MinimumGenesisActiveValidatorCount - 1; IList <DepositData> deposits = TestDeposit.PrepareGenesisDeposits(testServiceProvider, depositCount, gweiValues.MaximumEffectiveBalance, signed: true); IDepositStore depositStore = testServiceProvider.GetService <IDepositStore>(); foreach (DepositData deposit in deposits) { depositStore.Place(deposit); } Bytes32 eth1BlockHash = new Bytes32(Enumerable.Repeat((byte)0x12, 32).ToArray()); ulong eth1Timestamp = miscellaneousParameters.MinimumGenesisTime; // Act BeaconState state = beaconChain.InitializeBeaconStateFromEth1(eth1BlockHash, eth1Timestamp); // Assert IsValidGenesisState(testServiceProvider, state, false); }
public GenesisChainStart(ILogger <GenesisChainStart> logger, ChainConstants chainConstants, IOptionsMonitor <MiscellaneousParameters> miscellaneousParameterOptions, IOptionsMonitor <GweiValues> gweiValueOptions, IOptionsMonitor <InitialValues> initialValueOptions, IOptionsMonitor <TimeParameters> timeParameterOptions, IOptionsMonitor <StateListLengths> stateListLengthOptions, ICryptographyService cryptographyService, IStore store, BeaconStateAccessor beaconStateAccessor, BeaconStateTransition beaconStateTransition, IForkChoice forkChoice, IDepositStore depositStore) { _logger = logger; _beaconStateAccessor = beaconStateAccessor; _beaconStateTransition = beaconStateTransition; _forkChoice = forkChoice; _depositStore = depositStore; _chainConstants = chainConstants; _miscellaneousParameterOptions = miscellaneousParameterOptions; _gweiValueOptions = gweiValueOptions; _initialValueOptions = initialValueOptions; _timeParameterOptions = timeParameterOptions; _stateListLengthOptions = stateListLengthOptions; _cryptographyService = cryptographyService; _store = store; }
/// <summary> /// Prepare the state for the deposit, and create a deposit for the given validator, depositing the given amount. /// </summary> public static Deposit PrepareStateAndDeposit(IServiceProvider testServiceProvider, BeaconState state, ValidatorIndex validatorIndex, Gwei amount, Bytes32 withdrawalCredentials, bool signed) { ChainConstants chainConstants = testServiceProvider.GetService <ChainConstants>(); InitialValues initialValues = testServiceProvider.GetService <IOptions <InitialValues> >().Value; TimeParameters timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value; IBeaconChainUtility beaconChainUtility = testServiceProvider.GetService <IBeaconChainUtility>(); BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>(); IDepositStore depositStore = testServiceProvider.GetService <IDepositStore>(); byte[][] privateKeys = TestKeys.PrivateKeys(timeParameters).ToArray(); BlsPublicKey[] publicKeys = TestKeys.PublicKeys(timeParameters).ToArray(); byte[] privateKey = privateKeys[(int)(ulong)validatorIndex]; BlsPublicKey publicKey = publicKeys[(int)(ulong)validatorIndex]; if (withdrawalCredentials == Bytes32.Zero) { // insecurely use pubkey as withdrawal key if no credentials provided byte[] withdrawalCredentialBytes = TestSecurity.Hash(publicKey.AsSpan()); withdrawalCredentialBytes[0] = initialValues.BlsWithdrawalPrefix; withdrawalCredentials = new Bytes32(withdrawalCredentialBytes); } DepositData depositData = BuildDeposit(testServiceProvider, state, publicKey, privateKey, amount, withdrawalCredentials, signed); Deposit deposit = depositStore.Place(depositData); state.SetEth1DepositIndex(0); state.Eth1Data.SetDepositRoot(depositStore.DepositData.Root); state.Eth1Data.SetDepositCount((ulong)depositStore.Deposits.Count); return(deposit); }
public Eth1BridgeWorker(ILogger <Eth1BridgeWorker> logger, IHostEnvironment environment, IOptionsMonitor <AnchorState> anchorStateOptions, IClientVersion clientVersion, IEth1GenesisProvider eth1GenesisProvider, IEth1Genesis eth1Genesis, IDepositStore depositStore) { _logger = logger; _environment = environment; _anchorStateOptions = anchorStateOptions; _clientVersion = clientVersion; _eth1GenesisProvider = eth1GenesisProvider; _eth1Genesis = eth1Genesis; _depositStore = depositStore; }
public static BeaconState CreateValidBeaconState(IServiceProvider testServiceProvider, ulong?eth1TimestampOverride = null) { MiscellaneousParameters miscellaneousParameters = testServiceProvider.GetService <IOptions <MiscellaneousParameters> >().Value; GweiValues gweiValues = testServiceProvider.GetService <IOptions <GweiValues> >().Value; BeaconNode.GenesisChainStart beaconChain = testServiceProvider.GetService <BeaconNode.GenesisChainStart>(); int depositCount = miscellaneousParameters.MinimumGenesisActiveValidatorCount; IList <DepositData> deposits = TestDeposit.PrepareGenesisDeposits(testServiceProvider, depositCount, gweiValues.MaximumEffectiveBalance, signed: true); IDepositStore depositStore = testServiceProvider.GetService <IDepositStore>(); foreach (DepositData deposit in deposits) { depositStore.Place(deposit); } Bytes32 eth1BlockHash = new Bytes32(Enumerable.Repeat((byte)0x12, 32).ToArray()); ulong eth1Timestamp = eth1TimestampOverride ?? miscellaneousParameters.MinimumGenesisTime; BeaconState state = beaconChain.InitializeBeaconStateFromEth1(eth1BlockHash, eth1Timestamp); return(state); }
public QuickStartMockEth1GenesisProvider(ILogger <QuickStartMockEth1GenesisProvider> logger, ChainConstants chainConstants, IOptionsMonitor <GweiValues> gweiValueOptions, IOptionsMonitor <InitialValues> initialValueOptions, IOptionsMonitor <TimeParameters> timeParameterOptions, IOptionsMonitor <SignatureDomains> signatureDomainOptions, IOptionsMonitor <QuickStartParameters> quickStartParameterOptions, ICryptographyService crypto, IBeaconChainUtility beaconChainUtility, IDepositStore depositStore) { _logger = logger; _chainConstants = chainConstants; _gweiValueOptions = gweiValueOptions; _initialValueOptions = initialValueOptions; _timeParameterOptions = timeParameterOptions; _signatureDomainOptions = signatureDomainOptions; _quickStartParameterOptions = quickStartParameterOptions; _crypto = crypto; _beaconChainUtility = beaconChainUtility; _depositStore = depositStore; }
public void TestInitializeBeaconStateFromEth1() { bool useBls = true; // Arrange IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(useBls, useStore: true); ChainConstants chainConstants = testServiceProvider.GetService <ChainConstants>(); TimeParameters timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value; MiscellaneousParameters miscellaneousParameters = testServiceProvider.GetService <IOptions <MiscellaneousParameters> >().Value; GweiValues gweiValues = testServiceProvider.GetService <IOptions <GweiValues> >().Value; int depositCount = miscellaneousParameters.MinimumGenesisActiveValidatorCount; IList <DepositData> deposits = TestDeposit.PrepareGenesisDeposits(testServiceProvider, depositCount, gweiValues.MaximumEffectiveBalance, signed: useBls); IDepositStore depositStore = testServiceProvider.GetService <IDepositStore>(); foreach (DepositData depositData in deposits) { depositStore.Place(depositData); } Bytes32 eth1BlockHash = new Bytes32(Enumerable.Repeat((byte)0x12, 32).ToArray()); ulong eth1Timestamp = miscellaneousParameters.MinimumGenesisTime; BeaconNode.GenesisChainStart beaconChain = testServiceProvider.GetService <BeaconNode.GenesisChainStart>(); // Act //# initialize beacon_state BeaconState state = beaconChain.InitializeBeaconStateFromEth1(eth1BlockHash, eth1Timestamp); // Assert state.GenesisTime.ShouldBe(eth1Timestamp - eth1Timestamp % timeParameters.MinimumGenesisDelay + 2 * timeParameters.MinimumGenesisDelay); state.Validators.Count.ShouldBe(depositCount); state.Eth1Data.DepositRoot.ShouldBe(depositStore.DepositData.Root); state.Eth1Data.DepositCount.ShouldBe((ulong)depositCount); state.Eth1Data.BlockHash.ShouldBe(eth1BlockHash); }