From ab06c96dd32f3aaa8c7decc7bda791b8470557f7 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 20 Sep 2022 09:33:28 +0100 Subject: [PATCH 1/2] Adjust cirrus poll timeout and fix try catch --- .../CirrusContractClient.cs | 22 +++++++++++++------ .../InteropPoller.cs | 9 ++++---- src/Stratis.Bitcoin.Networks/StraxMain.cs | 3 ++- src/Stratis.Bitcoin.Networks/StraxTest.cs | 1 + .../Consensus/CheckpointsTest.cs | 4 ++-- .../Properties/AssemblyInfo.cs | 4 ++-- src/Stratis.Bitcoin/Stratis.Bitcoin.csproj | 2 +- src/Stratis.Sidechains.Networks/CirrusMain.cs | 3 ++- src/Stratis.Sidechains.Networks/CirrusTest.cs | 3 ++- 9 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.Interop/CirrusContractClient.cs b/src/Stratis.Bitcoin.Features.Interop/CirrusContractClient.cs index 5cf5267bf0..7fae8e45b2 100644 --- a/src/Stratis.Bitcoin.Features.Interop/CirrusContractClient.cs +++ b/src/Stratis.Bitcoin.Features.Interop/CirrusContractClient.cs @@ -259,25 +259,33 @@ public async Task GetReceiptAsync(string txHash) public async Task GetBlockByHeightAsync(int blockHeight) { - string blockHash = await this.cirrusInteropSettings.CirrusClientUrl + string blockHash; + + using (CancellationTokenSource cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(GetReceiptWaitTimeSeconds))) + { + blockHash = await this.cirrusInteropSettings.CirrusClientUrl .AppendPathSegment("api/Consensus/getblockhash") .SetQueryParam("height", blockHeight) - .GetJsonAsync() + .GetJsonAsync(cancellation.Token) .ConfigureAwait(false); + } - if (blockHash == null) + if (string.IsNullOrEmpty(blockHash)) return null; - var hexResponse = await this.cirrusInteropSettings.CirrusClientUrl + using (CancellationTokenSource cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(GetReceiptWaitTimeSeconds))) + { + var hexResponse = await this.cirrusInteropSettings.CirrusClientUrl .AppendPathSegment("api/BlockStore/block") .SetQueryParam("Hash", blockHash) .SetQueryParam("ShowTransactionDetails", false) .SetQueryParam("OutputJson", false) - .GetStringAsync() + .GetStringAsync(cancellation.Token) .ConfigureAwait(false); - var block = NBitcoin.Block.Parse(JsonConvert.DeserializeObject(hexResponse), this.chainIndexer.Network.Consensus.ConsensusFactory); - return block; + var block = NBitcoin.Block.Parse(JsonConvert.DeserializeObject(hexResponse), this.chainIndexer.Network.Consensus.ConsensusFactory); + return block; + } } public async Task GetRawTransactionAsync(string transactionId) diff --git a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs index 84c66959fd..61188ff4d9 100644 --- a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs +++ b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs @@ -284,12 +284,13 @@ public async Task InitializeAsync() return; } - // In the event that the last polled block was set back a considerable distance from the tip, we need to first catch up faster. - // If we are already in the acceptable range, the usual logic will apply. - await EnsureLastPolledBlockIsSyncedWithCirrusChainAsync().ConfigureAwait(false); - try { + // In the event that the last polled block was set back a considerable distance from the tip, we need to first catch up faster. + // If we are already in the acceptable range, the usual logic will apply. + // This needs to be in the try catch so that any exceptions doesnt break teh async cloop. + await EnsureLastPolledBlockIsSyncedWithCirrusChainAsync().ConfigureAwait(false); + CheckForBlockHeightOverrides(DestinationChain.CIRRUS); var cirrusTipHeight = this.chainIndexer.Tip.Height; diff --git a/src/Stratis.Bitcoin.Networks/StraxMain.cs b/src/Stratis.Bitcoin.Networks/StraxMain.cs index 4f7f15ed7e..aab63500f0 100644 --- a/src/Stratis.Bitcoin.Networks/StraxMain.cs +++ b/src/Stratis.Bitcoin.Networks/StraxMain.cs @@ -172,7 +172,8 @@ public StraxMain() { 600_000, new CheckpointInfo(new uint256("0xde6e45862b53aa12e68ebe1ce58962a35dc44c9b6357d6137d6f4d72a7799262"), new uint256("0xc1b1e2c3417c1d41e906a53028421bec3a1f8969cf38516671433c2c85ef09d3")) }, { 700_000, new CheckpointInfo(new uint256("0x9383c8d2cb72273ec784c8bca40fd8aedb5014080b30e664e7025f9733e28cd4"), new uint256("0x2a90ab7ce85e1733631282f9cc392aa8b6f8a352234a8c992d38ff1651b039af")) }, { 750_000, new CheckpointInfo(new uint256("0x16a24a00b59bf1f0a366be26f6da9bc12814f315cbaac6b536494555f065f5d0"), new uint256("0x54426d468d84dd4b54adbedf62458c175235e23af537876150853738b6adfacf")) }, - { 1_000_000, new CheckpointInfo(new uint256("0x07e8f90f21ecfe1141b6b0b6c59f36bf350239e2facd92cf3e68bb81e105a3cc"), new uint256("0xf50f158adb8242b89d38e097b505fd0339bbd696d8f158d2751fe9504f0409e9")) } + { 1_000_000, new CheckpointInfo(new uint256("0x07e8f90f21ecfe1141b6b0b6c59f36bf350239e2facd92cf3e68bb81e105a3cc"), new uint256("0xf50f158adb8242b89d38e097b505fd0339bbd696d8f158d2751fe9504f0409e9")) }, + { 1_200_000, new CheckpointInfo(new uint256("0xada257ccb7dad06680b54202695cc2615523d7405c151cd47f1d80a3f92706ae"), new uint256("0x6f6d74c6cd3ca84a9f2a1ff2ac40e5318acbe8bf76fbe0b9c174569f2421288f")) }, }; this.Bech32Encoders = new Bech32Encoder[2]; diff --git a/src/Stratis.Bitcoin.Networks/StraxTest.cs b/src/Stratis.Bitcoin.Networks/StraxTest.cs index 4ee7b5355d..131f47e269 100644 --- a/src/Stratis.Bitcoin.Networks/StraxTest.cs +++ b/src/Stratis.Bitcoin.Networks/StraxTest.cs @@ -160,6 +160,7 @@ public StraxTest() { 750_000, new CheckpointInfo(new uint256("0x592842f3e5af517b0ce6f451f6b61738a6dea1007ccbaab39f22878de8de78dc"), new uint256("0x6ee053737f80a3a5173c10a507b1d1ea2ec9f6fa6be07b2b9d26558e4622f4a4")) }, { 800_000, new CheckpointInfo(new uint256("0x70c51661a4b358c42984019ee5dac9faee2f724860f651f8d78ed309e137f957"), new uint256("0x82ddde3f4e73a2eb69907b3f07f1f70f4c3b7e95812590fdef1050afb253cf84")) }, { 1_000_000, new CheckpointInfo(new uint256("0xdde93ee6c33d08f3e7759b5f4e245dc716d7dc08444228bc6c8930d03add89f8"), new uint256("0xb6f4354685af869a59c020e6a7755366c12c99d348a14105e455b4d71a1113dd")) }, + { 1_250_000, new CheckpointInfo(new uint256("0xa8e76aaded9383220131dcd567e1fc7984c6703f03d6fd52809a29d37661898f"), new uint256("0x142064258753fbd80adf77540059985a075316d34cf479674d9fdc3e44216c54")) }, }; this.Bech32Encoders = new Bech32Encoder[2]; diff --git a/src/Stratis.Bitcoin.Tests/Consensus/CheckpointsTest.cs b/src/Stratis.Bitcoin.Tests/Consensus/CheckpointsTest.cs index 7427433b74..78fb48357f 100644 --- a/src/Stratis.Bitcoin.Tests/Consensus/CheckpointsTest.cs +++ b/src/Stratis.Bitcoin.Tests/Consensus/CheckpointsTest.cs @@ -74,7 +74,7 @@ public void GetLastCheckPointHeight_StraxMainnet_ReturnsLastCheckPointHeight() int result = checkpoints.GetLastCheckpointHeight(); - Assert.Equal(1_000_000, result); + Assert.Equal(1_200_000, result); } [Fact] @@ -84,7 +84,7 @@ public void GetLastCheckPointHeight_StraxTestnet_ReturnsLastCheckPointHeight() int result = checkpoints.GetLastCheckpointHeight(); - Assert.Equal(1_000_000, result); + Assert.Equal(1_250_000, result); } [Fact] diff --git a/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs b/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs index 8f77416663..92e3dc3fd8 100644 --- a/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs +++ b/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.2.2")] -[assembly: AssemblyFileVersion("1.3.2.2")] +[assembly: AssemblyVersion("1.3.2.3")] +[assembly: AssemblyFileVersion("1.3.2.3")] [assembly: InternalsVisibleTo("Stratis.Bitcoin.Tests")] \ No newline at end of file diff --git a/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj b/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj index fa075aab22..4c13a31387 100644 --- a/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj +++ b/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj @@ -14,7 +14,7 @@ false false false - 1.3.2.2 + 1.3.2.3 False ..\Stratis.ruleset Stratis Group Ltd. diff --git a/src/Stratis.Sidechains.Networks/CirrusMain.cs b/src/Stratis.Sidechains.Networks/CirrusMain.cs index 46ee8b66bd..3661650f55 100644 --- a/src/Stratis.Sidechains.Networks/CirrusMain.cs +++ b/src/Stratis.Sidechains.Networks/CirrusMain.cs @@ -288,7 +288,8 @@ public CirrusMain() { 3_500_000, new CheckpointInfo(new uint256("0x1772356d6498935ab93cbd5eaf1b868c5265480edeef2b5fec133fbc21b292cb")) }, { 3_700_000, new CheckpointInfo(new uint256("0x16b41558dedb4945476f0212034bd148bef3cdeccdd1b55a198f8b1d6900716b")) }, { 3_834_160, new CheckpointInfo(new uint256("0xa0e7b27d1e642301a5b3a985dc98953858d89849e9b864de7e9b62e6856973a0")) }, - { 4_100_000, new CheckpointInfo(new uint256("0x4f099739c22560ce27b7d5e6d30e86e7e6f52062504f0d31c25a427074de85f8")) } + { 4_100_000, new CheckpointInfo(new uint256("0x4f099739c22560ce27b7d5e6d30e86e7e6f52062504f0d31c25a427074de85f8")) }, + { 4_800_000, new CheckpointInfo(new uint256("0xed81ddcdd743bdc2c74bbf16fce61082409169c45f95cfc4767d6e50e1b2833d")) } }; this.DNSSeeds = new List diff --git a/src/Stratis.Sidechains.Networks/CirrusTest.cs b/src/Stratis.Sidechains.Networks/CirrusTest.cs index 30607d86f7..525b8d2dc0 100644 --- a/src/Stratis.Sidechains.Networks/CirrusTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusTest.cs @@ -241,7 +241,8 @@ public CirrusTest() { 3_219_570, new CheckpointInfo(new uint256("0xb08c34d0879c65f6e3649eff05853a8d38081d898230beb671b591179f57892d")) }, { 3_275_480, new CheckpointInfo(new uint256("0x70d4dd9bae9db409c0df441d3afb430821f85f166223357a456e4a2ba5c478af")) }, { 3_300_000, new CheckpointInfo(new uint256("0x83e45cb4c85087819169f3f0793eeacd1899a1b5882b505d8e407d0f035eb116")) }, - { 3_400_000, new CheckpointInfo(new uint256("0xa0d62c480085e20d94a8650949eb47579a62c4da99d5e78914f67bb911ce6b27")) } + { 3_400_000, new CheckpointInfo(new uint256("0xa0d62c480085e20d94a8650949eb47579a62c4da99d5e78914f67bb911ce6b27")) }, + { 3_850_000, new CheckpointInfo(new uint256("0xc427aca59ce98cb21a7ebd3b8850012277704625c334ed6715fd0e5277a11d42")) } }; this.DNSSeeds = new List From c116106291264306913f5d0cdee0a5400675d991 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 20 Sep 2022 09:38:28 +0100 Subject: [PATCH 2/2] Update src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs Co-authored-by: zeptin --- src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs index 61188ff4d9..11a5ba8f8d 100644 --- a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs +++ b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs @@ -288,7 +288,7 @@ public async Task InitializeAsync() { // In the event that the last polled block was set back a considerable distance from the tip, we need to first catch up faster. // If we are already in the acceptable range, the usual logic will apply. - // This needs to be in the try catch so that any exceptions doesnt break teh async cloop. + // This needs to be in the try catch so that any exceptions don't break the async loop. await EnsureLastPolledBlockIsSyncedWithCirrusChainAsync().ConfigureAwait(false); CheckForBlockHeightOverrides(DestinationChain.CIRRUS);