-
Notifications
You must be signed in to change notification settings - Fork 1k
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
NeoToken: accept candidate registration via onNEP17Payment #3597
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,14 +332,42 @@ public BigInteger UnclaimedGas(DataCache snapshot, UInt160 account, uint end) | |
return CalculateBonus(snapshot, state, end); | ||
} | ||
|
||
[ContractMethod(Hardfork.HF_Echidna, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)] | ||
private async ContractTask OnNEP17Payment(ApplicationEngine engine, UInt160 from, BigInteger amount, StackItem data) | ||
{ | ||
if (engine.CallingScriptHash != GAS.Hash) | ||
throw new InvalidOperationException("only GAS is accepted"); | ||
|
||
if ((long)amount != GetRegisterPrice(engine.SnapshotCache)) | ||
throw new ArgumentException("incorrect GAS amount for registration"); | ||
|
||
var pubkey = ECPoint.DecodePoint(data.GetSpan(), ECCurve.Secp256r1); | ||
|
||
if (!RegisterInternal(engine, pubkey)) | ||
throw new InvalidOperationException("failed to register candidate"); | ||
|
||
await GAS.Burn(engine, Hash, amount); | ||
} | ||
|
||
[ContractMethod(true, Hardfork.HF_Echidna, RequiredCallFlags = CallFlags.States)] | ||
[ContractMethod(Hardfork.HF_Echidna, /* */ RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)] | ||
private bool RegisterCandidate(ApplicationEngine engine, ECPoint pubkey) | ||
{ | ||
if (!engine.CheckWitnessInternal(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())) | ||
// This check can be removed post-Echidna if compatible, | ||
// RegisterInternal does this anyway. | ||
var index = engine.PersistingBlock?.Index ?? Ledger.CurrentIndex(engine.SnapshotCache); | ||
if (!engine.ProtocolSettings.IsHardforkEnabled(Hardfork.HF_Echidna, index) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should allow it also with Echidna, it doesn't hurt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will require us keeping it forever then (in which case it's easier to duplicate the check). But my intention was to drop this check here eventually (keeping it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Vote up for this, we may remove this code after transition to Echidna, and the code will be more pretty. But we need an issue for that in order not to forget. |
||
!engine.CheckWitnessInternal(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())) | ||
return false; | ||
// In the unit of datoshi, 1 datoshi = 1e-8 GAS | ||
engine.AddFee(GetRegisterPrice(engine.SnapshotCache)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not return false if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't help. The appropriate amount of GAS is already in the system fee (which is burnt forever before transaction is executed). If not, it'll fail and still burn whatever GAS is in the system fee. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And create a new syscall, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can it help? We need GAS. It either comes from the system fee or via a transfer. The first one burns the fee irrespective of the outcome. The second is what we have here. The only other option is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por testing you can try and for execute you can not try 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And we have one. It's NEP-27. Allows to send any amounts of any token to some contract safely.
Once upon a time there was #2444. And then there was #2560. It can't work, system fee must be burned into ashes prior to execution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This problem is #3552 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour is different, before if was wrong signed, the fee was not burned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The system fee is already gone by the time this executes (whether it's sufficient or not). The only thing left here is #3597 (comment), I can fix it, OK.
AnnaShaleva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return RegisterInternal(engine, pubkey); | ||
} | ||
|
||
private bool RegisterInternal(ApplicationEngine engine, ECPoint pubkey) | ||
{ | ||
if (!engine.CheckWitnessInternal(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())) | ||
return false; | ||
StorageKey key = CreateStorageKey(Prefix_Candidate).Add(pubkey); | ||
StorageItem item = engine.SnapshotCache.GetAndChange(key, () => new StorageItem(new CandidateState())); | ||
CandidateState state = item.GetInteroperable<CandidateState>(); | ||
|
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.
We don't burn it before throw?
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.
throw
is likeABORT
here, transaction will end up inFAULT
state, nothing happened.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.
a reason why a want to update these exception name to uncatchableexception~~~
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.
Uncatchable
can also be misunderstood, I can catch it in various places, it's just that VM/contracts are not even aware of this happening.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.
uncatachable should be named as normal. Name should be
VMException
with inner exception of normal name. Thats kind of how it done currently in the vm.