Exemplo n.º 1
0
        public void Throws_on_theoretical_contract_crash()
        {
            var contractAddress = Address.OfContract(_senderPublicKey.ToKvmAddress(), 0);

            _stateProvider.CreateAccount(contractAddress, 1000.Kat());
            var codeHash = _stateProvider.UpdateCode(Bytes.FromHexString("0x01"));

            _stateProvider.UpdateCodeHash(contractAddress, codeHash, _specProvider.GenesisSpec);
            _stateProvider.Commit(_specProvider.GenesisSpec);

            var delta = EntryUtils.PrepareSingleContractEntryDelta(null, _senderPublicKey, 0,
                                                                   "0x60016000526001601FF300");

            delta.PublicEntries[0].GasLimit        = 1_000_000L;
            delta.PublicEntries[0].ReceiverAddress = ByteString.Empty;
            delta.PublicEntries[0].Signature       = delta.PublicEntries[0]
                                                     .GenerateSignature(_cryptoContext, _senderPrivateKey, _signingContext);

            var tracer = Substitute.For <ITxTracer>();

            tracer.IsTracingReceipt.Returns(true);

            _executor.Execute(delta, tracer);

            tracer.Received().MarkAsFailed(contractAddress, 1_000_000L, Arg.Any <byte[]>(), null);
        }
Exemplo n.º 2
0
        public void Empty_commit_restore()
        {
            StateProvider provider = new StateProvider(new TrieStore(new MemDb(), Logger), _codeDb, Logger);

            provider.Commit(Frontier.Instance);
            provider.Restore(-1);
        }
Exemplo n.º 3
0
 private void AddAccount(StateProvider stateProvider, Address account, UInt256 initialBalance)
 {
     stateProvider.CreateAccount(account, initialBalance);
     stateProvider.Commit(MuirGlacier.Instance, null);
     stateProvider.CommitTree();
     _dbProvider.StateDb.Commit();
 }
Exemplo n.º 4
0
        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, 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, AlwaysValidBlockValidator.Instance, new RewardCalculator(specProvider), transactionProcessor,
                                                               stateDb, codeDb, new MemDb(), 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,
                false);

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

            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));

            _ethModule = new EthModule(LimboLogs.Instance, bridge);
        }
Exemplo n.º 5
0
        public void GlobalSetup()
        {
            ByteCode = Bytes.FromHexString(Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE") ?? string.Empty);
            Console.WriteLine($"Running benchmark for bytecode {ByteCode?.ToHexString()}");

            TrieStore      trieStore = new(new MemDb(), new OneLoggerLogManager(NullLogger.Instance));
            IKeyValueStore codeDb    = new MemDb();

            _stateProvider = new StateProvider(trieStore, codeDb, new OneLoggerLogManager(NullLogger.Instance));
            _stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            _stateProvider.Commit(_spec);

            _storageProvider = new StorageProvider(trieStore, _stateProvider, new OneLoggerLogManager(NullLogger.Instance));

            _worldState = new WorldState(_stateProvider, _storageProvider);

            _virtualMachine = new VirtualMachine(_blockhashProvider, MainnetSpecProvider.Instance, LimboLogs.Instance);

            _environment = new ExecutionEnvironment
            {
                ExecutingAccount   = Address.Zero,
                CodeSource         = Address.Zero,
                Caller             = Address.Zero,
                CodeInfo           = new CodeInfo(ByteCode),
                Value              = 0,
                TransferValue      = 0,
                TxExecutionContext = new TxExecutionContext(_header, Address.Zero, 0)
            };

            _evmState = new EvmState(long.MaxValue, _environment, ExecutionType.Transaction, true, _worldState.TakeSnapshot(), false);
        }
Exemplo n.º 6
0
        private static void InitializeTestState(GeneralStateTest test, StateProvider stateProvider,
                                                IStorageProvider storageProvider, ISpecProvider specProvider)
        {
            foreach (KeyValuePair <Address, AccountState> accountState in test.Pre)
            {
                foreach (KeyValuePair <UInt256, byte[]> storageItem in accountState.Value.Storage)
                {
                    storageProvider.Set(new StorageCell(accountState.Key, storageItem.Key),
                                        storageItem.Value.WithoutLeadingZeros().ToArray());
                }

                stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance);
                Keccak codeHash = stateProvider.UpdateCode(accountState.Value.Code);
                stateProvider.UpdateCodeHash(accountState.Key, codeHash, specProvider.GenesisSpec);
                stateProvider.SetNonce(accountState.Key, accountState.Value.Nonce);
            }

            storageProvider.Commit();
            stateProvider.Commit(specProvider.GenesisSpec);

            storageProvider.CommitTrees(0);
            stateProvider.CommitTree(0);

            storageProvider.Reset();
            stateProvider.Reset();
        }
