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

Policy inputs checks #1938

Merged
merged 10 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
8 changes: 6 additions & 2 deletions src/neo/SmartContract/Native/PolicyContract.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma warning disable IDE0051

using Neo.Ledger;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract.Manifest;
using System;
Expand Down Expand Up @@ -87,8 +89,8 @@ public bool IsAnyAccountBlocked(StoreView snapshot, params UInt160[] hashes)
[ContractMethod(0_03000000, CallFlags.AllowModifyStates)]
private bool SetMaxBlockSize(ApplicationEngine engine, uint value)
{
if (value > Message.PayloadMaxSize) return false;
if (!CheckCommittee(engine)) return false;
if (Network.P2P.Message.PayloadMaxSize <= value) return false;
StorageItem storage = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_MaxBlockSize), () => new StorageItem());
storage.Set(value);
return true;
Expand All @@ -97,6 +99,7 @@ private bool SetMaxBlockSize(ApplicationEngine engine, uint value)
[ContractMethod(0_03000000, CallFlags.AllowModifyStates)]
private bool SetMaxTransactionsPerBlock(ApplicationEngine engine, uint value)
{
if (value > Block.MaxTransactionsPerBlock) return false;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
if (!CheckCommittee(engine)) return false;
StorageItem storage = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_MaxTransactionsPerBlock), () => new StorageItem());
storage.Set(value);
Expand All @@ -106,8 +109,8 @@ private bool SetMaxTransactionsPerBlock(ApplicationEngine engine, uint value)
[ContractMethod(0_03000000, CallFlags.AllowModifyStates)]
private bool SetMaxBlockSystemFee(ApplicationEngine engine, long value)
{
if (!CheckCommittee(engine)) return false;
if (value <= 4007600) return false;
if (!CheckCommittee(engine)) return false;
StorageItem storage = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_MaxBlockSystemFee), () => new StorageItem());
storage.Set(value);
return true;
Expand All @@ -116,6 +119,7 @@ private bool SetMaxBlockSystemFee(ApplicationEngine engine, long value)
[ContractMethod(0_03000000, CallFlags.AllowModifyStates)]
private bool SetFeePerByte(ApplicationEngine engine, long value)
{
if (value < 0) return false;
if (!CheckCommittee(engine)) return false;
StorageItem storage = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_FeePerByte), () => new StorageItem());
storage.Set(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Check_SetMaxBlockSize()
// More than expected

ret = NativeContract.Policy.Call(snapshot, new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr),
"setMaxBlockSize", new ContractParameter(ContractParameterType.Integer) { Value = Neo.Network.P2P.Message.PayloadMaxSize });
"setMaxBlockSize", new ContractParameter(ContractParameterType.Integer) { Value = Neo.Network.P2P.Message.PayloadMaxSize + 1 });
ret.Should().BeOfType<VM.Types.Boolean>();
ret.GetBoolean().Should().BeFalse();

Expand Down