-
Notifications
You must be signed in to change notification settings - Fork 1k
[N3] Request blocked funds #4328
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
base: master-n3
Are you sure you want to change the base?
Conversation
|
Looks good to me. Need #4271 |
|
Regarding waiting time, please vote. Six months = 👍, one year = ❤️, two years = 🎉. |
Can one year be equivalent to the |
I think they are two different things. |
| try | ||
| { | ||
| engine.CallContract(contractHash, "transfer", CallFlags.All, | ||
| new VM.Types.Array(engine.ReferenceCounter, | ||
| [account.ToArray(), NativeContract.Treasury.Hash.ToArray(), balance, StackItem.Null])); | ||
|
|
||
| // Execute transfer | ||
| context = engine.CurrentContext; | ||
| while (engine.InvocationStack.Contains(context!)) debugger.StepInto(); | ||
|
|
||
| // check result | ||
| var result = engine.Pop().GetBoolean(); | ||
| if (!result) | ||
| throw new InvalidOperationException($"Transfer of {balance} from {account} to {committeeMultiSigAddr} failed in contract {contractHash}."); | ||
| } | ||
| catch { throw; } | ||
| finally | ||
| { | ||
| // Reset witnesses | ||
|
|
||
| state.NativeCallingScriptHash = bak; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is: In RecoverFundsFinish, when calling transfer via CallContract, the new execution context wasn’t given NativeCallingScriptHash.
| try | |
| { | |
| engine.CallContract(contractHash, "transfer", CallFlags.All, | |
| new VM.Types.Array(engine.ReferenceCounter, | |
| [account.ToArray(), NativeContract.Treasury.Hash.ToArray(), balance, StackItem.Null])); | |
| // Execute transfer | |
| context = engine.CurrentContext; | |
| while (engine.InvocationStack.Contains(context!)) debugger.StepInto(); | |
| // check result | |
| var result = engine.Pop().GetBoolean(); | |
| if (!result) | |
| throw new InvalidOperationException($"Transfer of {balance} from {account} to {committeeMultiSigAddr} failed in contract {contractHash}."); | |
| } | |
| catch { throw; } | |
| finally | |
| { | |
| // Reset witnesses | |
| state.NativeCallingScriptHash = bak; | |
| } | |
| ExecutionContext? transferContext = null; | |
| UInt160? transferContextBak = null; | |
| try | |
| { | |
| engine.CallContract(contractHash, "transfer", CallFlags.All, | |
| new VM.Types.Array(engine.ReferenceCounter, | |
| [account.ToArray(), NativeContract.Treasury.Hash.ToArray(), balance, StackItem.Null])); | |
| // Set NativeCallingScriptHash for the new context to allow transfer to pass witness check | |
| transferContext = engine.CurrentContext; | |
| var transferContextState = transferContext.GetState<ExecutionContextState>(); | |
| transferContextBak = transferContextState.NativeCallingScriptHash; | |
| transferContextState.NativeCallingScriptHash = account; | |
| // Execute transfer | |
| while (engine.InvocationStack.Contains(transferContext!)) debugger.StepInto(); | |
| // check result | |
| var result = engine.Pop().GetBoolean(); | |
| if (!result) | |
| throw new InvalidOperationException($"Transfer of {balance} from {account} to {NativeContract.Treasury.Hash} failed in contract {contractHash}."); | |
| } | |
| catch { throw; } | |
| finally | |
| { | |
| // Reset witnesses | |
| if (transferContext != null) | |
| { | |
| var transferContextState = transferContext.GetState<ExecutionContextState>(); | |
| transferContextState.NativeCallingScriptHash = transferContextBak; | |
| } | |
| state.NativeCallingScriptHash = bak; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try with @roman-khimov idea
| // Remove request funds if any | ||
|
|
||
| key = CreateStorageKey(Prefix_BlockedAccountRequestFunds, account); | ||
| engine.SnapshotCache.Delete(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need an event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, it would also be acceptable if there were events for blocking and unblocking accounts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| [ContractMethod(Hardfork.HF_Faun, CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)] | ||
| public void RecoverFundsFinish(ApplicationEngine engine, UInt160 account, VM.Types.Array extraTokens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can transfer tokens one by one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can't reset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we can transfer tokens one by one.
Co-authored-by: Owen <[email protected]>
Co-authored-by: Erik Zhang <[email protected]>
| if (balance > 0) | ||
| { | ||
| // transfer | ||
| var result = await engine.CallFromNativeContractAsync<bool>(account, contractHash, "transfer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@superboyiii I receive an error in your UT in CalculateBonus:
var expectEnd = Ledger.CurrentIndex(snapshot) + 1;
if (expectEnd != end) throw new ArgumentOutOfRangeException(nameof(end));
if (state.BalanceHeight >= end) return BigInteger.Zero;
But it should work with real environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require #4388
Co-authored-by: Erik Zhang <[email protected]>

Description
Adds a function to recover locked funds after one year, requiring approval from 19 of 21 committee nodes. This recovery can only be executed once the period has elapsed and enforces the signature requirement to ensure security and consensus.
Type of change
How Has This Been Tested?
Checklist: