Пример #1
0
        public Keccak SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            if (tx.Signature == null)
            {
                if (_wallet.IsUnlocked(tx.SenderAddress))
                {
                    Sign(tx);
                }
                else
                {
                    throw new SecurityException("Your account is locked. Unlock the account via CLI, personal_unlockAccount or use Trusted Signer.");
                }
            }

            tx.Hash      = tx.CalculateHash();
            tx.Timestamp = _timestamper.EpochSeconds;

            AddTxResult result = _txPool.AddTransaction(tx, txHandlingOptions);

            if (result == AddTxResult.OwnNonceAlreadyUsed && (txHandlingOptions & TxHandlingOptions.ManagedNonce) == TxHandlingOptions.ManagedNonce)
            {
                // below the temporary NDM support - needs some review
                tx.Nonce = _txPool.ReserveOwnTransactionNonce(tx.SenderAddress);
                Sign(tx);
                tx.Hash = tx.CalculateHash();
                _txPool.AddTransaction(tx, txHandlingOptions);
            }

            return(tx.Hash);
        }
Пример #2
0
        protected void Handle(TransactionsMessage msg)
        {
            // TODO: disable that when IsMining is set to true
            if (!_txFilteringDisabled && (_isDowngradedDueToTxFlooding || 10 < _random.Next(0, 99)))
            {
                // we only accept 10% of transactions from downgraded nodes
                return;
            }

            Metrics.Eth62TransactionsReceived++;
            for (int i = 0; i < msg.Transactions.Count; i++)
            {
                Transaction transaction = msg.Transactions[i];
                transaction.DeliveredBy = Node.Id;
                transaction.Timestamp   = _timestamper.EpochSeconds;
                AddTxResult result = _txPool.AddTransaction(transaction, TxHandlingOptions.None);
                if (result != AddTxResult.Added)
                {
                    _notAcceptedTxsSinceLastCheck++;
                }

                if (Logger.IsTrace)
                {
                    Logger.Trace($"{Node:c} sent {transaction.Hash} tx and it was {result} (chain ID = {transaction.Signature.ChainId})");
                }
            }
        }
Пример #3
0
        public void should_add_valid_transactions()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx     = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(1);
            result.Should().Be(AddTxResult.Added);
        }
Пример #4
0
        public void should_add_valid_transactions()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx     = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, RopstenSpecProvider.ByzantiumBlockNumber).TestObject;
            AddTxResult result = _txPool.AddTransaction(tx, 1);

            _txPool.GetPendingTransactions().Length.Should().Be(1);
            result.Should().Be(AddTxResult.Added);
        }
Пример #5
0
        public void should_ignore_old_scheme_signatures()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx     = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, 1).TestObject;
            AddTxResult result = _txPool.AddTransaction(tx, 1);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.OldScheme);
        }
Пример #6
0
        public void should_ignore_transactions_with_different_chain_id()
        {
            _txPool = CreatePool(_noTxStorage);
            EthereumEcdsa ecdsa  = new EthereumEcdsa(ChainId.Mainnet, _logManager);
            Transaction   tx     = Build.A.Transaction.SignedAndResolved(ecdsa, TestItem.PrivateKeyA).TestObject;
            AddTxResult   result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.InvalidChainId);
        }
Пример #7
0
        public void should_ignore_transactions_with_different_chain_id()
        {
            _txPool = CreatePool(_noTxStorage);
            EthereumEcdsa ecdsa  = new EthereumEcdsa(MainNetSpecProvider.Instance, _logManager);
            Transaction   tx     = Build.A.Transaction.SignedAndResolved(ecdsa, TestItem.PrivateKeyA, MainNetSpecProvider.ByzantiumBlockNumber).TestObject;
            AddTxResult   result = _txPool.AddTransaction(tx, 1);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.InvalidChainId);
        }
Пример #8
0
        public void should_ignore_transactions_too_far_into_future()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx = Build.A.Transaction.WithNonce(_txPool.FutureNonceRetention + 1).SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx);
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.FutureNonce);
        }
Пример #9
0
        public void should_not_ignore_old_scheme_signatures()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, false).TestObject;

            EnsureSenderBalance(tx);
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(1);
            result.Should().Be(AddTxResult.Added);
        }
