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

1559 rpc #22964

Merged
merged 25 commits into from
Jun 2, 2021
Merged

1559 rpc #22964

merged 25 commits into from
Jun 2, 2021

Conversation

holiman
Copy link
Contributor

@holiman holiman commented May 28, 2021

Replaces #22834

I'm a bit unsure about the gpo, and how we want it to behave.

Comment on lines 177 to 210
if gasPrice == nil && feeCap == nil && tip == nil {
log.Warn("At least one of gasPrice, feeCap, tip should be set. Defaulting to 0 gas price.")
gasPrice = new(big.Int)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems wrong to me. Shouldn't it be either gasPrice or both feeCap and tip ?

Copy link
Member

Choose a reason for hiding this comment

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

I believe my reasoning for this was to allow some of the RPC methods that don't care about gas price (I think trace_call is an example) to not need to specify any fee mechanics. So the idea is to default gasPrice to 0 if no fee parameters are defined. I think this was the behaviour before 1559 txs were introduced.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I think we need to be explicit here. These if clauses are too convoluted and hard to reason (see error below). IMHO we should handle. (legacytx, 1554tx, and if both is missing do something meaningful).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree it's a bit convoluted now. Do you have any particular scheme in mind? My last commit just adds more convolution into the mix

internal/ethapi/transaction_args.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
}
return result
}

// newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation
func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction {
return newRPCTransaction(tx, common.Hash{}, 0, 0)
return newRPCTransaction(tx, common.Hash{}, 0, 0, nil)
Copy link
Member

Choose a reason for hiding this comment

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

We kind of know the base fee for the pending block, don't we? Shouldn't we set that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we do, do we?

Copy link
Member

Choose a reason for hiding this comment

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

Since the base fee depends on the parent block, we should be able determine the base fee for the pending block by calculating the base fee using the current block?

Copy link
Member

Choose a reason for hiding this comment

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

Since we can calculate the pending bloxk's basefee, I think we should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, pushed a commit, PTAL

internal/ethapi/api.go Outdated Show resolved Hide resolved
@holiman holiman force-pushed the 1559-rpc branch 2 times, most recently from a9ec536 to aaeeb54 Compare May 30, 2021 18:14
@holiman
Copy link
Contributor Author

holiman commented May 30, 2021

Rebased, fixed some of the concerns. My questions are still to be resolved, though

@holiman holiman added the london label May 30, 2021
func (t transactionsByGasPrice) Less(i, j int) bool { return t[i].FeeCapCmp(t[j]) < 0 }
func (t transactionsByTip) Len() int { return len(t) }
func (t transactionsByTip) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t transactionsByTip) Less(i, j int) bool { return t[i].TipCmp(t[j]) < 0 }
Copy link
Member

Choose a reason for hiding this comment

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

Why should we sort the transaction by the tip in order to suggest a suitable tip?
I think we should sort by effective_tip.

Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

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

I think the price oracle part is not correct.

All we need to change is to return a suggested "effective_tip". For the legacy transactions, this effective_tip can be used as theGasPrice directly; for the 1559 transactions, this effective_tip can be used as the tip field.

We don't need this two APIs SuggestPrice and SuggestTip. We should make the result suitable for both legacy transactions and 1559.

}

func (b *EthAPIBackend) SuggestFeeCap(ctx context.Context) (*big.Int, error) {
return new(big.Int).Mul(b.CurrentBlock().BaseFee(), common.Big2), nil
Copy link
Member

Choose a reason for hiding this comment

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

If the network is congested, then at the worst case, the transaction can't be included after 6 blocks.

>>> 1.125 ** 6
2.0272865295410156

I'm not sure what's the best factor here. Perhaps we can use the gpo for some congestion information. For example if all the previous blocks are fulled with transactions, then this number can be a bit larger.

But for the first version, this hard coded number LGTM. Just throw out the thoughts here.

Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is a good direction and something that @MicahZoltu brought up here: ethereum/execution-specs#201 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend reading the linked discussion for full context, but my preference is that Ethereum clients don't suggest a fee cap to users because users will use it out of habit instead of changing their behavior to what is optimal for them and the network, which is to set the fee cap to their willingness to pay.

result.FeeCap = (*hexutil.Big)(tx.FeeCap())
result.Tip = (*hexutil.Big)(tx.Tip())
// if the transaction has been mined, compute the effective gas price
if baseFee != nil && blockHash != (common.Hash{}) {
Copy link
Member

Choose a reason for hiding this comment

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

This might be worth a cross client sync, just so we behave similar to others (e.g. do we or do we not return gasPrice for pending txs)?

}
// If baseFee provided, set gasPrice to effectiveGasPrice.
if baseFee != nil {
gasPrice = math.BigMin(new(big.Int).Add(tip, baseFee), feeCap)
Copy link
Member

Choose a reason for hiding this comment

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

If I have a baseFee and gasPrice != nil && tip == nil && fee == nil, I'd expect this to ether blow up, or be very incorrect :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's gonna panic https://play.golang.org/p/Xxfr6yqdwNK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bleh, this method is so messy, particularly since it doesn't return an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, pushed a fix

Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced it's ok though. If gasPrice is specified, it should be treated as a legacy tx and not overridden.

Copy link
Member

Choose a reason for hiding this comment

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

Here's a counter proposal that should clean things up a bit https://gist.github.com/karalabe/91716ea8ae7e7e9fa81ffcee7d68a8b4

Copy link
Member

Choose a reason for hiding this comment

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

@karalabe this is to simulate the behaviour in Transaction.AsMessage

// If baseFee provided, set gasPrice to effectiveGasPrice.
if baseFee != nil {
msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.tip, baseFee), msg.feeCap)
}

I believe this is only used to propogate the effectiveTip to the gasprice opcode. It may be better to just have this implemented in the state_transition logic rather than AsMessage?

Copy link
Member

Choose a reason for hiding this comment

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

The idea is that it's ok to try and be smart and guess non-specified fields, but if we got invalid combos, I feel it's a bad idea to "fix it" automagically, we should just reject it.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense.

@fvictorio
Copy link
Contributor

Does this line

https://github.com/holiman/go-ethereum/blob/8317d8aa1430cd019eaf182adfad0e4c30868d81/params/config.go#L246

should have a big.NewInt(0) instead of a nil for the London block? I tested another PR in --dev mode and EIP-1559 txs were not working, and from what I could understand the problem was there.

@holiman
Copy link
Contributor Author

holiman commented Jun 1, 2021

@fvictorio yes, I started that little change (setting londonblock in xxAllProtocolChanges) in this PR: #22901

Unfortunately, doing so opens up a huge can of bugs, so it's better to not do it until the base is stabilised.

gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Aug 25, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Aug 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Aug 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Aug 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 2, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 6, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 9, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 9, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 9, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 12, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 12, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 19, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 21, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 22, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 22, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 23, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 26, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Sep 27, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 9, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 17, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 18, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 25, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 25, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 29, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 30, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 31, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Oct 31, 2024
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Nov 1, 2024
wanwiset25 pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants