Exemplo n.º 1
0
        private ProcessorConfiguration <TEntityIn, TEntityOut> GetConfig <TEntityIn, TEntityOut>
            () where TEntityOut : class, new()
        {
            var spec = new SpecProvider <TEntityOut>();

            var col = new SpecProvider <IEnumerable <TEntityOut> >();

            return(new ProcessorConfiguration <TEntityIn, TEntityOut>(spec, col));
        }
Exemplo n.º 2
0
        protected void AndGivenASetOfSpecificationsForAddresses()
        {
            _specProviderFroAddress = new SpecProvider <Address>();

            _specProviderFroAddress.Add(a =>
            {
                if (a.ContactId == 0)
                {
                    return(new SpecResult("Contact Id has not been assigned."));
                }

                return(SpecResult.Success);
            }, "Key", "Description");
        }
            protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolTxSource, ISealer sealer,
                                                                      ITransactionComparerProvider transactionComparerProvider)
            {
                MiningConfig miningConfig = new() { MinGasPrice = UInt256.One };

                SpecProvider.UpdateMergeTransitionInfo(1, 0);

                BlockProducerEnvFactory blockProducerEnvFactory = new BlockProducerEnvFactory(
                    DbProvider,
                    BlockTree,
                    ReadOnlyTrieStore,
                    SpecProvider,
                    BlockValidator,
                    NoBlockRewards.Instance,
                    ReceiptStorage,
                    BlockPreprocessorStep,
                    TxPool,
                    transactionComparerProvider,
                    miningConfig,
                    LogManager)
                {
                    TransactionsExecutorFactory =
                        new AABlockProducerTransactionsExecutorFactory(
                            SpecProvider,
                            LogManager,
                            Signer,
                            EntryPointAddresses)
                };

                UserOperationTxSource = new(UserOperationTxBuilder, UserOperationPool, UserOperationSimulator, SpecProvider, State, Signer, LogManager.GetClassLogger());

                PostMergeBlockProducer CreatePostMergeBlockProducer(IBlockProductionTrigger blockProductionTrigger,
                                                                    ITxSource?txSource = null)
                {
                    var blockProducerEnv = blockProducerEnvFactory.Create(txSource);

                    return(new PostMergeBlockProducerFactory(SpecProvider, SealEngine, Timestamper, miningConfig,
                                                             LogManager, GasLimitCalculator).Create(
                               blockProducerEnv, blockProductionTrigger));
                }

                IBlockProducer blockProducer =
                    CreatePostMergeBlockProducer(BlockProductionTrigger, UserOperationTxSource);

                blockProducer.BlockProduced += OnBlockProduced;

                return(blockProducer);
            }
Exemplo n.º 4
0
        protected void AndGivenASetOfSpecificationsForSource()
        {
            _specProvider = new SpecProvider <Dto1>();

            _specProvider.Add(a =>
            {
                if (a.Source.Key == "Key-5")
                {
                    return(new SpecResult("Arbitrary invalid reason."));
                }

                return(SpecResult.Success);
            }, "Key", "Description");

            _specProvider.MergeFrom(m => m.Contact, new SpecProvider <Contact>());
        }
