From 6f17f9bf547f63edb8034b58218b529850c33f5c Mon Sep 17 00:00:00 2001 From: Kevin Loubser Date: Wed, 31 May 2023 08:57:49 +0200 Subject: [PATCH 1/2] Fix hardcoding of conversion request type detection on CRS --- .../InteropPoller.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs index 0f829781ac..471af158fa 100644 --- a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs +++ b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs @@ -420,7 +420,7 @@ private async Task PollCirrusForTransfersAsync() NBitcoin.Block block = await this.cirrusClient.GetBlockByHeightAsync(applicableHeight).ConfigureAwait(false); if (block == null) { - this.logger.Info($"Unable to retrieve block at height {applicableHeight}."); + this.logger.Info($"Unable to retrieve Cirrus block at height {applicableHeight}."); // We shouldn't update the block height before returning because we might skip a block. return; @@ -443,7 +443,7 @@ private async Task PollCirrusForTransfersAsync() // This is probably a normal Cirrus transfer (if null), or a failed contract call that should be ignored. if (receipt == null || !receipt.Success) { - this.logger.Debug($"Transaction {transaction.GetHash()} did not contain a receipt."); + this.logger.Debug($"Transaction {transaction.GetHash()} (CRS) did not contain a receipt."); continue; } @@ -470,7 +470,7 @@ private async Task PollCirrusForTransfersAsync() if (watchedErc721Contracts.Contains(receipt.To)) contractType = ContractType.ERC721; - // This is a special case, and will be a mint if the transfer is being made to the federation multisig contract. + // This is a special case, and will be a mint if the NFT transfer is being made to the federation multisig contract (i.e. in the relevant Transfer log). if (watchedSrc721Contracts.Contains(receipt.To)) { contractType = ContractType.ERC721; @@ -489,13 +489,25 @@ private async Task PollCirrusForTransfersAsync() continue; } + // This is a safety check, BurnWithMetadata logs should not be getting emitted for non-burn transfers (i.e. transfers where the To address is not zero). But it is possible that a contract erroneously does so. + if (conversionRequestType == ConversionRequestType.Burn && receipt.To != "0000000000000000000000000000000000000000") + { + continue; + } + + // It can only be an xRC721 mint if the multisig contract is the recipient on CRS. + if (conversionRequestType == ConversionRequestType.Mint && srcDetails.To != this.interopSettings.CirrusSettings.CirrusMultisigContractAddress) + { + continue; + } + this.logger.Info($"Found a valid {(contractType == ContractType.ERC721 ? "SRC721->ERC721" : "SRC20->ERC20")} {(conversionRequestType == ConversionRequestType.Burn ? "burn" : "transfer")} transaction with metadata: {srcDetails.To}."); // Create the conversion request object. var request = new ConversionRequest() { RequestId = receipt.TransactionHash, - RequestType = ConversionRequestType.Burn, + RequestType = conversionRequestType, Amount = ConvertBigIntegerToUint256(srcDetails.Value), BlockHeight = applicableHeight, DestinationAddress = srcDetails.To, @@ -520,7 +532,7 @@ private async Task PollCirrusForTransfersAsync() // If a dynamic fee could not be determined, ignore the fee for now. // Subsequent work in progress will allow us to reprocess "missed" multisig fees. if (feeDeterminedByMultiSig == null || (feeDeterminedByMultiSig != null && feeDeterminedByMultiSig.State != InteropFeeState.AgreeanceConcluded)) - this.logger.Warn($"A dynamic fee for SRC20->ERC20 request '{receipt.TransactionHash}' could not be determined, ignoring fee until reprocessing at some later stage."); + this.logger.Warn($"A dynamic fee for {(contractType == ContractType.ERC721 ? "SRC721->ERC721" : "SRC20->ERC20")} request '{receipt.TransactionHash}' could not be determined, ignoring fee until reprocessing at some later stage."); else ProcessConversionRequestFee(feeProvidedFromTransaction, feeDeterminedByMultiSig, receipt, applicableHeight, block); From 5f1241a85edc6c45062040b1ccc06614bb387059 Mon Sep 17 00:00:00 2001 From: Kevin Loubser Date: Wed, 31 May 2023 09:15:09 +0200 Subject: [PATCH 2/2] Remove duplicated code --- src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs index 471af158fa..d111332438 100644 --- a/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs +++ b/src/Stratis.Bitcoin.Features.Interop/InteropPoller.cs @@ -550,17 +550,6 @@ private async Task PollCirrusForTransfersAsync() { this.conversionRequestRepository.Save(request); } - - this.logger.Info($"A transfer request from CRS to '{tokenString}' will be processed."); - - request.Processed = false; - request.RequestStatus = ConversionRequestStatus.Unprocessed; - request.TokenContract = contractMapping.Key; - - lock (this.repositoryLock) - { - this.conversionRequestRepository.Save(request); - } } } catch (Exception e)