diff --git a/Framework/BlockchainUtils/BlockTimeFinder.cs b/Framework/BlockchainUtils/BlockTimeFinder.cs index c6f10573..ee49836c 100644 --- a/Framework/BlockchainUtils/BlockTimeFinder.cs +++ b/Framework/BlockchainUtils/BlockTimeFinder.cs @@ -20,9 +20,10 @@ namespace BlockchainUtils public BlockTimeEntry Get(ulong blockNumber) { - bounds.Initialize(); var b = cache.Get(blockNumber); if (b != null) return b; + + bounds.Initialize(); return GetBlock(blockNumber); } diff --git a/Framework/BlockchainUtils/BlockchainBounds.cs b/Framework/BlockchainUtils/BlockchainBounds.cs index 27328669..32ce728f 100644 --- a/Framework/BlockchainUtils/BlockchainBounds.cs +++ b/Framework/BlockchainUtils/BlockchainBounds.cs @@ -87,6 +87,8 @@ private void AddCurrentBlock() { var currentBlockNumber = web3.GetCurrentBlockNumber(); + if (Current != null && Current.BlockNumber == currentBlockNumber) return; + var blockTime = web3.GetTimestampForBlock(currentBlockNumber); if (blockTime == null) throw new Exception("Unable to get dateTime for current block."); AddCurrentBlock(currentBlockNumber, blockTime.Value); diff --git a/Framework/NethereumWorkflow/Web3Wrapper.cs b/Framework/NethereumWorkflow/Web3Wrapper.cs index a68ad2e4..b7859685 100644 --- a/Framework/NethereumWorkflow/Web3Wrapper.cs +++ b/Framework/NethereumWorkflow/Web3Wrapper.cs @@ -19,23 +19,40 @@ namespace NethereumWorkflow public ulong GetCurrentBlockNumber() { - var number = Time.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync()); - return Convert.ToUInt64(number.ToDecimal()); + return Retry(() => + { + var number = Time.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync()); + return Convert.ToUInt64(number.ToDecimal()); + }); } public DateTime? GetTimestampForBlock(ulong blockNumber) { - try + return Retry(() => { - var block = Time.Wait(web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(new BlockParameter(blockNumber))); - if (block == null) return null; - return DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(block.Timestamp.ToDecimal())).UtcDateTime; - } - catch (Exception ex) - { - log.Error("Exception while getting timestamp for block: " + ex); - return null; - } + try + { + var block = Time.Wait(web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(new BlockParameter(blockNumber))); + if (block == null) return null; + return DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(block.Timestamp.ToDecimal())).UtcDateTime; + } + catch (Exception ex) + { + log.Error("Exception while getting timestamp for block: " + ex); + return null; + } + }); + } + + private T Retry(Func action) + { + var retry = new Retry(nameof(Web3Wrapper), + maxTimeout: TimeSpan.FromSeconds(30), + sleepAfterFail: TimeSpan.FromSeconds(3), + onFail: f => { }, + failFast: false); + + return retry.Run(action); } } } diff --git a/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs b/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs index 72a56681..f22dbaf0 100644 --- a/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs +++ b/Tests/CodexReleaseTests/MarketTests/MarketplaceAutoBootstrapDistTest.cs @@ -122,7 +122,8 @@ namespace CodexReleaseTests.MarketTests var result = new ChainMonitor(log, contracts, startUtc); result.Start(() => { - Assert.Fail("Failure in chain monitor."); + log.Error("Failure in chain monitor. No chain updates after this point."); + //Assert.Fail("Failure in chain monitor."); }); return result; } diff --git a/Tests/CodexReleaseTests/MarketTests/MultipleContractsTest.cs b/Tests/CodexReleaseTests/MarketTests/MultipleContractsTest.cs index 73b3fa91..aa5329ff 100644 --- a/Tests/CodexReleaseTests/MarketTests/MultipleContractsTest.cs +++ b/Tests/CodexReleaseTests/MarketTests/MultipleContractsTest.cs @@ -5,11 +5,11 @@ using Utils; namespace CodexReleaseTests.MarketTests { - [TestFixture(8, 3, 1)] + //[TestFixture(8, 3, 1)] [TestFixture(8, 4, 1)] - [TestFixture(10, 5, 1)] - [TestFixture(10, 6, 1)] - [TestFixture(10, 6, 3)] + //[TestFixture(10, 5, 1)] + //[TestFixture(10, 6, 1)] + //[TestFixture(10, 6, 3)] public class MultipleContractsTest : MarketplaceAutoBootstrapDistTest { public MultipleContractsTest(int hosts, int slots, int tolerance) @@ -33,7 +33,7 @@ namespace CodexReleaseTests.MarketTests [Test] [Combinatorial] public void MultipleContractGenerations( - [Values(10)] int numGenerations) + [Values(50)] int numGenerations) { var hosts = StartHosts(); var clients = StartClients(); @@ -96,7 +96,7 @@ namespace CodexReleaseTests.MarketTests MinRequiredNumberOfNodes = (uint)slots, NodeFailureTolerance = (uint)tolerance, PricePerBytePerSecond = pricePerBytePerSecond, - ProofProbability = 20, + ProofProbability = 1, CollateralPerByte = 1.TstWei() }); } diff --git a/Tests/CodexReleaseTests/Parallelism.cs b/Tests/CodexReleaseTests/Parallelism.cs index eb2da742..a1b26c73 100644 --- a/Tests/CodexReleaseTests/Parallelism.cs +++ b/Tests/CodexReleaseTests/Parallelism.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -[assembly: LevelOfParallelism(4)] +[assembly: LevelOfParallelism(1)] namespace CodexReleaseTests.DataTests { }