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

Add system fee refundable attribute #2905

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ZhangTao1596
Copy link
Contributor

Fix #2845

Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that invasive/complex otherwise, a nice prototype and I think we can have in the base protocol as well.

if len(attrs) != 0 {
consumed := ic.TxesConsumed[tx.Hash()]
if consumed < tx.SystemFee {
g.mint(ic, tx.Sender(), big.NewInt(tx.SystemFee-consumed), false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still check tx.Sender() for being a contract address here. Contract addresses are predictable, one can precalculate it, send some GAS to it, use it as a sender in a transaction and deploy a contract in the same block (making regular address a contract address).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or actually this can't happen because to be a sender an account should not just have some GAS, but also pass a witness check. Contract scripts are very specific and not supposed to ever pass it if they're not deployed. When deployed, a previous check is already sufficient.

pkg/core/interop/context.go Outdated Show resolved Hide resolved
"github.com/nspcc-dev/neo-go/pkg/io"
)

// Conflicts represents attribute for refund gas transaction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Conflicts/RefundableSystemFee

Comment on lines +851 to +853
if len(tx.GetAttributes(transaction.RefundableSystemFeeT)) > 0 {
netFee += s.chain.SystemFeeRefundCost()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have deprecated (c *Client) AddNetworkFee method that is about to be removed, but still have to give a proper response. @roman-khimov, do we need to consider its updating?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it goes away earlier than this PR gets in.

@@ -127,6 +132,11 @@ func newPolicy() *Policy {
md = newMethodAndPrice(p.unblockAccount, 1<<15, callflag.States)
p.AddMethod(md, desc)

desc = newDescriptor("setSystemFeeRefundCost", smartcontract.VoidType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please, add getSystemFeeRefundCost method to the Policy manifest as far?

@@ -127,6 +132,11 @@ func newPolicy() *Policy {
md = newMethodAndPrice(p.unblockAccount, 1<<15, callflag.States)
p.AddMethod(md, desc)

desc = newDescriptor("setSystemFeeRefundCost", smartcontract.VoidType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please, update the native Policy interop wrapper (https://github.com/nspcc-dev/neo-go/blob/master/pkg/interop/native/policy/policy.go)?

@@ -127,6 +132,11 @@ func newPolicy() *Policy {
md = newMethodAndPrice(p.unblockAccount, 1<<15, callflag.States)
p.AddMethod(md, desc)

desc = newDescriptor("setSystemFeeRefundCost", smartcontract.VoidType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please, update the Policy RPC client wrapper (https://github.com/nspcc-dev/neo-go/blob/master/pkg/rpcclient/policy/policy.go)? If I'm not mistaken, it can be done automatically with the help of RPC wrappers generator, @roman-khimov?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no, those are hand-tuned l33t wrappers. Autogenerated ones can be used as a basis for new methods, but we need to have better comments (like other methods have now) anyway.

Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this attribute to ensure it works as intended? TestBlockchain_VerifyTx can be extended for verification code added here and then some test is needed to check two transactions executing some silly RET opcode with excessive system fee, one not using the attribute and another one using it.

Right now we're at the feasibility stage for this attribute/approach. It seems to be fine and if we can prove it with a test, then yes, it can be a very nice protocol change.

@ZhangTao1596
Copy link
Contributor Author

Can we add a test for this attribute to ensure it works as intended? TestBlockchain_VerifyTx can be extended for verification code added here and then some test is needed to check two transactions executing some silly RET opcode with excessive system fee, one not using the attribute and another one using it.

Right now we're at the feasibility stage for this attribute/approach. It seems to be fine and if we can prove it with a test, then yes, it can be a very nice protocol change.

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement GAS refund attribute
3 participants