Exemplo n.º 5
0
        protected void GivenASpecProviderWithCustomRules()
        {
            var specProvider = new SpecProvider <TestClass>();

            specProvider.Add(s =>
            {
                // ReSharper disable once ConvertIfStatementToReturnStatement
                if (s.Name == "John")
                {
                    return(new SpecResult("Name can't be John"));
                }

                return(SpecResult.Success);
            }, "NameNotJohn", "Name can't be john for some reason defined by the business");

            _rules = specProvider.GetSpecifications().ToArray();
        }
            protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolTxSource, ISealer sealer,
                                                                      ITransactionComparerProvider transactionComparerProvider)
            {
                MiningConfig miningConfig = new() { MinGasPrice = UInt256.One };

                SpecProvider.UpdateMergeTransitionInfo(1, 0);

                BlockProducerEnvFactory blockProducerEnvFactory = new(
                    DbProvider,
                    BlockTree,
                    ReadOnlyTrieStore,
                    SpecProvider,
                    BlockValidator,
                    NoBlockRewards.Instance,
                    ReceiptStorage,
                    BlockPreprocessorStep,
                    TxPool,
                    transactionComparerProvider,
                    miningConfig,
                    LogManager)
                {
                    TransactionsExecutorFactory =
                        new MevBlockProducerTransactionsExecutorFactory(SpecProvider, LogManager)
                };

                PostMergeBlockProducer CreatePostMergeBlockProducer(IBlockProductionTrigger blockProductionTrigger,
                                                                    ITxSource?txSource = null)
                {
                    BlockProducerEnv blockProducerEnv = blockProducerEnvFactory.Create(txSource);

                    return(new PostMergeBlockProducerFactory(SpecProvider, SealEngine, Timestamper, miningConfig,
                                                             LogManager).Create(
                               blockProducerEnv, blockProductionTrigger, txSource));
                }

                MevBlockProducer.MevBlockProducerInfo CreateProducer(int bundleLimit = 0,
                                                                     ITxSource?additionalTxSource = null)
                {
                    // TODO: this could be simplified a lot of the parent was not retrieved, not sure why do we need the parent here
                    bool BundleLimitTriggerCondition(BlockProductionEventArgs e)
                    {
                        // TODO: why do we need this parent? later we use only the current block number
                        BlockHeader?parent = BlockTree.GetProducedBlockParent(e.ParentHeader);

                        if (parent is not null)
                        {
                            // ToDo resolved conflict parent.Timestamp?
                            IEnumerable <MevBundle> bundles = BundlePool.GetBundles(parent.Number + 1, parent.Timestamp);
                            return(bundles.Count() >= bundleLimit);
                        }

                        return(false);
                    }

                    IManualBlockProductionTrigger manualTrigger = new BuildBlocksWhenRequested();
                    IBlockProductionTrigger       trigger       = manualTrigger;

                    if (bundleLimit != 0)
                    {
                        trigger = new TriggerWithCondition(manualTrigger, BundleLimitTriggerCondition);
                    }

                    IBlockProducer producer = CreatePostMergeBlockProducer(trigger, additionalTxSource);

                    return(new MevBlockProducer.MevBlockProducerInfo(producer, manualTrigger, new BeneficiaryTracer()));
                }

                int megabundleProducerCount = _relayAddresses.Any() ? 1 : 0;
                List <MevBlockProducer.MevBlockProducerInfo> blockProducers =
                    new(_maxMergedBundles + megabundleProducerCount + 1);

                // Add non-mev block
                MevBlockProducer.MevBlockProducerInfo standardProducer = CreateProducer();
                blockProducers.Add(standardProducer);

                // Try blocks with all bundle numbers <= maxMergedBundles
                for (int bundleLimit = 1; bundleLimit <= _maxMergedBundles; bundleLimit++)
                {
                    BundleSelector bundleSelector = new(BundlePool, bundleLimit);
                    BundleTxSource bundleTxSource = new(bundleSelector, Timestamper);
                    MevBlockProducer.MevBlockProducerInfo bundleProducer = CreateProducer(bundleLimit, bundleTxSource);
                    blockProducers.Add(bundleProducer);
                }

                if (megabundleProducerCount > 0)
                {
                    MegabundleSelector megabundleSelector = new(BundlePool);
                    BundleTxSource     megabundleTxSource = new(megabundleSelector, Timestamper);
                    MevBlockProducer.MevBlockProducerInfo bundleProducer = CreateProducer(0, megabundleTxSource);
                    blockProducers.Add(bundleProducer);
                }

                MevBlockProducer blockProducer = new MevBlockProducer(BlockProductionTrigger, LogManager, blockProducers.ToArray());

                blockProducer.BlockProduced += OnBlockProduced;
                return(blockProducer);
            }
        protected void GivenASpecProvider()
        {
            var specProvider = new SpecProvider <TestEntity>();

            _entitySpecs = specProvider.GetSpecifications().ToArray();
        }
Exemplo n.º 8
0
        protected void AndGivenAWiredUpContainer()
        {
            _cb = new ContainerBuilder();

            _cb.RegisterGeneric(typeof(SpecProvider <>))
            .As(typeof(IProvideSpecifications <>))
            .As(typeof(SpecProvider <>))
            .SingleInstance();

            _cb.RegisterGeneric(typeof(Processor <,>))
            .As(typeof(Processor <,>));

            _cb.RegisterGeneric(typeof(ProcessorEngine <>))
            .As(typeof(ProcessorEngine <>));

            _cb.RegisterGeneric(typeof(ProcessorConfiguration <,>))
            .As(typeof(ProcessorConfiguration <,>));

            //specialist
            _cb.Register(m =>
            {
                var s = new SpecProvider <Dto1>();

                s.Add(a =>
                {
                    if (a.Source.Key == "Key-5")
                    {
                        return(new SpecResult("Arbitrary invalid reason."));
                    }

                    return(SpecResult.Success);
                }, "Key", "Description");

                s.MergeFrom(mq => mq.Contact, m.Resolve <SpecProvider <Contact> >());
                return(s);
            }).AsSelf().AsImplementedInterfaces();

            _cb.Register(m =>
            {
                var s = new SpecProvider <Address>();

                s.Add(a =>
                {
                    if (a.ContactId == 0)
                    {
                        return(new SpecResult("Contact Id has not been assigned."));
                    }

                    return(SpecResult.Success);
                }, "Key", "Description");
                return(s);
            }).AsSelf().AsImplementedInterfaces();

            _cb.Register(m =>
            {
                var s = new FlowSnapshotRepo <FlowSnapshot>(Environment.CurrentDirectory);
                return(s);
            }).AsSelf().AsImplementedInterfaces();

            _container = _cb.Build();
        }