public void CanCoreSyncFromStratis() { using (NodeBuilder builder = NodeBuilder.Create()) { var stratisNode = builder.CreateStratisPowNode(); var coreNodeSync = builder.CreateNode(); var coreCreateNode = builder.CreateNode(); builder.StartAll(); // not in IBD stratisNode.FullNode.ChainBehaviorState.SetIsInitialBlockDownload(false, DateTime.UtcNow.AddMinutes(5)); // first seed a core node with blocks and sync them to a stratis node // and wait till the stratis node is fully synced var tip = coreCreateNode.FindBlock(5).Last(); stratisNode.CreateRPCClient().AddNode(coreCreateNode.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreCreateNode.CreateRPCClient().GetBestBlockHash()); TestHelper.WaitLoop(() => stratisNode.FullNode.HighestPersistedBlock().HashBlock == stratisNode.FullNode.Chain.Tip.HashBlock); var 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()) { var stratisNode = builder.CreateStratisPowNode(); var coreNode = builder.CreateNode(); builder.StartAll(); // not in IBD stratisNode.FullNode.InitialBlockDownloadState.SetIsInitialBlockDownload(false, DateTime.UtcNow.AddMinutes(5)); 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); 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 CanStratisSyncFromStratis() { using (NodeBuilder builder = NodeBuilder.Create()) { var stratisNode = builder.CreateStratisPowNode(); var stratisNodeSync = builder.CreateStratisPowNode(); var coreCreateNode = builder.CreateNode(); builder.StartAll(); stratisNode.NotInIBD(); stratisNodeSync.NotInIBD(); // first seed a core node with blocks and sync them to a stratis node // and wait till the stratis node is fully synced var tip = coreCreateNode.FindBlock(5).Last(); stratisNode.CreateRPCClient().AddNode(coreCreateNode.Endpoint, true); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreCreateNode.CreateRPCClient().GetBestBlockHash()); var bestBlockHash = stratisNode.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); // add a new stratis node which will download // the blocks using the GetData payload stratisNodeSync.CreateRPCClient().AddNode(stratisNode.Endpoint, true); // wait for download and assert TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == stratisNodeSync.CreateRPCClient().GetBestBlockHash()); bestBlockHash = stratisNodeSync.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); } }
public void CanStratisSyncFromCore() { using (NodeBuilder builder = NodeBuilder.Create()) { var stratisNode = builder.CreateStratisPowNode(); var coreNode = builder.CreateNode(); 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); 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 CanStratisSyncFromCore() { using (NodeBuilder builder = NodeBuilder.Create()) { var stratisNode = builder.CreateStratisNode(); var coreNode = builder.CreateNode(); builder.StartAll(); // not in IBD stratisNode.FullNode.ChainBehaviorState.SetIsInitialBlockDownload(false, DateTime.UtcNow.AddMinutes(5)); var tip = coreNode.FindBlock(10).Last(); stratisNode.CreateRPCClient().AddNode(coreNode.Endpoint, true); Eventually(() => 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); tip = coreNode.FindBlock(10).Last(); coreNode.CreateRPCClient().AddNode(stratisNode.Endpoint, true); Eventually(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash()); bestBlockHash = stratisNode.CreateRPCClient().GetBestBlockHash(); Assert.Equal(tip.GetHash(), bestBlockHash); //For Core synching from Stratis, need to save blocks in stratis } }
public void CanHandleReorgs() { using (NodeBuilder builder = NodeBuilder.Create()) { var stratisNode = builder.CreateStratisNode(); var coreNode1 = builder.CreateNode(); var coreNode2 = builder.CreateNode(); builder.StartAll(); //Core1 discovers 10 blocks, sends to stratis var 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 TestSegwitActivation() { using (NodeBuilder builder = NodeBuilder.Create(version: "0.15.1")) { CoreNode coreNode = builder.CreateNode(false); coreNode.ConfigParameters.AddOrReplace("debug", "1"); coreNode.ConfigParameters.AddOrReplace("printtoconsole", "0"); coreNode.Start(); CoreNode node1 = builder.CreateStratisPowNode(true, fullNodeBuilder => { fullNodeBuilder .UseConsensus() .UseBlockStore() .UseMempool() .UseBlockNotification() .UseTransactionNotification() .AddMining() .UseWallet() .UseApi() .AddRPC(); }); WalletManager wm1 = node1.FullNode.NodeService <IWalletManager>() as WalletManager; wm1.CreateWallet("Test1", "alice1"); RPCClient rpc1 = node1.CreateRPCClient(); RPCClient coreRpc = coreNode.CreateRPCClient(); coreRpc.AddNode(node1.Endpoint, false); rpc1.AddNode(coreNode.Endpoint, false); coreRpc.Generate(450); BIP9DeploymentsArray bip9Constants = node1.FullNode.Network.Consensus.BIP9Deployments; ConsensusLoop consensusLoop = node1.FullNode.NodeService <ConsensusLoop>(); ThresholdState[] bip9State = consensusLoop.NodeDeployments.BIP9.GetStates(node1.FullNode.Chain.Tip.Previous); Money amount = new Money(5.0m, MoneyUnit.BTC); HdAddress destination1 = wm1.GetUnusedAddress(new WalletAccountReference("alice1", "account 0")); coreRpc.SendToAddress(BitcoinAddress.Create(destination1.Address, Network.RegTest), amount); coreRpc.Generate(1); Assert.Equal(ThresholdState.Active, bip9State.GetValue((int)BIP9Deployments.Segwit)); } }
public void TestSegwit_MinedOnCore_ActivatedOn_StratisNode() { using (NodeBuilder builder = NodeBuilder.Create(version: "0.15.1")) { CoreNode coreNode = builder.CreateNode(false); coreNode.ConfigParameters.AddOrReplace("debug", "1"); coreNode.ConfigParameters.AddOrReplace("printtoconsole", "0"); coreNode.Start(); CoreNode stratisNode = builder.CreateStratisPowNode(true, fullNodeBuilder => { fullNodeBuilder .UseConsensus() .UseBlockStore() .UseWallet() .UseMempool() .AddMining() .AddRPC(); }); 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 = Network.RegTest.Consensus.BIP9Deployments[BIP9Deployments.Segwit]; Network.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); TestHelper.WaitLoop(() => stratisNode.CreateRPCClient().GetBestBlockHash() == coreNode.CreateRPCClient().GetBestBlockHash()); // 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. IConsensusLoop consensusLoop = stratisNode.FullNode.NodeService <IConsensusLoop>(); 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 { Network.RegTest.Consensus.BIP9Deployments[BIP9Deployments.Segwit] = prevSegwitDeployment; } } }