Skip to content

Commit c2c3757

Browse files
dangershonysondreb
andauthored
Remove the constructors from options (#146)
* Remove the constructors from options * Upgrade the SDK for .NET Core * Make sure we use runtime 3.1.4 * Remove the installation/setup of .NET SDK on build agent, this is pre-installed. * Change the output assembly for NBitcoin Tests. * Add some hardwired visible to attributes for NBitcoin project Co-authored-by: SondreB <sondre@outlook.com>
1 parent 99774a8 commit c2c3757

29 files changed

Lines changed: 202 additions & 403 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ jobs:
3636
run: |
3737
echo "::set-env name=VERSION::$(npm run version --silent)"
3838
39-
- name: Setup .NET Core
40-
uses: actions/setup-dotnet@v1
41-
with:
42-
dotnet-version: '3.1.101'
43-
4439
- name: Unit Test
4540
run: dotnet test -v=normal --no-build --filter FullyQualifiedName!~IntegrationTests --configuration ${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_PATH}}
4641

.github/workflows/publish-release.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jobs:
1919
steps:
2020

2121
- uses: actions/checkout@v1
22-
23-
- name: Setup .NET Core
24-
uses: actions/setup-dotnet@v1
25-
with:
26-
dotnet-version: '3.1.101'
2722

2823
- name: Setup NuGet
2924
uses: NuGet/setup-nuget@v1.0.2

.github/workflows/pull-request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424

2525
- uses: actions/checkout@v1
2626

27-
- name: Setup .NET Core
28-
uses: actions/setup-dotnet@v1
29-
with:
30-
dotnet-version: '3.1.101'
27+
# - name: Setup .NET Core
28+
# uses: actions/setup-dotnet@v1
29+
# with:
30+
# dotnet-version: '3.1.300'
3131

3232
- name: Restore
3333
run: dotnet restore ${{env.SOLUTION_PATH}}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Setup .NET Core
2929
uses: actions/setup-dotnet@v1
3030
with:
31-
dotnet-version: '3.1.101'
31+
dotnet-version: '3.1.202'
3232

3333
- name: Restore
3434
run: dotnet restore ${{env.SOLUTION_PATH}}

src/Directory.Build.props

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<Version>1.0.10</Version>
4-
<RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>
4+
<RuntimeFrameworkVersion>3.1.4</RuntimeFrameworkVersion>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<IsPackable>false</IsPackable>
77
<Authors>Blockcore</Authors>
@@ -18,12 +18,19 @@
1818

1919
<Target Name="AddInternalsVisibleTo" BeforeTargets="CoreCompile">
2020
<ItemGroup>
21-
<!-- We don't need this at the moment, so not added. -->
22-
<!--
21+
22+
<!--<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
23+
<_Parameter1>NBitcoin.Tests</_Parameter1>
24+
</AssemblyAttribute>
25+
2326
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
24-
<_Parameter1>$(AssemblyName).Tests</_Parameter1>
27+
<_Parameter1>Blockcore.NBitcoin.Tests</_Parameter1>
2528
</AssemblyAttribute>-->
2629

30+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
31+
<_Parameter1>$(AssemblyName).Tests</_Parameter1>
32+
</AssemblyAttribute>
33+
2734
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
2835
<_Parameter1>$(PackageId).Tests</_Parameter1>
2936
</AssemblyAttribute>

src/External/NBitcoin.Tests/NBitcoin.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<PropertyGroup>
44
<PackageId>Blockcore.NBitcoin.Tests</PackageId>
5+
<AssemblyName>Blockcore.NBitcoin.Tests</AssemblyName>
6+
<AssemblyName>Blockcore.NBitcoin.Tests</AssemblyName>
57
</PropertyGroup>
68

79
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/External/NBitcoin/ConsensusOptions.cs

Lines changed: 19 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ public class ConsensusOptions
1414
public const int SerializeTransactionNoWitness = 0x40000000;
1515

1616
/// <summary>Maximum size for a block in bytes. </summary>
17-
public uint MaxBlockBaseSize { get; set; }
17+
public uint MaxBlockBaseSize { get; set; } = 1000000;
1818

1919
/// <summary>The maximum allowed weight for a block, see BIP 141 (network rule)</summary>
20-
public uint MaxBlockWeight { get; set; }
20+
public uint MaxBlockWeight { get; set; } = 4000000;
2121

