public void Should_count_valid_megabundles() { var ecdsa = Substitute.For <IEthereumEcdsa>(); ecdsa.RecoverAddress(Arg.Any <Signature>(), Arg.Any <Keccak>()).Returns(TestItem.AddressB); TestBundlePool bundlePool = CreateTestBundlePool(ecdsa); int beforeMegabundlesReceived = Metrics.MegabundlesReceived; int beforeValidMegabundlesReceived = Metrics.ValidMegabundlesReceived; int beforeBundlesSimulated = Metrics.BundlesSimulated; bundlePool.AddMegabundle(new MevMegabundle(1, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject })); bundlePool.AddMegabundle(new MevMegabundle(1, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject })); bundlePool.AddMegabundle(new MevMegabundle(3, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject })); bundlePool.AddMegabundle(new MevMegabundle(4, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject })); int deltaMegabundlesReceived = Metrics.MegabundlesReceived - beforeMegabundlesReceived; int deltaValidMegabundlesReceived = Metrics.ValidMegabundlesReceived - beforeValidMegabundlesReceived; int deltaMegabundlesSimulated = Metrics.BundlesSimulated - beforeBundlesSimulated; deltaMegabundlesReceived.Should().Be(4); deltaValidMegabundlesReceived.Should().Be(4); deltaMegabundlesSimulated.Should().Be(2); // first two megeabundles are at current head }
public void Should_count_invalid_bundles() { TestBundlePool bundlePool = CreateTestBundlePool(); int beforeBundlesReceived = Metrics.BundlesReceived; int beforeValidBundlesReceived = Metrics.ValidBundlesReceived; int beforeBundlesSimulated = Metrics.BundlesSimulated; MevBundle[] bundles = new[] { new MevBundle(1, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 5, 0), // invalid new MevBundle(2, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 0, 0), new MevBundle(3, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 0, long.MaxValue), // invalid new MevBundle(4, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 0, 0) }; foreach (MevBundle mevBundle in bundles) { bundlePool.AddBundle(mevBundle); } int deltaBundlesReceived = Metrics.BundlesReceived - beforeBundlesReceived; int deltaValidBundlesReceived = Metrics.ValidBundlesReceived - beforeValidBundlesReceived; int deltaBundlesSimulated = Metrics.BundlesSimulated - beforeBundlesSimulated; deltaBundlesReceived.Should().Be(4); deltaValidBundlesReceived.Should().Be(2); deltaBundlesSimulated.Should().Be(0); // should not simulate invalid bundle }
public void Should_count_invalid_megabundles() { var ecdsa = Substitute.For <IEthereumEcdsa>(); MevMegabundle[] bundles = new[] { new MevMegabundle(1, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, minTimestamp: 5, maxTimestamp: 0), // invalid new MevMegabundle(2, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, minTimestamp: 0, maxTimestamp: 0), // invalid relay address new MevMegabundle(3, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, minTimestamp: 0, maxTimestamp: long.MaxValue), // invalid new MevMegabundle(4, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, minTimestamp: 0, maxTimestamp: 0) }; ecdsa.RecoverAddress(Arg.Any <Signature>(), bundles[2].Hash).Returns(TestItem.AddressC); // not in list of trusted relay addresses ecdsa.RecoverAddress(Arg.Any <Signature>(), bundles[3].Hash).Returns(TestItem.AddressB); // trusted relay address TestBundlePool bundlePool = CreateTestBundlePool(ecdsa); int beforeMegabundlesReceived = Metrics.MegabundlesReceived; int beforeValidMegabundlesReceived = Metrics.ValidMegabundlesReceived; int beforeMegabundlesSimulated = Metrics.BundlesSimulated; foreach (MevMegabundle mevMegabundle in bundles) { bundlePool.AddMegabundle(mevMegabundle); } int deltaBundlesReceived = Metrics.MegabundlesReceived - beforeMegabundlesReceived; int deltaValidBundlesReceived = Metrics.ValidMegabundlesReceived - beforeValidMegabundlesReceived; int deltaBundlesSimulated = Metrics.BundlesSimulated - beforeMegabundlesSimulated; deltaBundlesReceived.Should().Be(4); deltaValidBundlesReceived.Should().Be(1); deltaBundlesSimulated.Should().Be(0); // should not simulate invalid bundle }
protected override BlockProcessor CreateBlockProcessor() { BlockValidator = CreateBlockValidator(); BlockProcessor blockProcessor = new( SpecProvider, BlockValidator, NoBlockRewards.Instance, new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, Storage, ReceiptStorage, NullWitnessCollector.Instance, LogManager); _tracerFactory = new TracerFactory( DbProvider, BlockTree, ReadOnlyTrieStore, BlockPreprocessorStep, SpecProvider, LogManager, ProcessingOptions.ProducingBlock); TxBundleSimulator txBundleSimulator = new(_tracerFactory, GasLimitCalculator, Timestamper, TxPool, SpecProvider, Signer); BundlePool = new TestBundlePool(BlockTree, txBundleSimulator, Timestamper, new TxValidator(BlockTree.ChainId), SpecProvider, _mevConfig, LogManager, EthereumEcdsa); return(blockProcessor); }
public void Should_count_valid_bundles() { TestBundlePool bundlePool = CreateTestBundlePool(); int beforeBundlesReceived = Metrics.BundlesReceived; int beforeValidBundlesReceived = Metrics.ValidBundlesReceived; int beforeBundlesSimulated = Metrics.BundlesSimulated; bundlePool.AddBundle(new MevBundle(1, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject, Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).WithNonce(1).TestObject }, 0, 0)); bundlePool.AddBundle(new MevBundle(1, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 0, 0)); bundlePool.AddBundle(new MevBundle(3, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 0, 0)); bundlePool.AddBundle(new MevBundle(4, new [] { Build.A.TypedTransaction <BundleTransaction>().SignedAndResolved(TestItem.PrivateKeyA).TestObject }, 0, 0)); int deltaBundlesReceived = Metrics.BundlesReceived - beforeBundlesReceived; int deltaValidBundlesReceived = Metrics.ValidBundlesReceived - beforeValidBundlesReceived; int deltaBundlesSimulated = Metrics.BundlesSimulated - beforeBundlesSimulated; deltaBundlesReceived.Should().Be(4); deltaValidBundlesReceived.Should().Be(4); deltaBundlesSimulated.Should().Be(2); // only first two bundles are at current head }