From 5b912fe949d859283800c4db511c1bb858883ccc Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 4 Mar 2024 21:58:57 +0300 Subject: [PATCH] NEO: clear LastGasPerVote when voting for NULL, fix #2894 This value won't be used in any way, so save some bytes of storage. Signed-off-by: Roman Khimov --- src/Neo/SmartContract/Native/NeoToken.cs | 4 ++++ tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/Neo/SmartContract/Native/NeoToken.cs b/src/Neo/SmartContract/Native/NeoToken.cs index 96e362dd33..c28a548d0e 100644 --- a/src/Neo/SmartContract/Native/NeoToken.cs +++ b/src/Neo/SmartContract/Native/NeoToken.cs @@ -393,6 +393,10 @@ private async ContractTask Vote(ApplicationEngine engine, UInt160 account, { validator_new.Votes += state_account.Balance; } + else + { + state_account.LastGasPerVote = 0; + } engine.SendNotification(Hash, "Vote", new VM.Types.Array(engine.ReferenceCounter) { account.ToArray(), from?.ToArray() ?? StackItem.Null, voteTo?.ToArray() ?? StackItem.Null, state_account.Balance }); if (gasDistribution is not null) diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs index 73cf286652..0a19314153 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs @@ -192,11 +192,13 @@ public void Check_Vote_VoteToNull() var accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable(); accountState.Balance = 100; snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true })); + snapshot.Add(CreateStorageKey(23, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new BigInteger(100500))); var ret = Check_Vote(snapshot, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock); ret.Result.Should().BeTrue(); ret.State.Should().BeTrue(); accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable(); accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G); + accountState.LastGasPerVote.Should().Be(100500); //from vote to null account G votes becomes 0 var G_stateValidator = snapshot.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable(); @@ -211,6 +213,7 @@ public void Check_Vote_VoteToNull() G_stateValidator.Votes.Should().Be(0); accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable(); accountState.VoteTo.Should().Be(null); + accountState.LastGasPerVote.Should().Be(0); } [TestMethod]