Пример #10
0
        public void should_ignore_already_known()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx      = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, RopstenSpecProvider.ByzantiumBlockNumber).TestObject;
            AddTxResult result1 = _txPool.AddTransaction(tx, 1, TxHandlingOptions.PersistentBroadcast);
            AddTxResult result2 = _txPool.AddTransaction(tx, 1, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(1);
            result1.Should().Be(AddTxResult.Added);
            result2.Should().Be(AddTxResult.AlreadyKnown);
        }
Пример #11
0
        public void should_ignore_old_nonce_transactions()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx);
            _stateProvider.IncrementNonce(tx.SenderAddress);
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.OldNonce);
        }
Пример #12
0
        public void should_ignore_tx_gas_limit_exceeded()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx = Build.A.Transaction
                             .WithGasLimit(_txGasLimit + 1)
                             .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx);
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.GasLimitExceeded);
        }
Пример #13
0
        public void should_ignore_overflow_transactions()
        {
            _txPool = CreatePool(_noTxStorage);
            Transaction tx = Build.A.Transaction.WithGasPrice(UInt256.MaxValue / Transaction.BaseTxGasCost)
                             .WithGasLimit(Transaction.BaseTxGasCost)
                             .WithValue(Transaction.BaseTxGasCost)
                             .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx);
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.BalanceOverflow);
        }
Пример #14
0
        public Keccak SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            foreach (var sealer in _sealers)
            {
                sealer.Seal(tx);

                AddTxResult result = _txPool.AddTransaction(tx, txHandlingOptions);

                if (result != AddTxResult.OwnNonceAlreadyUsed || (txHandlingOptions & TxHandlingOptions.ManagedNonce) != TxHandlingOptions.ManagedNonce)
                {
                    break;
                }
            }

            return(tx.Hash);
        }
Пример #15
0
        public void should_ignore_insufficient_funds_for_eip1559_transactions()
        {
            var specProvider = Substitute.For <ISpecProvider>();

            specProvider.GetSpec(Arg.Any <long>()).Returns(London.Instance);
            var         txPool = CreatePool(_noTxStorage, null, specProvider);
            Transaction tx     = Build.A.Transaction
                                 .WithType(TxType.EIP1559).WithFeeCap(20)
                                 .WithChainId(ChainId.Mainnet)
                                 .WithValue(5).SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx.SenderAddress, tx.FeeCap * (UInt256)tx.GasLimit); // without tx.Value so we should have InsufficientFunds
            AddTxResult result = txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.InsufficientFunds);
        }
Пример #16
0
        public void should_accept_access_list_transactions_only_when_eip2930_enabled([Values(false, true)] bool eip2930Enabled)
        {
            if (!eip2930Enabled)
            {
                _blockFinder.FindBestSuggestedHeader().Returns(Build.A.BlockHeader.WithNumber(RopstenSpecProvider.BerlinBlockNumber - 1).TestObject);
            }

            _txPool = CreatePool(_noTxStorage);
            Transaction tx = Build.A.Transaction
                             .WithType(TxType.AccessList)
                             .WithChainId(ChainId.Mainnet)
                             .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx);
            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(eip2930Enabled ? 1 : 0);
            result.Should().Be(eip2930Enabled ? AddTxResult.Added : AddTxResult.Invalid);
        }
Пример #17
0
        private void Handle(TransactionsMessage msg)
        {
            for (int i = 0; i < msg.Transactions.Length; i++)
            {
                var transaction = msg.Transactions[i];
                transaction.DeliveredBy = Node.Id;
                transaction.Timestamp   = _timestamp.EpochSeconds;
                AddTxResult result = _txPool.AddTransaction(transaction, SyncServer.Head.Number);
                if (result == AddTxResult.AlreadyKnown)
                {
                    _notAcceptedTxsSinceLastCheck++;
                }

                if (Logger.IsTrace)
                {
                    Logger.Trace($"{Node.Id} sent {transaction.Hash} and it was {result} (chain ID = {transaction.Signature.GetChainId})");
                }
            }
        }
