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 UpdateCounter issues #2697

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions src/neo/SmartContract/Native/ContractManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private ContractTask Update(ApplicationEngine engine, byte[] nefFile, byte[] man

var contract = engine.Snapshot.GetAndChange(CreateStorageKey(Prefix_Contract).Add(engine.CallingScriptHash))?.GetInteroperable<ContractState>();
if (contract is null) throw new InvalidOperationException($"Updating Contract Does Not Exist: {engine.CallingScriptHash}");
if (contract.UpdateCounter == ushort.MaxValue) throw new InvalidOperationException($"The contract reached the maximum number of updates.");

if (nefFile != null)
{
Expand Down Expand Up @@ -250,6 +251,9 @@ private void Destroy(ApplicationEngine engine)
engine.Snapshot.Delete(ckey);
foreach (var (key, _) in engine.Snapshot.Find(StorageKey.CreateSearchPrefix(contract.Id, ReadOnlySpan<byte>.Empty)))
engine.Snapshot.Delete(key);
// lock contract
Policy.BlockAccount(engine.Snapshot, hash);
// emit event
engine.SendNotification(Hash, "Destroy", new VM.Types.Array { hash.ToArray() });
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/neo/SmartContract/Native/PolicyContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ private void SetStoragePrice(ApplicationEngine engine, uint value)
private bool BlockAccount(ApplicationEngine engine, UInt160 account)
{
if (!CheckCommittee(engine)) throw new InvalidOperationException();
return BlockAccount(engine.Snapshot, account);
}

internal bool BlockAccount(DataCache snapshot, UInt160 account)
{
if (IsNative(account)) throw new InvalidOperationException("It's impossible to block a native contract.");

var key = CreateStorageKey(Prefix_BlockedAccount).Add(account);
if (engine.Snapshot.Contains(key)) return false;
if (snapshot.Contains(key)) return false;

engine.Snapshot.Add(key, new StorageItem(Array.Empty<byte>()));
snapshot.Add(key, new StorageItem(Array.Empty<byte>()));
return true;
}

Expand Down