22-
/// <summary>Thee minimum feerate for a transaction in blocks mined.</summary>
23-
public long MinBlockFeeRate { get; set; }
22+
/// <summary>Thee minimum fee-rate (fee per kb) a transaction is paying
23+
/// in order to be included by the miner when mining a block.
24+
/// </summary>
25+
public long MinBlockFeeRate { get; set; } = 1000;
2426

2527
/// <summary>The maximum allowed size for a serialized block, in bytes (only for buffer size limits). </summary>
26-
public uint MaxBlockSerializedSize { get; set; }
28+
public uint MaxBlockSerializedSize { get; set; } = 4000000;
2729

28-
/// <summary>Scale of witness vs other transaction data. e.g. if set to 4, then witnesses have 1/4 the weight per byte of other transaction data. </summary>
29-
public int WitnessScaleFactor { get; set; }
30+
/// <summary>Scale of witness vs other transaction data. e.g. if set to 4,
31+
/// then witnesses have 1/4 the weight per byte of other transaction data.
32+
/// </summary>
33+
public int WitnessScaleFactor { get; set; } = 4;
3034

3135
/// <summary>
3236
/// Changing the default transaction version requires a two step process:
@@ -36,89 +40,26 @@ public class ConsensusOptions
3640
/// <see cref="MaxStandardVersion"/> will be equal.</item>
3741
/// </list>
3842
/// </summary>
39-
public int MaxStandardVersion { get; set; }
43+
public int MaxStandardVersion { get; set; } = 2;
4044

4145
/// <summary>The maximum weight for transactions we're willing to relay/mine.</summary>
42-
public int MaxStandardTxWeight { get; set; }
46+
public int MaxStandardTxWeight { get; set; } = 400000;
4347

4448
/// <summary>The maximum allowed number of signature check operations in a block (network rule).</summary>
45-
public int MaxBlockSigopsCost { get; set; }
49+
public int MaxBlockSigopsCost { get; set; } = 80000;
4650

4751
/// <summary>The maximum number of sigops we're willing to relay/mine in a single tx.</summary>
48-
public int MaxStandardTxSigopsCost { get; set; }
52+
/// <remarks>
53+
/// This value is calculated based on <see cref="MaxBlockSigopsCost"/> dived by 5.
54+
/// </remarks>
55+
public int MaxStandardTxSigopsCost { get; set; } = 80000 / 5; // MaxBlockSigopsCost / 5
4956

5057
/// <summary>Block Height at which the node should enforce the use of <see cref="EnforcedMinProtocolVersion"/>.
5158
/// Can be set to zero to indicate that the minimum supported protocol version will not change depending on the block height.</summary>
52-
public int EnforceMinProtocolVersionAtBlockHeight { get; set; }
59+
public int EnforceMinProtocolVersionAtBlockHeight { get; set; } = 0;
5360

5461
/// <summary>The minimum protocol version which should be used from block height defined in <see cref="EnforceMinProtocolVersionAtBlockHeight"/></summary>
5562
public uint? EnforcedMinProtocolVersion { get; set; }
56-
57-
/// <summary>
58-
/// Initializes the default values. Currently only used for initialising Bitcoin networks and testing.
59-
/// </summary>
60-
public ConsensusOptions()
61-
{
62-
// TODO: Remove this constructor. Should always set explicitly.
63-
this.MaxBlockSerializedSize = 4000000;
64-
this.MaxBlockWeight = 4000000;
65-
this.MinBlockFeeRate = 1000;
66-
this.WitnessScaleFactor = 4;
67-
this.MaxStandardVersion = 2;
68-
this.MaxStandardTxWeight = 400000;
69-
this.MaxBlockBaseSize = 1000000;
70-
this.MaxBlockSigopsCost = 80000;
71-
this.MaxStandardTxSigopsCost = this.MaxBlockSigopsCost / 5;
72-
this.EnforceMinProtocolVersionAtBlockHeight = 0;
73-
}
74-
75-
/// <summary>
76-
/// Initializes all values. Used by networks that use block weight rules.
77-
/// </summary>
78-
public ConsensusOptions(
79-
uint maxBlockBaseSize,
80-
uint maxBlockWeight,
81-
uint maxBlockSerializedSize,
82-
int witnessScaleFactor,
83-
int maxStandardVersion,
84-
int maxStandardTxWeight,
85-
int maxBlockSigopsCost,
86-
int maxStandardTxSigopsCost)
87-
{
88-
this.MaxBlockBaseSize = maxBlockBaseSize;
89-
this.MaxBlockWeight = maxBlockWeight;
90-
this.MaxBlockSerializedSize = maxBlockSerializedSize;
91-
this.WitnessScaleFactor = witnessScaleFactor;
92-
this.MaxStandardVersion = maxStandardVersion;
93-
this.MaxStandardTxWeight = maxStandardTxWeight;
94-
this.MaxBlockSigopsCost = maxBlockSigopsCost;
95-
this.MaxStandardTxSigopsCost = maxStandardTxSigopsCost;
96-
}
97-
98-
/// <summary>
99-
/// Initializes values for networks that use block size rules.
100-
/// </summary>
101-
public ConsensusOptions(
102-
uint maxBlockBaseSize,
103-
int maxStandardVersion,
104-
int maxStandardTxWeight,
105-
int maxBlockSigopsCost,
106-
int maxStandardTxSigopsCost,
107-
int witnessScaleFactor)
108-
{
109-
this.MaxBlockBaseSize = maxBlockBaseSize;
110-
111-
// Having witnessScale = 1 and setting the weight to be the same value as the base size
112-
// will result in all checks comparing size in bytes.
113-
this.MaxBlockWeight = maxBlockBaseSize;
114-
this.MaxBlockSerializedSize = maxBlockBaseSize;
115-
this.WitnessScaleFactor = witnessScaleFactor;
116-
117-
this.MaxStandardVersion = maxStandardVersion;
118-
this.MaxStandardTxWeight = maxStandardTxWeight;
119-
this.MaxBlockSigopsCost = maxBlockSigopsCost;
120-
this.MaxStandardTxSigopsCost = maxStandardTxSigopsCost;
121-
}
12263
}
12364

12465
/// <summary>
@@ -150,42 +91,6 @@ public class PosConsensusOptions : ConsensusOptions
15091
/// </summary>
15192
public const int MaxMerkleProofSerializedSize = 512;
15293

153-
/// <summary>
154-
/// Initializes the default values.
155-
/// </summary>
156-
public PosConsensusOptions()
157-
{
158-
}
159-
160-
/// <summary>
161-
/// Initializes all values. Used by networks that use block weight rules.
162-
/// </summary>
163-
public PosConsensusOptions(
164-
uint maxBlockBaseSize,
165-
uint maxBlockWeight,
166-
uint maxBlockSerializedSize,
167-
int witnessScaleFactor,
168-
int maxStandardVersion,
169-
int maxStandardTxWeight,
170-
int maxBlockSigopsCost,
171-
int maxStandardTxSigopsCost) : base(maxBlockBaseSize, maxBlockWeight, maxBlockSerializedSize, witnessScaleFactor, maxStandardVersion, maxStandardTxWeight, maxBlockSigopsCost, maxStandardTxSigopsCost)
172-
{
173-
}
174-
175-
/// <summary>
176-
/// Initializes values for networks that use block size rules.
177-
/// </summary>
178-
public PosConsensusOptions(
179-
uint maxBlockBaseSize,
180-
int maxStandardVersion,
181-
int maxStandardTxWeight,
182-
int maxBlockSigopsCost,
183-
int maxStandardTxSigopsCost,
184-
int witnessScaleFactor
185-
) : base(maxBlockBaseSize, maxStandardVersion, maxStandardTxWeight, maxBlockSigopsCost, maxStandardTxSigopsCost, witnessScaleFactor)
186-
{
187-
}
188-
18994
/// <summary>
19095
/// Gets the minimum confirmations amount required for a coin to be good enough to participate in staking.
19196
/// </summary>

src/External/NBitcoin/NBitcoin.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@
3737
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
3838
</ItemGroup>
3939

40+
<ItemGroup>
41+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
42+
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
43+
</AssemblyAttribute>
44+
45+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
46+
<_Parameter1>NBitcoin.Tests</_Parameter1>
47+
</AssemblyAttribute>
48+
49+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
50+
<_Parameter1>Blockcore.NBitcoin.Tests</_Parameter1>
51+
</AssemblyAttribute>
52+
</ItemGroup>
53+
4054
</Project>

