Skip to content

Commit

Permalink
Move MaxValidUntilBlockIncrement & MaxTraceableBlocks to protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin Qiao committed Nov 3, 2020
1 parent 5800cf2 commit 9db6700
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Neo.Network.P2P.Payloads
public class Transaction : IEquatable<Transaction>, IInventory, IInteroperable
{
public const int MaxTransactionSize = 102400;
public const uint MaxValidUntilBlockIncrement = 2102400;
/// <summary>
/// Maximum number of attributes that can be contained within a transaction
/// </summary>
Expand Down Expand Up @@ -283,7 +282,7 @@ bool IInventory.Verify(StoreView snapshot)

public virtual VerifyResult VerifyStateDependent(StoreView snapshot, TransactionVerificationContext context)
{
if (ValidUntilBlock <= snapshot.Height || ValidUntilBlock > snapshot.Height + MaxValidUntilBlockIncrement)
if (ValidUntilBlock <= snapshot.Height || ValidUntilBlock > snapshot.Height + ProtocolSettings.Default.MaxValidUntilBlockIncrement)
return VerifyResult.Expired;
foreach (UInt160 hash in GetScriptHashesForVerifying(snapshot))
if (NativeContract.Policy.IsBlocked(snapshot, hash))
Expand Down
4 changes: 4 additions & 0 deletions src/neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ProtocolSettings
public string[] SeedList { get; }
public uint MillisecondsPerBlock { get; }
public int MemoryPoolMaxTransactions { get; }
public uint MaxValidUntilBlockIncrement { get; }
public uint MaxTraceableBlocks { get; }

static ProtocolSettings _default;

Expand Down Expand Up @@ -94,6 +96,8 @@ private ProtocolSettings(IConfigurationSection section)
};
this.MillisecondsPerBlock = section.GetValue("MillisecondsPerBlock", 15000u);
this.MemoryPoolMaxTransactions = Math.Max(1, section.GetValue("MemoryPoolMaxTransactions", 50_000));
this.MaxValidUntilBlockIncrement = section.GetValue("MaxValidUntilBlockIncrement", 5760u);
this.MaxTraceableBlocks = section.GetValue("MaxTraceableBlocks", 2_102_400u);
}
}
}
4 changes: 1 addition & 3 deletions src/neo/SmartContract/ApplicationEngine.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Neo.SmartContract
{
partial class ApplicationEngine
{
public const uint MaxTraceableBlocks = Transaction.MaxValidUntilBlockIncrement;

public static readonly InteropDescriptor System_Blockchain_GetHeight = Register("System.Blockchain.GetHeight", nameof(GetBlockchainHeight), 0_00000400, CallFlags.AllowStates, true);
public static readonly InteropDescriptor System_Blockchain_GetBlock = Register("System.Blockchain.GetBlock", nameof(GetBlock), 0_02500000, CallFlags.AllowStates, true);
public static readonly InteropDescriptor System_Blockchain_GetTransaction = Register("System.Blockchain.GetTransaction", nameof(GetTransaction), 0_01000000, CallFlags.AllowStates, true);
Expand Down Expand Up @@ -97,7 +95,7 @@ protected internal ContractState GetContract(UInt160 hash)
private static bool IsTraceableBlock(StoreView snapshot, uint index)
{
if (index > snapshot.Height) return false;
return index + MaxTraceableBlocks > snapshot.Height;
return index + ProtocolSettings.Default.MaxTraceableBlocks > snapshot.Height;
}
}
}
2 changes: 1 addition & 1 deletion src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private Transaction MakeTransaction(StoreView snapshot, byte[] script, Signer[]
Version = 0,
Nonce = (uint)rand.Next(),
Script = script,
ValidUntilBlock = snapshot.Height + Transaction.MaxValidUntilBlockIncrement,
ValidUntilBlock = snapshot.Height + ProtocolSettings.Default.MaxValidUntilBlockIncrement,
Signers = GetSigners(account, cosigners),
Attributes = attributes,
};
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/SmartContract/UT_Syscalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void System_Blockchain_GetBlock()
// Not traceable block

var height = snapshot.BlockHashIndex.GetAndChange();
height.Index = block.Index + Transaction.MaxValidUntilBlockIncrement;
height.Index = block.Index + ProtocolSettings.Default.MaxTraceableBlocks;

var blocks = snapshot.Blocks;
var txs = snapshot.Transactions;
Expand Down

0 comments on commit 9db6700

Please sign in to comment.