private static Transaction[] GenerateTxsForRefunds(IGrouping <Address, DepositDetails> depositGroup, DevKeyStoreWallet wallet) { Console.WriteLine(); Console.Write($"Provide nonce for {depositGroup.Key}: "); int nonce = int.Parse(Console.ReadLine()); Console.Write($"Provide address to send the refund to: "); string hexAddress = Console.ReadLine(); Address refundTo = new Address(hexAddress); SecureString securedPassword = ConsoleUtils.ReadSecret("Provide password: "******"Password has been accepted."); Console.WriteLine(); Console.WriteLine($"Great, will generate refund transactions for deposits of {depositGroup.Key} starting with nonce {nonce}. ETH/DAI will be sent to {refundTo}."); List <Transaction> transactions = new List <Transaction>(depositGroup.Count()); foreach (DepositDetails depositDetails in depositGroup) { Deposit deposit = depositDetails.Deposit; RefundClaim refundClaim = new RefundClaim(deposit.Id, depositDetails.DataAsset.Id, deposit.Units, deposit.Value, deposit.ExpiryTime, depositDetails.Pepper, depositDetails.DataAsset.Provider.Address, refundTo); UInt256 gasPrice = 20.GWei(); AbiEncoder abiEncoder = new AbiEncoder(); byte[] txData = abiEncoder.Encode(AbiEncodingStyle.IncludeSignature, ContractData.ClaimRefundSig, depositDetails.DataAsset.Id, refundClaim.Units, refundClaim.Value, refundClaim.ExpiryTime, refundClaim.Pepper, refundClaim.Provider, depositDetails.Consumer); Transaction transaction = new Transaction(); transaction.Value = 0; transaction.Data = txData; transaction.To = new Address("0xb1AD03b75bD9E5AB89968D7a37d99F9dd220796D"); transaction.SenderAddress = depositDetails.Consumer; transaction.GasLimit = 100000; transaction.GasPrice = gasPrice; transaction.Nonce = (UInt256)nonce++; wallet.Sign(transaction, ChainId.Mainnet); EthereumEcdsa ecdsa = new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance); Address recoveredAddress = ecdsa.RecoverAddress(transaction); if (recoveredAddress != transaction.SenderAddress) { Console.WriteLine("Signature failure"); return(new Transaction[0]); } transactions.Add(transaction); } return(transactions.ToArray()); } Console.WriteLine("Incorrect password."); return(new Transaction[0]); }
protected override BlockProcessor CreateBlockProcessor() { AbiEncoder abiEncoder = AbiEncoder.Instance; ReadOnlyTransactionProcessorSource = new ReadOnlyTxProcessingEnv( DbProvider, new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly(), BlockTree, SpecProvider, LimboLogs.Instance); RegisterContract = new RegisterContract(abiEncoder, ChainSpec.Parameters.Registrar, ReadOnlyTransactionProcessorSource); CertifierContract = new CertifierContract( abiEncoder, RegisterContract, ReadOnlyTransactionProcessorSource); return(new AuRaBlockProcessor( SpecProvider, Always.Valid, new RewardCalculator(SpecProvider), new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, Storage, ReceiptStorage, LimboLogs.Instance, BlockTree)); }
protected override void InitSealEngine() { if (_context.DbProvider == null) { throw new StepDependencyException(nameof(_context.DbProvider)); } if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.EthereumEcdsa == null) { throw new StepDependencyException(nameof(_context.EthereumEcdsa)); } if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } AbiEncoder abiEncoder = new AbiEncoder(); _context.ValidatorStore = new ValidatorStore(_context.DbProvider.BlockInfosDb); IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource = new ReadOnlyTransactionProcessorSource(_context.DbProvider, _context.BlockTree, _context.SpecProvider, _context.LogManager); IAuRaValidatorProcessorExtension validatorProcessorExtension = new AuRaValidatorProcessorFactory(_context.StateProvider, abiEncoder, _context.TransactionProcessor, readOnlyTransactionProcessorSource, _context.BlockTree, _context.ReceiptStorage, _context.ValidatorStore, _context.LogManager) .CreateValidatorProcessor(_context.ChainSpec.AuRa.Validators); AuRaStepCalculator auRaStepCalculator = new AuRaStepCalculator(_context.ChainSpec.AuRa.StepDuration, _context.Timestamper); _context.SealValidator = new AuRaSealValidator(_context.ChainSpec.AuRa, auRaStepCalculator, _context.ValidatorStore, _context.EthereumEcdsa, _context.LogManager); _context.RewardCalculatorSource = AuRaRewardCalculator.GetSource(_context.ChainSpec.AuRa, abiEncoder); _context.Sealer = new AuRaSealer(_context.BlockTree, _context.ValidatorStore, auRaStepCalculator, _context.NodeKey.Address, new BasicWallet(_context.NodeKey), new ValidSealerStrategy(), _context.LogManager); _context.AuRaBlockProcessorExtension = validatorProcessorExtension; }
/// <summary> /// Calls the function in contract, state modification is allowed. /// </summary> /// <param name="header">Header in which context the call is done.</param> /// <param name="function">Function in contract that is being called.</param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="arguments">Arguments to the function.</param> /// <returns>Deserialized return value of the <see cref="function"/> based on its definition.</returns> protected object[] Call(BlockHeader header, AbiFunctionDescription function, Address sender, params object[] arguments) { var transaction = GenerateTransaction <SystemTransaction>(function, sender, arguments); var result = Call(header, transaction); var objects = AbiEncoder.Decode(function.GetReturnInfo(), result); return(objects); }
public void Test(AbiTest abiTest) { AbiEncoder encoder = new AbiEncoder(); AbiSignature signature = new AbiSignature(abiTest.Name, abiTest.Types); byte[] encoded = encoder.Encode(signature, abiTest.Args).Slice(4); Assert.True(Bytes.AreEqual(abiTest.Result, encoded)); }
public UInt256?BlockGasLimit(BlockHeader parentHeader) { this.BlockActivationCheck(parentHeader); var function = Definition.GetFunction(nameof(BlockGasLimit)); var bytes = Constant.CallRaw(parentHeader, function, Address.Zero); return((bytes?.Length ?? 0) == 0 ? (UInt256?)null : (UInt256)AbiEncoder.Decode(function.GetReturnInfo(), bytes)[0]); }
/// <summary> /// Calls the function in contract, state modification is allowed. /// </summary> /// <param name="header">Header in which context the call is done.</param> /// <param name="functionName"></param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="gasLimit">Gas limit for generated transaction.</param> /// <param name="arguments">Arguments to the function.</param> /// <returns>Deserialized return value of the <see cref="functionName"/> based on its definition.</returns> protected object[] Call(BlockHeader header, string functionName, Address sender, long gasLimit, params object[] arguments) { var function = AbiDefinition.GetFunction(functionName); var transaction = GenerateTransaction <SystemTransaction>(functionName, sender, gasLimit, header, arguments); var result = Call(header, transaction); var objects = AbiEncoder.Decode(function.GetReturnInfo(), result); return(objects); }
public void SetUp() { _fileSystem = Substitute.For <IFileSystem>(); const string expectedFilePath = "contracts/MerkleTreeSHA.bin"; _fileSystem.File.ReadAllLinesAsync(expectedFilePath).Returns(File.ReadAllLines(expectedFilePath)); _abiEncoder = new AbiEncoder(); _baselineDb = new MemDb(); _metadataBaselineDb = new MemDb(); }
protected object[] DecodeData(AbiEncodingInfo abiEncodingInfo, byte[] data) { try { return(AbiEncoder.Decode(abiEncodingInfo, data)); } catch (Exception e) { throw new AbiException($"Cannot decode return data for function {abiEncodingInfo.Signature} for contract {ContractAddress}.", e); } }
/// <summary> /// Same as <see cref="Call(Nethermind.Core.BlockHeader,AbiFunctionDescription,Address,object[])"/> but returns false instead of throwing <see cref="AuRaException"/>. /// </summary> /// <param name="header">Header in which context the call is done.</param> /// <param name="function">Function in contract that is being called.</param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="result">Deserialized return value of the <see cref="function"/> based on its definition.</param> /// <param name="arguments">Arguments to the function.</param> /// <returns>true if function was <see cref="StatusCode.Success"/> otherwise false.</returns> protected bool TryCall(BlockHeader header, AbiFunctionDescription function, Address sender, out object[] result, params object[] arguments) { var transaction = GenerateTransaction <SystemTransaction>(function, sender, arguments); if (TryCall(header, transaction, out var bytes)) { result = AbiEncoder.Decode(function.GetReturnInfo(), bytes); return(true); } result = null; return(false); }
/// <summary> /// Same as <see cref="Call(Nethermind.Core.BlockHeader,AbiFunctionDescription,Address,object[])"/> but returns false instead of throwing <see cref="AbiException"/>. /// </summary> /// <param name="header">Header in which context the call is done.</param> /// <param name="functionName"></param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="gasLimit">Gas limit for generated transaction.</param> /// <param name="result">Deserialized return value of the <see cref="functionName"/> based on its definition.</param> /// <param name="arguments">Arguments to the function.</param> /// <returns>true if function was <see cref="StatusCode.Success"/> otherwise false.</returns> protected bool TryCall(BlockHeader header, string functionName, Address sender, long gasLimit, out object[] result, params object[] arguments) { var function = AbiDefinition.GetFunction(functionName); var transaction = GenerateTransaction <SystemTransaction>(functionName, sender, gasLimit, header, arguments); if (TryCall(header, transaction, out var bytes)) { result = AbiEncoder.Decode(function.GetReturnInfo(), bytes); return(true); } result = null; return(false); }
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 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(); var depositService = new DepositService(blockchainBridge, 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, blockchainBridge))); }
public static IServices Init(RequiredServices 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); UnlockHardcodedAccounts(providerAddress, consumerAddress, services.Wallet); var readOnlyDbProvider = new ReadOnlyDbProvider(services.RocksProvider, false); var filterStore = new FilterStore(); var filterManager = new FilterManager(filterStore, services.BlockProcessor, services.TransactionPool, services.LogManager); var state = new RpcState(services.BlockTree, services.SpecProvider, readOnlyDbProvider, services.LogManager); var blockchainBridge = new BlockchainBridge( state.StateReader, state.StateProvider, state.StorageProvider, state.BlockTree, services.TransactionPool, services.TransactionPoolInfoProvider, services.ReceiptStorage, filterStore, filterManager, services.Wallet, state.TransactionProcessor, services.Ecdsa); var dataHeaderRlpDecoder = new DataHeaderDecoder(); var encoder = new AbiEncoder(); var depositService = new DepositService(blockchainBridge, encoder, services.Wallet, config, LimboLogs.Instance); var ndmConsumerChannelManager = services.NdmConsumerChannelManager; var ndmDataPublisher = services.NdmDataPublisher; var jsonRpcNdmConsumerChannel = new JsonRpcNdmConsumerChannel(); // ndmConsumerChannelManager.Add(jsonRpcNdmConsumerChannel); return(new Services(services, new CreatedServices(consumerAddress, encoder, dataHeaderRlpDecoder, depositService, ndmDataPublisher, jsonRpcNdmConsumerChannel, ndmConsumerChannelManager, blockchainBridge))); }
public void Test_abi_encoding() { string text = string.Empty; string[] potentialLocations = new string[] { Path.Combine(TestContext.CurrentContext.TestDirectory, "basic_abi_tests.json"), Path.Combine(TestContext.CurrentContext.WorkDirectory, "basic_abi_tests.json"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory ?? string.Empty, "basic_abi_tests.json"), Path.Combine(AppDomain.CurrentDomain.DynamicDirectory ?? string.Empty, "basic_abi_tests.json"), }; foreach (string potentialLocation in potentialLocations) { try { text = File.ReadAllText(potentialLocation); break; } catch (IOException) { TestContext.WriteLine($"Could not find test in {potentialLocation}"); } } Dictionary <string, AbiTest> tests = JsonConvert.DeserializeObject <Dictionary <string, AbiTest> >(text); foreach ((string testName, AbiTest abiTest) in tests) { AbiSignature signature = new AbiSignature( testName, abiTest.Types.Select(t => _abiTypes[t]).ToArray()); AbiEncoder encoder = new AbiEncoder(); byte[] abi = encoder.Encode(AbiEncodingStyle.None, signature, abiTest.Args.Select(JsonToObject).ToArray()); abi.Should().BeEquivalentTo(Bytes.FromHexString(abiTest.Result)); } }
protected override BlockProcessor CreateBlockProcessor() { AbiEncoder abiEncoder = new AbiEncoder(); ReadOnlyTxProcessorSource readOnlyTransactionProcessorSource = new ReadOnlyTxProcessorSource(DbProvider, BlockTree, SpecProvider, LimboLogs.Instance); CertifierContract = new CertifierContract( abiEncoder, new RegisterContract(abiEncoder, ChainSpec.Parameters.Registrar, readOnlyTransactionProcessorSource), readOnlyTransactionProcessorSource); return(new AuRaBlockProcessor( SpecProvider, Always.Valid, new RewardCalculator(SpecProvider), TxProcessor, StateDb, CodeDb, State, Storage, TxPool, ReceiptStorage, LimboLogs.Instance, BlockTree)); }
private void InitSealEngine(IList <IAdditionalBlockProcessor> blockPreProcessors) { switch (_chainSpec.SealEngineType) { case SealEngineType.None: _sealer = NullSealEngine.Instance; _sealValidator = NullSealEngine.Instance; _rewardCalculator = NoBlockRewards.Instance; break; case SealEngineType.Clique: _rewardCalculator = NoBlockRewards.Instance; CliqueConfig cliqueConfig = new CliqueConfig(); cliqueConfig.BlockPeriod = _chainSpec.Clique.Period; cliqueConfig.Epoch = _chainSpec.Clique.Epoch; _snapshotManager = new SnapshotManager(cliqueConfig, _dbProvider.BlocksDb, _blockTree, _ethereumEcdsa, _logManager); _sealValidator = new CliqueSealValidator(cliqueConfig, _snapshotManager, _logManager); _recoveryStep = new CompositeDataRecoveryStep(_recoveryStep, new AuthorRecoveryStep(_snapshotManager)); if (_initConfig.IsMining) { _sealer = new CliqueSealer(new BasicWallet(_nodeKey), cliqueConfig, _snapshotManager, _nodeKey.Address, _logManager); } else { _sealer = NullSealEngine.Instance; } break; case SealEngineType.NethDev: _sealer = NullSealEngine.Instance; _sealValidator = NullSealEngine.Instance; _rewardCalculator = NoBlockRewards.Instance; break; case SealEngineType.Ethash: _rewardCalculator = new RewardCalculator(_specProvider); var difficultyCalculator = new DifficultyCalculator(_specProvider); if (_initConfig.IsMining) { _sealer = new EthashSealer(new Ethash(_logManager), _logManager); } else { _sealer = NullSealEngine.Instance; } _sealValidator = new EthashSealValidator(_logManager, difficultyCalculator, new Ethash(_logManager)); break; case SealEngineType.AuRa: var abiEncoder = new AbiEncoder(); var validatorProcessor = new AuRaAdditionalBlockProcessorFactory(_stateProvider, abiEncoder, _transactionProcessor, _logManager) .CreateValidatorProcessor(_chainSpec.AuRa.Validators); _sealer = new AuRaSealer(); _sealValidator = new AuRaSealValidator(validatorProcessor, _ethereumEcdsa, _logManager); _rewardCalculator = new AuRaRewardCalculator(_chainSpec.AuRa, abiEncoder, _transactionProcessor); blockPreProcessors.Add(validatorProcessor); break; default: throw new NotSupportedException($"Seal engine type {_chainSpec.SealEngineType} is not supported in Nethermind"); } }
private static async Task RunBenchmarkBlocks() { Rlp.RegisterDecoders(typeof(ParityTraceDecoder).Assembly); /* logging & instrumentation */ _logManager = new NLogManager("perfTest.logs.txt", null); _logger = _logManager.GetClassLogger(); if (_logger.IsInfo) { _logger.Info("Deleting state DBs"); } DeleteDb(FullStateDbPath); DeleteDb(FullCodeDbPath); DeleteDb(FullReceiptsDbPath); DeleteDb(FullPendingTxsDbPath); if (_logger.IsInfo) { _logger.Info("State DBs deleted"); } /* load spec */ ChainSpecLoader loader = new ChainSpecLoader(new EthereumJsonSerializer()); string path = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"chainspec", "ropsten.json")); _logger.Info($"Loading ChainSpec from {path}"); ChainSpec chainSpec = loader.Load(File.ReadAllText(path)); _logger.Info($"ChainSpec loaded"); var specProvider = new ChainSpecBasedSpecProvider(chainSpec); IRewardCalculator rewardCalculator = new RewardCalculator(specProvider); var dbProvider = new RocksDbProvider(DbBasePath, DbConfig.Default, _logManager, true, true); var stateDb = dbProvider.StateDb; var codeDb = dbProvider.CodeDb; var traceDb = dbProvider.TraceDb; var blocksDb = dbProvider.BlocksDb; var headersDb = dbProvider.HeadersDb; var blockInfosDb = dbProvider.BlockInfosDb; var receiptsDb = dbProvider.ReceiptsDb; /* state & storage */ var stateProvider = new StateProvider(stateDb, codeDb, _logManager); var storageProvider = new StorageProvider(stateDb, stateProvider, _logManager); var ethereumSigner = new EthereumEcdsa(specProvider, _logManager); var transactionPool = new TxPool( NullTxStorage.Instance, Timestamper.Default, ethereumSigner, specProvider, new TxPoolConfig(), stateProvider, _logManager); var blockInfoRepository = new ChainLevelInfoRepository(blockInfosDb); var blockTree = new UnprocessedBlockTreeWrapper(new BlockTree(blocksDb, headersDb, blockInfosDb, blockInfoRepository, specProvider, transactionPool, _logManager)); var receiptStorage = new InMemoryReceiptStorage(); IBlockDataRecoveryStep recoveryStep = new TxSignaturesRecoveryStep(ethereumSigner, transactionPool, _logManager); /* blockchain processing */ IList <IAdditionalBlockProcessor> blockProcessors = new List <IAdditionalBlockProcessor>(); var blockhashProvider = new BlockhashProvider(blockTree, LimboLogs.Instance); var virtualMachine = new VirtualMachine(stateProvider, storageProvider, blockhashProvider, specProvider, _logManager); var processor = new TransactionProcessor(specProvider, stateProvider, storageProvider, virtualMachine, _logManager); ISealValidator sealValidator; if (specProvider.ChainId == RopstenSpecProvider.Instance.ChainId) { var difficultyCalculator = new DifficultyCalculator(specProvider); sealValidator = new EthashSealValidator(_logManager, difficultyCalculator, new Ethash(_logManager)); } else if (chainSpec.SealEngineType == SealEngineType.Clique) { var snapshotManager = new SnapshotManager(CliqueConfig.Default, blocksDb, blockTree, ethereumSigner, _logManager); sealValidator = new CliqueSealValidator(CliqueConfig.Default, snapshotManager, _logManager); rewardCalculator = NoBlockRewards.Instance; recoveryStep = new CompositeDataRecoveryStep(recoveryStep, new AuthorRecoveryStep(snapshotManager)); } else if (chainSpec.SealEngineType == SealEngineType.AuRa) { var abiEncoder = new AbiEncoder(); var validatorProcessor = new AuRaAdditionalBlockProcessorFactory(dbProvider.StateDb, stateProvider, abiEncoder, processor, blockTree, receiptStorage, _logManager) .CreateValidatorProcessor(chainSpec.AuRa.Validators); sealValidator = new AuRaSealValidator(chainSpec.AuRa, new AuRaStepCalculator(chainSpec.AuRa.StepDuration, new Timestamper()), validatorProcessor, ethereumSigner, _logManager); rewardCalculator = new AuRaRewardCalculator(chainSpec.AuRa, abiEncoder, processor); blockProcessors.Add(validatorProcessor); } else { throw new NotSupportedException(); } /* store & validation */ var headerValidator = new HeaderValidator(blockTree, sealValidator, specProvider, _logManager); var ommersValidator = new OmmersValidator(blockTree, headerValidator, _logManager); var transactionValidator = new TxValidator(chainSpec.ChainId); var blockValidator = new BlockValidator(transactionValidator, headerValidator, ommersValidator, specProvider, _logManager); /* blockchain processing */ var blockProcessor = new BlockProcessor(specProvider, blockValidator, rewardCalculator, processor, stateDb, codeDb, traceDb, stateProvider, storageProvider, transactionPool, receiptStorage, _logManager, blockProcessors); var blockchainProcessor = new BlockchainProcessor(blockTree, blockProcessor, recoveryStep, _logManager, true, false); if (chainSpec.SealEngineType == SealEngineType.AuRa) { stateProvider.CreateAccount(Address.Zero, UInt256.Zero); storageProvider.Commit(); stateProvider.Commit(Homestead.Instance); var finalizationManager = new AuRaBlockFinalizationManager(blockTree, blockInfoRepository, blockProcessor, blockProcessors.OfType <IAuRaValidator>().First(), _logManager); } foreach ((Address address, ChainSpecAllocation allocation) in chainSpec.Allocations) { stateProvider.CreateAccount(address, allocation.Balance); if (allocation.Code != null) { Keccak codeHash = stateProvider.UpdateCode(allocation.Code); stateProvider.UpdateCodeHash(address, codeHash, specProvider.GenesisSpec); } if (allocation.Constructor != null) { Transaction constructorTransaction = new Transaction(true) { SenderAddress = address, Init = allocation.Constructor, GasLimit = chainSpec.Genesis.GasLimit }; processor.Execute(constructorTransaction, chainSpec.Genesis.Header, NullTxTracer.Instance); } } _logger.Info($"Allocations configured, committing..."); stateProvider.Commit(specProvider.GenesisSpec); _logger.Info($"Finalizing genesis..."); chainSpec.Genesis.Header.StateRoot = stateProvider.StateRoot; chainSpec.Genesis.Header.Hash = BlockHeader.CalculateHash(chainSpec.Genesis.Header); if (chainSpec.Genesis.Hash != blockTree.Genesis.Hash) { throw new Exception("Unexpected genesis hash"); } _logger.Info($"Starting benchmark processor..."); /* start processing */ BigInteger totalGas = BigInteger.Zero; Stopwatch stopwatch = new Stopwatch(); Block currentHead; long maxMemory = 0; blockTree.NewHeadBlock += (sender, args) => { currentHead = args.Block; if (currentHead.Number == 0) { return; } maxMemory = Math.Max(maxMemory, GC.GetTotalMemory(false)); totalGas += currentHead.GasUsed; if ((BigInteger)args.Block.Number % 10000 == 9999) { stopwatch.Stop(); long ms = 1_000L * stopwatch.ElapsedTicks / Stopwatch.Frequency; BigInteger number = args.Block.Number + 1; _logger.Warn($"TOTAL after {number} (ms) : " + ms); _logger.Warn($"TOTAL after {number} blocks/s : {(decimal) currentHead.Number / (ms / 1000m),5}"); _logger.Warn($"TOTAL after {number} Mgas/s : {((decimal) totalGas / 1000000) / (ms / 1000m),5}"); _logger.Warn($"TOTAL after {number} max mem : {maxMemory}"); _logger.Warn($"TOTAL after {number} GC (0/1/2) : {GC.CollectionCount(0)}/{GC.CollectionCount(1)}/{GC.CollectionCount(2)}"); _logger.Warn($"Is server GC {number} : {System.Runtime.GCSettings.IsServerGC}"); _logger.Warn($"GC latency mode {number} : {System.Runtime.GCSettings.LatencyMode}"); _logger.Warn($"TOTAL after {number} blocks DB reads : {Store.Metrics.BlocksDbReads}"); _logger.Warn($"TOTAL after {number} blocks DB writes : {Store.Metrics.BlocksDbWrites}"); _logger.Warn($"TOTAL after {number} infos DB reads : {Store.Metrics.BlockInfosDbReads}"); _logger.Warn($"TOTAL after {number} infos DB writes : {Store.Metrics.BlockInfosDbWrites}"); _logger.Warn($"TOTAL after {number} state tree reads : {Store.Metrics.StateTreeReads}"); _logger.Warn($"TOTAL after {number} state tree writes : {Store.Metrics.StateTreeWrites}"); _logger.Warn($"TOTAL after {number} state DB reads : {Store.Metrics.StateDbReads}"); _logger.Warn($"TOTAL after {number} state DB writes : {Store.Metrics.StateDbWrites}"); _logger.Warn($"TOTAL after {number} storage tree reads : {Store.Metrics.StorageTreeReads}"); _logger.Warn($"TOTAL after {number} storage tree writes : {Store.Metrics.StorageTreeWrites}"); _logger.Warn($"TOTAL after {number} tree node hash : {Store.Metrics.TreeNodeHashCalculations}"); _logger.Warn($"TOTAL after {number} tree node RLP decode : {Store.Metrics.TreeNodeRlpDecodings}"); _logger.Warn($"TOTAL after {number} tree node RLP encode : {Store.Metrics.TreeNodeRlpEncodings}"); _logger.Warn($"TOTAL after {number} code DB reads : {Store.Metrics.CodeDbReads}"); _logger.Warn($"TOTAL after {number} code DB writes : {Store.Metrics.CodeDbWrites}"); _logger.Warn($"TOTAL after {number} receipts DB reads : {Store.Metrics.ReceiptsDbReads}"); _logger.Warn($"TOTAL after {number} receipts DB writes : {Store.Metrics.ReceiptsDbWrites}"); _logger.Warn($"TOTAL after {number} other DB reads : {Store.Metrics.OtherDbReads}"); _logger.Warn($"TOTAL after {number} other DB writes : {Store.Metrics.OtherDbWrites}"); _logger.Warn($"TOTAL after {number} EVM exceptions : {Evm.Metrics.EvmExceptions}"); _logger.Warn($"TOTAL after {number} SLOAD opcodes : {Evm.Metrics.SloadOpcode}"); _logger.Warn($"TOTAL after {number} SSTORE opcodes : {Evm.Metrics.SstoreOpcode}"); _logger.Warn($"TOTAL after {number} EXP opcodes : {Evm.Metrics.ModExpOpcode}"); _logger.Warn($"TOTAL after {number} BLOCKHASH opcodes : {Evm.Metrics.BlockhashOpcode}"); _logger.Warn($"TOTAL after {number} EVM calls : {Evm.Metrics.Calls}"); _logger.Warn($"TOTAL after {number} RIPEMD Precompiles : {Evm.Metrics.Ripemd160Precompile}"); _logger.Warn($"TOTAL after {number} SHA256 Precompiles : {Evm.Metrics.Sha256Precompile}"); // disk space stopwatch.Start(); } }; bool isStarted = false; TaskCompletionSource <object> completionSource = new TaskCompletionSource <object>(); blockTree.NewBestSuggestedBlock += (sender, args) => { if (!isStarted) { blockchainProcessor.Process(blockTree.FindBlock(blockTree.Genesis.Hash, BlockTreeLookupOptions.RequireCanonical), ProcessingOptions.None, NullBlockTracer.Instance); stopwatch.Start(); blockchainProcessor.Start(); isStarted = true; } if (args.Block.Number == BlocksToLoad) { completionSource.SetResult(null); } }; await Task.WhenAny(completionSource.Task, blockTree.LoadBlocksFromDb(CancellationToken.None, 0, 10000, BlocksToLoad)); await blockchainProcessor.StopAsync(true).ContinueWith( t => { if (t.IsFaulted) { _logger.Error("processing failed", t.Exception); _logger.Error("inner", t.Exception.InnerException); Console.ReadLine(); } _logger.Info("Block processing completed."); }); stopwatch.Stop(); Console.ReadLine(); }
/// <summary> /// Generates transaction. /// That transaction can be added to a produced block or broadcasted - if <see cref="GeneratedTransaction"/> is used as <see cref="T"/>. /// That transaction can be used in <see cref="CallableContract.Call(Nethermind.Core.BlockHeader,Nethermind.Core.Transaction)"/> if <see cref="SystemTransaction"/> is used as <see cref="T"/>. /// </summary> /// <param name="functionName">Function in contract that is called by the transaction.</param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="gasLimit">Gas limit for generated transaction.</param> /// <param name="contractAddress">address of the contract</param> /// <param name="arguments">Arguments to the function.</param> /// <typeparam name="T">Type of <see cref="Transaction"/>.</typeparam> /// <returns>Transaction.</returns> protected Transaction GenerateTransaction <T>(string functionName, Address sender, long gasLimit, Address contractAddress, params object[] arguments) where T : Transaction, new() => GenerateTransaction <T>(AbiEncoder.Encode(AbiDefinition.GetFunction(functionName).GetCallInfo(), arguments), sender, contractAddress, gasLimit);
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 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))); }
protected object[] DecodeData(AbiEncodingInfo abiEncodingInfo, byte[] data) => AbiEncoder.Decode(abiEncodingInfo, data);
protected object[] DecodeReturnData(string functionName, byte[] data) { return(AbiEncoder.Decode(AbiDefinition.GetFunction(functionName).GetReturnInfo(), data)); }
/// <summary> /// Generates transaction. /// That transaction can be added to a produced block or broadcasted - if <see cref="GeneratedTransaction"/> is used as <see cref="T"/>. /// That transaction can be used in <see cref="Call(Nethermind.Core.BlockHeader,Nethermind.Core.Transaction)"/> if <see cref="SystemTransaction"/> is used as <see cref="T"/>. /// </summary> /// <param name="function">Function in contract that is called by the transaction.</param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="arguments">Arguments to the function.</param> /// <typeparam name="T">Type of <see cref="Transaction"/>.</typeparam> /// <returns>Transaction.</returns> protected Transaction GenerateTransaction <T>(AbiFunctionDescription function, Address sender, params object[] arguments) where T : Transaction, new() => GenerateTransaction <T>(AbiEncoder.Encode(function.GetCallInfo(), arguments), sender);