public void CanHandleReorgs() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode stratisNode = builder.CreateStratisPowNode(this.regTest).Start(); CoreNode coreNode1 = builder.CreateBitcoinCoreNode().Start(); CoreNode coreNode2 = builder.CreateBitcoinCoreNode().Start(); //Core1 discovers 10 blocks, sends to stratis coreNode1.FindBlock(10).Last(); TestHelper.ConnectAndSync(stratisNode, coreNode1); TestHelper.Disconnect(stratisNode, coreNode1); //Core2 discovers 20 blocks, sends to stratis coreNode2.FindBlock(20).Last(); TestHelper.ConnectAndSync(stratisNode, coreNode2); TestHelper.Disconnect(stratisNode, coreNode2); ((CachedCoinView)stratisNode.FullNode.CoinView()).FlushAsync().Wait(); //Core1 discovers 30 blocks, sends to stratis coreNode1.FindBlock(30).Last(); TestHelper.ConnectAndSync(stratisNode, coreNode1); TestHelper.Disconnect(stratisNode, coreNode1); //Core2 discovers 50 blocks, sends to stratis coreNode2.FindBlock(50).Last(); TestHelper.ConnectAndSync(stratisNode, coreNode2); TestHelper.Disconnect(stratisNode, coreNode2); ((CachedCoinView)stratisNode.FullNode.CoinView()).FlushAsync().Wait(); TestHelper.WaitLoop(() => TestHelper.AreNodesSynced(stratisNode, coreNode2)); } }
public void CanCoreSyncFromStratis() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode stratisNode = builder.CreateStratisPowNode(); CoreNode coreNodeSync = builder.CreateBitcoinCoreNode(); CoreNode coreCreateNode = builder.CreateBitcoinCoreNode(); builder.StartAll(); stratisNode.NotInIBD(); // first seed a core node with blocks and sync them to a stratis node // and wait till the stratis node is fully synced Block tip = coreCreateNode.FindBlock(5).Last(); stratisNode.CreateRPCClient().AddNode(coreCreateNode.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreCreateNode.CreateRPCClient().GetBestBlockHash()); TestHelper.WaitLoop(() => stratisNode.FullNode.GetBlockStoreTip().HashBlock == stratisNode.FullNode.Chain.Tip.HashBlock); uint256 bestBlockHash = stratisNode.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); // add a new stratis node which will download // the blocks using the GetData payload coreNodeSync.CreateRPCClient().AddNode(stratisNode.Endpoint, true); // wait for download and assert TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNodeSync.CreateRPCClient().GetBestBlockHash()); bestBlockHash = coreNodeSync.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); } }
public void CanStratisSyncFromCore() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode stratisNode = builder.CreateStratisPowNode(); CoreNode coreNode = builder.CreateBitcoinCoreNode(); builder.StartAll(); stratisNode.NotInIBD(); Block tip = coreNode.FindBlock(10).Last(); RPCClient stratisNodeRpcClient = stratisNode.CreateRPCClient(); stratisNodeRpcClient.AddNode(coreNode.Endpoint, true); RPCClient coreNodeRpcClient = coreNode.CreateRPCClient(); TestHelper.WaitLoop(() => stratisNodeRpcClient.GetBestBlockHash() == coreNodeRpcClient.GetBestBlockHash()); uint256 bestBlockHash = stratisNodeRpcClient.GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); stratisNodeRpcClient.RemoveNode(coreNode.Endpoint); TestHelper.WaitLoop(() => coreNodeRpcClient.GetPeersInfo() .All(pi => pi.Address.MapToIpv6().ToString() != coreNode.Endpoint.MapToIpv6().ToString())); tip = coreNode.FindBlock(10).Last(); coreNodeRpcClient.AddNode(stratisNode.Endpoint, true); TestHelper.WaitLoop(() => stratisNodeRpcClient.GetBestBlockHash() == coreNodeRpcClient.GetBestBlockHash()); bestBlockHash = stratisNodeRpcClient.GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); } }
public void CanStratisSyncFromCore() { using (NodeBuilder builder = NodeBuilder.Create()) { var stratisNode = builder.CreateStratisPowNode(); var coreNode = builder.CreateBitcoinCoreNode(); builder.StartAll(); stratisNode.NotInIBD(); var tip = coreNode.FindBlock(10).Last(); stratisNode.CreateRPCClient().AddNode(coreNode.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash()); var bestBlockHash = stratisNode.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); //Now check if Core connect to stratis stratisNode.CreateRPCClient().RemoveNode(coreNode.Endpoint); TestHelper.WaitLoop(() => coreNode.CreateRPCClient().GetPeersInfo().Length == 0); tip = coreNode.FindBlock(10).Last(); coreNode.CreateRPCClient().AddNode(stratisNode.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash()); bestBlockHash = stratisNode.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); } }
public void TestSegwit_AlwaysActivatedOn_StratisNode() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode coreNode = builder.CreateBitcoinCoreNode(version: "0.18.0", useNewConfigStyle: true); coreNode.Start(); CoreNode stratisNode = builder.CreateStratisPowNode(KnownNetworks.RegTest).Start(); RPCClient stratisNodeRpc = stratisNode.CreateRPCClient(); RPCClient coreRpc = coreNode.CreateRPCClient(); coreRpc.AddNode(stratisNode.Endpoint, false); stratisNodeRpc.AddNode(coreNode.Endpoint, false); coreRpc.Generate(1); var cancellationToken = new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token; TestBase.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash(), cancellationToken: cancellationToken); var consensusLoop = stratisNode.FullNode.NodeService <IConsensusRuleEngine>() as ConsensusRuleEngine; ThresholdState[] segwitActiveState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.ChainIndexer.GetHeader(1)); // Check that segwit got activated at genesis. Assert.Equal(ThresholdState.Active, segwitActiveState.GetValue((int)BitcoinBIP9Deployments.Segwit)); } }
public void TestSegwit_MinedOnCore_ActivatedOn_StratisNode() { // This test only verifies that the BIP9 machinery is operating correctly on the Stratis PoW node. // Since newer versions of Bitcoin Core have segwit always activated from genesis, there is no need to // perform the reverse version of this test. Much more important are the P2P and mempool tests for // segwit transactions. using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode coreNode = builder.CreateBitcoinCoreNode(version: "0.15.1"); coreNode.Start(); CoreNode stratisNode = builder.CreateStratisPowNode(KnownNetworks.RegTest).Start(); RPCClient stratisNodeRpc = stratisNode.CreateRPCClient(); RPCClient coreRpc = coreNode.CreateRPCClient(); coreRpc.AddNode(stratisNode.Endpoint, false); stratisNodeRpc.AddNode(coreNode.Endpoint, false); // Core (in version 0.15.1) only mines segwit blocks above a certain height on regtest // See issue for more details https://github.com/stratisproject/StratisBitcoinFullNode/issues/1028 BIP9DeploymentsParameters prevSegwitDeployment = KnownNetworks.RegTest.Consensus.BIP9Deployments[BitcoinBIP9Deployments.Segwit]; KnownNetworks.RegTest.Consensus.BIP9Deployments[BitcoinBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Test", 1, 0, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold); try { // Generate 450 blocks, block 431 will be segwit activated. coreRpc.Generate(450); var cancellationToken = new CancellationTokenSource(TimeSpan.FromMinutes(2)).Token; TestBase.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash(), cancellationToken: cancellationToken); // Segwit activation on Bitcoin regtest. // - On regtest deployment state changes every 144 blocks, the threshold for activating a rule is 108 blocks. // Segwit deployment status should be: // - Defined up to block 142. // - Started at block 143 to block 286. // - LockedIn 287 (as segwit should already be signaled in blocks). // - Active at block 431. var consensusLoop = stratisNode.FullNode.NodeService <IConsensusRuleEngine>() as ConsensusRuleEngine; ThresholdState[] segwitDefinedState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.ChainIndexer.GetHeader(142)); ThresholdState[] segwitStartedState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.ChainIndexer.GetHeader(143)); ThresholdState[] segwitLockedInState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.ChainIndexer.GetHeader(287)); ThresholdState[] segwitActiveState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.ChainIndexer.GetHeader(431)); // Check that segwit got activated at block 431. Assert.Equal(ThresholdState.Defined, segwitDefinedState.GetValue((int)BitcoinBIP9Deployments.Segwit)); Assert.Equal(ThresholdState.Started, segwitStartedState.GetValue((int)BitcoinBIP9Deployments.Segwit)); Assert.Equal(ThresholdState.LockedIn, segwitLockedInState.GetValue((int)BitcoinBIP9Deployments.Segwit)); Assert.Equal(ThresholdState.Active, segwitActiveState.GetValue((int)BitcoinBIP9Deployments.Segwit)); } finally { KnownNetworks.RegTest.Consensus.BIP9Deployments[BitcoinBIP9Deployments.Segwit] = prevSegwitDeployment; } } }
public void TestSegwit_MinedOnCore_ActivatedOn_StratisNode() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode coreNode = builder.CreateBitcoinCoreNode(version: "0.15.1"); coreNode.ConfigParameters.AddOrReplace("debug", "1"); coreNode.ConfigParameters.AddOrReplace("printtoconsole", "0"); coreNode.Start(); CoreNode stratisNode = builder.CreateStratisPowNode(KnownNetworks.RegTest); stratisNode.Start(); RPCClient stratisNodeRpc = stratisNode.CreateRPCClient(); RPCClient coreRpc = coreNode.CreateRPCClient(); coreRpc.AddNode(stratisNode.Endpoint, false); stratisNodeRpc.AddNode(coreNode.Endpoint, false); // core (in version 0.15.1) only mines segwit blocks above a certain height on regtest // future versions of core will change that behaviour so this test may need to be changed in the future // see issue for more details https://github.com/stratisproject/StratisBitcoinFullNode/issues/1028 BIP9DeploymentsParameters prevSegwitDeployment = KnownNetworks.RegTest.Consensus.BIP9Deployments[BIP9Deployments.Segwit]; KnownNetworks.RegTest.Consensus.BIP9Deployments[BIP9Deployments.Segwit] = new BIP9DeploymentsParameters(1, 0, DateTime.Now.AddDays(50).ToUnixTimestamp()); try { // generate 450 blocks, block 431 will be segwit activated. coreRpc.Generate(450); var cancellationToken = new CancellationTokenSource(TimeSpan.FromMinutes(2)).Token; TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash(), cancellationToken: cancellationToken); // segwit activation on Bitcoin regtest. // - On regtest deployment state changes every 144 block, the threshold for activating a rule is 108 blocks. // segwit deployment status should be: // - Defined up to block 142. // - Started at block 143 to block 286 . // - LockedIn 287 (as segwit should already be signaled in blocks). // - Active at block 431. var consensusLoop = stratisNode.FullNode.NodeService <IConsensusRuleEngine>() as ConsensusRuleEngine; ThresholdState[] segwitDefinedState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.Chain.GetBlock(142)); ThresholdState[] segwitStartedState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.Chain.GetBlock(143)); ThresholdState[] segwitLockedInState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.Chain.GetBlock(287)); ThresholdState[] segwitActiveState = consensusLoop.NodeDeployments.BIP9.GetStates(stratisNode.FullNode.Chain.GetBlock(431)); // check that segwit is got activated at block 431 Assert.Equal(ThresholdState.Defined, segwitDefinedState.GetValue((int)BIP9Deployments.Segwit)); Assert.Equal(ThresholdState.Started, segwitStartedState.GetValue((int)BIP9Deployments.Segwit)); Assert.Equal(ThresholdState.LockedIn, segwitLockedInState.GetValue((int)BIP9Deployments.Segwit)); Assert.Equal(ThresholdState.Active, segwitActiveState.GetValue((int)BIP9Deployments.Segwit)); } finally { KnownNetworks.RegTest.Consensus.BIP9Deployments[BIP9Deployments.Segwit] = prevSegwitDeployment; } } }
public void CanCoreSyncFromStratis() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode stratisNode = builder.CreateStratisPowNode(this.powNetwork).Start(); CoreNode coreNodeSync = builder.CreateBitcoinCoreNode().Start(); CoreNode coreCreateNode = builder.CreateBitcoinCoreNode().Start(); // first seed a core node with blocks and sync them to a stratis node // and wait till the stratis node is fully synced Block tip = coreCreateNode.FindBlock(5).Last(); TestHelper.ConnectAndSync(stratisNode, coreCreateNode); TestHelper.WaitLoop(() => stratisNode.FullNode.ConsensusManager().Tip.Block.GetHash() == tip.GetHash()); // add a new stratis node which will download // the blocks using the GetData payload TestHelper.ConnectAndSync(coreNodeSync, stratisNode); } }
public void CanHandleReorgs() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode stratisNode = builder.CreateStratisPowNode(); CoreNode coreNode1 = builder.CreateBitcoinCoreNode(); CoreNode coreNode2 = builder.CreateBitcoinCoreNode(); builder.StartAll(); //Core1 discovers 10 blocks, sends to stratis Block tip = coreNode1.FindBlock(10).Last(); stratisNode.CreateRPCClient().AddNode(coreNode1.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode1.CreateRPCClient().GetBestBlockHash()); stratisNode.CreateRPCClient().RemoveNode(coreNode1.Endpoint); //Core2 discovers 20 blocks, sends to stratis tip = coreNode2.FindBlock(20).Last(); stratisNode.CreateRPCClient().AddNode(coreNode2.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode2.CreateRPCClient().GetBestBlockHash()); stratisNode.CreateRPCClient().RemoveNode(coreNode2.Endpoint); ((CachedCoinView)stratisNode.FullNode.CoinView()).FlushAsync().Wait(); //Core1 discovers 30 blocks, sends to stratis tip = coreNode1.FindBlock(30).Last(); stratisNode.CreateRPCClient().AddNode(coreNode1.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode1.CreateRPCClient().GetBestBlockHash()); stratisNode.CreateRPCClient().RemoveNode(coreNode1.Endpoint); //Core2 discovers 50 blocks, sends to stratis tip = coreNode2.FindBlock(50).Last(); stratisNode.CreateRPCClient().AddNode(coreNode2.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode2.CreateRPCClient().GetBestBlockHash()); stratisNode.CreateRPCClient().RemoveNode(coreNode2.Endpoint); ((CachedCoinView)stratisNode.FullNode.CoinView()).FlushAsync().Wait(); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode2.CreateRPCClient().GetBestBlockHash()); } }
public void CanStratisSyncFromCore() { using (NodeBuilder builder = NodeBuilder.Create(this)) { CoreNode stratisNode = builder.CreateStratisPowNode(this.powNetwork).Start(); CoreNode coreNode = builder.CreateBitcoinCoreNode().Start(); Block tip = coreNode.FindBlock(10).Last(); TestHelper.ConnectAndSync(stratisNode, coreNode); TestHelper.Disconnect(stratisNode, coreNode); coreNode.FindBlock(10).Last(); TestHelper.ConnectAndSync(coreNode, stratisNode); } }