From ba8a51d54668b89dd4cf537a63d32c2cb3f12d85 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 16 Mar 2021 16:16:23 +0000 Subject: [PATCH 1/6] Fix DevMode send transaction --- .../ColdStakingWalletService.cs | 14 ++++++++--- .../TestPoAMiner.cs | 7 ++++-- .../PoATestsBase.cs | 2 +- .../FederationManager.cs | 5 +--- src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs | 23 +++++++++++-------- .../PoASettings.cs | 8 +------ .../Controllers/SmartContractsController.cs | 12 +++++----- .../Services/WalletService.cs | 22 +++++++----------- .../Configuration/NodeSettings.cs | 17 ++++++++++++++ .../Properties/launchSettings.json | 9 ++++++++ .../CollateralPoAMiner.cs | 7 ++++-- .../CollateralCheckerTests.cs | 2 +- .../FederationGatewayControllerTests.cs | 2 +- 13 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 src/Stratis.CirrusMinerD/Properties/launchSettings.json diff --git a/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingWalletService.cs b/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingWalletService.cs index 5382cde0bf..3ee8592493 100644 --- a/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingWalletService.cs +++ b/src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingWalletService.cs @@ -7,6 +7,7 @@ using NBitcoin; using NBitcoin.Policy; using Stratis.Bitcoin.Builder.Feature; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Features.BlockStore; @@ -21,9 +22,16 @@ namespace Stratis.Bitcoin.Features.ColdStaking /// /// Contains modified implementations of the methods suitable for cold staking. /// - public class ColdStakingWalletService : WalletService + public sealed class ColdStakingWalletService : WalletService { - public ColdStakingWalletService(ILoggerFactory loggerFactory, IWalletManager walletManager, IConsensusManager consensusManager, IWalletTransactionHandler walletTransactionHandler, IWalletSyncManager walletSyncManager, IConnectionManager connectionManager, Network network, ChainIndexer chainIndexer, IBroadcasterManager broadcasterManager, IDateTimeProvider dateTimeProvider, IUtxoIndexer utxoIndexer, IWalletFeePolicy walletFeePolicy) : base(loggerFactory, walletManager, consensusManager, walletTransactionHandler, walletSyncManager, connectionManager, network, chainIndexer, broadcasterManager, dateTimeProvider, utxoIndexer, walletFeePolicy) + public ColdStakingWalletService( + ILoggerFactory loggerFactory, IWalletManager walletManager, + IConsensusManager consensusManager, IWalletTransactionHandler walletTransactionHandler, + IWalletSyncManager walletSyncManager, IConnectionManager connectionManager, + Network network, ChainIndexer chainIndexer, IBroadcasterManager broadcasterManager, + IDateTimeProvider dateTimeProvider, IUtxoIndexer utxoIndexer, + IWalletFeePolicy walletFeePolicy, NodeSettings nodeSettings) + : base(loggerFactory, walletManager, consensusManager, walletTransactionHandler, walletSyncManager, connectionManager, network, chainIndexer, broadcasterManager, dateTimeProvider, utxoIndexer, walletFeePolicy, nodeSettings) { } @@ -77,7 +85,7 @@ public override async Task OfflineSignRequest(Offli var coldAccountAddresses = coldAccount.GetCombinedAddresses(); hdAddress = coldAccountAddresses.FirstOrDefault(a => a.Address == address || a.Bech32Address == address); } - + // It is possible that the address is outside the gap limit. So if it is not found we optimistically presume the address descriptors will fill in the missing information later. if (hdAddress != null) { diff --git a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoAMiner.cs b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoAMiner.cs index 6745c5be77..d49c8ca3a9 100644 --- a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoAMiner.cs +++ b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoAMiner.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging; using NBitcoin; using Stratis.Bitcoin.AsyncWork; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Consensus.Validators; @@ -42,8 +43,10 @@ public TestPoAMiner( VotingManager votingManager, PoASettings poAMinerSettings, IAsyncProvider asyncProvider, - IIdleFederationMembersKicker idleFederationMembersKicker) : base(consensusManager, dateTimeProvider, network, nodeLifetime, loggerFactory, ibdState, blockDefinition, slotsManager, - connectionManager, poaHeaderValidator, federationManager, integrityValidator, walletManager, nodeStats, votingManager, poAMinerSettings, asyncProvider, idleFederationMembersKicker) + IIdleFederationMembersKicker idleFederationMembersKicker, + NodeSettings nodeSettings) + : base(consensusManager, dateTimeProvider, network, nodeLifetime, loggerFactory, ibdState, blockDefinition, slotsManager, + connectionManager, poaHeaderValidator, federationManager, integrityValidator, walletManager, nodeStats, votingManager, poAMinerSettings, asyncProvider, idleFederationMembersKicker, nodeSettings) { this.timeProvider = dateTimeProvider as EditableTimeProvider; diff --git a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs index ae84044aa6..c973e9d041 100644 --- a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs +++ b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs @@ -110,7 +110,7 @@ public static (IFederationManager federationManager, IFederationHistory federati var counterChainSettings = new CounterChainSettings(nodeSettings, new CounterChainNetworkWrapper(new StraxRegTest())); - var federationManager = new FederationManager(fullNode.Object, network, nodeSettings, signals, new PoASettings(nodeSettings), counterChainSettings); + var federationManager = new FederationManager(fullNode.Object, network, nodeSettings, signals, counterChainSettings); var asyncProvider = new AsyncProvider(loggerFactory, signals); var finalizedBlockRepo = new FinalizedBlockInfoRepository(new LevelDbKeyValueRepository(nodeSettings.DataFolder, dbreezeSerializer), asyncProvider); finalizedBlockRepo.LoadFinalizedBlockInfoAsync(network).GetAwaiter().GetResult(); diff --git a/src/Stratis.Bitcoin.Features.PoA/FederationManager.cs b/src/Stratis.Bitcoin.Features.PoA/FederationManager.cs index 016ce78d9f..8d74ff6eea 100644 --- a/src/Stratis.Bitcoin.Features.PoA/FederationManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/FederationManager.cs @@ -80,7 +80,6 @@ public sealed class FederationManager : IFederationManager private readonly ILogger logger; private readonly PoANetwork network; private readonly NodeSettings nodeSettings; - private readonly PoASettings poaSettings; private readonly ISignals signals; private int? multisigMinersApplicabilityHeight; @@ -91,14 +90,12 @@ public FederationManager( Network network, NodeSettings nodeSettings, ISignals signals, - PoASettings poaSettings, ICounterChainSettings counterChainSettings = null) { this.counterChainSettings = counterChainSettings; this.fullNode = fullNode; this.network = Guard.NotNull(network as PoANetwork, nameof(network)); this.nodeSettings = Guard.NotNull(nodeSettings, nameof(nodeSettings)); - this.poaSettings = poaSettings; this.signals = Guard.NotNull(signals, nameof(signals)); this.logger = LogManager.GetCurrentClassLogger(); @@ -142,7 +139,7 @@ public void Initialize() private bool InitializeFederationMemberKey() { - if (!this.poaSettings.DevMode) + if (!this.nodeSettings.DevMode) { // Load key. Key key = new KeyTool(this.nodeSettings.DataFolder).LoadPrivateKey(); diff --git a/src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs b/src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs index e72c0fe974..8b4d13d7f5 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using NBitcoin; using Stratis.Bitcoin.AsyncWork; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Configuration.Logging; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Consensus; @@ -70,13 +71,15 @@ public class PoAMiner : IPoAMiner private readonly IIdleFederationMembersKicker idleFederationMembersKicker; + private readonly NodeSettings nodeSettings; + private readonly IWalletManager walletManager; protected readonly VotingManager votingManager; private readonly VotingDataEncoder votingDataEncoder; - private readonly PoASettings settings; + private readonly PoASettings poaSettings; private readonly IAsyncProvider asyncProvider; @@ -102,7 +105,8 @@ public PoAMiner( VotingManager votingManager, PoASettings poAMinerSettings, IAsyncProvider asyncProvider, - IIdleFederationMembersKicker idleFederationMembersKicker) + IIdleFederationMembersKicker idleFederationMembersKicker, + NodeSettings nodeSettings) { this.consensusManager = consensusManager; this.dateTimeProvider = dateTimeProvider; @@ -116,13 +120,14 @@ public PoAMiner( this.integrityValidator = integrityValidator; this.walletManager = walletManager; this.votingManager = votingManager; - this.settings = poAMinerSettings; + this.poaSettings = poAMinerSettings; this.asyncProvider = asyncProvider; this.idleFederationMembersKicker = idleFederationMembersKicker; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.cancellation = CancellationTokenSource.CreateLinkedTokenSource(new[] { nodeLifetime.ApplicationStopping }); this.votingDataEncoder = new VotingDataEncoder(loggerFactory); + this.nodeSettings = nodeSettings; nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name); } @@ -144,11 +149,11 @@ private async Task CreateBlocksAsync() try { this.logger.LogDebug("IsInitialBlockDownload={0}, AnyConnectedPeers={1}, BootstrappingMode={2}, IsFederationMember={3}", - this.ibdState.IsInitialBlockDownload(), this.connectionManager.ConnectedPeers.Any(), this.settings.BootstrappingMode, this.federationManager.IsFederationMember); + this.ibdState.IsInitialBlockDownload(), this.connectionManager.ConnectedPeers.Any(), this.poaSettings.BootstrappingMode, this.federationManager.IsFederationMember); // Don't mine in IBD or if we aren't connected to any node (unless bootstrapping mode is enabled). // Don't try to mine if we aren't a federation member. - bool cantMineAtAll = (this.ibdState.IsInitialBlockDownload() || !this.connectionManager.ConnectedPeers.Any()) && !this.settings.BootstrappingMode; + bool cantMineAtAll = (this.ibdState.IsInitialBlockDownload() || !this.connectionManager.ConnectedPeers.Any()) && !this.poaSettings.BootstrappingMode; if (cantMineAtAll || !this.federationManager.IsFederationMember) { if (!cantMineAtAll) @@ -193,10 +198,10 @@ private async Task CreateBlocksAsync() // There is therefore no point keeping this mode enabled once this node has mined successfully. // Additionally, keeping it enabled may result in network splits if this node becomes disconnected from its peers for a prolonged period. // If DevMode is enabled the miner will conitnue it's bootstrapped mining, i.e. without any connections. - if (this.settings.BootstrappingMode && !this.settings.DevMode) + if (this.poaSettings.BootstrappingMode && !this.nodeSettings.DevMode) { this.logger.LogInformation("Disabling bootstrap mode as a block has been successfully mined."); - this.settings.DisableBootstrap(); + this.poaSettings.DisableBootstrap(); } } catch (OperationCanceledException) @@ -281,9 +286,9 @@ protected async Task MineBlockAtTimestampAsync(uint timestamp) // If an address is specified for mining then preferentially use that. // The private key for this address is not used for block signing, so it can be any valid address. // Since it is known which miner mines in each block already it does not change the privacy level that every block mines to the same address. - if (!string.IsNullOrWhiteSpace(this.settings.MineAddress)) + if (!string.IsNullOrWhiteSpace(this.poaSettings.MineAddress)) { - this.walletScriptPubKey = BitcoinAddress.Create(this.settings.MineAddress, this.network).ScriptPubKey; + this.walletScriptPubKey = BitcoinAddress.Create(this.poaSettings.MineAddress, this.network).ScriptPubKey; } else { diff --git a/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs b/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs index 16416064b8..66c24138ea 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs @@ -3,7 +3,7 @@ namespace Stratis.Bitcoin.Features.PoA { - public class PoASettings + public sealed class PoASettings { /// /// String value that defines the devmode flag in config. @@ -15,11 +15,6 @@ public class PoASettings /// public bool BootstrappingMode { get; private set; } - /// - /// A flag that allows the miner to continue its bootstrapped mining, whilst having no connections. - /// - public bool DevMode { get; private set; } - /// /// An address to use when mining, if not specified an address from the wallet will be used. /// @@ -32,7 +27,6 @@ public PoASettings(NodeSettings nodeSettings) TextFileConfiguration config = nodeSettings.ConfigReader; this.BootstrappingMode = config.GetOrDefault("bootstrap", false); - this.DevMode = config.GetOrDefault(DevModeParam, false); this.MineAddress = config.GetOrDefault("mineaddress", null); } diff --git a/src/Stratis.Bitcoin.Features.SmartContracts/ReflectionExecutor/Controllers/SmartContractsController.cs b/src/Stratis.Bitcoin.Features.SmartContracts/ReflectionExecutor/Controllers/SmartContractsController.cs index b38a2c532e..c2a74a856e 100644 --- a/src/Stratis.Bitcoin.Features.SmartContracts/ReflectionExecutor/Controllers/SmartContractsController.cs +++ b/src/Stratis.Bitcoin.Features.SmartContracts/ReflectionExecutor/Controllers/SmartContractsController.cs @@ -10,9 +10,9 @@ using Microsoft.Extensions.Logging; using NBitcoin; using Newtonsoft.Json; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Controllers; -using Stratis.Bitcoin.Features.PoA; using Stratis.Bitcoin.Features.SmartContracts.Models; using Stratis.Bitcoin.Features.SmartContracts.Wallet; using Stratis.Bitcoin.Features.Wallet; @@ -56,7 +56,7 @@ public class SmartContractsController : FeatureController private readonly ILocalExecutor localExecutor; private readonly ISmartContractTransactionService smartContractTransactionService; private readonly IConnectionManager connectionManager; - private readonly PoASettings poaSettings; + private readonly NodeSettings nodeSettings; public SmartContractsController(IBroadcasterManager broadcasterManager, IBlockStore blockStore, @@ -72,7 +72,7 @@ public SmartContractsController(IBroadcasterManager broadcasterManager, ILocalExecutor localExecutor, ISmartContractTransactionService smartContractTransactionService, IConnectionManager connectionManager, - PoASettings poASettings = null) + NodeSettings nodeSettings) { this.stateRoot = stateRoot; this.contractDecompiler = contractDecompiler; @@ -88,7 +88,7 @@ public SmartContractsController(IBroadcasterManager broadcasterManager, this.localExecutor = localExecutor; this.smartContractTransactionService = smartContractTransactionService; this.connectionManager = connectionManager; - this.poaSettings = poASettings; + this.nodeSettings = nodeSettings; } /// @@ -517,7 +517,7 @@ public async Task BuildAndSendCreateSmartContractTransactionAsync return ModelStateErrors.BuildErrorResponse(this.ModelState); // Ignore this check if the node is running dev mode. - if ((this.poaSettings != null && !this.poaSettings.DevMode) && !this.connectionManager.ConnectedPeers.Any()) + if (!this.nodeSettings.DevMode && !this.connectionManager.ConnectedPeers.Any()) { this.logger.LogTrace("(-)[NO_CONNECTED_PEERS]"); return ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Can't send transaction as the node requires at least one connection.", string.Empty); @@ -570,7 +570,7 @@ public async Task BuildAndSendCallSmartContractTransactionAsync([ return ModelStateErrors.BuildErrorResponse(this.ModelState); // Ignore this check if the node is running dev mode. - if ((this.poaSettings != null && !this.poaSettings.DevMode) && !this.connectionManager.ConnectedPeers.Any()) + if (!this.nodeSettings.DevMode && !this.connectionManager.ConnectedPeers.Any()) { this.logger.LogTrace("(-)[NO_CONNECTED_PEERS]"); return ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Can't send transaction as the node requires at least one connection.", string.Empty); diff --git a/src/Stratis.Bitcoin.Features.Wallet/Services/WalletService.cs b/src/Stratis.Bitcoin.Features.Wallet/Services/WalletService.cs index c4921f211d..8fbf18cfed 100644 --- a/src/Stratis.Bitcoin.Features.Wallet/Services/WalletService.cs +++ b/src/Stratis.Bitcoin.Features.Wallet/Services/WalletService.cs @@ -11,6 +11,7 @@ using NBitcoin; using NBitcoin.Policy; using Stratis.Bitcoin.Builder.Feature; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Features.BlockStore; @@ -39,6 +40,7 @@ public class WalletService : IWalletService private readonly ILogger logger; private readonly IUtxoIndexer utxoIndexer; private readonly IWalletFeePolicy walletFeePolicy; + private readonly NodeSettings nodeSettings; public WalletService(ILoggerFactory loggerFactory, IWalletManager walletManager, @@ -51,7 +53,8 @@ public WalletService(ILoggerFactory loggerFactory, IBroadcasterManager broadcasterManager, IDateTimeProvider dateTimeProvider, IUtxoIndexer utxoIndexer, - IWalletFeePolicy walletFeePolicy) + IWalletFeePolicy walletFeePolicy, + NodeSettings nodeSettings) { this.walletManager = walletManager; this.consensusManager = consensusManager; @@ -66,6 +69,7 @@ public WalletService(ILoggerFactory loggerFactory, this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.utxoIndexer = utxoIndexer; this.walletFeePolicy = walletFeePolicy; + this.nodeSettings = nodeSettings; } public async Task> GetWalletNames( @@ -483,17 +487,15 @@ public async Task SplitCoins(SplitCoinsRequest reque }, cancellationToken); } - public async Task SendTransaction(SendTransactionRequest request, - CancellationToken cancellationToken) + public async Task SendTransaction(SendTransactionRequest request, CancellationToken cancellationToken) { return await Task.Run(() => { - if (!this.connectionManager.ConnectedPeers.Any()) + if (!this.nodeSettings.DevMode && !this.connectionManager.ConnectedPeers.Any()) { this.logger.LogTrace("(-)[NO_CONNECTED_PEERS]"); - throw new FeatureException(HttpStatusCode.Forbidden, - "Can't send transaction: sending transaction requires at least one connection!", string.Empty); + throw new FeatureException(HttpStatusCode.Forbidden, "Can't send transaction: sending transaction requires at least one connection.", string.Empty); } Transaction transaction = this.network.CreateTransaction(request.Hex); @@ -1557,13 +1559,5 @@ private int GetTransactionSizeForUtxoCount(List utxos, i // Note that this is the virtual size taking the witness scale factor of the current network into account, and not the raw byte count. return this.walletTransactionHandler.EstimateSize(context); } - - private TransactionItemModel FindSimilarReceivedTransactionOutput(List items, - TransactionData transaction) - { - return items.FirstOrDefault(i => i.Id == transaction.Id && - i.Type == TransactionItemType.Received && - i.ConfirmedInBlock == transaction.BlockHeight); - } } } diff --git a/src/Stratis.Bitcoin/Configuration/NodeSettings.cs b/src/Stratis.Bitcoin/Configuration/NodeSettings.cs index b9b0d66728..f479606506 100644 --- a/src/Stratis.Bitcoin/Configuration/NodeSettings.cs +++ b/src/Stratis.Bitcoin/Configuration/NodeSettings.cs @@ -35,6 +35,11 @@ public static string NormalizeDirectorySeparator(this string path) /// public class NodeSettings : IDisposable { + /// + /// String value that defines the devmode flag in config. + /// + public const string DevModeParam = "devmode"; + /// The version of the protocol supported by the current implementation of the Full Node. public const ProtocolVersion SupportedProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION; @@ -109,6 +114,15 @@ public class NodeSettings : IDisposable /// public FeeRate MinRelayTxFeeRate { get; private set; } + /// + /// A flag that allows node to start in developer (dev) mode. + /// + /// This is primarily in situations where the node is required to mine and/or send and build transactions + /// whilst in a closed (no connections) environment. + /// + /// + public bool DevMode { get; private set; } + /// /// Initializes a new instance of the object. /// @@ -234,6 +248,9 @@ public NodeSettings(Network network = null, ProtocolVersion protocolVersion = Su // Load the configuration. this.LoadConfiguration(); + + // Set the devmode flag. + this.DevMode = this.ConfigReader.GetOrDefault(DevModeParam, false); } /// Determines whether to print help and exit. diff --git a/src/Stratis.CirrusMinerD/Properties/launchSettings.json b/src/Stratis.CirrusMinerD/Properties/launchSettings.json new file mode 100644 index 0000000000..32bdd418ee --- /dev/null +++ b/src/Stratis.CirrusMinerD/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "profiles": { + "Stratis.CirrusMinerD": { + "commandName": "Project", + "commandLineArgs": "-devmode", + "sqlDebugging": true + } + } +} \ No newline at end of file diff --git a/src/Stratis.Features.Collateral/CollateralPoAMiner.cs b/src/Stratis.Features.Collateral/CollateralPoAMiner.cs index 96db9e2779..7c48071556 100644 --- a/src/Stratis.Features.Collateral/CollateralPoAMiner.cs +++ b/src/Stratis.Features.Collateral/CollateralPoAMiner.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using NBitcoin; using Stratis.Bitcoin.AsyncWork; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Consensus.Validators; @@ -41,9 +42,11 @@ public class CollateralPoAMiner : PoAMiner public CollateralPoAMiner(IConsensusManager consensusManager, IDateTimeProvider dateTimeProvider, Network network, INodeLifetime nodeLifetime, ILoggerFactory loggerFactory, IInitialBlockDownloadState ibdState, BlockDefinition blockDefinition, ISlotsManager slotsManager, IConnectionManager connectionManager, JoinFederationRequestMonitor joinFederationRequestMonitor, PoABlockHeaderValidator poaHeaderValidator, IFederationManager federationManager, IIntegrityValidator integrityValidator, IWalletManager walletManager, ChainIndexer chainIndexer, - INodeStats nodeStats, VotingManager votingManager, PoASettings poAMinerSettings, ICollateralChecker collateralChecker, IAsyncProvider asyncProvider, ICounterChainSettings counterChainSettings, IIdleFederationMembersKicker idleFederationMembersKicker) + INodeStats nodeStats, VotingManager votingManager, PoASettings poAMinerSettings, ICollateralChecker collateralChecker, IAsyncProvider asyncProvider, ICounterChainSettings counterChainSettings, + IIdleFederationMembersKicker idleFederationMembersKicker, + NodeSettings nodeSettings) : base(consensusManager, dateTimeProvider, network, nodeLifetime, loggerFactory, ibdState, blockDefinition, slotsManager, connectionManager, - poaHeaderValidator, federationManager, integrityValidator, walletManager, nodeStats, votingManager, poAMinerSettings, asyncProvider, idleFederationMembersKicker) + poaHeaderValidator, federationManager, integrityValidator, walletManager, nodeStats, votingManager, poAMinerSettings, asyncProvider, idleFederationMembersKicker, nodeSettings) { this.counterChainNetwork = counterChainSettings.CounterChainNetwork; this.collateralChecker = collateralChecker; diff --git a/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs b/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs index d3a9d1797b..2ddc97e156 100644 --- a/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs +++ b/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs @@ -71,7 +71,7 @@ private void InitializeCollateralChecker([CallerMemberName] string callingMethod chainIndexerMock.Setup(x => x.Tip).Returns(new ChainedHeader(header, header.GetHash(), 0)); var fullNode = new Mock(); - IFederationManager federationManager = new FederationManager(fullNode.Object, network, nodeSettings, signals, new PoASettings(nodeSettings), counterChainSettings); + IFederationManager federationManager = new FederationManager(fullNode.Object, network, nodeSettings, signals, counterChainSettings); var votingManager = new VotingManager(federationManager, loggerFactory, new Mock().Object, new Mock().Object, nodeSettings.DataFolder, dbreezeSerializer, signals, finalizedBlockRepo, network); var federationHistory = new FederationHistory(federationManager, votingManager); votingManager.Initialize(federationHistory); diff --git a/src/Stratis.Features.FederatedPeg.Tests/ControllersTests/FederationGatewayControllerTests.cs b/src/Stratis.Features.FederatedPeg.Tests/ControllersTests/FederationGatewayControllerTests.cs index 56ee779310..6d4084b394 100644 --- a/src/Stratis.Features.FederatedPeg.Tests/ControllersTests/FederationGatewayControllerTests.cs +++ b/src/Stratis.Features.FederatedPeg.Tests/ControllersTests/FederationGatewayControllerTests.cs @@ -244,7 +244,7 @@ private void CreateFederationManager(NodeSettings nodeSettings) var counterChainSettings = new CounterChainSettings(nodeSettings, new CounterChainNetworkWrapper(new StraxRegTest())); - this.federationManager = new FederationManager(fullNode.Object, this.network, NodeSettings.Default(this.network), this.signals, new PoASettings(nodeSettings), counterChainSettings); + this.federationManager = new FederationManager(fullNode.Object, this.network, NodeSettings.Default(this.network), this.signals, counterChainSettings); VotingManager votingManager = InitializeVotingManager(nodeSettings); From a46f70513c5a89c834fded0270593c53e7cc3f9d Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 16 Mar 2021 16:20:11 +0000 Subject: [PATCH 2/6] Self Review --- src/Stratis.Bitcoin.Features.PoA/PoASettings.cs | 5 ----- src/Stratis.CirrusMinerD/Program.cs | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs b/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs index 66c24138ea..5653e3a2c1 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoASettings.cs @@ -5,11 +5,6 @@ namespace Stratis.Bitcoin.Features.PoA { public sealed class PoASettings { - /// - /// String value that defines the devmode flag in config. - /// - public const string DevModeParam = "devmode"; - /// /// Allows mining in case node is in IBD and not connected to anyone. /// diff --git a/src/Stratis.CirrusMinerD/Program.cs b/src/Stratis.CirrusMinerD/Program.cs index 9471982dde..3bf2b95a46 100644 --- a/src/Stratis.CirrusMinerD/Program.cs +++ b/src/Stratis.CirrusMinerD/Program.cs @@ -12,7 +12,6 @@ using Stratis.Bitcoin.Features.MemoryPool; using Stratis.Bitcoin.Features.Miner; using Stratis.Bitcoin.Features.Notifications; -using Stratis.Bitcoin.Features.PoA; using Stratis.Bitcoin.Features.RPC; using Stratis.Bitcoin.Features.SmartContracts; using Stratis.Bitcoin.Features.SmartContracts.PoA; @@ -43,7 +42,7 @@ public static async Task MainAsync(string[] args) { bool isMainchainNode = args.FirstOrDefault(a => a.ToLower() == MainchainArgument) != null; bool isSidechainNode = args.FirstOrDefault(a => a.ToLower() == SidechainArgument) != null; - bool startInDevMode = args.FirstOrDefault(a => a.ToLower() == $"-{PoASettings.DevModeParam}") != null; + bool startInDevMode = args.FirstOrDefault(a => a.ToLower() == $"-{NodeSettings.DevModeParam}") != null; IFullNode fullNode = null; From 108aa66123ac9333f8cf0147d841053955c84922 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 16 Mar 2021 16:21:59 +0000 Subject: [PATCH 3/6] Update launchSettings.json --- src/Stratis.CirrusMinerD/Properties/launchSettings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Stratis.CirrusMinerD/Properties/launchSettings.json b/src/Stratis.CirrusMinerD/Properties/launchSettings.json index 32bdd418ee..9f22644a25 100644 --- a/src/Stratis.CirrusMinerD/Properties/launchSettings.json +++ b/src/Stratis.CirrusMinerD/Properties/launchSettings.json @@ -2,7 +2,6 @@ "profiles": { "Stratis.CirrusMinerD": { "commandName": "Project", - "commandLineArgs": "-devmode", "sqlDebugging": true } } From 5d3eee3391d311fd8a3bde845b0c1df7fc607305 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 16 Mar 2021 16:23:51 +0000 Subject: [PATCH 4/6] Delete launchSettings.json --- src/Stratis.CirrusMinerD/Properties/launchSettings.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/Stratis.CirrusMinerD/Properties/launchSettings.json diff --git a/src/Stratis.CirrusMinerD/Properties/launchSettings.json b/src/Stratis.CirrusMinerD/Properties/launchSettings.json deleted file mode 100644 index 9f22644a25..0000000000 --- a/src/Stratis.CirrusMinerD/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "Stratis.CirrusMinerD": { - "commandName": "Project", - "sqlDebugging": true - } - } -} \ No newline at end of file From e81cd43fa2ba8b74b0488ef181d3d0d1de192965 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 16 Mar 2021 17:18:17 +0000 Subject: [PATCH 5/6] Fix Test --- .../WalletControllerTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs b/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs index 4d23b4e1c6..6861189cfc 100644 --- a/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs +++ b/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs @@ -11,6 +11,7 @@ using Moq; using Moq.AutoMock; using NBitcoin; +using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Connection; using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Features.Wallet.Broadcasting; @@ -2638,6 +2639,7 @@ private WalletController GetWalletController() mocker.Use(typeof(IConsensusManager), this.GetMock(true)); mocker.Use(typeof(IDateTimeProvider), this.GetMock() ?? DateTimeProvider.Default); mocker.Use(typeof(IConnectionManager), this.GetMock(true)); + mocker.Use(typeof(NodeSettings), NodeSettings.Default(this.Network)); mocker.Use(typeof(IWalletService), this.GetMock() ?? mocker.CreateInstance()); return mocker.CreateInstance(); From 8ed30a76f379811c479187e8d34472b6cc276002 Mon Sep 17 00:00:00 2001 From: Francois de la Rouviere Date: Tue, 16 Mar 2021 17:21:03 +0000 Subject: [PATCH 6/6] Update WalletControllerTest.cs --- .../WalletControllerTest.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs b/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs index 6861189cfc..2052787f8e 100644 --- a/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs +++ b/src/Stratis.Bitcoin.Features.Wallet.Tests/WalletControllerTest.cs @@ -1955,7 +1955,7 @@ public async Task SendTransactionSuccessfulReturnsWalletSendTransactionModelResp } [Fact] - public async Task SendTransactionFailedBecauseNoNodesConnected() + public async Task SendTransactionFailedBecauseNoNodesConnectedAsync() { var mockBroadcasterManager = this.ConfigureMock(); @@ -1965,8 +1965,7 @@ public async Task SendTransactionFailedBecauseNoNodesConnected() var controller = this.GetWalletController(); - IActionResult result = - await controller.SendTransaction(new SendTransactionRequest(new uint256(15555).ToString())); + IActionResult result = await controller.SendTransaction(new SendTransactionRequest(new uint256(15555).ToString())); var errorResult = Assert.IsType(result); var errorResponse = Assert.IsType(errorResult.Value); @@ -1974,8 +1973,7 @@ public async Task SendTransactionFailedBecauseNoNodesConnected() ErrorModel error = errorResponse.Errors[0]; Assert.Equal(403, error.Status); - Assert.Equal("Can't send transaction: sending transaction requires at least one connection!", - error.Message); + Assert.Equal("Can't send transaction: sending transaction requires at least one connection.", error.Message); } [Fact]