private bool IsCertified(Transaction tx, BlockHeader parentHeader)
        {
            if (!tx.GasPrice.IsZero) // only 0 gas price transactions are system transactions and can be whitelissted
            {
                return(false);
            }

            Address sender = tx.SenderAddress;

            if (_logger.IsTrace)
            {
                _logger.Trace($"Checking service transaction checker contract from {sender}.");
            }
            IDictionary <Address, bool> cache = GetCache(parentHeader.Hash);

            if (cache.TryGetValue(sender, out bool isCertified))
            {
                return(isCertified);
            }

            try
            {
                return(cache[sender] = _certifierContract.Certified(parentHeader, sender));
            }
            catch (AbiException e)
            {
                if (_logger.IsError)
                {
                    _logger.Error($"Call to certifier contract failed on block {parentHeader.ToString(BlockHeader.Format.FullHashAndNumber)} {new StackTrace()}.", e);
                }
                return(false);
            }
        }
Beispiel #2
0
        public void SetUp()
        {
            _certifierContract  = Substitute.For <ICertifierContract>();
            _notCertifiedFilter = Substitute.For <ITxFilter>();

            _notCertifiedFilter.IsAllowed(Arg.Any <Transaction>(), Arg.Any <BlockHeader>())
            .Returns((false, string.Empty));

            _certifierContract.Certified(Arg.Any <BlockHeader>(),
                                         Arg.Is <Address>(a => TestItem.Addresses.Take(3).Contains(a)))
            .Returns(true);

            _filter = new TxCertifierFilter(_certifierContract, _notCertifiedFilter, LimboLogs.Instance);
        }
        public void SetUp()
        {
            _certifierContract  = Substitute.For <ICertifierContract>();
            _notCertifiedFilter = Substitute.For <ITxFilter>();
            _specProvider       = Substitute.For <ISpecProvider>();

            _notCertifiedFilter.IsAllowed(Arg.Any <Transaction>(), Arg.Any <BlockHeader>())
            .Returns(AcceptTxResult.Invalid);

            _certifierContract.Certified(Arg.Any <BlockHeader>(),
                                         Arg.Is <Address>(a => TestItem.Addresses.Take(3).Contains(a)))
            .Returns(true);

            _filter = new TxCertifierFilter(_certifierContract, _notCertifiedFilter, _specProvider, LimboLogs.Instance);
        }
Beispiel #4
0
        private bool IsCertified(Transaction tx, BlockHeader parentHeader)
        {
            bool isEip1559Enabled = _specProvider.GetSpec(parentHeader.Number + 1).IsEip1559Enabled;
            bool checkByFeeCap    = isEip1559Enabled && tx.IsEip1559;

            if (checkByFeeCap && !tx.FeeCap.IsZero) // only 0 gas price transactions are system transactions and can be whitelissted
            {
                return(false);
            }
            else if (!tx.GasPrice.IsZero && !checkByFeeCap)
            {
                return(false);
            }

            Address sender = tx.SenderAddress;

            if (_logger.IsTrace)
            {
                _logger.Trace($"Checking service transaction checker contract from {sender}.");
            }
            IDictionary <Address, bool> cache = GetCache(parentHeader.Hash);

            if (cache.TryGetValue(sender, out bool isCertified))
            {
                tx.IsServiceTransaction = isCertified;
                return(isCertified);
            }

            try
            {
                bool isCertifiedByContract = _certifierContract.Certified(parentHeader, sender);
                tx.IsServiceTransaction = isCertifiedByContract;
                return(cache[sender] = isCertifiedByContract);
            }
            catch (AbiException e)
            {
                if (_logger.IsError)
                {
                    _logger.Error($"Call to certifier contract failed on block {parentHeader.ToString(BlockHeader.Format.FullHashAndNumber)}.", e);
                }
                return(false);
            }
        }
        private bool IsCertified(Transaction tx, BlockHeader parentHeader)
        {
            Address sender = tx.SenderAddress;

            if (tx.IsZeroGasPrice(parentHeader, _specProvider) && sender is not null)
            {
                if (_logger.IsTrace)
                {
                    _logger.Trace($"Checking service transaction checker contract from {sender}.");
                }
                IDictionary <Address, bool> cache = GetCache(parentHeader.Hash);

                if (cache.TryGetValue(sender, out bool isCertified))
                {
                    tx.IsServiceTransaction = isCertified;
                    return(isCertified);
                }

                try
                {
                    bool isCertifiedByContract = _certifierContract.Certified(parentHeader, sender);
                    tx.IsServiceTransaction = isCertifiedByContract;
                    return(cache[sender] = isCertifiedByContract);
                }
                catch (AbiException e)
                {
                    if (_logger.IsError)
                    {
                        _logger.Error($"Call to certifier contract failed on block {parentHeader.ToString(BlockHeader.Format.FullHashAndNumber)}.", e);
                    }
                    return(false);
                }
            }

            return(false);
        }