Skip to content

Conversation

@txhsl
Copy link
Contributor

@txhsl txhsl commented Aug 24, 2023

Close #4.

This PR is going to add a policy check to Geth transaction pool. Whenever there is a new transaction trying to be added into legacypool or blobpool, the method ValidateTransactionWithState will read a minGasPrice and a blocked status from current blockchain state database. The method will not use EVM but compute the index key and access the contract storage directly.

The PolicyAddress is going to be a field of ChainConfig, and be set to zero address by default. So if there is no policy contract or the field is missing in configuration, then the value of minGasPrice and blocked will be both zero and all transactions will pass the check.

@txhsl txhsl assigned txhsl and unassigned txhsl Aug 25, 2023
@txhsl txhsl linked an issue Sep 19, 2023 that may be closed by this pull request
2 tasks
@nicolegys
Copy link
Collaborator

Is minGasPrice an addtion to the existing tx gas price check mechanism? The gasprice must be high enough to cover the requirement of the calling pool and block producer, and also not less than minGasPrice?

@txhsl
Copy link
Contributor Author

txhsl commented Dec 8, 2023

Is minGasPrice an addtion to the existing tx gas price check mechanism? The gasprice must be high enough to cover the requirement of the calling pool and block producer, and also not less than minGasPrice?

Yes, it is a policy of the lowest gas price that a transaction sender should provide. And this policy will be added to block verification as well in the future, when Bane's DBFT is built up.

@nicolegys
Copy link
Collaborator

merge?

@AnnaShaleva
Copy link
Member

@txhsl, we have a dedicated issue for PrepareRequest verification, could you please write a couple of words about minGasPrice requirement to #53? This constraint then will likely be implemented as a part of PrepareRequest verification. Or at list it won't hang in the air and we'll transfer it to a separate issue if needed.

@nicolegys
Copy link
Collaborator

Can we move on?

Now we have,

  1. base fee and priority fee limit by orginal Geth source code, which priority fee is set by every CN node and now it will be sent to coinbase.
  2. minGasPrice limit by policy contract.

What the newest fee rules?
#53 (comment)

@txhsl
Copy link
Contributor Author

txhsl commented Jan 23, 2024

Can we move on?

Now we have,

  1. base fee and priority fee limit by orginal Geth source code, which priority fee is set by every CN node and now it will be sent to coinbase.
  2. minGasPrice limit by policy contract.

What the newest fee rules? #53 (comment)

As far as I remember, we may going to add the base fee configuration into Policy contract, this PR will update after related contract is updated.

I'm free to do it now, but some research is necessary as well, especially when the priority fee is set by every CN but equally shared to everyone. It's different from Geth.

@AnnaShaleva
Copy link
Member

I'd like to review this PR as far, but let's agree on the final version of #7 firstly and merge it. After this we can rebase this PR onto #7.

@txhsl
Copy link
Contributor Author

txhsl commented Jan 23, 2024

Sure.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

Let's rebase it to the fresh master.

@txhsl txhsl changed the title apply policy check to txpool apply policy check to txpool and block verification Mar 29, 2024
@txhsl
Copy link
Contributor Author

txhsl commented Mar 29, 2024

@chenquanyu Need your review about policy check in block verification, related to #138.

@AnnaShaleva AnnaShaleva modified the milestone: v0.1.0 Mar 29, 2024
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

The code itself LGTM, let's squash the commits since it's a separate logical block of changes and wait for #7 to be merged. We need to test this PR against the updated master after #7 merge.

