Beispiel #1
0
    public void should_pick_tx_with_lowest_nonce_from_bucket()
    {
        _txPoolConfig = new TxPoolConfig()
        {
            PeerNotificationThreshold = 5
        };
        _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager);
        _headInfo.CurrentBaseFee.Returns(0.GWei());

        const int addedTxsCount = 5;

        Transaction[] transactions = new Transaction[addedTxsCount];

        for (int i = 0; i < addedTxsCount; i++)
        {
            transactions[i] = Build.A.Transaction
                              .WithNonce((UInt256)i)
                              .WithGasPrice(i.GWei())
                              .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA)
                              .TestObject;

            _broadcaster.Broadcast(transactions[i], true);
        }
        _broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

        IList <Transaction> pickedTxs = _broadcaster.GetPersistentTxsToSend();

        pickedTxs.Count.Should().Be(1);

        List <Transaction> expectedTxs = new() { transactions[0] };

        expectedTxs.Should().BeEquivalentTo(pickedTxs);
    }
}
Beispiel #2
0
    public void should_pick_best_persistent_txs_to_broadcast(int threshold)
    {
        _txPoolConfig = new TxPoolConfig()
        {
            PeerNotificationThreshold = threshold
        };
        _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager);
        _headInfo.CurrentBaseFee.Returns(0.GWei());

        int addedTxsCount = TestItem.PrivateKeys.Length;

        Transaction[] transactions = new Transaction[addedTxsCount];

        for (int i = 0; i < addedTxsCount; i++)
        {
            transactions[i] = Build.A.Transaction
                              .WithGasPrice(i.GWei())
                              .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeys[i])
                              .TestObject;

            _broadcaster.Broadcast(transactions[i], true);
        }

        _broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

        List <Transaction> pickedTxs = _broadcaster.GetPersistentTxsToSend().ToList();

        int expectedCount = threshold <= 0 ? 0 : addedTxsCount;

        pickedTxs.Count.Should().Be(expectedCount);
    }
Beispiel #3
0
 public void Setup()
 {
     _logManager    = LimboLogs.Instance;
     _specProvider  = RopstenSpecProvider.Instance;
     _ethereumEcdsa = new EthereumEcdsa(_specProvider.ChainId, _logManager);
     _blockTree     = Substitute.For <IBlockTree>();
     _comparer      = new TransactionComparerProvider(_specProvider, _blockTree).GetDefaultComparer();
     _txPoolConfig  = new TxPoolConfig();
     _headInfo      = Substitute.For <IChainHeadInfoProvider>();
 }
Beispiel #4
0
    public void should_not_pick_1559_txs_with_MaxFeePerGas_lower_than_CurrentBaseFee(int threshold)
    {
        _txPoolConfig = new TxPoolConfig()
        {
            PeerNotificationThreshold = threshold
        };
        _broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager);

        const int currentBaseFeeInGwei = 250;

        _headInfo.CurrentBaseFee.Returns(currentBaseFeeInGwei.GWei());
        Block headBlock = Build.A.Block
                          .WithNumber(RopstenSpecProvider.LondonBlockNumber)
                          .WithBaseFeePerGas(currentBaseFeeInGwei.GWei())
                          .TestObject;

        _blockTree.Head.Returns(headBlock);

        int addedTxsCount = TestItem.PrivateKeys.Length;

        Transaction[] transactions = new Transaction[addedTxsCount];

        for (int i = 0; i < addedTxsCount; i++)
        {
            transactions[i] = Build.A.Transaction
                              .WithType(TxType.EIP1559)
                              .WithMaxFeePerGas(i.GWei())
                              .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeys[i])
                              .TestObject;

            _broadcaster.Broadcast(transactions[i], true);
        }

        _broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

        IList <Transaction> pickedTxs = _broadcaster.GetPersistentTxsToSend();

        int expectedCount = Math.Min(addedTxsCount * threshold / 100 + 1, addedTxsCount - currentBaseFeeInGwei);

        pickedTxs.Count.Should().Be(expectedCount);

        List <Transaction> expectedTxs = new();

        for (int i = 1; i <= expectedCount; i++)
        {
            expectedTxs.Add(transactions[addedTxsCount - i]);
        }

        expectedTxs.Should().BeEquivalentTo(pickedTxs, o => o.Excluding(transaction => transaction.MaxFeePerGas));
    }
Beispiel #5
0
        private PendingTxThresholdValidator GetValidator(int obsoletePendingTransactionInterval = 15,
                                                         int removePendingTransactionInterval   = 600)
        {
            _obsoletePendingTransactionInterval = obsoletePendingTransactionInterval;
            _removePendingTransactionInterval   = removePendingTransactionInterval;

            TxPoolConfig config = new TxPoolConfig
            {
                ObsoletePendingTransactionInterval = _obsoletePendingTransactionInterval,
                RemovePendingTransactionInterval   = _removePendingTransactionInterval
            };

            return(new PendingTxThresholdValidator(config));
        }