Exemplo n.º 7
0
        public void GlobalSetup()
        {
            ByteCode = Bytes.FromHexString(Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE"));
            Console.WriteLine($"Running benchmark for bytecode {ByteCode?.ToHexString()}");
            IDb             codeDb  = new StateDb();
            ISnapshotableDb stateDb = new StateDb();

            _stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance);
            _stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            _stateProvider.Commit(_spec);

            _storageProvider = new StorageProvider(stateDb, _stateProvider, LimboLogs.Instance);
            _virtualMachine  = new VirtualMachine(_stateProvider, _storageProvider, _blockhashProvider, MainnetSpecProvider.Instance, LimboLogs.Instance);

            _environment = new ExecutionEnvironment();
            _environment.ExecutingAccount = Address.Zero;
            _environment.CodeSource       = Address.Zero;
            _environment.Originator       = Address.Zero;
            _environment.Sender           = Address.Zero;
            _environment.CodeInfo         = new CodeInfo(ByteCode);
            _environment.GasPrice         = 0;
            _environment.Value            = 0;
            _environment.TransferValue    = 0;
            _environment.CurrentBlock     = _header;

            _evmState = new EvmState(long.MaxValue, _environment, ExecutionType.Transaction, false, true, false);
        }
Exemplo n.º 8
0
        public void Non_existing()
        {
            StorageCell  storageCell = new StorageCell(_address1, UInt256.One);
            IReleaseSpec spec        = MuirGlacier.Instance;

            MemDb           stateDb         = new MemDb();
            TrieStore       trieStore       = new TrieStore(stateDb, Logger);
            StateProvider   provider        = new StateProvider(trieStore, new MemDb(), Logger);
            StorageProvider storageProvider = new StorageProvider(trieStore, provider, Logger);

            void CommitEverything()
            {
                storageProvider.Commit();
                storageProvider.CommitTrees(0);
                provider.Commit(spec);
                provider.CommitTree(0);
            }

            provider.CreateAccount(_address1, 1);
            storageProvider.Set(storageCell, new byte[] { 1 });
            CommitEverything();
            Keccak stateRoot0 = provider.StateRoot;

            StateReader reader =
                new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger);
            Keccak storageRoot = reader.GetStorageRoot(stateRoot0, _address1);

            reader.GetStorage(storageRoot, storageCell.Index + 1).Should().BeEquivalentTo(new byte[] { 0 });
            reader.GetStorage(Keccak.EmptyTreeHash, storageCell.Index + 1).Should().BeEquivalentTo(new byte[] { 0 });
        }
Exemplo n.º 9
0
        /**
         * @TODO this should extend file system based tests and resolve tests via autofac container
         */
        public DeltaExecutorTests()
        {
            _specProvider  = new CatalystSpecProvider();
            _stateProvider = new StateProvider(new StateDb(), new StateDb(), LimboLogs.Instance);
            var  storageProvider = new StorageProvider(new StateDb(), _stateProvider, LimboLogs.Instance);
            IKvm virtualMachine  = new KatVirtualMachine(_stateProvider, storageProvider, new StateUpdateHashProvider(),
                                                         _specProvider, LimboLogs.Instance);
            var logger = Substitute.For <ILogger>();

            logger.IsEnabled(Arg.Any <LogEventLevel>()).Returns(true);

            _senderPrivateKey = _cryptoContext.GeneratePrivateKey();
            _senderPublicKey  = _senderPrivateKey.GetPublicKey();

            _recipient  = _cryptoContext.GeneratePrivateKey().GetPublicKey();
            _poorSender = _cryptoContext.GeneratePrivateKey().GetPublicKey();

            _stateProvider.CreateAccount(_poorSender.ToKvmAddress(), 0.Kat());
            _stateProvider.CreateAccount(_senderPublicKey.ToKvmAddress(), 1000.Kat());
            _stateProvider.CreateAccount(Address.Zero, 1000.Kat());
            _stateProvider.Commit(_specProvider.GenesisSpec);

            _executor = new DeltaExecutor(_specProvider, _stateProvider, storageProvider, virtualMachine,
                                          new FfiWrapper(), logger);

            _signingContext = new SigningContext
            {
                NetworkType   = NetworkType.Devnet,
                SignatureType = SignatureType.TransactionPublic
            };
        }
