Skip to content

Commit

Permalink
Merge pull request stratisproject#17 from block-core/segwit
Browse files Browse the repository at this point in the history
Merge Segwit to master
  • Loading branch information
dangershony authored Nov 17, 2019
2 parents 6ef036a + 49b36a1 commit 26ec44f
Show file tree
Hide file tree
Showing 122 changed files with 5,142 additions and 1,015 deletions.
6 changes: 3 additions & 3 deletions Scripts/LaunchSidechainMasternode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ function Check-TimeDifference
{
Write-Host "Checking UTC Time Difference" -ForegroundColor Cyan
$timeDifSamples = @([int16]::MaxValue,[int16]::MaxValue,[int16]::MaxValue)
$timeDifSamples[0] = New-TimeSpan -Start (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -End ( Invoke-WebRequest http://worldtimeapi.org/api/timezone/UTC | ConvertFrom-Json | Select-Object -ExpandProperty utc_datetime ) | Select-Object -ExpandProperty TotalSeconds
$timeDifSamples[1] = New-TimeSpan -Start (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -End ( Invoke-WebRequest http://worldtimeapi.org/api/timezone/UTC | ConvertFrom-Json | Select-Object -ExpandProperty utc_datetime ) | Select-Object -ExpandProperty TotalSeconds
$timeDifSamples[2] = New-TimeSpan -Start (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -End ( Invoke-WebRequest http://worldtimeapi.org/api/timezone/UTC | ConvertFrom-Json | Select-Object -ExpandProperty utc_datetime ) | Select-Object -ExpandProperty TotalSeconds
$timeDifSamples[0] = New-TimeSpan -Start (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -End ( Invoke-WebRequest http://worldtimeapi.org/api/timezone/Etc/GMT | ConvertFrom-Json | Select-Object -ExpandProperty utc_datetime ) | Select-Object -ExpandProperty TotalSeconds
$timeDifSamples[1] = New-TimeSpan -Start (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -End ( Invoke-WebRequest http://worldtimeapi.org/api/timezone/Etc/GMT | ConvertFrom-Json | Select-Object -ExpandProperty utc_datetime ) | Select-Object -ExpandProperty TotalSeconds
$timeDifSamples[2] = New-TimeSpan -Start (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ") -End ( Invoke-WebRequest http://worldtimeapi.org/api/timezone/Etc/GMT | ConvertFrom-Json | Select-Object -ExpandProperty utc_datetime ) | Select-Object -ExpandProperty TotalSeconds

$timeDif = Get-Median -numberSeries $timeDifSamples

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 6 additions & 9 deletions src/NBitcoin.Tests/NetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ public void StratisMainIsInitializedCorrectly()
Assert.Equal("STRAT", network.CoinTicker);

Assert.Equal(2, network.Bech32Encoders.Length);
Assert.Null(network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS]);
Assert.Null(network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS]);
Assert.Equal(new Bech32Encoder("strat").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString());
Assert.Equal(new Bech32Encoder("strat").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString());

Assert.Equal(12, network.Base58Prefixes.Length);
Assert.Equal(new byte[] { (63) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]);
Expand Down Expand Up @@ -377,7 +377,6 @@ public void StratisMainIsInitializedCorrectly()
Assert.False(network.Consensus.PowNoRetargeting);
Assert.Equal(1916, network.Consensus.RuleChangeActivationThreshold);
Assert.Equal(2016, network.Consensus.MinerConfirmationWindow);
Assert.Null(network.Consensus.BIP9Deployments[StratisBIP9Deployments.TestDummy]);
Assert.Equal(12500, network.Consensus.LastPOWBlock);
Assert.True(network.Consensus.IsProofOfStake);
Assert.Equal(105, network.Consensus.CoinType);
Expand Down Expand Up @@ -421,8 +420,8 @@ public void StratisTestnetIsInitializedCorrectly()
Assert.Equal("TSTRAT", network.CoinTicker);

Assert.Equal(2, network.Bech32Encoders.Length);
Assert.Null(network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS]);
Assert.Null(network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS]);
Assert.Equal(new Bech32Encoder("tstrat").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString());
Assert.Equal(new Bech32Encoder("tstrat").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString());

Assert.Equal(12, network.Base58Prefixes.Length);
Assert.Equal(new byte[] { (65) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]);
Expand Down Expand Up @@ -454,7 +453,6 @@ public void StratisTestnetIsInitializedCorrectly()
Assert.False(network.Consensus.PowNoRetargeting);
Assert.Equal(1916, network.Consensus.RuleChangeActivationThreshold);
Assert.Equal(2016, network.Consensus.MinerConfirmationWindow);
Assert.Null(network.Consensus.BIP9Deployments[StratisBIP9Deployments.TestDummy]);
Assert.Equal(12500, network.Consensus.LastPOWBlock);
Assert.True(network.Consensus.IsProofOfStake);
Assert.Equal(105, network.Consensus.CoinType);
Expand Down Expand Up @@ -498,8 +496,8 @@ public void StratisRegTestIsInitializedCorrectly()
Assert.Equal("TSTRAT", network.CoinTicker);

Assert.Equal(2, network.Bech32Encoders.Length);
Assert.Null(network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS]);
Assert.Null(network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS]);
Assert.Equal(new Bech32Encoder("tstrat").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString());
Assert.Equal(new Bech32Encoder("tstrat").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString());

Assert.Equal(12, network.Base58Prefixes.Length);
Assert.Equal(new byte[] { (65) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]);
Expand Down Expand Up @@ -531,7 +529,6 @@ public void StratisRegTestIsInitializedCorrectly()
Assert.True(network.Consensus.PowNoRetargeting);
Assert.Equal(1916, network.Consensus.RuleChangeActivationThreshold);
Assert.Equal(2016, network.Consensus.MinerConfirmationWindow);
Assert.Null(network.Consensus.BIP9Deployments[StratisBIP9Deployments.TestDummy]);
Assert.Equal(12500, network.Consensus.LastPOWBlock);
Assert.True(network.Consensus.IsProofOfStake);
Assert.Equal(105, network.Consensus.CoinType);
Expand Down
3 changes: 3 additions & 0 deletions src/NBitcoin/Consensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class Consensus : IConsensus
/// <inheritdoc />
public bool IsProofOfStake { get; }

/// <inheritdoc />
public bool PosEmptyCoinbase { get; set; }

/// <inheritdoc />
public uint256 DefaultAssumeValid { get; }

Expand Down
11 changes: 7 additions & 4 deletions src/NBitcoin/ConsensusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ public ConsensusOptions(
int maxStandardVersion,
int maxStandardTxWeight,
int maxBlockSigopsCost,
int maxStandardTxSigopsCost)
int maxStandardTxSigopsCost,
int witnessScaleFactor)
{
this.MaxBlockBaseSize = maxBlockBaseSize;

// Having witnessScale = 1 and setting the weight to be the same value as the base size
// will result in all checks comparing size in bytes.
this.MaxBlockWeight = maxBlockBaseSize;
this.MaxBlockSerializedSize = maxBlockBaseSize;
this.WitnessScaleFactor = 1;
this.WitnessScaleFactor = witnessScaleFactor;

this.MaxStandardVersion = maxStandardVersion;
this.MaxStandardTxWeight = maxStandardTxWeight;
Expand Down Expand Up @@ -179,8 +180,9 @@ public PosConsensusOptions(
int maxStandardVersion,
int maxStandardTxWeight,
int maxBlockSigopsCost,
int maxStandardTxSigopsCost
) : base(maxBlockBaseSize, maxStandardVersion, maxStandardTxWeight, maxBlockSigopsCost, maxStandardTxSigopsCost)
int maxStandardTxSigopsCost,
int witnessScaleFactor
) : base(maxBlockBaseSize, maxStandardVersion, maxStandardTxWeight, maxBlockSigopsCost, maxStandardTxSigopsCost, witnessScaleFactor)
{
}

Expand All @@ -191,6 +193,7 @@ int maxStandardTxSigopsCost
/// <param name="network">The network.</param>
public virtual int GetStakeMinConfirmations(int height, Network network)
{
// TODO: Is there supposed to be a defined activation height for regtest?
if (network.NetworkType == NetworkType.Testnet || network.NetworkType == NetworkType.Regtest)
return height < CoinstakeMinConfirmationActivationHeightTestnet ? 10 : 20;

Expand Down
10 changes: 10 additions & 0 deletions src/NBitcoin/IConsensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public interface IConsensus
/// <summary>PoW blocks are not accepted after block with height <see cref="Consensus.LastPOWBlock"/>.</summary>
int LastPOWBlock { get; set; }

/// <summary>
/// This flag will restrict the coinbase in a POS network to be empty.
/// For legacy POS the coinbase is required to be empty.
/// </summary>
/// <remarks>
/// Some implementations will put extra data in the coinbase (for example the witness commitment)
/// To allow such data to be in the coinbase we use this flag, a POS network that already has that limitation will use the coinbase input instead.
/// </remarks>
bool PosEmptyCoinbase { get; set; }

/// <summary>
/// An indicator whether this is a Proof Of Stake network.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion src/NBitcoin/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ public enum ScriptVerify : uint
| Witness
| DiscourageUpgradableWitnessProgram
| NullFail
| MinimalIf
| MinimalIf,

/// <summary>
/// For convenience, standard but not mandatory verify flags
/// </summary>
StandardNotMandatory = Standard & ~Mandatory
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion src/NBitcoin/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ public WitScript WitScript
}
}

public bool WitScriptEmpty
{
get
{
return this.WitScript == WitScript.Empty || this.WitScript == null;
}
}

#region IBitcoinSerializable Members

public void ReadWrite(BitcoinStream stream)
Expand Down Expand Up @@ -1893,7 +1901,7 @@ public bool HasWitness
{
get
{
return this.Inputs.Any(i => i.WitScript != WitScript.Empty && i.WitScript != null);
return this.Inputs.Any(i => i.WitScriptEmpty == false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static void Main(string[] args)
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

// for debug benchmark, adds "new DebugInProcessConfig()"
// BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
//BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
}
}
}
6 changes: 0 additions & 6 deletions src/Stratis.Bitcoin.Features.BlockStore/BlockStoreFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ public override Task InitializeAsync()
// TODO: Add NetworkLimited which is what BTC uses for pruned nodes.
this.connectionManager.Parameters.Services = (this.storeSettings.PruningEnabled ? NetworkPeerServices.Nothing : NetworkPeerServices.Network);

// Temporary measure to support asking witness data on BTC.
// At some point NetworkPeerServices will move to the Network class,
// Then this values should be taken from there.
if (!this.network.Consensus.IsProofOfStake)
this.connectionManager.Parameters.Services |= NetworkPeerServices.NODE_WITNESS;

this.blockStoreSignaled.Initialize();

this.addressIndexer.Initialize();
Expand Down
Loading

0 comments on commit 26ec44f

Please sign in to comment.