Comment on lines 367 to 377
func (b *EthAPIBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return b.gpo.SuggestTipCap(ctx)
suggestTipCap, err := b.gpo.SuggestTipCap(ctx)
if err != nil {
return nil, err
}
stateDb, err := b.eth.BlockChain().StateAt(b.CurrentHeader().Root)
if err != nil {
return nil, err
}
minGasTipCap := stateDb.GetState(systemcontracts.PolicyProxyHash, systemcontracts.GetMinGasTipCapStateHash()).Big()
return cmath.BigMax(suggestTipCap, minGasTipCap), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it's necessary but this change makes the value of eth_gasPrice inaccurate, e.g.
When baseFee is 7 wei, miner.gasPrice is 1 Gwei(just like in T2), policy_minGasTipCap is 1.000000005 Gwei, eth_gasPrice will return policy_minGasTipCap+baseFee which is 1.000000012 Gwei as suggested gasPrice, while 1.000000007 Gwei is enough.
The root cause is, miners still rely on their own miner_gasPrice setting and network baseFee to decide whether to package a tx.

Copy link
Contributor Author

@txhsl txhsl Apr 14, 2024

Choose a reason for hiding this comment

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

The policy check in mempool and consensus will filter them out, but yes, I'm worried about the capability with eth_feehistory and related tools e.g. Metamask. In fact, it seems not working well.

@chenquanyu is going to set fixed basefee for burning, then only gastip can be shared as governance reward. If we don't use an "inaccurate" price, then governance reward can be always 0 with empty blocks.

Copy link
Collaborator

@nicolegys nicolegys Apr 15, 2024

Choose a reason for hiding this comment

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

@chenquanyu is going to set fixed basefee for burning

0.0 What do you mean by set fixed basefee for burning? Burning block.basefee like ethereum or burning a fixed value?

I'm worried about the capability with eth_feehistory and related tools e.g. Metamask.

What's wrong with eth_feehistory? I see it just returns baseFeePerGas and gasUsedRatio, and seems OK.

If we don't use an "inaccurate" price, then governance reward can be always 0 with empty blocks.

Why? Empty blocks means no tx, no tx so no governance reward, it's OK. If you mean that empty blocks makes baseFee drop to the lowest value nearly 0, we still have miner settings to ensure governance reward.

But anyway, policy check prevent malicious txs with low fees from entering the pool. So by the way, I wonder if we still need --txpool.nolocals for t3 seeds, because node doesn't store transactions.rlp with this flag, txs in the txpool will be lost if the node restarts.

Copy link
Contributor Author

@txhsl txhsl Apr 15, 2024

Choose a reason for hiding this comment

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

Burning block.basefee like ethereum or burning a fixed value?

Still burn block.basefee, but maybe not based on the same rule.

What's wrong with eth_feehistory?

eth_feehistory works well. But I tested it with Metamask, which set 1.5 Gwei as default when 5 blocks in feehistory are all empty, so when I improved minGasTipCap above that, this default setting got RPC errors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

eth_feehistory works well. But I tested it with Metamask, which set 1.5 Gwei as default when 5 blocks in feehistory are all empty, so when I improved minGasTipCap above that, this default setting got RPC errors.

What RPC error have you encountered?

1713164366975
I can set the feeCap and tipCap to the lowest value, and the tx succeed.

1713164393083

Even can set them lower than the network required. Although Metamask shows warning, tx can be sent to node txpool successfully, and whether it's packaged or not is a matter of miner.

I think the issue is that Metamask has its own way of calculating fees, users can't get appropriate fee value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The minGasPrice in #7 genesis file is extremely low, try to change this line and you may get RPC error.

Copy link
Member

Choose a reason for hiding this comment

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

Ref. #167.

}
// Ensure the transaction is allowed by policy
// Apply policy minimum gas tip cap
var minGasTipCap = st.state.GetState(systemcontracts.PolicyProxyHash, systemcontracts.GetMinGasTipCapStateHash())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a question here. As this will fetch the latest state of the chain. Does this affect transactions that follows after a MinGasTip-changing tx that appeared in the same block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will, so I think you mean, it will lead to a case that some transactions accepted by txpool will be rejected by consensus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check #166 if necessary, there is the latest code.

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.

Apply policies in txpool

8 participants