Exemplo n.º 10
0
        private void AddCode(StateProvider stateProvider, Address account, byte[] code)
        {
            Keccak codeHash = stateProvider.UpdateCode(code);
            stateProvider.UpdateCodeHash(account, codeHash, MuirGlacier.Instance);

            stateProvider.Commit(MainnetSpecProvider.Instance.GenesisSpec, NullStateTracer.Instance);
        }
Exemplo n.º 11
0
        public async Task Can_ask_about_storage_in_parallel()
        {
            StorageCell     storageCell     = new StorageCell(_address1, UInt256.One);
            IReleaseSpec    spec            = MuirGlacier.Instance;
            MemDb           stateDb         = new MemDb();
            TrieStore       trieStore       = new TrieStore(stateDb, Logger);
            StateProvider   provider        = new StateProvider(trieStore, new MemDb(), Logger);
            StorageProvider storageProvider = new StorageProvider(trieStore, provider, Logger);

            void UpdateStorageValue(byte[] newValue)
            {
                storageProvider.Set(storageCell, newValue);
            }

            void AddOneToBalance()
            {
                provider.AddToBalance(_address1, 1, spec);
            }

            void CommitEverything()
            {
                storageProvider.Commit();
                storageProvider.CommitTrees(0);
                provider.Commit(spec);
                provider.CommitTree(0);
            }

            provider.CreateAccount(_address1, 1);
            CommitEverything();

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 1 });
            CommitEverything();
            Keccak stateRoot0 = provider.StateRoot;

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 2 });
            CommitEverything();
            Keccak stateRoot1 = provider.StateRoot;

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 3 });
            CommitEverything();
            Keccak stateRoot2 = provider.StateRoot;

            AddOneToBalance();
            UpdateStorageValue(new byte[] { 4 });
            CommitEverything();
            Keccak stateRoot3 = provider.StateRoot;

            StateReader reader =
                new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger);

            Task a = StartStorageTask(reader, stateRoot0, storageCell, new byte[] { 1 });
            Task b = StartStorageTask(reader, stateRoot1, storageCell, new byte[] { 2 });
            Task c = StartStorageTask(reader, stateRoot2, storageCell, new byte[] { 3 });
            Task d = StartStorageTask(reader, stateRoot3, storageCell, new byte[] { 4 });

            await Task.WhenAll(a, b, c, d);
        }
Exemplo n.º 12
0
        public void Empty_commit_restore()
        {
            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.Commit(Frontier.Instance);
            provider.Restore(-1);
        }
        public void GlobalSetup()
        {
            TrieStore      trieStore = new(new MemDb(), new OneLoggerLogManager(NullLogger.Instance));
            IKeyValueStore codeDb    = new MemDb();

            _stateProvider = new StateProvider(trieStore, codeDb, new OneLoggerLogManager(NullLogger.Instance));
            _stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            _stateProvider.Commit(_spec);

            _storageProvider = new StorageProvider(trieStore, _stateProvider, new OneLoggerLogManager(NullLogger.Instance));

            _worldState = new WorldState(_stateProvider, _storageProvider);
            Console.WriteLine(MuirGlacier.Instance);
            _virtualMachine = new VirtualMachine(_blockhashProvider, MainnetSpecProvider.Instance, new OneLoggerLogManager(NullLogger.Instance));

            _environment = new ExecutionEnvironment
            {
                ExecutingAccount   = Address.Zero,
                CodeSource         = Address.Zero,
                Caller             = Address.Zero,
                CodeInfo           = new CodeInfo(Bytecode),
                Value              = 0,
                TransferValue      = 0,
                TxExecutionContext = new TxExecutionContext(_header, Address.Zero, 0)
            };

            _evmState = new EvmState(100_000_000L, _environment, ExecutionType.Transaction, true, _worldState.TakeSnapshot(), false);
        }
Exemplo n.º 14
0
        public void Is_empty_account()
        {
            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(_address1, 0);
            provider.Commit(Frontier.Instance);
            Assert.True(provider.IsEmptyAccount(_address1));
        }
