Пример #1
0
        public void Initialize()
        {
            Rlp.RegisterDecoders(typeof(ParityTraceDecoder).Assembly);

            _ethSerializer = new EthereumJsonSerializer();
            ISpecProvider   specProvider  = MainNetSpecProvider.Instance;
            IEthereumEcdsa  ethereumEcdsa = new EthereumEcdsa(specProvider, LimboLogs.Instance);
            ITxStorage      txStorage     = new InMemoryTxStorage();
            ISnapshotableDb stateDb       = new StateDb();
            ISnapshotableDb codeDb        = new StateDb();
            IStateReader    stateReader   = new StateReader(stateDb, codeDb, LimboLogs.Instance);
            IStateProvider  stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance);

            stateProvider.CreateAccount(TestItem.AddressA, 1000.Ether());
            stateProvider.CreateAccount(TestItem.AddressB, 1000.Ether());
            stateProvider.CreateAccount(TestItem.AddressC, 1000.Ether());
            byte[] code     = Bytes.FromHexString("0xabcd");
            Keccak codeHash = Keccak.Compute(code);

            stateProvider.UpdateCode(code);
            stateProvider.UpdateCodeHash(TestItem.AddressA, codeHash, specProvider.GenesisSpec);

            IStorageProvider storageProvider = new StorageProvider(stateDb, stateProvider, LimboLogs.Instance);

            storageProvider.Set(new StorageAddress(TestItem.AddressA, UInt256.One), Bytes.FromHexString("0xabcdef"));
            storageProvider.Commit();

            stateProvider.Commit(specProvider.GenesisSpec);

            ITxPool txPool = new TxPool(txStorage, Timestamper.Default, ethereumEcdsa, specProvider, new TxPoolConfig(), stateProvider, LimboLogs.Instance);

            IDb        blockDb     = new MemDb();
            IDb        headerDb    = new MemDb();
            IDb        blockInfoDb = new MemDb();
            IDb        traceDb     = new MemDb();
            IBlockTree blockTree   = new BlockTree(blockDb, headerDb, blockInfoDb, new ChainLevelInfoRepository(blockDb), specProvider, txPool, LimboLogs.Instance);

            IReceiptStorage      receiptStorage = new InMemoryReceiptStorage();
            VirtualMachine       virtualMachine = new VirtualMachine(stateProvider, storageProvider, new BlockhashProvider(blockTree, LimboLogs.Instance), specProvider, LimboLogs.Instance);
            TransactionProcessor txProcessor    = new TransactionProcessor(specProvider, stateProvider, storageProvider, virtualMachine, LimboLogs.Instance);
            IBlockProcessor      blockProcessor = new BlockProcessor(specProvider, AlwaysValidBlockValidator.Instance, new RewardCalculator(specProvider), txProcessor, stateDb, codeDb, traceDb, stateProvider, storageProvider, txPool, receiptStorage, LimboLogs.Instance);

            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, blockProcessor, txPool, LimboLogs.Instance);

            _blockchainBridge = new BlockchainBridge(stateReader, stateProvider, storageProvider, blockTree, txPool, receiptStorage, filterStore, filterManager, NullWallet.Instance, txProcessor, ethereumEcdsa);

            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(blockTree, blockProcessor, new TxSignaturesRecoveryStep(ethereumEcdsa, txPool, LimboLogs.Instance), LimboLogs.Instance, true, true);

            blockchainProcessor.Start();

            ManualResetEventSlim resetEvent = new ManualResetEventSlim(false);

            blockTree.NewHeadBlock += (s, e) =>
            {
                if (e.Block.Number == 9)
                {
                    resetEvent.Set();
                }
            };

            Block genesis = Build.A.Block.Genesis.WithStateRoot(new Keccak("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject;

            blockTree.SuggestBlock(genesis);

            Block previousBlock = genesis;

            for (int i = 1; i < 10; i++)
            {
                Block block = Build.A.Block.WithNumber(i).WithParent(previousBlock).WithStateRoot(new Keccak("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject;
                blockTree.SuggestBlock(block);
                previousBlock = block;
            }

            resetEvent.Wait();
            _ethModule = new EthModule(LimboLogs.Instance, _blockchainBridge);
            _blockTree = blockTree;
        }
Пример #2
0
        private void Initialize(bool auRa = false)
        {
            ISpecProvider  specProvider  = MainnetSpecProvider.Instance;
            IEthereumEcdsa ethereumEcdsa = new EthereumEcdsa(specProvider, LimboLogs.Instance);
            ITxStorage     txStorage     = new InMemoryTxStorage();

            _stateDb = new StateDb();
            ISnapshotableDb codeDb      = new StateDb();
            IStateReader    stateReader = new StateReader(_stateDb, codeDb, LimboLogs.Instance);

            _stateProvider = new StateProvider(_stateDb, codeDb, LimboLogs.Instance);
            _stateProvider.CreateAccount(TestItem.AddressA, 1000.Ether());
            _stateProvider.CreateAccount(TestItem.AddressB, 1000.Ether());
            _stateProvider.CreateAccount(TestItem.AddressC, 1000.Ether());
            byte[] code     = Bytes.FromHexString("0xabcd");
            Keccak codeHash = Keccak.Compute(code);

            _stateProvider.UpdateCode(code);
            _stateProvider.UpdateCodeHash(TestItem.AddressA, codeHash, specProvider.GenesisSpec);

            IStorageProvider storageProvider = new StorageProvider(_stateDb, _stateProvider, LimboLogs.Instance);

            storageProvider.Set(new StorageCell(TestItem.AddressA, UInt256.One), Bytes.FromHexString("0xabcdef"));
            storageProvider.Commit();

            _stateProvider.Commit(specProvider.GenesisSpec);
            _stateProvider.CommitTree();

            ITxPool txPool = new TxPool.TxPool(txStorage, Timestamper.Default, ethereumEcdsa, specProvider, new TxPoolConfig(), _stateProvider, LimboLogs.Instance);

            IDb        blockDb     = new MemDb();
            IDb        headerDb    = new MemDb();
            IDb        blockInfoDb = new MemDb();
            IBlockTree blockTree   = new BlockTree(blockDb, headerDb, blockInfoDb, new ChainLevelInfoRepository(blockDb), specProvider, txPool, NullBloomStorage.Instance, LimboLogs.Instance);

            IReceiptStorage      receiptStorage = new InMemoryReceiptStorage();
            VirtualMachine       virtualMachine = new VirtualMachine(_stateProvider, storageProvider, new BlockhashProvider(blockTree, LimboLogs.Instance), specProvider, LimboLogs.Instance);
            TransactionProcessor txProcessor    = new TransactionProcessor(specProvider, _stateProvider, storageProvider, virtualMachine, LimboLogs.Instance);
            IBlockProcessor      blockProcessor = new BlockProcessor(specProvider, Always.Valid, new RewardCalculator(specProvider), txProcessor, _stateDb, codeDb, _stateProvider, storageProvider, txPool, receiptStorage, LimboLogs.Instance);

            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, blockProcessor, txPool, LimboLogs.Instance);

            _blockchainBridge = new BlockchainBridge(stateReader, _stateProvider, storageProvider, blockTree, txPool, receiptStorage, filterStore, filterManager, NullWallet.Instance, txProcessor, ethereumEcdsa, NullBloomStorage.Instance, LimboLogs.Instance, false);

            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(blockTree, blockProcessor, new TxSignaturesRecoveryStep(ethereumEcdsa, txPool, LimboLogs.Instance), LimboLogs.Instance, true);

            blockchainProcessor.Start();

            ManualResetEventSlim resetEvent = new ManualResetEventSlim(false);

            blockTree.NewHeadBlock += (s, e) =>
            {
                Console.WriteLine(e.Block.Header.Hash);
                if (e.Block.Number == 9)
                {
                    resetEvent.Set();
                }
            };

            var genesisBlockBuilder = Build.A.Block.Genesis.WithStateRoot(new Keccak("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f"));

            if (auRa)
            {
                genesisBlockBuilder.WithAura(0, new byte[65]);
            }

            Block genesis = genesisBlockBuilder.TestObject;

            blockTree.SuggestBlock(genesis);

            Block previousBlock = genesis;

            for (int i = 1; i < 10; i++)
            {
                List <Transaction> transactions = new List <Transaction>();
                for (int j = 0; j < i; j++)
                {
                    transactions.Add(Build.A.Transaction.WithNonce((UInt256)j).SignedAndResolved().TestObject);
                }

                BlockBuilder builder = Build.A.Block.WithNumber(i).WithParent(previousBlock).WithTransactions(transactions.ToArray()).WithStateRoot(new Keccak("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f"));
                if (auRa)
                {
                    builder.WithAura(i, i.ToByteArray());
                }

                Block block = builder.TestObject;
                blockTree.SuggestBlock(block);
                previousBlock = block;
            }

            IReceiptsRecovery receiptsRecovery = new ReceiptsRecovery();
            IReceiptFinder    receiptFinder    = new FullInfoReceiptFinder(receiptStorage, receiptsRecovery, blockTree);

            resetEvent.Wait(2000);
            _traceModule = new TraceModule(receiptFinder, new Tracer(_stateProvider, blockchainProcessor), _blockchainBridge);
            _blockTree   = blockTree;
        }
Пример #3
0
        private async Task InitBlockchain(InitParams initParams)
        {
            ChainSpec chainSpec = LoadChainSpec(initParams.ChainSpecPath);

            /* spec */
            // TODO: rebuild to use chainspec
            ISpecProvider specProvider;

            if (chainSpec.ChainId == RopstenSpecProvider.Instance.ChainId)
            {
                specProvider = RopstenSpecProvider.Instance;
            }
            else if (chainSpec.ChainId == MainNetSpecProvider.Instance.ChainId)
            {
                specProvider = MainNetSpecProvider.Instance;
            }
            else
            {
                throw new NotSupportedException($"Not yet tested, not yet supported ChainId {chainSpec.ChainId}");
            }

            var ethereumSigner   = new EthereumSigner(specProvider, _logManager);
            var transactionStore = new TransactionStore();
            var sealEngine       = ConfigureSealEngine(transactionStore, ethereumSigner, initParams);

            /* sync */
            var blocksDb     = new DbOnTheRocks(Path.Combine(_dbBasePath, DbOnTheRocks.BlocksDbPath));
            var blockInfosDb = new DbOnTheRocks(Path.Combine(_dbBasePath, DbOnTheRocks.BlockInfosDbPath));
            var receiptsDb   = new DbOnTheRocks(Path.Combine(_dbBasePath, DbOnTheRocks.ReceiptsDbPath));

            /* blockchain */
            var blockTree            = new BlockTree(blocksDb, blockInfosDb, receiptsDb, specProvider, _logManager);
            var difficultyCalculator = new DifficultyCalculator(specProvider);

            /* validation */
            var headerValidator = new HeaderValidator(difficultyCalculator, blockTree, sealEngine, specProvider, _logManager);
            var ommersValidator = new OmmersValidator(blockTree, headerValidator, _logManager);
            var txValidator     = new TransactionValidator(new SignatureValidator(specProvider.ChainId));
            var blockValidator  = new BlockValidator(txValidator, headerValidator, ommersValidator, specProvider, _logManager);

            /* state */
            var dbProvider      = new RocksDbProvider(_dbBasePath, _logManager);
            var codeDb          = new DbOnTheRocks(Path.Combine(_dbBasePath, DbOnTheRocks.CodeDbPath));
            var stateDb         = new DbOnTheRocks(Path.Combine(_dbBasePath, DbOnTheRocks.StateDbPath));
            var stateTree       = new StateTree(stateDb);
            var stateProvider   = new StateProvider(stateTree, codeDb, _logManager);
            var storageProvider = new StorageProvider(dbProvider, stateProvider, _logManager);

            /* blockchain processing */
            var blockhashProvider    = new BlockhashProvider(blockTree);
            var virtualMachine       = new VirtualMachine(stateProvider, storageProvider, blockhashProvider, _logManager);
            var transactionProcessor = new TransactionProcessor(specProvider, stateProvider, storageProvider, virtualMachine, _tracer, _logManager);
            var rewardCalculator     = new RewardCalculator(specProvider);
            var blockProcessor       = new BlockProcessor(specProvider, blockValidator, rewardCalculator, transactionProcessor, dbProvider, stateProvider, storageProvider, transactionStore, _logManager);

            _blockchainProcessor = new BlockchainProcessor(blockTree, sealEngine, transactionStore, difficultyCalculator, blockProcessor, ethereumSigner, _logManager);

            // create shared objects between discovery and peer manager
            _nodeFactory       = new NodeFactory();
            _nodeStatsProvider = new NodeStatsProvider(_configProvider);
            var jsonSerializer = new JsonSerializer(_logManager);
            var encrypter      = new AesEncrypter(_configProvider, _logManager);

            _keyStore = new FileKeyStore(_configProvider, jsonSerializer, encrypter, _cryptoRandom, _logManager);

            //creating blockchain bridge
            BlockchainBridge = new BlockchainBridge(ethereumSigner, stateProvider, _keyStore, blockTree, stateDb, transactionStore);
            EthereumSigner   = ethereumSigner;

            _blockchainProcessor.Start();
            LoadGenesisBlock(chainSpec, string.IsNullOrWhiteSpace(initParams.GenesisHash) ? null : new Keccak(initParams.GenesisHash), blockTree, stateProvider, specProvider);
            await StartProcessing(blockTree, transactionStore, blockValidator, headerValidator, txValidator, initParams);
        }
Пример #4
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliApiBuilder)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, _blockTree, _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _transactionPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _transactionPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor);

            TransactionPool debugTransactionPool = new TransactionPool(new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider),
                                                                       new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval),
                                                                       _timestamp,
                                                                       _ethereumSigner,
                                                                       _specProvider,
                                                                       _logManager,
                                                                       _initConfig.RemovePendingTransactionInterval,
                                                                       _initConfig.PeerNotificationThreshold);

            var debugReceiptStorage             = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider);
            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, debugTransactionPool, debugReceiptStorage);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_jsonSerializer, _configProvider, _logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_configProvider, _logManager, debugBridge, _jsonSerializer);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealer is CliqueSealer)
            {
                CliqueModule cliqueModule = new CliqueModule(_configProvider, _logManager, _jsonSerializer, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _configProvider, _logManager, _jsonSerializer);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_configProvider, _logManager, _jsonSerializer);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_configProvider, _logManager, _jsonSerializer, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            if (_initConfig.NetworkEnabled && _initConfig.SynchronizationEnabled)
            {
                NetModule netModule = new NetModule(_configProvider, _logManager, _jsonSerializer, new NetBridge(_enode, _syncManager, _peerManager));
                _rpcModuleProvider.Register <INetModule>(netModule);
            }

            TraceModule traceModule = new TraceModule(_configProvider, _logManager, _jsonSerializer, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
Пример #5
0
        public INdmServices Init(NdmRequiredServices services)
        {
            AddDecoders();
            var config          = services.NdmConfig;
            var consumerAddress = string.IsNullOrWhiteSpace(config.ConsumerAddress)
                ? Address.Zero
                : new Address(config.ConsumerAddress);
            var contractAddress = string.IsNullOrWhiteSpace(config.ContractAddress)
                ? Address.Zero
                : new Address(config.ContractAddress);

            var configId                = config.Id;
            var configManager           = services.ConfigManager;
            var logManager              = services.LogManager;
            var timestamper             = services.Timestamper;
            var wallet                  = services.Wallet;
            var readOnlyTree            = new ReadOnlyBlockTree(services.BlockTree);
            var readOnlyDbProvider      = new ReadOnlyDbProvider(services.RocksProvider, false);
            var readOnlyTxProcessingEnv = new ReadOnlyTxProcessingEnv(readOnlyDbProvider, readOnlyTree,
                                                                      services.SpecProvider, logManager);
            var blockchainBridge = new BlockchainBridge(
                readOnlyTxProcessingEnv.StateReader,
                readOnlyTxProcessingEnv.StateProvider,
                readOnlyTxProcessingEnv.StorageProvider,
                readOnlyTxProcessingEnv.BlockTree,
                services.TransactionPool,
                services.ReceiptStorage,
                services.FilterStore,
                services.FilterManager,
                wallet,
                readOnlyTxProcessingEnv.TransactionProcessor,
                services.Ecdsa);
            var dataAssetRlpDecoder = new DataAssetDecoder();
            var encoder             = new AbiEncoder();

            INdmBlockchainBridge ndmBlockchainBridge;

            if (config.ProxyEnabled)
            {
                services.JsonRpcClientProxy.SetUrls(config.JsonRpcUrlProxies);
                ndmBlockchainBridge = new NdmBlockchainBridgeProxy(services.EthJsonRpcClientProxy);
            }
            else
            {
                ndmBlockchainBridge = new NdmBlockchainBridge(blockchainBridge, services.TransactionPool);
            }

            var gasPriceService = new GasPriceService(services.HttpClient, configManager, configId, timestamper,
                                                      logManager);
            var transactionService = new TransactionService(ndmBlockchainBridge, wallet, configManager, configId,
                                                            logManager);
            var depositService            = new DepositService(ndmBlockchainBridge, encoder, wallet, contractAddress);
            var ndmConsumerChannelManager = services.NdmConsumerChannelManager;
            var ndmDataPublisher          = services.NdmDataPublisher;
            var jsonRpcNdmConsumerChannel = new JsonRpcNdmConsumerChannel();

//            ndmConsumerChannelManager.Add(jsonRpcNdmConsumerChannel);

            return(new Services(services, new NdmCreatedServices(consumerAddress, encoder, dataAssetRlpDecoder,
                                                                 depositService, gasPriceService, transactionService, ndmDataPublisher, jsonRpcNdmConsumerChannel,
                                                                 ndmConsumerChannelManager, ndmBlockchainBridge)));
        }
Пример #6
0
        public INdmServices Init(NdmRequiredServices services)
        {
            AddDecoders();
            var config          = services.NdmConfig;
            var consumerAddress = string.IsNullOrWhiteSpace(config.ConsumerAddress)
                ? Address.Zero
                : new Address(config.ConsumerAddress);
            var contractAddress = string.IsNullOrWhiteSpace(config.ContractAddress)
                ? Address.Zero
                : new Address(config.ContractAddress);

            var configId                = config.Id;
            var configManager           = services.ConfigManager;
            var logManager              = services.LogManager;
            var timestamper             = services.Timestamper;
            var wallet                  = services.Wallet;
            var readOnlyTree            = new ReadOnlyBlockTree(services.BlockTree);
            var readOnlyDbProvider      = new ReadOnlyDbProvider(services.RocksProvider, false);
            var readOnlyTxProcessingEnv = new ReadOnlyTxProcessingEnv(readOnlyDbProvider, readOnlyTree,
                                                                      services.SpecProvider, logManager);
            var jsonRpcConfig    = services.ConfigProvider.GetConfig <IJsonRpcConfig>();
            var blockchainBridge = new BlockchainBridge(
                readOnlyTxProcessingEnv.StateReader,
                readOnlyTxProcessingEnv.StateProvider,
                readOnlyTxProcessingEnv.StorageProvider,
                readOnlyTxProcessingEnv.BlockTree,
                services.TransactionPool,
                services.ReceiptFinder,
                services.FilterStore,
                services.FilterManager,
                wallet,
                readOnlyTxProcessingEnv.TransactionProcessor,
                services.Ecdsa,
                services.BloomStorage,
                logManager,
                false,
                jsonRpcConfig.FindLogBlockDepthLimit);
            var dataAssetRlpDecoder = new DataAssetDecoder();
            var encoder             = new AbiEncoder();

            INdmBlockchainBridge ndmBlockchainBridge;

            if (config.ProxyEnabled)
            {
                if (config.JsonRpcUrlProxies == null || services.EthJsonRpcClientProxy == null)
                {
                    throw new InvalidDataException("JSON RPC proxy is enabled but the proxies were not initialized properly.");
                }

                services.JsonRpcClientProxy !.SetUrls(config.JsonRpcUrlProxies !);
                ndmBlockchainBridge = new NdmBlockchainBridgeProxy(services.EthJsonRpcClientProxy);
            }
            else
            {
                ndmBlockchainBridge = new NdmBlockchainBridge(blockchainBridge, services.TransactionPool);
            }

            var gasPriceService = new GasPriceService(services.HttpClient, configManager, configId, timestamper,
                                                      logManager);
            var transactionService = new TransactionService(ndmBlockchainBridge, wallet, configManager, configId,
                                                            logManager);
            var depositService            = new DepositService(ndmBlockchainBridge, encoder, wallet, contractAddress);
            var ndmConsumerChannelManager = services.NdmConsumerChannelManager;
            var ndmDataPublisher          = services.NdmDataPublisher;
            var jsonRpcNdmConsumerChannel = new JsonRpcNdmConsumerChannel(logManager);

            if (config.JsonRpcDataChannelEnabled)
            {
                ndmConsumerChannelManager.Add(jsonRpcNdmConsumerChannel);
            }

            return(new Services(services, new NdmCreatedServices(consumerAddress, encoder, dataAssetRlpDecoder,
                                                                 depositService, gasPriceService, transactionService, ndmDataPublisher, jsonRpcNdmConsumerChannel,
                                                                 ndmConsumerChannelManager, ndmBlockchainBridge)));
        }
        public void GlobalSetup()
        {
            ISnapshotableDb codeDb      = new StateDb();
            ISnapshotableDb stateDb     = new StateDb();
            IDb             blockInfoDb = new MemDb(10, 5);

            ISpecProvider specProvider = MainnetSpecProvider.Instance;
            IReleaseSpec  spec         = MainnetSpecProvider.Instance.GenesisSpec;

            StateProvider stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance);

            stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            stateProvider.Commit(spec);

            StorageProvider storageProvider = new StorageProvider(stateDb, stateProvider, LimboLogs.Instance);
            StateReader     stateReader     = new StateReader(stateDb, codeDb, LimboLogs.Instance);

            ChainLevelInfoRepository chainLevelInfoRepository = new ChainLevelInfoRepository(blockInfoDb);
            BlockTree blockTree = new BlockTree(new MemDb(), new MemDb(), blockInfoDb, chainLevelInfoRepository, specProvider, NullTxPool.Instance, NullBloomStorage.Instance, LimboLogs.Instance);

            _blockhashProvider = new BlockhashProvider(blockTree, LimboLogs.Instance);
            _virtualMachine    = new VirtualMachine(stateProvider, storageProvider, _blockhashProvider, specProvider, LimboLogs.Instance);

            Block genesisBlock = Build.A.Block.Genesis.TestObject;

            blockTree.SuggestBlock(genesisBlock);

            Block block1 = Build.A.Block.WithParent(genesisBlock).WithNumber(1).TestObject;

            blockTree.SuggestBlock(block1);

            TransactionProcessor transactionProcessor
                = new TransactionProcessor(MainnetSpecProvider.Instance, stateProvider, storageProvider, _virtualMachine, LimboLogs.Instance);

            BlockProcessor blockProcessor = new BlockProcessor(specProvider, Always.Valid, new RewardCalculator(specProvider), transactionProcessor,
                                                               stateDb, codeDb, stateProvider, storageProvider, NullTxPool.Instance, NullReceiptStorage.Instance, LimboLogs.Instance);

            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(
                blockTree,
                blockProcessor,
                new TxSignaturesRecoveryStep(new EthereumEcdsa(specProvider, LimboLogs.Instance), NullTxPool.Instance, LimboLogs.Instance),
                LimboLogs.Instance,
                false);

            blockchainProcessor.Process(genesisBlock, ProcessingOptions.None, NullBlockTracer.Instance);
            blockchainProcessor.Process(block1, ProcessingOptions.None, NullBlockTracer.Instance);

            IBloomStorage bloomStorage = new BloomStorage(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory());

            BlockchainBridge bridge = new BlockchainBridge(
                stateReader,
                stateProvider,
                storageProvider,
                blockTree,
                NullTxPool.Instance,
                NullReceiptStorage.Instance,
                NullFilterStore.Instance,
                NullFilterManager.Instance,
                new DevWallet(new WalletConfig(), LimboLogs.Instance),
                transactionProcessor,
                new EthereumEcdsa(MainnetSpecProvider.Instance, LimboLogs.Instance),
                bloomStorage,
                LimboLogs.Instance,
                false);

            _ethModule = new EthModule(new JsonRpcConfig(), bridge, LimboLogs.Instance);
        }