src/Features/Blockcore.Features.PoA/PoAConsensusOptions.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,25 @@ public class PoAConsensusOptions : ConsensusOptions
1313
/// Use <see cref="IFederationManager.GetFederationMembers"/> as a source of
1414
/// up to date federation keys.
1515
/// </remarks>
16-
public List<IFederationMember> GenesisFederationMembers { get; protected set; }
16+
public List<IFederationMember> GenesisFederationMembers { get; set; }
1717

18-
public uint TargetSpacingSeconds { get; protected set; }
18+
public uint TargetSpacingSeconds { get; set; }
1919

2020
/// <summary>Adds capability of voting for adding\kicking federation members and other things.</summary>
21-
public bool VotingEnabled { get; protected set; }
21+
public bool VotingEnabled { get; set; }
2222

2323
/// <summary>Makes federation members kick idle members.</summary>
2424
/// <remarks>Requires voting to be enabled to be set <c>true</c>.</remarks>
25-
public bool AutoKickIdleMembers { get; protected set; }
25+
public bool AutoKickIdleMembers { get; set; }
2626

2727
/// <summary>Time that federation member has to be idle to be kicked by others in case <see cref="AutoKickIdleMembers"/> is enabled.</summary>
28-
public uint FederationMemberMaxIdleTimeSeconds { get; protected set; }
28+
public uint FederationMemberMaxIdleTimeSeconds { get; set; } = 60 * 60 * 24 * 7;
2929

3030
/// <summary>Initializes values for networks that use block size rules.</summary>
31-
public PoAConsensusOptions(
32-
uint maxBlockBaseSize,
33-
int maxStandardVersion,
34-
int maxStandardTxWeight,
35-
int maxBlockSigopsCost,
36-
int maxStandardTxSigopsCost,
37-
List<IFederationMember> genesisFederationMembers,
38-
uint targetSpacingSeconds,
39-
bool votingEnabled,
40-
bool autoKickIdleMembers,
41-
uint federationMemberMaxIdleTimeSeconds = 60 * 60 * 24 * 7)
42-
: base(maxBlockBaseSize, maxStandardVersion, maxStandardTxWeight, maxBlockSigopsCost, maxStandardTxSigopsCost, witnessScaleFactor: 1)
31+
public PoAConsensusOptions()
4332
{
44-
this.GenesisFederationMembers = genesisFederationMembers;
45-
this.TargetSpacingSeconds = targetSpacingSeconds;
46-
this.VotingEnabled = votingEnabled;
47-
this.AutoKickIdleMembers = autoKickIdleMembers;
48-
this.FederationMemberMaxIdleTimeSeconds = federationMemberMaxIdleTimeSeconds;
49-
5033
if (this.AutoKickIdleMembers && !this.VotingEnabled)
5134
throw new ArgumentException("Voting should be enabled for automatic kicking to work.");
5235
}
5336
}
54-
}
37+
}

src/Features/Blockcore.Features.PoA/PoANetwork.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,19 @@ public PoANetwork()
8484
new FederationMember(new PubKey("022f8ad1799fd281fc9519814d20a407ed120ba84ec24cca8e869b811e6f6d4590"))
8585
};
8686

87-
var consensusOptions = new PoAConsensusOptions(
88-
maxBlockBaseSize: 1_000_000,
89-
maxStandardVersion: 2,
90-
maxStandardTxWeight: 100_000,
91-
maxBlockSigopsCost: 20_000,
92-
maxStandardTxSigopsCost: 20_000 / 5,
93-
genesisFederationMembers: genesisFederationMembers,
94-
targetSpacingSeconds: 16,
95-
votingEnabled: true,
96-
autoKickIdleMembers: true
97-
);
87+
var consensusOptions = new PoAConsensusOptions
88+
{
89+
MaxBlockBaseSize = 1_000_000,
90+
MaxStandardVersion = 2,
91+
MaxStandardTxWeight = 100_000,
92+
MaxBlockSigopsCost = 20_000,
93+
MaxStandardTxSigopsCost = 20_000 / 5,
94+
95+
GenesisFederationMembers = genesisFederationMembers,
96+
TargetSpacingSeconds = 16,
97+
VotingEnabled = true,
98+
AutoKickIdleMembers = true
99+
};
98100

99101
var buriedDeployments = new BuriedDeploymentsArray
100102
{

0 commit comments

Comments
 (0)