Ejemplo n.º 1
0
        private void OnFillMemoryPool(IEnumerable <Transaction> transactions)
        {
            // Invalidate all the transactions in the memory pool, to avoid any failures when adding new transactions.
            MemPool.InvalidateAllTransactions();

            // Add the transactions to the memory pool
            foreach (var tx in transactions)
            {
                if (View.ContainsTransaction(tx.Hash))
                {
                    continue;
                }
                if (!NativeContract.Policy.CheckPolicy(tx, currentSnapshot))
                {
                    continue;
                }
                // First remove the tx if it is unverified in the pool.
                MemPool.TryRemoveUnVerified(tx.Hash, out _);
                // Verify the the transaction
                if (tx.Verify(currentSnapshot, MemPool.SendersFeeMonitor.GetSenderFee(tx.Sender)) != VerifyResult.Succeed)
                {
                    continue;
                }
                // Add to the memory pool
                MemPool.TryAdd(tx.Hash, tx);
            }
            // Transactions originally in the pool will automatically be reverified based on their priority.

            Sender.Tell(new FillCompleted());
        }
Ejemplo n.º 2
0
        private void OnFillMemoryPool(IEnumerable <Transaction> transactions)
        {
            // Invalidate all the transactions in the memory pool, to avoid any failures when adding new transactions.
            MemPool.InvalidateAllTransactions();

            // Add the transactions to the memory pool
            foreach (var tx in transactions)
            {
                if (tx.Type == TransactionType.MinerTransaction)
                {
                    continue;
                }
                if (Store.ContainsTransaction(tx.Hash))
                {
                    continue;
                }
                if (!Plugin.CheckPolicy(tx))
                {
                    continue;
                }
                // First remove the tx if it is unverified in the pool.
                MemPool.TryRemoveUnVerified(tx.Hash, out _);
                // Verify the the transaction
                if (!tx.Verify(currentSnapshot, MemPool.GetVerifiedTransactions()))
                {
                    continue;
                }
                // Add to the memory pool
                MemPool.TryAdd(tx.Hash, tx);
            }
            // Transactions originally in the pool will automatically be reverified based on their priority.

            Sender.Tell(new FillCompleted());
        }
Ejemplo n.º 3
0
        private RelayResultReason OnNewTransaction(Transaction transaction)
        {
            if (transaction.Type == TransactionType.MinerTransaction)
            {
                return(RelayResultReason.Invalid);
            }
            if (ContainsTransaction(transaction.Hash))
            {
                return(RelayResultReason.AlreadyExists);
            }
            if (!MemPool.CanTransactionFitInPool(transaction))
            {
                return(RelayResultReason.OutOfMemory);
            }
            if (!transaction.Verify(currentSnapshot, MemPool.GetVerifiedTransactions()))
            {
                return(RelayResultReason.Invalid);
            }
            if (!Plugin.CheckPolicy(transaction))
            {
                return(RelayResultReason.PolicyFail);
            }

            if (!MemPool.TryAdd(transaction.Hash, transaction))
            {
                return(RelayResultReason.OutOfMemory);
            }

            system.LocalNode.Tell(new LocalNode.RelayDirectly {
                Inventory = transaction
            });
            return(RelayResultReason.Succeed);
        }
Ejemplo n.º 4
0
        private void OnParallelVerified(ParallelVerified parallelVerified)
        {
            RelayResultReason reason = parallelVerified.VerifyResult;

            if (reason == RelayResultReason.Succeed)
            {
                if (View.ContainsTransaction(parallelVerified.Transaction.Hash))
                {
                    reason = RelayResultReason.AlreadyExists;
                }
                else if (!MemPool.CanTransactionFitInPool(parallelVerified.Transaction))
                {
                    reason = RelayResultReason.OutOfMemory;
                }
                else if (!MemPool.TryAdd(parallelVerified.Transaction.Hash, parallelVerified.Transaction))
                {
                    reason = RelayResultReason.OutOfMemory;
                }
                else if (parallelVerified.ShouldRelay)
                {
                    system.LocalNode.Tell(new LocalNode.RelayDirectly {
                        Inventory = parallelVerified.Transaction
                    });
                }
            }
            Sender.Tell(reason);
        }
