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

Burn sys_fee #1430

Merged
merged 9 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public int Size
}

/// <summary>
/// Distributed to NEO holders.
/// Fee to be burned.
vncoelho marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public long SystemFee
{
Expand Down
30 changes: 0 additions & 30 deletions src/neo/SmartContract/Native/Tokens/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
using Neo.Cryptography.ECC;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Linq;
using System.Numerics;
using VMArray = Neo.VM.Types.Array;

namespace Neo.SmartContract.Native.Tokens
{
Expand All @@ -21,8 +16,6 @@ public sealed class GasToken : Nep5Token<Nep5AccountState>
public override string Symbol => "gas";
public override byte Decimals => 8;

private const byte Prefix_SystemFeeAmount = 15;

internal GasToken()
{
}
Expand All @@ -44,30 +37,7 @@ protected override bool OnPersist(ApplicationEngine engine)
ECPoint[] validators = NEO.GetNextBlockValidators(engine.Snapshot);
UInt160 primary = Contract.CreateSignatureRedeemScript(validators[engine.Snapshot.PersistingBlock.ConsensusData.PrimaryIndex]).ToScriptHash();
Mint(engine, primary, engine.Snapshot.PersistingBlock.Transactions.Sum(p => p.NetworkFee));
BigInteger sys_fee = GetSysFeeAmount(engine.Snapshot, engine.Snapshot.PersistingBlock.Index - 1) + engine.Snapshot.PersistingBlock.Transactions.Sum(p => p.SystemFee);
shargon marked this conversation as resolved.
Show resolved Hide resolved
StorageKey key = CreateStorageKey(Prefix_SystemFeeAmount, BitConverter.GetBytes(engine.Snapshot.PersistingBlock.Index));
engine.Snapshot.Storages.Add(key, new StorageItem
{
Value = sys_fee.ToByteArrayStandard(),
IsConstant = true
});
return true;
}

[ContractMethod(0_01000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "index" }, SafeMethod = true)]
private StackItem GetSysFeeAmount(ApplicationEngine engine, VMArray args)
{
uint index = (uint)args[0].GetBigInteger();
return GetSysFeeAmount(engine.Snapshot, index);
}

public BigInteger GetSysFeeAmount(StoreView snapshot, uint index)
{
if (index == 0) return Blockchain.GenesisBlock.Transactions.Sum(p => p.SystemFee);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the SysFeeAmount ? If we want to increase the circulation of gas, will it depend on the SysFeeAmount?

StorageKey key = CreateStorageKey(Prefix_SystemFeeAmount, BitConverter.GetBytes(index));
StorageItem storage = snapshot.Storages.TryGet(key);
if (storage is null) return BigInteger.Zero;
return new BigInteger(storage.Value);
}
}
}
1 change: 0 additions & 1 deletion src/neo/SmartContract/Native/Tokens/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ private BigInteger CalculateBonus(StoreView snapshot, BigInteger value, uint sta
}
amount += (iend - istart) * Blockchain.GenerationAmount[ustart];
}
amount += (GAS.GetSysFeeAmount(snapshot, end - 1) - (start == 0 ? 0 : GAS.GetSysFeeAmount(snapshot, start - 1))) / GAS.Factor;
return value * amount * GAS.Factor / TotalAmount;
}

Expand Down
42 changes: 0 additions & 42 deletions tests/neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Neo.SmartContract.Native;
using Neo.UnitTests.Extensions;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -138,46 +137,5 @@ public void Check_BadScript()

NativeContract.GAS.Invoke(engine).Should().BeFalse();
}

[TestMethod]
public void TestGetSysFeeAmount1()
{
using (ApplicationEngine engine = NativeContract.GAS.TestCall("getSysFeeAmount", 2u))
{
engine.ResultStack.Peek().GetBigInteger().Should().Be(new BigInteger(0));
engine.ResultStack.Peek().GetType().Should().Be(typeof(Integer));
}

using (ApplicationEngine engine = NativeContract.GAS.TestCall("getSysFeeAmount", 0u))
{
engine.ResultStack.Peek().GetBigInteger().Should().Be(new BigInteger(0));
}
}

[TestMethod]
public void TestGetSysFeeAmount2()
{
var snapshot = Blockchain.Singleton.GetSnapshot();
NativeContract.GAS.GetSysFeeAmount(snapshot, 0).Should().Be(new BigInteger(0));
NativeContract.GAS.GetSysFeeAmount(snapshot, 1).Should().Be(new BigInteger(0));

byte[] key = BitConverter.GetBytes(1);
StorageKey storageKey = new StorageKey
{
Id = NativeContract.GAS.Id,
Key = new byte[sizeof(byte) + key.Length]
};
storageKey.Key[0] = 15;
key.CopyTo(storageKey.Key.AsSpan(1));

BigInteger sys_fee = new BigInteger(10);
snapshot.Storages.Add(storageKey, new StorageItem
{
Value = sys_fee.ToByteArrayStandard(),
IsConstant = true
});

NativeContract.GAS.GetSysFeeAmount(snapshot, 1).Should().Be(sys_fee);
}
}
}