Example #1
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);
        }
Example #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());
        }