Ejemplo n.º 5
0
        private void OnNewTransaction(Transaction transaction, bool relay)
        {
            RelayResultReason reason;

            if (ContainsTransaction(transaction.Hash))
            {
                reason = RelayResultReason.AlreadyExists;
            }
            else if (!MemPool.CanTransactionFitInPool(transaction))
            {
                reason = RelayResultReason.OutOfMemory;
            }
            else
            {
                reason = transaction.Verify(currentSnapshot, MemPool.SendersFeeMonitor.GetSenderFee(transaction.Sender));
            }

            if (reason == RelayResultReason.Succeed)
            {
                if (!MemPool.TryAdd(transaction.Hash, transaction))
                {
                    reason = RelayResultReason.OutOfMemory;
                }
                else if (relay)
                {
                    system.LocalNode.Tell(new LocalNode.RelayDirectly {
                        Inventory = transaction
                    });
                }
            }

            Sender.Tell(reason);
        }
Ejemplo n.º 6
0
        private RelayResultReason OnNewTransaction(Transaction transaction, bool relay)
        {
            if (ContainsTransaction(transaction.Hash))
            {
                return(RelayResultReason.AlreadyExists);
            }
            if (!MemPool.CanTransactionFitInPool(transaction))
            {
                return(RelayResultReason.OutOfMemory);
            }
            if (!transaction.Verify(currentSnapshot, MemPool.SendersFeeMonitor.GetSenderFee(transaction.Sender)))
            {
                return(RelayResultReason.Invalid);
            }
            if (!NativeContract.Policy.CheckPolicy(transaction, currentSnapshot))
            {
                return(RelayResultReason.PolicyFail);
            }

            if (!MemPool.TryAdd(transaction.Hash, transaction))
            {
                return(RelayResultReason.OutOfMemory);
            }
            if (relay)
            {
                system.LocalNode.Tell(new LocalNode.RelayDirectly {
                    Inventory = transaction
                });
            }
            return(RelayResultReason.Succeed);
        }
Ejemplo n.º 7
0
 private VerifyResult OnNewTransaction(Transaction transaction)
 {
     if (ContainsTransaction(transaction.Hash))
     {
         return(VerifyResult.AlreadyExists);
     }
     return(MemPool.TryAdd(transaction, currentSnapshot));
 }
Ejemplo n.º 8
0
        private void OnFillMemoryPool(IEnumerable <Transaction> transactions)
        {
            // Invalidate all the transactions in the memory pool, to avoid any failures when adding new transactions.
            MemPool.InvalidateAllTransactions();

            // Add the transactions to the memory pool
            foreach (var tx in transactions)
            {
                if (View.ContainsTransaction(tx.Hash))
                {
                    continue;
                }
                // First remove the tx if it is unverified in the pool.
                MemPool.TryRemoveUnVerified(tx.Hash, out _);
                // Add to the memory pool
                MemPool.TryAdd(tx, currentSnapshot);
            }
            // Transactions originally in the pool will automatically be reverified based on their priority.

            Sender.Tell(new FillCompleted());
        }
Ejemplo n.º 9
0
        private VerifyResult OnNewTransaction(Transaction transaction)
        {
            if (ContainsTransaction(transaction.Hash))
            {
                return(VerifyResult.AlreadyExists);
            }
            if (!MemPool.CanTransactionFitInPool(transaction))
            {
                return(VerifyResult.OutOfMemory);
            }
            VerifyResult reason = transaction.Verify(currentSnapshot, MemPool.SendersFeeMonitor.GetSenderFee(transaction.Sender));

            if (reason != VerifyResult.Succeed)
            {
                return(reason);
            }
            if (!MemPool.TryAdd(transaction.Hash, transaction))
            {
                return(VerifyResult.OutOfMemory);
            }
            return(VerifyResult.Succeed);
        }