Пример #1
0
        public IStore GetGenesisStore(BeaconState genesisState)
        {
            MiscellaneousParameters miscellaneousParameters = _miscellaneousParameterOptions.CurrentValue;
            MaxOperationsPerBlock   maxOperationsPerBlock   = _maxOperationsPerBlockOptions.CurrentValue;

            Hash32      stateRoot    = _cryptographyService.HashTreeRoot(genesisState);
            BeaconBlock genesisBlock = new BeaconBlock(stateRoot);

            Hash32 root = _cryptographyService.SigningRoot(genesisBlock);

            Checkpoint justifiedCheckpoint = new Checkpoint(_initialValueOptions.CurrentValue.GenesisEpoch, root);
            Checkpoint finalizedCheckpoint = new Checkpoint(_initialValueOptions.CurrentValue.GenesisEpoch, root);

            if (_logger.IsInfo())
            {
                Log.CreateGenesisStore(_logger, genesisBlock, genesisState, justifiedCheckpoint, root, null);
            }

            Dictionary <Hash32, BeaconBlock> blocks = new Dictionary <Hash32, BeaconBlock>
            {
                [root] = genesisBlock
            };
            Dictionary <Hash32, BeaconState> blockStates = new Dictionary <Hash32, BeaconState>
            {
                [root] = BeaconState.Clone(genesisState)
            };
            Dictionary <Checkpoint, BeaconState> checkpointStates = new Dictionary <Checkpoint, BeaconState>
            {
                [justifiedCheckpoint] = BeaconState.Clone(genesisState)
            };

            IStore store = _storeProvider.CreateStore(
                genesisState.GenesisTime,
                genesisState.GenesisTime,
                justifiedCheckpoint,
                finalizedCheckpoint,
                justifiedCheckpoint,
                blocks,
                blockStates,
                checkpointStates,
                new Dictionary <ValidatorIndex, LatestMessage>()
                );

            return(store);
        }
Пример #2
0
        public IStore GetGenesisStore(BeaconState genesisState)
        {
            var miscellaneousParameters = _miscellaneousParameterOptions.CurrentValue;
            var maxOperationsPerBlock   = _maxOperationsPerBlockOptions.CurrentValue;

            var stateRoot           = genesisState.HashTreeRoot(miscellaneousParameters, _timeParameterOptions.CurrentValue, _stateListLengthOptions.CurrentValue, maxOperationsPerBlock);
            var genesisBlock        = new BeaconBlock(stateRoot);
            var root                = genesisBlock.SigningRoot(miscellaneousParameters, maxOperationsPerBlock);
            var justifiedCheckpoint = new Checkpoint(_initialValueOptions.CurrentValue.GenesisEpoch, root);
            var finalizedCheckpoint = new Checkpoint(_initialValueOptions.CurrentValue.GenesisEpoch, root);

            _logger.LogInformation(Event.CreateGenesisStore, "Creating genesis store with block {BeaconBlock} for state {BeaconState}, with checkpoint {JustifiedCheckpoint}, with signing root {SigningRoot}",
                                   genesisBlock, genesisState, justifiedCheckpoint, root);

            var blocks = new Dictionary <Hash32, BeaconBlock>
            {
                [root] = genesisBlock
            };
            var blockStates = new Dictionary <Hash32, BeaconState>
            {
                [root] = BeaconState.Clone(genesisState)
            };
            var checkpointStates = new Dictionary <Checkpoint, BeaconState>
            {
                [justifiedCheckpoint] = BeaconState.Clone(genesisState)
            };

            var store = _storeProvider.CreateStore(
                genesisState.GenesisTime,
                genesisState.GenesisTime,
                justifiedCheckpoint,
                finalizedCheckpoint,
                justifiedCheckpoint,
                blocks,
                blockStates,
                checkpointStates,
                new Dictionary <ValidatorIndex, LatestMessage>()
                );

            return(store);
        }