-
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
auto-claim gas if it's needed #2008
Conversation
@neo-project/ngd-shanghai Could you help me testing it? |
How about here: Line 309 in 028f4b5
Besides, how about an overide func |
It's a good idea :), we can change it later if this work. |
If the gas is not enough, users can buy some on the exchange. |
Yes, but moving the logic from |
return balance >= fee; | ||
if (balance >= fee) return true; | ||
|
||
BigInteger unclaimed = NativeContract.NEO.UnclaimedGas(snapshot, tx.Sender, snapshot.Height); |
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.
This is in the hot path for transaction verification and after #1848 this call can be quite expensive (with a number of DB accesses).
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.
But I think this is necessary anyway @roman-khimov , because we must know if someone has enough funds for transfer, during Verification... it really costs to calculate, but we don't need precise value. Maybe, if we have some caching on unclaimedGas values, we could call some method EnoughUnclaimedGas(VALUE)
, so that if caching already has enough, we don't recalculate. Truth is, we just need to know if Unclaimed is bigger than VALUE, not its precise value.
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.
If it has funds, there will be no problem, otherwise, we need to check it.
@@ -27,6 +27,7 @@ protected override void OnPersist(ApplicationEngine engine) | |||
long totalNetworkFee = 0; | |||
foreach (Transaction tx in engine.Snapshot.PersistingBlock.Transactions) | |||
{ | |||
NEO.DistributeGas(engine, tx.Sender); |
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.
@shargon, maybe it should only distributeGAS for the tx.Sender
that needs it.
In this sense, perhaps we could have a flag before return balance + unclaimed >= fee;
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.
Please, take a look again
@superboyiii could you test it please? |
It is a barrier that we can avoid, @erikzhang, at least for a basic transaction, if the user holds NEO for some couple of time. |
@erikzhang As @vncoelho said, it will help with adoption, impatient users always can buy GAS. |
@superboyiii please check it again |
Line 323 in faa698e
@shargon We're using this MakeTransaction(TransferOutput[] outputs, UInt160 from = null, Signer[] cosigners = null) for send command. Need using unclaimedGas as balance as well.https://github.com/neo-project/neo-node/blob/a7f06cab3f5cb3099ba7e75ba3d1e18d6eda337d/neo-cli/CLI/MainService.Wallet.cs#L475 |
I think for neo-core it's OK now, but we need modify more on neo-node and neo-modules. |
I'm not sure if we really need it. Originally, if there was no GAS in my account, I know the transaction would fail. Now even if I transfer all the GAS away, it may still be claimed automatically. |
unclaimed gas + claimed gas = your gas. I think it makes sense. No need to ask user know how much they need to claim because the claim mechanism is never important. If we can claim for user, we just do it. And CLI should show |
But it is a benefit more than a problem. Otherwise, in many cases this gas was like burned. |
It benefits a lot in initial NEO transaction. Exchange don't allow a little gas withdraw, that means you need buy a certain amount of GAS just for one transaction. It's not good for NEO flowability and it makes exchange difficult for initial NEO3 technicial integration. |
On a real network we'll get 100 tx in a block and all of them will come from different addresses. So we'll distribute GAS for all of them and invoke And accepting a transaction which can't really pay according to the state we have at the current height is still a little scary to me, even though it doesn't seem to create any issues if GAS is to be distributed before writing the commission off the balance. |
foreach (Transaction tx in engine.PersistingBlock.Transactions) | ||
{ | ||
if (distributed.Add(tx.Sender)) NEO.DistributeGas(engine, tx.Sender); |
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.
This is just to ensure that it is distributed only once per Persist
, right?
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.
Isn't there any need to avoid the
protected override void OnBalanceChanging(ApplicationEngine engine, UInt160 account, NeoAccountState state, BigInteger amount) |
If the transfer also changes NEO's balance?
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're running this line in OnPersist
context. It invokes GAS.Mint
. It calls PostTransfer
. Which calls onNEP17Payment
. That fails. What are we gonna do then? Fail persisting a block? Not an option. Ignore this problem and fail GAS distribution? Fine, except some storage changes are already in-flight in this context and, most importantly, tx.Sender
may just not have enough GAS for the Burn()
one line below. So, what are the options we have?
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.
@roman-khimov it's the same problem here
neo/src/neo/SmartContract/Native/NeoToken.cs
Line 161 in bfbb78b
GAS.Mint(engine, account, gasPerBlock * CommitteeRewardRatio / 100, false); |
I think that we should not rise
onNEP17Payment
during OnPersist
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.
It's not. This invocation specifically has false
for callOnPayment
. And we only have simple standard accounts in the committee (their keys are known).
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'll put "false" here too
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 don't think it's legal to do this! Unlike committee members transaction sender can be anything, including deployed contract. And deployed contract must be invoked on this mint.
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.
Yes, I we merge it, the generated gas will come to not call onNEP17Payment
, before this PR it does....
@erikzhang @shargon @roman-khimov @vncoelho Let's move on? If we'd like to do this, we shall merge it ASAP and modify neo-node and neo-modules before RC1. |
@erikzhang Need your review. |
I agree with @roman-khimov. And I think we shouldn't merge this PR. |
Close #1078