Пример #1
0
        public void TestReVerifyTopUnverifiedTransactionsIfNeeded()
        {
            _unit = new MemoryPool(TestBlockchain.TheNeoSystem, 600);
            _unit.LoadPolicy(Blockchain.Singleton.GetSnapshot());
            AddTransaction(CreateTransaction(100000001));
            AddTransaction(CreateTransaction(100000001));
            AddTransaction(CreateTransaction(100000001));
            AddTransaction(CreateTransaction(1));
            _unit.VerifiedCount.Should().Be(4);
            _unit.UnVerifiedCount.Should().Be(0);

            _unit.InvalidateVerifiedTransactions();
            _unit.VerifiedCount.Should().Be(0);
            _unit.UnVerifiedCount.Should().Be(4);

            AddTransactions(511); // Max per block currently is 512
            _unit.VerifiedCount.Should().Be(511);
            _unit.UnVerifiedCount.Should().Be(4);

            var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, Blockchain.Singleton.GetSnapshot());

            result.Should().BeTrue();
            _unit.VerifiedCount.Should().Be(512);
            _unit.UnVerifiedCount.Should().Be(3);

            result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, Blockchain.Singleton.GetSnapshot());
            result.Should().BeTrue();
            _unit.VerifiedCount.Should().Be(514);
            _unit.UnVerifiedCount.Should().Be(1);

            result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, Blockchain.Singleton.GetSnapshot());
            result.Should().BeFalse();
            _unit.VerifiedCount.Should().Be(515);
            _unit.UnVerifiedCount.Should().Be(0);
        }
Пример #2
0
        public void TestReVerifyTopUnverifiedTransactionsIfNeeded()
        {
            _unit = new MemoryPool(new VauthSystem(ProtocolSettings.Default with {
                MemoryPoolMaxTransactions = 600
            }));

            AddTransaction(CreateTransaction(100000001));
            AddTransaction(CreateTransaction(100000001));
            AddTransaction(CreateTransaction(100000001));
            AddTransaction(CreateTransaction(1));
            _unit.VerifiedCount.Should().Be(4);
            _unit.UnVerifiedCount.Should().Be(0);

            _unit.InvalidateVerifiedTransactions();
            _unit.VerifiedCount.Should().Be(0);
            _unit.UnVerifiedCount.Should().Be(4);

            AddTransactions(511); // Max per block currently is 512
            _unit.VerifiedCount.Should().Be(511);
            _unit.UnVerifiedCount.Should().Be(4);

            var result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(1, GetSnapshot());

            result.Should().BeTrue();
            _unit.VerifiedCount.Should().Be(512);
            _unit.UnVerifiedCount.Should().Be(3);

            result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(2, GetSnapshot());
            result.Should().BeTrue();
            _unit.VerifiedCount.Should().Be(514);
            _unit.UnVerifiedCount.Should().Be(1);

            result = _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(3, GetSnapshot());
            result.Should().BeFalse();
            _unit.VerifiedCount.Should().Be(515);
            _unit.UnVerifiedCount.Should().Be(0);
        }
Пример #3
0
        public void BlockPersistMovesTxToUnverifiedAndReverification()
        {
            AddTransactions(70);

            _unit.SortedTxCount.Should().Be(70);

            var block = new Block
            {
                Header       = new Header(),
                Transactions = _unit.GetSortedVerifiedTransactions().Take(10)
                               .Concat(_unit.GetSortedVerifiedTransactions().Take(5)).ToArray()
            };

            _unit.UpdatePoolForBlockPersisted(block, GetSnapshot());
            _unit.InvalidateVerifiedTransactions();
            _unit.SortedTxCount.Should().Be(0);
            _unit.UnverifiedSortedTxCount.Should().Be(60);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot());
            _unit.SortedTxCount.Should().Be(10);
            _unit.UnverifiedSortedTxCount.Should().Be(50);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot());
            _unit.SortedTxCount.Should().Be(20);
            _unit.UnverifiedSortedTxCount.Should().Be(40);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot());
            _unit.SortedTxCount.Should().Be(30);
            _unit.UnverifiedSortedTxCount.Should().Be(30);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot());
            _unit.SortedTxCount.Should().Be(40);
            _unit.UnverifiedSortedTxCount.Should().Be(20);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot());
            _unit.SortedTxCount.Should().Be(50);
            _unit.UnverifiedSortedTxCount.Should().Be(10);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, GetSnapshot());
            _unit.SortedTxCount.Should().Be(60);
            _unit.UnverifiedSortedTxCount.Should().Be(0);
        }
Пример #4
0
        public void BlockPersistMovesTxToUnverifiedAndReverification()
        {
            AddTransactions(70);

            _unit.SortedTxCount.ShouldBeEquivalentTo(70);

            var block = new Block
            {
                Transactions = _unit.GetSortedVerifiedTransactions().Take(10)
                               .Concat(_unit.GetSortedVerifiedTransactions().Take(5)).ToArray()
            };

            _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot());
            _unit.InvalidateVerifiedTransactions();
            _unit.SortedTxCount.ShouldBeEquivalentTo(0);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(60);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedTxCount.ShouldBeEquivalentTo(10);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(50);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedTxCount.ShouldBeEquivalentTo(20);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(40);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedTxCount.ShouldBeEquivalentTo(30);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(30);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedTxCount.ShouldBeEquivalentTo(40);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(20);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedTxCount.ShouldBeEquivalentTo(50);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(10);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedTxCount.ShouldBeEquivalentTo(60);
            _unit.UnverifiedSortedTxCount.ShouldBeEquivalentTo(0);
        }
Пример #5
0
        public void BlockPersistMovesTxToUnverifiedAndReverification()
        {
            AddHighPriorityTransactions(70);
            AddLowPriorityTransactions(30);

            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(70);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(30);

            var block = new Block
            {
                Transactions = _unit.GetSortedVerifiedTransactions().Take(10)
                               .Concat(_unit.GetSortedVerifiedTransactions().Where(x => x.IsLowPriority).Take(5)).ToArray()
            };

            _unit.UpdatePoolForBlockPersisted(block, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(0);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(0);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(60);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(25);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(9);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(1);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(51);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(24);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(18);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(2);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(42);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(23);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(27);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(3);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(33);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(22);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(36);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(4);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(24);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(21);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(45);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(5);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(15);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(20);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(54);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(6);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(6);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(19);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(60);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(10);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(0);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(15);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(60);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(20);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(0);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(5);

            _unit.ReVerifyTopUnverifiedTransactionsIfNeeded(10, Blockchain.Singleton.GetSnapshot());
            _unit.SortedHighPrioTxCount.ShouldBeEquivalentTo(60);
            _unit.SortedLowPrioTxCount.ShouldBeEquivalentTo(25);
            _unit.UnverifiedSortedHighPrioTxCount.ShouldBeEquivalentTo(0);
            _unit.UnverifiedSortedLowPrioTxCount.ShouldBeEquivalentTo(0);
        }