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

Fix 1244 Mempool.ReverifyTransactions #1248

Merged
merged 35 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
93060a2
Merge pull request #1 from neo-project/master
Tommo-L Jun 4, 2019
f4371d3
Merge pull request #3 from neo-project/master
Tommo-L Jun 20, 2019
5784ac5
Merge pull request #5 from neo-project/master
Tommo-L Jun 28, 2019
d8ab5e2
Merge pull request #6 from neo-project/master
Tommo-L Jul 8, 2019
9a1f07a
Merge pull request #7 from neo-project/master
Tommo-L Jul 16, 2019
ee20bc9
add internal to DB and WriteBatch
eryeer Jul 16, 2019
4d873e2
Merge branch 'master' into master
eryeer Jul 17, 2019
81dd495
Merge branch 'master' into master
lock9 Jul 18, 2019
5518fbd
Merge branch 'master' into master
eryeer Jul 22, 2019
60a1845
Merge pull request #8 from neo-project/master
Tommo-L Sep 23, 2019
97c2f34
Merge pull request #9 from neo-project/master
Tommo-L Sep 26, 2019
639c739
Merge remote-tracking branch 'upstream/master'
Sep 27, 2019
6376be1
Merge remote-tracking branch 'upstream/master'
Oct 9, 2019
b76b04d
reset db.cs writebatch.cs
Oct 12, 2019
a34254b
Merge remote-tracking branch 'upstream/master'
Oct 18, 2019
aee96f8
Merge remote-tracking branch 'upstream/master'
Oct 22, 2019
6636ce8
Merge remote-tracking branch 'upstream/master'
Oct 25, 2019
b0a4165
Merge remote-tracking branch 'upstream/master'
Nov 4, 2019
298c7da
Merge remote-tracking branch 'upstream/master'
Nov 8, 2019
4dd37bb
Merge remote-tracking branch 'upstream/master'
hope2028 Nov 11, 2019
a156012
Merge remote-tracking branch 'upstream/master'
Nov 13, 2019
59432fc
Merge remote-tracking branch 'upstream/master'
Nov 15, 2019
1c743e0
fix Nep5Token.Burn method
Nov 15, 2019
bb9a379
format
Nov 15, 2019
43985bd
format
Nov 15, 2019
c18c09d
reset and fix memorypool.ReverifyTransactions
Nov 18, 2019
22c87f2
Merge branch 'fix_1244_sysfee' of https://github.com/Tommo-L/neo into…
Nov 18, 2019
922c7a4
reset and fix ReverifyTransactions
Nov 18, 2019
9b28079
Merge branch 'master' into fix_1244_sysfee
Nov 18, 2019
6b9b849
add ut
Nov 19, 2019
c1bec9e
remove commit
Nov 19, 2019
6b30c05
fix BlockPersistAndReverificationWillAbandonTxAsBalanceTransfered.bal…
Nov 20, 2019
e8fd7b9
update comments
Nov 20, 2019
d15781d
Merge branch 'master' into fix_1244_sysfee
Nov 20, 2019
ea3b18d
Merge branch 'master' into fix_1244_sysfee
shargon Nov 21, 2019
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
15 changes: 3 additions & 12 deletions neo.UnitTests/SmartContract/Native/Tokens/UT_GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,13 @@ public void Check_BalanceOfTransferAndBurn()
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
NativeContract.GAS.Burn(engine, new UInt160(to), BigInteger.MinusOne));

// Burn more than expected

Assert.ThrowsException<InvalidOperationException>(() =>
NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(3000600000000001)));

// Real burn

NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(1));
NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(1)).Should().Be(1);

NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(3000599999999999);

keyCount.Should().Be(snapshot.Storages.GetChangeSet().Count());

// Burn all

NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(3000599999999999));
// Burn more than expected
NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(3000600000000000)).Should().Be(3000599999999999);

(keyCount - 1).Should().Be(snapshot.Storages.GetChangeSet().Count());

Expand Down
19 changes: 16 additions & 3 deletions neo/SmartContract/Native/Tokens/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ internal override bool Initialize(ApplicationEngine engine)
protected override bool OnPersist(ApplicationEngine engine)
{
if (!base.OnPersist(engine)) return false;
BigInteger totalNetworkFee = 0;
BigInteger totalSysFee = 0;
foreach (Transaction tx in engine.Snapshot.PersistingBlock.Transactions)
Burn(engine, tx.Sender, tx.SystemFee + tx.NetworkFee);
{
BigInteger burned = Burn(engine, tx.Sender, tx.SystemFee + tx.NetworkFee);
if (burned >= tx.NetworkFee)
{
totalNetworkFee += tx.NetworkFee;
totalSysFee += burned - tx.NetworkFee;
}
else
{
totalNetworkFee += burned;
}
}
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);
Mint(engine, primary, totalNetworkFee);
BigInteger sys_fee = GetSysFeeAmount(engine.Snapshot, engine.Snapshot.PersistingBlock.Index - 1) + totalSysFee;
StorageKey key = CreateStorageKey(Prefix_SystemFeeAmount, BitConverter.GetBytes(engine.Snapshot.PersistingBlock.Index));
engine.Snapshot.Storages.Add(key, new StorageItem
{
Expand Down
17 changes: 14 additions & 3 deletions neo/SmartContract/Native/Tokens/Nep5Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,25 @@ internal protected virtual void Mint(ApplicationEngine engine, UInt160 account,
engine.SendNotification(Hash, new StackItem[] { "Transfer", StackItem.Null, account.ToArray(), amount });
}

internal protected virtual void Burn(ApplicationEngine engine, UInt160 account, BigInteger amount)
/// <summary>
/// Burn token, when the account balance less than amount, it will burn all the balance of the account
/// </summary>
/// <param name="engine">The application engine</param>
/// <param name="account">The burning account</param>
/// <param name="amount">The amount to be burned</param>
/// <returns>The actual amount of burned</returns>
internal protected virtual BigInteger Burn(ApplicationEngine engine, UInt160 account, BigInteger amount)
{
if (amount.Sign < 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (amount.IsZero) return;
if (amount.IsZero) return amount;
StorageKey key = CreateAccountKey(account);
StorageItem storage = engine.Snapshot.Storages.GetAndChange(key);
TState state = new TState();
state.FromByteArray(storage.Value);
if (state.Balance < amount) throw new InvalidOperationException();
if (state.Balance < amount)
{
amount = state.Balance;
}
OnBalanceChanging(engine, account, state, -amount);
if (state.Balance == amount)
{
Expand All @@ -111,6 +121,7 @@ internal protected virtual void Burn(ApplicationEngine engine, UInt160 account,
totalSupply -= amount;
storage.Value = totalSupply.ToByteArray();
engine.SendNotification(Hash, new StackItem[] { "Transfer", account.ToArray(), StackItem.Null, amount });
return amount;
}

[ContractMethod(0, ContractParameterType.String, Name = "name", SafeMethod = true)]
Expand Down