Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge latest PRs into 1.4.0.7 #1116

Draft
wants to merge 45 commits into
base: release/1.4.0.7
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5686118
Added two RPC methods for listing transactions (#941)
zeptin Mar 23, 2022
2fdc28c
Resolve various code warnings (#950)
quantumagi Mar 30, 2022
d969b1b
[IBD/Rewind] Refactor RecoverStoreTip (#943)
quantumagi Apr 11, 2022
6b1918e
Add "minblksdownload" command-line option (#954)
quantumagi Apr 11, 2022
81d6c47
[IBD/Rewind] Forego unused transactions and unnecessary commits in po…
quantumagi Apr 11, 2022
1bb22ca
[IBD/Rewind] Optimize commitment height rule (#931)
quantumagi Apr 11, 2022
2fba695
[TODO] Make ConsensusOptions non-mutable (#885)
quantumagi Apr 11, 2022
76f005f
Fix merge (#967)
quantumagi Apr 30, 2022
c29ac8f
[API] Add hex version of getblockheader (#983)
zeptin May 15, 2022
949e96d
Add BaseSettings class (#991)
quantumagi May 31, 2022
fc64ab6
Add GetBlocks and CommonBlock APIs for chain synchronisation (#985)
quantumagi May 31, 2022
ca700cf
Refactor MinerSettings (#992)
quantumagi May 31, 2022
696bb0d
Refactor ApiSettings (#993)
quantumagi Jun 4, 2022
47ec7c3
Make BatchBlocksFrom re-usable (#1010)
quantumagi Jun 30, 2022
580120c
Remove ScriptDestinationReader (#1011)
quantumagi Jul 2, 2022
1b8182b
Optimise tx hash caclulation (#1015)
quantumagi Jul 4, 2022
5c2317e
Move CachedCoinView initialization from PowConsensusRuleEngine (#1014)
quantumagi Jul 4, 2022
5f69d62
Optimize PubKey ToHex, GetHashCode and Equals (#968)
quantumagi Jul 6, 2022
4616675
[IBD/Rewind] Optimize P2PKHNotContractRule (#930)
quantumagi Jul 6, 2022
31bfe8f
Enable coin view to "catch up" if forked or below chain tip (#1016)
quantumagi Jul 12, 2022
e645315
Merge CoinDb implementations (#1017)
quantumagi Jul 12, 2022
1a3c4fa
Combine ChainStore implementations (#1025)
quantumagi Jul 25, 2022
0eb359e
Combine KeyValueStore implementations (#1029)
quantumagi Aug 4, 2022
b17790d
Remove redundant CoinDb code (#1021)
quantumagi Aug 8, 2022
7954a39
Combine BlockRepository implementations (#1030)
quantumagi Aug 8, 2022
a235ef6
Fix MinerPairStarts test case (#1034)
quantumagi Aug 10, 2022
213b3f0
Fix CI errors (#1043)
quantumagi Aug 18, 2022
bad86c7
Combine ProvenBlockHeaderRepository implementations (#1041)
quantumagi Aug 18, 2022
d699589
Resolve separate DBreeze CoinDb implementation (#1036)
quantumagi Aug 22, 2022
c4e7433
Fix tests
quantumagi Jan 31, 2023
52a6fe4
Fix attempt to use NFTTransferIndexer with Strax (#1068)
quantumagi Oct 5, 2022
709de1f
Remove unused checkpoints from CachedCoinView constructor (#1071)
quantumagi Oct 7, 2022
1ef2dd5
Pass ChainIndexer argument via CachedCoinView constructor (#1072)
quantumagi Oct 11, 2022
fcc3b4e
Bump version to 1.5.0.0 (#1077)
quantumagi Oct 25, 2022
5440972
Fix GetBlockData (#1079)
quantumagi Oct 27, 2022
4170264
Fix endianness of delete on rewind table (#1080)
quantumagi Oct 30, 2022
901ba40
Fix EnableAutoKickAsync (#1082)
quantumagi Oct 31, 2022
7d49e0b
Fix TestDBreezeSerialization test case (#1081)
quantumagi Oct 31, 2022
cb3d333
Optimise GetLastBalanceDecreaseTransaction (#1085)
quantumagi Nov 1, 2022
d5706ba
Refactor WhitelistedHashesRepository (#1090)
quantumagi Nov 8, 2022
602664e
Update BTC checkpoints (#1096)
zeptin Nov 23, 2022
3b50801
Add -blockmintxfee setting (#1097)
zeptin Dec 4, 2022
d11fc47
Fix merge
quantumagi Jan 31, 2023
9c735d0
Merge with latest 1.4.0.7 updates
quantumagi Feb 15, 2023
8b46959
Revert inadvertent changes
quantumagi Feb 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/FederationSetup/FederationSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.5.0.0</Version>
<TargetFramework>net6.0</TargetFramework>
<Version>1.4.0.7</Version>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/FodyNlogAdapter/FodyNlogAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>FodyNlogAdapter</AssemblyName>
<Version>1.4.0.7</Version>
<Version>1.5.0.0</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
<PackageId>Stratis.Utils.FodyNlogAdapter</PackageId>
Expand Down
10 changes: 5 additions & 5 deletions src/NBitcoin.Tests/ChainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void CanSaveChain()
ChainedHeader fork = this.AppendBlock(chain);
this.AppendBlock(chain);

var chain2 = new ChainIndexer(this.network).Load(chain.ToBytes());
ChainIndexer chain2 = new ChainIndexer(this.network).Load(chain.ToBytes());
Assert.True(chain.Tip.HashBlock == chain2.Tip.HashBlock);
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public void CanBuildChain()
[Trait("UnitTest", "UnitTest")]
public void CanCalculateDifficulty()
{
var main = new ChainIndexer(this.network).Load(this.LoadMainChain());
ChainIndexer main = new ChainIndexer(this.network).Load(this.LoadMainChain());
// The state of the line separators may be affected by copy operations - so do an environment independent line split...
string[] histories = File.ReadAllText(TestDataLocations.GetFileFromDataFolder("targethistory.csv")).Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

Expand All @@ -161,7 +161,7 @@ public void CanCalculateDifficulty()
BlockHeader block = main.GetHeader(height).Header;

Assert.Equal(expectedTarget, block.Bits);
Target target = main.GetHeader(height).GetWorkRequired(network);
Target target = main.GetHeader(height).GetWorkRequired(this.network);
Assert.Equal(expectedTarget, target);
}
}
Expand All @@ -170,7 +170,7 @@ public void CanCalculateDifficulty()
[Trait("UnitTest", "UnitTest")]
public void CanValidateChain()
{
var main = new ChainIndexer(this.network).Load(this.LoadMainChain());
ChainIndexer main = new ChainIndexer(this.network).Load(this.LoadMainChain());
foreach (ChainedHeader h in main.EnumerateToTip(main.Genesis))
{
Assert.True(h.Validate(this.network));
Expand Down Expand Up @@ -340,7 +340,7 @@ private ChainIndexer CreateChain(BlockHeader genesis, int height)
{
var chain = new ChainIndexer(this.network);

var chainedHeaderPrev = chain.Tip;
ChainedHeader chainedHeaderPrev = chain.Tip;

for (int i = 0; i < height; i++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/NBitcoin.Tests/NetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void ReadMagicByteWithFirstByteDuplicated()
[Trait("UnitTest", "UnitTest")]
public void BitcoinMainnetIsInitializedCorrectly()
{
Assert.Equal(17, this.networkMain.Checkpoints.Count);
Assert.Equal(18, this.networkMain.Checkpoints.Count);
Assert.Equal(6, this.networkMain.DNSSeeds.Count);
Assert.Equal(512, this.networkMain.SeedNodes.Count);

Expand Down Expand Up @@ -143,7 +143,7 @@ public void BitcoinMainnetIsInitializedCorrectly()
Assert.Equal(Utils.UnixTimeToDateTime(1510704000), this.networkMain.Consensus.BIP9Deployments[BitcoinBIP9Deployments.Segwit].Timeout);
Assert.Equal(0, this.networkMain.Consensus.CoinType);
Assert.False(this.networkMain.Consensus.IsProofOfStake);
Assert.Equal(new uint256("0x0000000000000000000f1c54590ee18d15ec70e68c8cd4cfbadb1b4f11697eee"), this.networkMain.Consensus.DefaultAssumeValid);
Assert.Equal(new uint256("0x00000000000000000003e1d91b245eb32787afb10afe49b61621375361221c38"), this.networkMain.Consensus.DefaultAssumeValid);
Assert.Equal(100, this.networkMain.Consensus.CoinbaseMaturity);
Assert.Equal(0, this.networkMain.Consensus.PremineReward);
Assert.Equal(0, this.networkMain.Consensus.PremineHeight);
Expand All @@ -163,7 +163,7 @@ public void BitcoinTestnetIsInitializedCorrectly()
{
Network network = KnownNetworks.TestNet;

Assert.Equal(13, network.Checkpoints.Count);
Assert.Equal(14, network.Checkpoints.Count);
Assert.Equal(3, network.DNSSeeds.Count);
Assert.Empty(network.SeedNodes);

Expand Down Expand Up @@ -224,7 +224,7 @@ public void BitcoinTestnetIsInitializedCorrectly()
Assert.Equal(Utils.UnixTimeToDateTime(1493596800), network.Consensus.BIP9Deployments[BitcoinBIP9Deployments.Segwit].Timeout);
Assert.Equal(1, network.Consensus.CoinType);
Assert.False(network.Consensus.IsProofOfStake);
Assert.Equal(new uint256("0x0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75"), network.Consensus.DefaultAssumeValid);
Assert.Equal(new uint256("000000000000075566fba6ca27a2e4c8b33c7763f8a5f917b231b0d88c743af8"), network.Consensus.DefaultAssumeValid);
Assert.Equal(100, network.Consensus.CoinbaseMaturity);
Assert.Equal(0, network.Consensus.PremineReward);
Assert.Equal(0, network.Consensus.PremineHeight);
Expand Down
17 changes: 8 additions & 9 deletions src/NBitcoin/ConsensusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace NBitcoin
{
/// <summary>
/// An extension to <see cref="Consensus"/> to enable additional options to the consensus data.
/// TODO: Make immutable.
/// </summary>
public class ConsensusOptions
{
Expand All @@ -14,16 +13,16 @@ public class ConsensusOptions
public const int SerializeTransactionNoWitness = 0x40000000;

/// <summary>Maximum size for a block in bytes.</summary>
public uint MaxBlockBaseSize { get; set; }
public uint MaxBlockBaseSize { get; protected set; }

/// <summary>The maximum allowed weight for a block, see BIP 141 (network rule)</summary>
public uint MaxBlockWeight { get; set; }
public uint MaxBlockWeight { get; protected set; }

/// <summary>The maximum allowed size for a serialized block, in bytes (only for buffer size limits). </summary>
public uint MaxBlockSerializedSize { get; set; }
public uint MaxBlockSerializedSize { get; protected set; }

/// <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>
public int WitnessScaleFactor { get; set; }
public int WitnessScaleFactor { get; protected set; }

/// <summary>
/// Changing the default transaction version requires a two step process:
Expand All @@ -33,16 +32,16 @@ public class ConsensusOptions
/// <see cref="MaxStandardVersion"/> will be equal.</item>
/// </list>
/// </summary>
public int MaxStandardVersion { get; set; }
public int MaxStandardVersion { get; protected set; }

/// <summary>The maximum weight for transactions we're willing to relay/mine.</summary>
public int MaxStandardTxWeight { get; set; }
public int MaxStandardTxWeight { get; protected set; }

/// <summary>The maximum allowed number of signature check operations in a block (network rule).</summary>
public int MaxBlockSigopsCost { get; set; }
public int MaxBlockSigopsCost { get; protected set; }

/// <summary>The maximum number of sigops we're willing to relay/mine in a single tx.</summary>
public int MaxStandardTxSigopsCost { get; set; }
public int MaxStandardTxSigopsCost { get; protected set; }

/// <summary>Block Height at which the node should enforce the use of <see cref="EnforcedMinProtocolVersion"/>.
/// Can be set to zero to indicate that the minimum supported protocol version will not change depending on the block height.</summary>
Expand Down
44 changes: 35 additions & 9 deletions src/NBitcoin/PubKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,26 @@ public bool Verify(uint256 hash, byte[] sig)
return Verify(hash, ECDSASignature.FromDER(sig));
}

private string hexStr = null;

public string ToHex()
{
return Encoders.Hex.EncodeData(this.vch);
this.hexStr ??= Encoders.Hex.EncodeData(this.vch);

return this.hexStr;
}

#region IBitcoinSerializable Members

public void ReadWrite(BitcoinStream stream)
{
stream.ReadWrite(ref this.vch);
if(!stream.Serializing) this._ECKey = new ECKey(this.vch, false);

if (!stream.Serializing)
{
this._ECKey = new ECKey(this.vch, false);
this.hexStr = null;
}
}

#endregion
Expand Down Expand Up @@ -345,18 +354,33 @@ public PubKey Derivate(byte[] cc, uint nChild, out byte[] ccChild)

public override bool Equals(object obj)
{
var item = obj as PubKey;
if(item == null)
return obj != null && Equals(obj as PubKey);
}

public bool Equals(PubKey other)
{
if ((object)other == null)
return false;

if (other.vch.Length != this.vch.Length)
return false;
return ToHex().Equals(item.ToHex());

for (int i = 0; i < other.vch.Length; i++)
if (other.vch[i] != this.vch[i])
return false;

return true;
}

public static bool operator ==(PubKey a, PubKey b)
{
if(ReferenceEquals(a, b))
if (ReferenceEquals(a, b))
return true;
if(((object)a == null) || ((object)b == null))

if (((object)a == null) != ((object)b == null))
return false;
return a.ToHex() == b.ToHex();

return a.Equals(b);
}

public static bool operator !=(PubKey a, PubKey b)
Expand All @@ -366,17 +390,19 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return ToHex().GetHashCode();
return (((((this.vch[1] << 8) + this.vch[2]) << 8) + this.vch[3]) << 8) + this.vch[4];
}

public PubKey UncoverSender(Key ephem, PubKey scan)
{
return Uncover(ephem, scan);
}

public PubKey UncoverReceiver(Key scan, PubKey ephem)
{
return Uncover(scan, ephem);
}

public PubKey Uncover(Key priv, PubKey pub)
{
X9ECParameters curve = ECKey.Secp256k1;
Expand Down
2 changes: 1 addition & 1 deletion src/NBitcoin/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public TxDestination GetDestination(Network network)
ScriptId scriptHashParams = PayToScriptHashTemplate.Instance.ExtractScriptPubKeyParameters(this);
if (scriptHashParams != null)
return scriptHashParams;
TxDestination wit = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters(network, this);
TxDestination wit = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters(this);
return wit;
}

Expand Down
4 changes: 2 additions & 2 deletions src/NBitcoin/ScriptEvaluationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public bool VerifyScript(Script scriptSig, Script scriptPubKey, TransactionCheck

if((this.ScriptVerify & ScriptVerify.Witness) != 0)
{
WitProgramParameters wit = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters2(this.Network, scriptPubKey);
WitProgramParameters wit = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters2(scriptPubKey);
if(wit != null)
{
hadWitness = true;
Expand Down Expand Up @@ -508,7 +508,7 @@ public bool VerifyScript(Script scriptSig, Script scriptPubKey, TransactionCheck
// P2SH witness program
if((this.ScriptVerify & ScriptVerify.Witness) != 0)
{
WitProgramParameters wit = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters2(this.Network, redeem);
WitProgramParameters wit = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters2(redeem);
if(wit != null)
{
hadWitness = true;
Expand Down
4 changes: 2 additions & 2 deletions src/NBitcoin/StandardScriptTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ public static bool ValidSegwitVersion(byte version)
return version == 0 || ((byte)OpcodeType.OP_1 <= version && version <= (byte)OpcodeType.OP_16);
}

public TxDestination ExtractScriptPubKeyParameters(Network network, Script scriptPubKey)
public TxDestination ExtractScriptPubKeyParameters(Script scriptPubKey)
{
if(!CheckScriptPubKey(scriptPubKey))
return null;
Expand All @@ -1158,7 +1158,7 @@ public TxDestination ExtractScriptPubKeyParameters(Network network, Script scrip
}
return null;
}
public WitProgramParameters ExtractScriptPubKeyParameters2(Network network, Script scriptPubKey)
public WitProgramParameters ExtractScriptPubKeyParameters2(Script scriptPubKey)
{
if(!CheckScriptPubKey(scriptPubKey))
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.Bitcoin.Cli/Stratis.Bitcoin.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Version>1.4.0.7</Version>
<Version>1.5.0.0</Version>
<Authors>Stratis Group Ltd.</Authors>
<Company>Stratis Group Ltd.</Company>
<Product />
Expand Down
5 changes: 3 additions & 2 deletions src/Stratis.Bitcoin.Features.Api/ApiFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NBitcoin;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Builder.Feature;
using Stratis.Bitcoin.Configuration.Settings;

namespace Stratis.Bitcoin.Features.Api
{
Expand Down Expand Up @@ -83,7 +84,7 @@ public override Task InitializeAsync()
/// <param name="network">The network to extract values from.</param>
public static void PrintHelp(Network network)
{
ApiSettings.PrintHelp(network);
BaseSettings.PrintHelp(typeof(ApiSettings), network);
}

/// <summary>
Expand All @@ -93,7 +94,7 @@ public static void PrintHelp(Network network)
/// <param name="network">The network to base the defaults off.</param>
public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network)
{
ApiSettings.BuildDefaultConfigurationFile(builder, network);
BaseSettings.BuildDefaultConfigurationFile(typeof(ApiSettings), builder, network);
}

/// <inheritdoc />
Expand Down
Loading