Exemplo n.º 15
0
        public void Is_empty_account()
        {
            StateProvider provider = new StateProvider(new TrieStore(new MemDb(), Logger), _codeDb, Logger);

            provider.CreateAccount(_address1, 0);
            provider.Commit(Frontier.Instance);
            Assert.True(provider.IsEmptyAccount(_address1));
        }
Exemplo n.º 16
0
        public void Can_collect_stats()
        {
            MemDb           memDb           = new MemDb();
            IDb             stateDb         = memDb;
            TrieStore       trieStore       = new TrieStore(stateDb, new MemoryLimit(0.MB()), Persist.EveryBlock, LimboLogs.Instance);
            StateProvider   stateProvider   = new StateProvider(trieStore, stateDb, LimboLogs.Instance);
            StorageProvider storageProvider = new StorageProvider(trieStore, stateProvider, LimboLogs.Instance);

            stateProvider.CreateAccount(TestItem.AddressA, 1);
            Keccak codeHash = stateProvider.UpdateCode(new byte[] { 1, 2, 3 });

            stateProvider.UpdateCodeHash(TestItem.AddressA, codeHash, Istanbul.Instance);

            stateProvider.CreateAccount(TestItem.AddressB, 1);
            Keccak codeHash2 = stateProvider.UpdateCode(new byte[] { 1, 2, 3, 4 });

            stateProvider.UpdateCodeHash(TestItem.AddressB, codeHash2, Istanbul.Instance);

            for (int i = 0; i < 1000; i++)
            {
                StorageCell storageCell = new StorageCell(TestItem.AddressA, (UInt256)i);
                storageProvider.Set(storageCell, new byte[] { (byte)i });
            }

            storageProvider.Commit();
            stateProvider.Commit(Istanbul.Instance);

            storageProvider.CommitTrees(0);
            stateProvider.CommitTree(0);
            storageProvider.CommitTrees(1);
            stateProvider.CommitTree(1);

            memDb.Delete(codeHash2); // missing code
            Keccak storageKey = new Keccak("0x345e54154080bfa9e8f20c99d7a0139773926479bc59e5b4f830ad94b6425332");

            memDb.Delete(storageKey); // deletes some storage
            trieStore.ClearCache();

            TrieStatsCollector statsCollector = new TrieStatsCollector(stateDb, LimboLogs.Instance);

            stateProvider.Accept(statsCollector, stateProvider.StateRoot);
            var stats = statsCollector.Stats;

            stats.CodeCount.Should().Be(1);
            stats.MissingCode.Should().Be(1);

            stats.NodesCount.Should().Be(1348);

            stats.StateBranchCount.Should().Be(1);
            stats.StateExtensionCount.Should().Be(1);
            stats.AccountCount.Should().Be(2);

            stats.StorageCount.Should().Be(1343);
            stats.StorageBranchCount.Should().Be(337);
            stats.StorageExtensionCount.Should().Be(12);
            stats.StorageLeafCount.Should().Be(994);
            stats.MissingStorage.Should().Be(1);
        }
        public void Disables_Eip158_for_system_transactions()
        {
            _stateProvider.CreateAccount(TestItem.PrivateKeyA.Address, 0.Ether());
            _stateProvider.Commit(_specProvider.GetSpec(1));

            var         blockNumber = MainNetSpecProvider.SpuriousDragonBlockNumber + 1;
            Transaction tx          = Build.A.SystemTransaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, blockNumber)
                                      .WithGasPrice(0)
                                      .WithValue(0)
                                      .TestObject;

            Block block = Build.A.Block.WithNumber(blockNumber).WithTransactions(tx).TestObject;

            BlockReceiptsTracer tracer = BuildTracer(block, tx, false, false);

            Execute(tracer, tx, block);
            _stateProvider.AccountExists(tx.SenderAddress).Should().BeTrue();
        }
Exemplo n.º 18
0
        public void Eip_158_touch_zero_value_system_account_is_not_deleted()
        {
            StateProvider provider   = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);
            var           systemUser = Address.SystemUser;

            provider.CreateAccount(systemUser, 0);
            provider.Commit(Homestead.Instance);

            var releaseSpec = new ReleaseSpec()
            {
                IsEip158Enabled = true
            };

            provider.UpdateCodeHash(systemUser, Keccak.OfAnEmptyString, releaseSpec);
            provider.Commit(releaseSpec);

            provider.GetAccount(systemUser).Should().NotBeNull();
        }
