Skip to content

Commit

Permalink
Merge pull request stratisproject#262 from fassadlr/channelnetwork
Browse files Browse the repository at this point in the history
[Channels] Subclass Network and create FeeNetwork / ChannelNetwork
  • Loading branch information
fassadlr authored Mar 13, 2020
2 parents 3374ff1 + 4c2a35b commit e20c8bf
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 1,288 deletions.
475 changes: 0 additions & 475 deletions src/NBitcoin.Tests/NetworkTests.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/NBitcoin.Tests/pos_transaction_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ private static StandardTransactionPolicy RelayPolicy(Network network)
{
MaxTransactionSize = null,
MaxTxFee = null,
MinRelayTxFee = new FeeRate(Money.Satoshis(network.MinRelayTxFee)),
MinRelayTxFee = new FeeRate(Money.Satoshis(((FeeNetwork)network).MinRelayTxFee)),
ScriptVerify = ScriptVerify.Standard & ~ScriptVerify.LowS
};
}
Expand Down
513 changes: 1 addition & 512 deletions src/NBitcoin.Tests/transaction_tests.cs

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/NBitcoin/FeeNetwork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace NBitcoin
{
public class FeeNetwork : Network
{
/// <summary>
/// Mininum fee rate for all transactions.
/// Fees smaller than this are considered zero fee for transaction creation.
/// Be careful setting this: if you set it to zero then a transaction spammer can cheaply fill blocks using
/// 1-satoshi-fee transactions. It should be set above the real cost to you of processing a transaction.
/// </summary>
/// <remarks>
/// The <see cref="MinRelayTxFee"/> and <see cref="MinTxFee"/> are typically the same value to prevent dos attacks on the network.
/// If <see cref="MinRelayTxFee"/> is less than <see cref="MinTxFee"/>, an attacker can broadcast a lot of transactions with fees between these two values,
/// which will lead to transactions filling the mempool without ever being mined.
/// </remarks>
public long MinTxFee { get; protected set; }

/// <summary>
/// A fee rate that will be used when fee estimation has insufficient data.
/// </summary>
public long FallbackFee { get; protected set; }

/// <summary>
/// The minimum fee under which transactions may be rejected from being relayed.
/// </summary>
/// <remarks>
/// The <see cref="MinRelayTxFee"/> and <see cref="MinTxFee"/> are typically the same value to prevent dos attacks on the network.
/// If <see cref="MinRelayTxFee"/> is less than <see cref="MinTxFee"/>, an attacker can broadcast a lot of transactions with fees between these two values,
/// which will lead to transactions filling the mempool without ever being mined.
/// </remarks>
public long MinRelayTxFee { get; protected set; }
}
}
35 changes: 1 addition & 34 deletions src/NBitcoin/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,6 @@ public abstract class Network
/// </summary>
public int MaxTipAge { get; protected set; }

/// <summary>
/// Mininum fee rate for all transactions.
/// Fees smaller than this are considered zero fee for transaction creation.
/// Be careful setting this: if you set it to zero then a transaction spammer can cheaply fill blocks using
/// 1-satoshi-fee transactions. It should be set above the real cost to you of processing a transaction.
/// </summary>
/// <remarks>
/// The <see cref="MinRelayTxFee"/> and <see cref="MinTxFee"/> are typically the same value to prevent dos attacks on the network.
/// If <see cref="MinRelayTxFee"/> is less than <see cref="MinTxFee"/>, an attacker can broadcast a lot of transactions with fees between these two values,
/// which will lead to transactions filling the mempool without ever being mined.
/// </remarks>
public long MinTxFee { get; protected set; }

/// <summary>
/// A fee rate that will be used when fee estimation has insufficient data.
/// </summary>
public long FallbackFee { get; protected set; }

/// <summary>
/// The minimum fee under which transactions may be rejected from being relayed.
/// </summary>
/// <remarks>
/// The <see cref="MinRelayTxFee"/> and <see cref="MinTxFee"/> are typically the same value to prevent dos attacks on the network.
/// If <see cref="MinRelayTxFee"/> is less than <see cref="MinTxFee"/>, an attacker can broadcast a lot of transactions with fees between these two values,
/// which will lead to transactions filling the mempool without ever being mined.
/// </remarks>
public long MinRelayTxFee { get; protected set; }

/// <summary>
/// Port on which to listen for incoming RPC connections.
/// </summary>
public int DefaultRPCPort { get; protected set; }

/// <summary>
/// Port on which to listen for incoming API connections.
/// </summary>
Expand All @@ -125,7 +92,7 @@ public abstract class Network
/// The default port on which nodes of this network communicate with external clients.
/// </summary>
public int DefaultPort { get; protected set; }

/// <summary>
/// The default port on which SignalR broadcasts for this network.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/NBitcoin/Policy/StandardTransactionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ public class StandardTransactionPolicy : ITransactionPolicy
/// </summary>
public bool CheckScriptPubKey { get; set; }

private readonly Network network;
private readonly FeeNetwork network;

public StandardTransactionPolicy(Network network)
{
this.network = network;
this.network = (FeeNetwork)network;
this.ScriptVerify = NBitcoin.ScriptVerify.Standard;
this.MaxTransactionSize = 100000;
// TODO: replace fee params with whats in Network.
this.MaxTxFee = new FeeRate(Money.Coins(0.1m));
this.MinRelayTxFee = new FeeRate(Money.Satoshis(network.MinRelayTxFee));
this.MinRelayTxFee = new FeeRate(Money.Satoshis(this.network.MinRelayTxFee));
this.CheckFee = true;
this.CheckScriptPubKey = true;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using NBitcoin;
using NBitcoin.DataEncoders;
using Stratis.Bitcoin.Consensus.Rules;
using Stratis.Bitcoin.Features.Consensus.Rules.CommonRules;
using Stratis.Bitcoin.Features.MemoryPool.Rules;
using Stratis.Bitcoin.Features.PoA.BasePoAFeatureConsensusRules;
Expand All @@ -21,7 +20,7 @@ namespace Stratis.Bitcoin.Features.PoA
/// Also feel free to change target spacing, premine height and premine reward.
/// Don't set target spacing to be less than 10 sec.
/// </remarks>
public class PoANetwork : Network
public class PoANetwork : FeeNetwork
{
/// <summary> The name of the root folder containing the different PoA blockchains.</summary>
private const string NetworkRootFolderName = "poa";
Expand Down Expand Up @@ -49,7 +48,6 @@ public PoANetwork()
this.DefaultPort = 16438;
this.DefaultMaxOutboundConnections = 16;
this.DefaultMaxInboundConnections = 109;
this.DefaultRPCPort = 16474;
this.DefaultAPIPort = 37221; // TODO: Confirm
this.MaxTipAge = 2 * 60 * 60;
this.MinTxFee = 10000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void BuildTransactionFeeTooLowDefaultsToMinimumFee()
TransactionBuildContext context = CreateContext(this.Network, testContext.WalletReference, "password", testContext.DestinationKeys.PubKey.ScriptPubKey, new Money(7500), FeeType.Low, 0);
Transaction transactionResult = testContext.WalletTransactionHandler.BuildTransaction(context);

Assert.Equal(new Money(this.Network.MinTxFee, MoneyUnit.Satoshi), context.TransactionFee);
Assert.Equal(new Money(((FeeNetwork)this.Network).MinTxFee, MoneyUnit.Satoshi), context.TransactionFee);
}

[Fact]
Expand Down
Loading

0 comments on commit e20c8bf

Please sign in to comment.