Skip to content

Commit 06d4345

Browse files
authored
Add MinimumDeploymentFee (#2140)
1 parent 780c325 commit 06d4345

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/neo/SmartContract/Native/ManagementContract.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public sealed class ManagementContract : NativeContract
1717
public override int Id => 0;
1818
public override uint ActiveBlockIndex => 0;
1919

20+
private const byte Prefix_MinimumDeploymentFee = 20;
2021
private const byte Prefix_NextAvailableId = 15;
2122
private const byte Prefix_Contract = 8;
2223

@@ -28,6 +29,11 @@ private int GetNextAvailableId(StoreView snapshot)
2829
return value;
2930
}
3031

32+
internal override void Initialize(ApplicationEngine engine)
33+
{
34+
engine.Snapshot.Storages.Add(CreateStorageKey(Prefix_MinimumDeploymentFee), new StorageItem(100_00000000));
35+
}
36+
3137
internal override void OnPersist(ApplicationEngine engine)
3238
{
3339
foreach (NativeContract contract in Contracts)
@@ -45,6 +51,20 @@ internal override void OnPersist(ApplicationEngine engine)
4551
}
4652
}
4753

54+
[ContractMethod(0_01000000, CallFlags.ReadStates)]
55+
private long GetMinimumDeploymentFee(StoreView snapshot)
56+
{
57+
return (long)(BigInteger)snapshot.Storages[CreateStorageKey(Prefix_MinimumDeploymentFee)];
58+
}
59+
60+
[ContractMethod(0_03000000, CallFlags.WriteStates)]
61+
private void SetMinimumDeploymentFee(ApplicationEngine engine, BigInteger value)
62+
{
63+
if (value < 0) throw new ArgumentOutOfRangeException(nameof(value));
64+
if (!CheckCommittee(engine)) throw new InvalidOperationException();
65+
engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_MinimumDeploymentFee)).Set(value);
66+
}
67+
4868
[ContractMethod(0_01000000, CallFlags.ReadStates)]
4969
public ContractState GetContract(StoreView snapshot, UInt160 hash)
5070
{
@@ -67,7 +87,10 @@ private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] ma
6787
if (manifest.Length == 0 || manifest.Length > ContractManifest.MaxLength)
6888
throw new ArgumentException($"Invalid Manifest Length: {manifest.Length}");
6989

70-
engine.AddGas(engine.StoragePrice * (nefFile.Length + manifest.Length));
90+
engine.AddGas(Math.Max(
91+
engine.StoragePrice * (nefFile.Length + manifest.Length),
92+
GetMinimumDeploymentFee(engine.Snapshot)
93+
));
7194

7295
NefFile nef = nefFile.AsSerializable<NefFile>();
7396
UInt160 hash = Helper.GetContractHash(tx.Sender, nef.Script);

tests/neo.UnitTests/Extensions/NativeContractExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Neo.UnitTests.Extensions
1010
{
1111
public static class NativeContractExtensions
1212
{
13-
public static ContractState DeployContract(this StoreView snapshot, UInt160 sender, byte[] nefFile, byte[] manifest, long gas = ApplicationEngine.TestModeGas)
13+
public static ContractState DeployContract(this StoreView snapshot, UInt160 sender, byte[] nefFile, byte[] manifest, long gas = 200_00000000)
1414
{
1515
var script = new ScriptBuilder();
1616
script.EmitAppCall(NativeContract.Management.Hash, "deploy", nefFile, manifest);

0 commit comments

Comments
 (0)