Skip to content

Commit

Permalink
Merge branch 'master' into chainindexer-getheader-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
rowandh committed Jul 20, 2021
2 parents 1fe1b6a + efae5a0 commit 1419bab
Show file tree
Hide file tree
Showing 174 changed files with 7,498 additions and 2,724 deletions.
8 changes: 4 additions & 4 deletions Docker/Stratis.CirrusD.TestNet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

ARG VERSION=master
ENV VERSION=${VERSION}
ARG APPVERSION=master
ENV APPVERSION=${APPVERSION}

RUN if [ "$VERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${VERSION}"; fi
RUN if [ "$APPVERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${APPVERSION}"; fi
RUN cd /StratisFullNode/src/Stratis.StraxD && dotnet build
VOLUME /root/.stratisfullnode
WORKDIR /StratisFullNode/src/Stratis.CirrusD
EXPOSE 26179 26175 38223
CMD ["dotnet", "run", "-testnet"]
ENTRYPOINT ["dotnet", "run", "-testnet"]
8 changes: 4 additions & 4 deletions Docker/Stratis.CirrusD/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

ARG VERSION=master
ENV VERSION=${VERSION}
ARG APPVERSION=master
ENV APPVERSION=${APPVERSION}

RUN if [ "$VERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${VERSION}"; fi
RUN if [ "$APPVERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${APPVERSION}"; fi
RUN cd /StratisFullNode/src/Stratis.StraxD && dotnet build
VOLUME /root/.stratisfullnode
WORKDIR /StratisFullNode/src/Stratis.CirrusD
EXPOSE 16179 16175 37223
CMD ["dotnet", "run"]
ENTRYPOINT ["dotnet", "run"]
8 changes: 4 additions & 4 deletions Docker/Stratis.StraxD.TestNet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

ARG VERSION=master
ENV VERSION=${VERSION}
ARG APPVERSION=master
ENV APPVERSION=${APPVERSION}

RUN if [ "$VERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${VERSION}"; fi
RUN if [ "$APPVERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${APPVERSION}"; fi
RUN cd /StratisFullNode/src/Stratis.StraxD && dotnet build
VOLUME /root/.stratisfullnode
WORKDIR /StratisFullNode/src/Stratis.StraxD
EXPOSE 27103 27104 27105
CMD ["dotnet", "run", "-testnet"]
ENTRYPOINT ["dotnet", "run", "-testnet"]
8 changes: 4 additions & 4 deletions Docker/Stratis.StraxD/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

ARG VERSION=master
ENV VERSION=${VERSION}
ARG APPVERSION=master
ENV APPVERSION=${APPVERSION}

RUN if [ "$VERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${VERSION}"; fi
RUN if [ "$APPVERSION" = "master" ]; then git clone https://github.com/stratisproject/StratisFullNode.git; else git clone https://github.com/stratisproject/StratisFullNode.git -b "release/${APPVERSION}"; fi
RUN cd /StratisFullNode/src/Stratis.StraxD && dotnet build
VOLUME /root/.stratisfullnode
WORKDIR /StratisFullNode/src/Stratis.StraxD
EXPOSE 17105 17104 17103
CMD ["dotnet", "run"]
ENTRYPOINT ["dotnet", "run"]
22 changes: 11 additions & 11 deletions Scripts/LaunchSidechainMasternode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ function Check-TimeDifference
Write-Host "Checking UTC Time Difference (unixtime.co.za)" -ForegroundColor Cyan
$timeDifSamples = @([int16]::MaxValue,[int16]::MaxValue,[int16]::MaxValue)
$SystemTime0 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime0 = (Invoke-WebRequest https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now -ErrorAction SilentlyContinue| Select-Object -ExpandProperty content)
$timeDifSamples[0] = $RemoteTime1 - $SystemTime1
$RemoteTime0 = (Invoke-WebRequest https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now -ErrorAction SilentlyContinue| Select-Object -ExpandProperty content).replace('"','')
$timeDifSamples[0] = $RemoteTime0 - $SystemTime0
$SystemTime1 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime1 = (Invoke-WebRequest https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now -ErrorAction SilentlyContinue | Select-Object -ExpandProperty content)
$RemoteTime1 = (Invoke-WebRequest https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now -ErrorAction SilentlyContinue | Select-Object -ExpandProperty content).replace('"','')
$timeDifSamples[1] = $RemoteTime1 - $SystemTime1
$SystemTime2 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime2 = (Invoke-WebRequest https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now -ErrorAction SilentlyContinue | Select-Object -ExpandProperty content)
$timeDifSamples[2] = $RemoteTime1 - $SystemTime1
$RemoteTime2 = (Invoke-WebRequest https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now -ErrorAction SilentlyContinue | Select-Object -ExpandProperty content).replace('"','')
$timeDifSamples[2] = $RemoteTime2 - $SystemTime2
$timeDif = Get-Median -numberSeries $timeDifSamples

if ( $timeDif -gt 2 -or $timeDif -lt 2 )
Expand All @@ -182,13 +182,13 @@ function Check-TimeDifference2
$timeDifSamples = @([int16]::MaxValue,[int16]::MaxValue,[int16]::MaxValue)
$SystemTime0 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime0 = (New-Timespan -Start (Get-Date "01/01/1970") -End ([datetime]::Parse((Invoke-WebRequest http://unixtimestamp.com/ -UseBasicParsing -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Headers).Date).ToUniversalTime())).TotalSeconds
$timeDifSamples[0] = $RemoteTime1 - $SystemTime1
$timeDifSamples[0] = $RemoteTime0 - $SystemTime0
$SystemTime1 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime1 = (New-Timespan -Start (Get-Date "01/01/1970") -End ([datetime]::Parse((Invoke-WebRequest http://unixtimestamp.com/ -UseBasicParsing -ErrorAction SilentlyContinue| Select-Object -ExpandProperty Headers).Date).ToUniversalTime())).TotalSeconds
$timeDifSamples[1] = $RemoteTime1 - $SystemTime1
$SystemTime2 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime2 = (New-Timespan -Start (Get-Date "01/01/1970") -End ([datetime]::Parse((Invoke-WebRequest http://unixtimestamp.com/ -UseBasicParsing -ErrorAction SilentlyContinue| Select-Object -ExpandProperty Headers).Date).ToUniversalTime())).TotalSeconds
$timeDifSamples[2] = $RemoteTime1 - $SystemTime1
$timeDifSamples[2] = $RemoteTime2 - $SystemTime2
$timeDif = Get-Median -numberSeries $timeDifSamples

if ( $timeDif -gt 2 -or $timeDif -lt -2 -or $timeDif -eq $null)
Expand All @@ -209,13 +209,13 @@ function Check-TimeDifference3
$timeDifSamples = @([int16]::MaxValue,[int16]::MaxValue,[int16]::MaxValue)
$SystemTime0 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime0 = (New-Timespan -Start (Get-Date "01/01/1970") -End ([datetime]::Parse((Invoke-WebRequest http://google.com/ -UseBasicParsing -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Headers).Date).ToUniversalTime())).TotalSeconds
$timeDifSamples[0] = $RemoteTime1 - $SystemTime1
$timeDifSamples[0] = $RemoteTime0 - $SystemTime0
$SystemTime1 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime1 = (New-Timespan -Start (Get-Date "01/01/1970") -End ([datetime]::Parse((Invoke-WebRequest http://google.com/ -UseBasicParsing -ErrorAction SilentlyContinue| Select-Object -ExpandProperty Headers).Date).ToUniversalTime())).TotalSeconds
$timeDifSamples[1] = $RemoteTime1 - $SystemTime1
$SystemTime2 = ((New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date).ToUniversalTime()).TotalSeconds)
$RemoteTime2 = (New-Timespan -Start (Get-Date "01/01/1970") -End ([datetime]::Parse((Invoke-WebRequest http://google.com/ -UseBasicParsing -ErrorAction SilentlyContinue| Select-Object -ExpandProperty Headers).Date).ToUniversalTime())).TotalSeconds
$timeDifSamples[2] = $RemoteTime1 - $SystemTime1
$timeDifSamples[2] = $RemoteTime2 - $SystemTime2
$timeDif = Get-Median -numberSeries $timeDifSamples

if ( $timeDif -gt 2 -or $timeDif -lt -2 -or $timeDif -eq $null)
Expand Down Expand Up @@ -490,11 +490,11 @@ if ( $NodeType -eq "50K" )
{
if ( $ethGasPrice )
{
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -interop=1 -ethereumaccount=$ethAddress -ethereumpassphrase=$ethPassword -multisigwalletcontractaddress=$ethMultiSigContract -wrappedstraxcontractaddress=$ethWrappedStraxContract -ethereumgasprice=$ethGasPrice -ethereumgas=$ethGasLimit" -PassThru
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract -eth_gasprice=$ethGasPrice -eth_gas=$ethGasLimit" -PassThru
}
Else
{
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -interop=1 -ethereumaccount=$ethAddress -ethereumpassphrase=$ethPassword -multisigwalletcontractaddress=$ethMultiSigContract -wrappedstraxcontractaddress=$ethWrappedStraxContract" -PassThru
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract" -PassThru
}
}
Else
Expand Down
2 changes: 0 additions & 2 deletions src/NBitcoin.Tests/NetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ public void StraxMainIsInitializedCorrectly()
{
Network network = this.straxMain;

Assert.Equal(16, network.Checkpoints.Count);
Assert.Equal(2, network.DNSSeeds.Count);
Assert.Empty(network.SeedNodes);

Expand Down Expand Up @@ -399,7 +398,6 @@ public void StraxTestnetIsInitializedCorrectly()
{
Network network = this.straxTest;

Assert.Equal(8, network.Checkpoints.Count);
Assert.Single(network.SeedNodes);

Assert.Equal("StraxTest", network.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
{
Title = "Stratis Node API",
Version = description.ApiVersion.ToString(),
Description = "Access to the Stratis Node's core features."
Description = "Access to the Stratis Node's api."
};

if (info.Version.Contains("dev"))
Expand Down
13 changes: 13 additions & 0 deletions src/Stratis.Bitcoin.Features.Api/NodeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,19 @@ public IActionResult GetAsyncLoops()
}
}

/// <summary>
/// Schedules data folder storing chain state in the <see cref="DataFolder"/> for deletion on the next graceful shutdown.
/// </summary>
/// <returns></returns>
[HttpDelete]
[Route("datafolder/chain")]
public IActionResult DeleteChain()
{
this.nodeSettings.DataFolder.ScheduleChainDeletion();

return Ok();
}

/// <summary>
/// Retrieves a transaction block given a valid hash.
/// This function is used by other methods in this class and not explicitly by RPC/API.
Expand Down
29 changes: 26 additions & 3 deletions src/Stratis.Bitcoin.Features.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Microsoft.AspNetCore.Builder;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Converters;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
Expand All @@ -28,6 +31,7 @@ public Startup(IWebHostEnvironment env, IFullNode fullNode)
}

private IFullNode fullNode;
private SwaggerUIOptions uiOptions;

public IConfigurationRoot Configuration { get; }

Expand Down Expand Up @@ -81,7 +85,17 @@ public void ConfigureServices(IServiceCollection services)
.AddNewtonsoftJson(options => {
Utilities.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings);
})
.AddControllers(this.fullNode.Services.Features, services);
.AddControllers(this.fullNode.Services.Features, services)
.ConfigureApplicationPartManager(a =>
{
foreach (ApplicationPart appPart in a.ApplicationParts.ToList())
{
if (appPart.Name != "Stratis.Features.Unity3dApi")
continue;

a.ApplicationParts.Remove(appPart);
}
});

// Enable API versioning.
// Note much of this is borrowed from https://github.com/microsoft/aspnet-api-versioning/blob/master/samples/aspnetcore/SwaggerSample/Startup.cs
Expand Down Expand Up @@ -109,8 +123,14 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();

// Register the Swagger generator. This will use the options we injected just above.
services.AddSwaggerGen();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("contracts", new OpenApiInfo { Title = "Contract API", Version = "1" });
});
services.AddSwaggerGenNewtonsoftSupport(); // Use Newtonsoft JSON serializer with swagger. Needs to be placed after AddSwaggerGen()

// Hack to be able to access and modify the options object
services.AddSingleton(_ => this.uiOptions);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down Expand Up @@ -141,6 +161,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
{
c.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
}

// Hack to be able to access and modify the options object configured here
this.uiOptions = c;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void GetBlockCount_ReturnsHeightFromChainState()
var chainState = new Mock<IChainState>();
var addressIndexer = new Mock<IAddressIndexer>();
var utxoIndexer = new Mock<IUtxoIndexer>();
var scriptAddressReader = Mock.Of<IScriptAddressReader>();

ChainIndexer chainIndexer = WalletTestsHelpers.GenerateChainWithHeight(3, new StraxTest());

Expand All @@ -162,7 +163,7 @@ public void GetBlockCount_ReturnsHeightFromChainState()
chainState.Setup(c => c.ConsensusTip)
.Returns(chainIndexer.GetHeaderByHeight(2));

var controller = new BlockStoreController(new StraxMain(), logger.Object, store.Object, chainState.Object, chainIndexer, addressIndexer.Object, utxoIndexer.Object);
var controller = new BlockStoreController(new StraxMain(), logger.Object, store.Object, chainState.Object, chainIndexer, addressIndexer.Object, utxoIndexer.Object, scriptAddressReader);

var json = (JsonResult)controller.GetBlockCount();
int result = int.Parse(json.Value.ToString());
Expand All @@ -177,6 +178,7 @@ private static (Mock<IBlockStore> store, BlockStoreController controller) GetCon
var chainState = new Mock<IChainState>();
var addressIndexer = new Mock<IAddressIndexer>();
var utxoIndexer = new Mock<IUtxoIndexer>();
var scriptAddressReader = Mock.Of<IScriptAddressReader>();

logger.Setup(l => l.CreateLogger(It.IsAny<string>())).Returns(Mock.Of<ILogger>);

Expand All @@ -185,7 +187,7 @@ private static (Mock<IBlockStore> store, BlockStoreController controller) GetCon
chain.Setup(c => c.GetHeaderByHash(It.IsAny<uint256>())).Returns(new ChainedHeader(block.Header, block.Header.GetHash(), 1));
chain.Setup(x => x.Tip).Returns(new ChainedHeader(block.Header, block.Header.GetHash(), 1));

var controller = new BlockStoreController(new StraxMain(), logger.Object, store.Object, chainState.Object, chain.Object, addressIndexer.Object, utxoIndexer.Object);
var controller = new BlockStoreController(new StraxMain(), logger.Object, store.Object, chainState.Object, chain.Object, addressIndexer.Object, utxoIndexer.Object, scriptAddressReader);

return (store, controller);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void PruneRepository_PruneAndCompact_FromGenesis_OnStartUp()
var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);

var blockRepository = new LevelDbBlockRepository(this.Network, dataFolder, dBreezeSerializer);
blockRepository.Initialize();
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Last().GetHash(), 50), posBlocks);

var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
Expand Down Expand Up @@ -57,6 +58,7 @@ public void PruneRepository_PruneAndCompact_MidChain_OnStartUp()
var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);

var blockRepository = new LevelDbBlockRepository(this.Network, dataFolder, dBreezeSerializer);
blockRepository.Initialize();
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Take(100).Last().GetHash(), 100), posBlocks.Take(100).ToList());

var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
Expand Down Expand Up @@ -96,6 +98,7 @@ public void PruneRepository_PruneAndCompact_OnShutDown()
var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);

var blockRepository = new LevelDbBlockRepository(this.Network, dataFolder, dBreezeSerializer);
blockRepository.Initialize();
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Last().GetHash(), 50), posBlocks);

var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
Expand Down
Loading

0 comments on commit 1419bab

Please sign in to comment.