Exemplo n.º 19
0
        public void Touch_empty_trace_does_not_throw()
        {
            ParityLikeTxTracer tracer = new ParityLikeTxTracer(Build.A.Block.TestObject, null, ParityTraceTypes.StateDiff);

            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(_address1, 0);
            Account account = provider.GetAccount(_address1);

            Assert.True(account.IsEmpty);
            provider.Commit(Frontier.Instance); // commit empty account (before the empty account fix in Spurious Dragon)
            Assert.True(provider.AccountExists(_address1));

            provider.Reset();                                             // clear all caches

            provider.GetBalance(_address1);                               // justcache
            provider.AddToBalance(_address1, 0, SpuriousDragon.Instance); // touch
            Assert.DoesNotThrow(() => provider.Commit(SpuriousDragon.Instance, tracer));
        }
Exemplo n.º 20
0
        public void GlobalSetup()
        {
            IDb             codeDb  = new StateDb();
            ISnapshotableDb stateDb = new StateDb();

            _stateProvider = new StateProvider(stateDb, codeDb, new OneLoggerLogManager(NullLogger.Instance));
            _stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            _stateProvider.Commit(_spec);

            EvmState evmState = new EvmState(1, default, default, true, true);
        public void Get_storage()
        {
            /* all testing will be touching just a single storage cell */
            var storageCell = new StorageCell(TestItem.AddressA, 1);

            /* to start with we need to create an account that we will be setting storage at */
            _stateProvider.CreateAccount(storageCell.Address, UInt256.One);
            _stateProvider.Commit(MuirGlacier.Instance);
            _stateProvider.CommitTree();

            /* at this stage we have an account with empty storage at the address that we want to test */

            byte[] initialValue = new byte[] { 1, 2, 3 };
            _storageProvider.Set(storageCell, initialValue);
            _storageProvider.Commit();
            _storageProvider.CommitTrees();
            _stateProvider.Commit(MuirGlacier.Instance);
            _stateProvider.CommitTree();

            var retrieved =
                _blockchainBridge.GetStorage(storageCell.Address, storageCell.Index, _stateProvider.StateRoot);

            retrieved.Should().BeEquivalentTo(initialValue);

            /* at this stage we set the value in storage to 1,2,3 at the tested storage cell */

            /* Now we are testing scenario where the storage is being changed by the block processor.
            *  To do that we create some different storage / state access stack that represents the processor.
            *  It is a different stack of objects than the one that is used by the blockchain bridge. */

            byte[] newValue = new byte[] { 1, 2, 3, 4, 5 };

            StateProvider processorStateProvider =
                new StateProvider(_dbProvider.StateDb, _dbProvider.CodeDb, LimboLogs.Instance);

            processorStateProvider.StateRoot = _stateProvider.StateRoot;

            StorageProvider processorStorageProvider =
                new StorageProvider(_dbProvider.StateDb, processorStateProvider, LimboLogs.Instance);

            processorStorageProvider.Set(storageCell, newValue);
            processorStorageProvider.Commit();
            processorStorageProvider.CommitTrees();
            processorStateProvider.Commit(MuirGlacier.Instance);
            processorStateProvider.CommitTree();

            /* At this stage the DB should have the storage value updated to 5.
             * We will try to retrieve the value by taking the state root from the processor.*/

            retrieved =
                _blockchainBridge.GetStorage(storageCell.Address, storageCell.Index, processorStateProvider.StateRoot);
            retrieved.Should().BeEquivalentTo(newValue);

            /* If it failed then it means that the blockchain bridge cached the previous call value */
        }
Exemplo n.º 22
0
        private void AddCode(StateProvider stateProvider, Address account, byte[] code)
        {
            Keccak codeHash = stateProvider.UpdateCode(code);

            stateProvider.UpdateCodeHash(account, codeHash, MuirGlacier.Instance);

            stateProvider.Commit(MainNetSpecProvider.Instance.GenesisSpec, null);
            stateProvider.CommitTree();
            _dbProvider.CodeDb.Commit();
            _dbProvider.StateDb.Commit();
        }
Exemplo n.º 23
0
        public void Can_collect_stats()
        {
            StateProvider provider = new StateProvider(new TrieStore(new MemDb(), Logger), _codeDb, Logger);

            provider.CreateAccount(TestItem.AddressA, 1.Ether());
            provider.Commit(MuirGlacier.Instance);
            provider.CommitTree(0);

            var stats = provider.CollectStats(_codeDb, Logger);

            stats.AccountCount.Should().Be(1);
        }
Exemplo n.º 24
0
        public void Can_accepts_visitors()
        {
            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(TestItem.AddressA, 1.Ether());
            provider.Commit(MuirGlacier.Instance);
            provider.CommitTree();

            TrieStatsCollector visitor = new TrieStatsCollector(new MemDb(), LimboLogs.Instance);

            provider.Accept(visitor, provider.StateRoot);
        }
Exemplo n.º 25
0
        public void Can_dump_state()
        {
            StateProvider provider = new StateProvider(new TrieStore(new MemDb(), Logger), _codeDb, Logger);

            provider.CreateAccount(TestItem.AddressA, 1.Ether());
            provider.Commit(MuirGlacier.Instance);
            provider.CommitTree(0);

            string state = provider.DumpState();

            state.Should().NotBeEmpty();
        }
Exemplo n.º 26
0
        public void Can_dump_state()
        {
            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(TestItem.AddressA, 1.Ether());
            provider.Commit(MuirGlacier.Instance);
            provider.CommitTree();

            string state = provider.DumpState();

            state.Should().NotBeEmpty();
        }
Exemplo n.º 27
0
        public void Can_collect_stats()
        {
            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(TestItem.AddressA, 1.Ether());
            provider.Commit(MuirGlacier.Instance);
            provider.CommitTree();

            var stats = provider.CollectStats();

            stats.AccountCount.Should().Be(1);
        }
Exemplo n.º 28
0
        public async Task Can_ask_about_balance_in_parallel()
        {
            IReleaseSpec  spec     = MainnetSpecProvider.Instance.GetSpec(MainnetSpecProvider.ConstantinopleFixBlockNumber);
            MemDb         stateDb  = new MemDb();
            StateProvider provider =
                new StateProvider(new TrieStore(stateDb, Logger), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(_address1, 0);
            provider.AddToBalance(_address1, 1, spec);
            provider.Commit(spec);
            provider.CommitTree(0);
            Keccak stateRoot0 = provider.StateRoot;

            provider.AddToBalance(_address1, 1, spec);
            provider.Commit(spec);
            provider.CommitTree(0);
            Keccak stateRoot1 = provider.StateRoot;

            provider.AddToBalance(_address1, 1, spec);
            provider.Commit(spec);
            provider.CommitTree(0);
            Keccak stateRoot2 = provider.StateRoot;

            provider.AddToBalance(_address1, 1, spec);
            provider.Commit(spec);
            provider.CommitTree(0);
            Keccak stateRoot3 = provider.StateRoot;

            provider.CommitTree(0);

            StateReader reader =
                new StateReader(new TrieStore(stateDb, LimboLogs.Instance), Substitute.For <IDb>(), Logger);

            Task a = StartTask(reader, stateRoot0, 1);
            Task b = StartTask(reader, stateRoot1, 2);
            Task c = StartTask(reader, stateRoot2, 3);
            Task d = StartTask(reader, stateRoot3, 4);

            await Task.WhenAll(a, b, c, d);
        }
Exemplo n.º 29
0
        public void Eip_158_zero_value_transfer_deletes()
        {
            StateTree     tree             = new StateTree(new MemDb());
            StateProvider frontierProvider = new StateProvider(tree, Substitute.For <IDb>(), Logger);

            frontierProvider.CreateAccount(_address1, 0);
            frontierProvider.Commit(Frontier.Instance);
            StateProvider provider = new StateProvider(tree, Substitute.For <IDb>(), Logger);

            provider.AddToBalance(_address1, 0, SpuriousDragon.Instance);
            provider.Commit(SpuriousDragon.Instance);
            Assert.False(provider.AccountExists(_address1));
        }
Exemplo n.º 30
0
        public void Keep_in_cache()
        {
            StateProvider provider = new StateProvider(new StateDb(new MemDb()), Substitute.For <IDb>(), Logger);

            provider.CreateAccount(_address1, 0);
            provider.Commit(Frontier.Instance);
            provider.GetBalance(_address1);
            provider.AddToBalance(_address1, 1, Frontier.Instance);
            provider.Restore(-1);
            provider.AddToBalance(_address1, 1, Frontier.Instance);
            provider.Restore(-1);
            provider.AddToBalance(_address1, 1, Frontier.Instance);
            provider.Restore(-1);
            Assert.AreEqual(UInt256.Zero, provider.GetBalance(_address1));
        }