Пример #8
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _txPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, new ReadOnlyBlockTree(_blockTree), _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _txPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _txPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor,
                _ethereumEcdsa);

            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, NullTxPool.Instance, NullReceiptStorage.Instance);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(_configProvider, debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_logManager, debugBridge);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealValidator is CliqueSealValidator)
            {
                CliqueModule cliqueModule = new CliqueModule(_logManager, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_ethereumEcdsa, _wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _logManager);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_logManager, _peerManager, _staticNodesManager);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_logManager, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            NetModule netModule = new NetModule(_logManager, new NetBridge(_enode, _syncServer, _peerManager));

            _rpcModuleProvider.Register <INetModule>(netModule);

            TraceModule traceModule = new TraceModule(blockchainBridge, _logManager, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
Пример #9
0
        public void GlobalSetup()
        {
            var dbProvider  = TestMemDbProvider.Init();
            IDb codeDb      = dbProvider.CodeDb;
            IDb stateDb     = dbProvider.StateDb;
            IDb blockInfoDb = new MemDb(10, 5);

            ISpecProvider specProvider = MainnetSpecProvider.Instance;
            IReleaseSpec  spec         = MainnetSpecProvider.Instance.GenesisSpec;
            var           trieStore    = new TrieStore(stateDb, LimboLogs.Instance);

            StateProvider stateProvider = new StateProvider(trieStore, codeDb, LimboLogs.Instance);

            stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            stateProvider.Commit(spec);

            StorageProvider storageProvider = new StorageProvider(trieStore, stateProvider, LimboLogs.Instance);
            StateReader     stateReader     = new StateReader(trieStore, codeDb, LimboLogs.Instance);

            ChainLevelInfoRepository chainLevelInfoRepository = new ChainLevelInfoRepository(blockInfoDb);
            BlockTree blockTree = new BlockTree(dbProvider, chainLevelInfoRepository, specProvider, NullBloomStorage.Instance, LimboLogs.Instance);

            _blockhashProvider = new BlockhashProvider(blockTree, LimboLogs.Instance);
            _virtualMachine    = new VirtualMachine(stateProvider, storageProvider, _blockhashProvider, specProvider, LimboLogs.Instance);

            Block genesisBlock = Build.A.Block.Genesis.TestObject;

            blockTree.SuggestBlock(genesisBlock);

            Block block1 = Build.A.Block.WithParent(genesisBlock).WithNumber(1).TestObject;

            blockTree.SuggestBlock(block1);

            TransactionProcessor transactionProcessor
                = new TransactionProcessor(MainnetSpecProvider.Instance, stateProvider, storageProvider, _virtualMachine, LimboLogs.Instance);

            BlockProcessor blockProcessor = new BlockProcessor(specProvider, Always.Valid, new RewardCalculator(specProvider), transactionProcessor,
                                                               stateProvider, storageProvider, NullTxPool.Instance, NullReceiptStorage.Instance, NullWitnessCollector.Instance, LimboLogs.Instance);

            EthereumEcdsa       ecdsa = new EthereumEcdsa(specProvider.ChainId, LimboLogs.Instance);
            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(
                blockTree,
                blockProcessor,
                new RecoverSignatures(
                    ecdsa,
                    NullTxPool.Instance,
                    specProvider,
                    LimboLogs.Instance),
                LimboLogs.Instance,
                BlockchainProcessor.Options.NoReceipts);

            blockchainProcessor.Process(genesisBlock, ProcessingOptions.None, NullBlockTracer.Instance);
            blockchainProcessor.Process(block1, ProcessingOptions.None, NullBlockTracer.Instance);

            IBloomStorage bloomStorage = new BloomStorage(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory());

            LogFinder logFinder = new LogFinder(
                blockTree,
                new InMemoryReceiptStorage(),
                bloomStorage,
                LimboLogs.Instance,
                new ReceiptsRecovery(ecdsa, specProvider));

            BlockchainBridge bridge = new BlockchainBridge(
                new ReadOnlyTxProcessingEnv(
                    new ReadOnlyDbProvider(dbProvider, false),
                    trieStore.AsReadOnly(),
                    new ReadOnlyBlockTree(blockTree),
                    specProvider,
                    LimboLogs.Instance),
                NullTxPool.Instance,
                NullReceiptStorage.Instance,
                NullFilterStore.Instance,
                NullFilterManager.Instance,
                ecdsa,
                Timestamper.Default,
                logFinder,
                false,
                false);

            _ethModule = new EthModule(
                new JsonRpcConfig(),
                bridge,
                blockTree,
                stateReader,
                NullTxPool.Instance,
                NullTxSender.Instance,
                NullWallet.Instance,
                LimboLogs.Instance);
        }
Пример #10
0
        private async Task InitBlockchain()
        {
            ChainSpec chainSpec = LoadChainSpec(_initConfig.ChainSpecPath);

            /* spec */
            // TODO: rebuild to use chainspec
            ISpecProvider specProvider;

            if (chainSpec.ChainId == RopstenSpecProvider.Instance.ChainId)
            {
                specProvider = RopstenSpecProvider.Instance;
            }
            else if (chainSpec.ChainId == MainNetSpecProvider.Instance.ChainId)
            {
                specProvider = MainNetSpecProvider.Instance;
            }
            else
            {
                throw new NotSupportedException($"Not yet tested, not yet supported ChainId {chainSpec.ChainId}");
            }

            var ethereumSigner = new EthereumSigner(
                specProvider,
                _logManager);

            var transactionStore = new TransactionStore();

            var sealEngine = ConfigureSealEngine(
                transactionStore,
                ethereumSigner);

            /* sync */
            IDbConfig dbConfig = _configProvider.GetConfig <IDbConfig>();

            foreach (PropertyInfo propertyInfo in typeof(IDbConfig).GetProperties())
            {
                _logger.Info($"DB {propertyInfo.Name}: {propertyInfo.GetValue(dbConfig)}");
            }

            var blocksDb = new DbOnTheRocks(
                Path.Combine(_dbBasePath, DbOnTheRocks.BlocksDbPath),
                dbConfig);

            var blockInfosDb = new DbOnTheRocks(
                Path.Combine(_dbBasePath, DbOnTheRocks.BlockInfosDbPath),
                dbConfig);

            var receiptsDb = new DbOnTheRocks(
                Path.Combine(_dbBasePath, DbOnTheRocks.ReceiptsDbPath),
                dbConfig);

            /* blockchain */
            _blockTree = new BlockTree(
                blocksDb,
                blockInfosDb,
                receiptsDb,
                specProvider,
                _logManager);

            var difficultyCalculator = new DifficultyCalculator(
                specProvider);

            /* validation */
            var headerValidator = new HeaderValidator(
                difficultyCalculator,
                _blockTree,
                sealEngine,
                specProvider,
                _logManager);

            var ommersValidator = new OmmersValidator(
                _blockTree,
                headerValidator,
                _logManager);

            var txValidator = new TransactionValidator(
                new SignatureValidator(specProvider.ChainId));

            var blockValidator = new BlockValidator(
                txValidator,
                headerValidator,
                ommersValidator,
                specProvider,
                _logManager);

            /* state */
            var dbProvider = new RocksDbProvider(
                _dbBasePath,
                _logManager,
                dbConfig);

            var stateDb = dbProvider.GetOrCreateStateDb();

            var stateTree = new StateTree(stateDb);

            var stateProvider = new StateProvider(
                stateTree,
                dbProvider.GetOrCreateCodeDb(),
                _logManager);

            var storageProvider = new StorageProvider(
                dbProvider,
                stateProvider,
                _logManager);

            /* blockchain processing */
            var blockhashProvider = new BlockhashProvider(
                _blockTree);

            var virtualMachine = new VirtualMachine(
                stateProvider,
                storageProvider,
                blockhashProvider,
                _logManager);

            var transactionProcessor = new TransactionProcessor(
                specProvider,
                stateProvider,
                storageProvider,
                virtualMachine,
                _tracer,
                _logManager);

            var rewardCalculator = new RewardCalculator(
                specProvider);

            var blockProcessor = new BlockProcessor(
                specProvider,
                blockValidator,
                rewardCalculator,
                transactionProcessor,
                dbProvider,
                stateProvider,
                storageProvider,
                transactionStore,
                _logManager);

            _blockchainProcessor = new BlockchainProcessor(
                _blockTree,
                sealEngine,
                transactionStore,
                difficultyCalculator,
                blockProcessor,
                ethereumSigner,
                _logManager, _perfService);

            // create shared objects between discovery and peer manager
            _nodeFactory       = new NodeFactory();
            _nodeStatsProvider = new NodeStatsProvider(_configProvider.GetConfig <IStatsConfig>(), _nodeFactory, _logManager);

            var jsonSerializer = new JsonSerializer(
                _logManager);

            var encrypter = new AesEncrypter(
                _configProvider,
                _logManager);

            _keyStore = new FileKeyStore(
                _configProvider,
                jsonSerializer,
                encrypter,
                _cryptoRandom,
                _logManager);

            //creating blockchain bridge
            BlockchainBridge = new BlockchainBridge(
                ethereumSigner,
                stateProvider,
                _keyStore,
                _blockTree,
                stateDb,
                transactionStore);

            EthereumSigner = ethereumSigner;

            _blockchainProcessor.Start();
            LoadGenesisBlock(chainSpec,
                             string.IsNullOrWhiteSpace(_initConfig.GenesisHash) ? null : new Keccak(_initConfig.GenesisHash),
                             _blockTree, stateProvider, specProvider);

#pragma warning disable 4014
            LoadBlocksFromDb();
#pragma warning restore 4014

            await InitializeNetwork(
                transactionStore,
                blockValidator,
                headerValidator,
                txValidator);
        }
Пример #11
0
        public INdmServices Init(NdmRequiredServices services)
        {
            AddDecoders();
            var config          = services.NdmConfig;
            var providerAddress = string.IsNullOrWhiteSpace(config.ProviderAddress)
                ? Address.Zero
                : new Address(config.ProviderAddress);
            var consumerAddress = string.IsNullOrWhiteSpace(config.ConsumerAddress)
                ? Address.Zero
                : new Address(config.ConsumerAddress);
            var contractAddress = string.IsNullOrWhiteSpace(config.ContractAddress)
                ? Address.Zero
                : new Address(config.ContractAddress);

            UnlockHardcodedAccounts(providerAddress, consumerAddress, services.Wallet);

            var logManager              = services.LogManager;
            var jsonSerializer          = services.JsonSerializer;
            var readOnlyTree            = new ReadOnlyBlockTree(services.BlockTree);
            var readOnlyDbProvider      = new ReadOnlyDbProvider(services.RocksProvider, false);
            var readOnlyTxProcessingEnv = new ReadOnlyTxProcessingEnv(readOnlyDbProvider, readOnlyTree,
                                                                      services.SpecProvider, logManager);
            var blockchainBridge = new BlockchainBridge(
                readOnlyTxProcessingEnv.StateReader,
                readOnlyTxProcessingEnv.StateProvider,
                readOnlyTxProcessingEnv.StorageProvider,
                readOnlyTxProcessingEnv.BlockTree,
                services.TransactionPool,
                services.ReceiptStorage,
                services.FilterStore,
                services.FilterManager,
                services.Wallet,
                readOnlyTxProcessingEnv.TransactionProcessor,
                services.Ecdsa);
            var dataAssetRlpDecoder = new DataAssetDecoder();
            var encoder             = new AbiEncoder();

            IEthJsonRpcClientProxy ethJsonRpcClientProxy = null;
            INdmBlockchainBridge   ndmBlockchainBridge;

            if (config.ProxyEnabled)
            {
                ethJsonRpcClientProxy = new EthJsonRpcClientProxy(new JsonRpcClientProxy(
                                                                      new DefaultHttpClient(new HttpClient(), jsonSerializer, logManager),
                                                                      config.JsonRpcUrlProxies));
                ndmBlockchainBridge = new NdmBlockchainBridgeProxy(ethJsonRpcClientProxy);
            }
            else
            {
                ndmBlockchainBridge = new NdmBlockchainBridge(blockchainBridge, services.TransactionPool);
            }

            var depositService = new DepositService(ndmBlockchainBridge, services.TransactionPool, encoder,
                                                    services.Wallet, contractAddress, logManager);
            var ndmConsumerChannelManager = services.NdmConsumerChannelManager;
            var ndmDataPublisher          = services.NdmDataPublisher;
            var jsonRpcNdmConsumerChannel = new JsonRpcNdmConsumerChannel();

//            ndmConsumerChannelManager.Add(jsonRpcNdmConsumerChannel);

            return(new Services(services, new NdmCreatedServices(consumerAddress, encoder, dataAssetRlpDecoder,
                                                                 depositService, ndmDataPublisher, jsonRpcNdmConsumerChannel, ndmConsumerChannelManager,
                                                                 ndmBlockchainBridge, ethJsonRpcClientProxy)));
        }