Пример #18
0
        protected void Handle(TransactionsMessage msg)
        {
            IList <Transaction> transactions = msg.Transactions;

            for (int i = 0; i < transactions.Count; i++)
            {
                Transaction tx = transactions[i];
                tx.DeliveredBy = Node.Id;
                tx.Timestamp   = _timestamper.UnixTime.Seconds;
                AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.None);
                _floodController.Report(result == AddTxResult.Added);

                if (Logger.IsTrace)
                {
                    Logger.Trace(
                        $"{Node:c} sent {tx.Hash} tx and it was {result} (chain ID = {tx.Signature?.ChainId})");
                }
            }
        }
Пример #19
0
        public ValueTask <Keccak> SendTransaction(Transaction tx, TxHandlingOptions txHandlingOptions)
        {
            // TODO: this is very not intuitive - can we fix it...?
            // maybe move nonce reservation to sender itself before sealing
            // sealers should behave like composite and not like chain of commands
            foreach (var sealer in _sealers)
            {
                sealer.Seal(tx, txHandlingOptions);

                AddTxResult result = _txPool.AddTransaction(tx, txHandlingOptions);

                if (result != AddTxResult.OwnNonceAlreadyUsed || (txHandlingOptions & TxHandlingOptions.ManagedNonce) != TxHandlingOptions.ManagedNonce)
                {
                    break;
                }
            }

            return(new ValueTask <Keccak>(tx.Hash));
        }
Пример #20
0
        public void should_ignore_overflow_transactions_gas_premium_and_fee_cap()
        {
            var specProvider = Substitute.For <ISpecProvider>();

            specProvider.GetSpec(Arg.Any <long>()).Returns(London.Instance);
            var         txPool = CreatePool(_noTxStorage, null, specProvider);
            Transaction tx     = Build.A.Transaction.WithGasPrice(UInt256.MaxValue / Transaction.BaseTxGasCost)
                                 .WithGasLimit(Transaction.BaseTxGasCost)
                                 .WithValue(Transaction.BaseTxGasCost)
                                 .WithFeeCap(UInt256.MaxValue - 10)
                                 .WithGasPremium((UInt256)15)
                                 .WithType(TxType.EIP1559)
                                 .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx.SenderAddress, UInt256.MaxValue);
            AddTxResult result = txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.BalanceOverflow);
        }
Пример #21
0
        public void should_ignore_transactions_with_insufficient_intrinsic_gas()
        {
            _txPool = CreatePool(_noTxStorage);
            EthereumEcdsa ecdsa = new EthereumEcdsa(ChainId.Mainnet, _logManager);
            Transaction   tx    = Build.A.Transaction
                                  .WithData(new byte[]
            {
                127, 243, 106, 181, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 162, 136, 9, 81, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 188, 120, 128, 96, 158, 141, 79, 126, 233, 131, 209, 47, 215, 166, 85, 190, 220, 187, 180, 115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 96, 44, 207, 221, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 233, 29, 21, 62, 11, 65, 81, 138, 44, 232, 221, 61, 121,
                68, 250, 134, 52, 99, 169, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 211, 17, 226, 235, 85, 242, 246, 138, 148, 64, 218, 56, 231, 152, 146, 16, 185, 160, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 22, 226, 139,
                67, 163, 88, 22, 43, 150, 247, 11, 77, 225, 76, 152, 164, 70, 95, 37
            })
                                  .SignedAndResolved()
                                  .TestObject;

            AddTxResult result = _txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            _txPool.GetPendingTransactions().Length.Should().Be(0);
            result.Should().Be(AddTxResult.Invalid);
        }
Пример #22
0
        public void should_accept_1559_transactions_only_when_eip1559_enabled([Values(false, true)] bool eip1559Enabled)
        {
            ISpecProvider specProvider = null;

            if (eip1559Enabled)
            {
                specProvider = Substitute.For <ISpecProvider>();
                specProvider.GetSpec(Arg.Any <long>()).Returns(London.Instance);
            }
            var         txPool = CreatePool(_noTxStorage, null, specProvider);
            Transaction tx     = Build.A.Transaction
                                 .WithType(TxType.EIP1559)
                                 .WithChainId(ChainId.Mainnet)
                                 .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

            EnsureSenderBalance(tx);
            AddTxResult result = txPool.AddTransaction(tx, TxHandlingOptions.PersistentBroadcast);

            txPool.GetPendingTransactions().Length.Should().Be(eip1559Enabled ? 1 : 0);
            result.Should().Be(eip1559Enabled ? AddTxResult.Added : AddTxResult.Invalid);
        }