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

Remove exchange rate calculation for non CELO denominated txs in state_transition #2299

Merged
merged 2 commits into from
May 15, 2024

Conversation

hbandura
Copy link
Contributor

Fix state_transition producing invalid gas used values for pre-H fork transactions by preventing from taking the exchange rate of fee currencies meant for only CELO denominated txs.

Rename some variables to be more specific about them applying only to this tx type.

Copy link

github-actions bot commented Apr 16, 2024

Coverage from tests in ./e2e_test/... for ./consensus/istanbul/... at commit 06eee2c

coverage: 51.2% of statements across all listed packages
coverage:  63.6% of statements in consensus/istanbul
coverage:  43.2% of statements in consensus/istanbul/announce
coverage:  56.0% of statements in consensus/istanbul/backend
coverage:   0.0% of statements in consensus/istanbul/backend/backendtest
coverage:  24.3% of statements in consensus/istanbul/backend/internal/replica
coverage:  65.9% of statements in consensus/istanbul/core
coverage:  50.0% of statements in consensus/istanbul/db
coverage:   0.0% of statements in consensus/istanbul/proxy
coverage:  64.2% of statements in consensus/istanbul/uptime
coverage:  51.8% of statements in consensus/istanbul/validator
coverage:  79.2% of statements in consensus/istanbul/validator/random

Copy link

github-actions bot commented Apr 16, 2024

5887 passed, 45 skipped

Comment on lines -220 to -225
var feeCurrency *common.Address = msg.FeeCurrency()
if msg.MaxFeeInFeeCurrency() != nil {
// Celo denominated tx
feeCurrency = nil
gasPriceMinimum = sysCtx.GetGasPriceMinimum(nil)
} else {
gasPriceMinimum = sysCtx.GetGasPriceMinimum(msg.FeeCurrency())
}
gasPriceMinimum = sysCtx.GetGasPriceMinimum(feeCurrency)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary? This seems to be functionally unchanged by the change. I.E sysCtx.GetGasPriceMinimum is called once with either nil or a fee currency.

Copy link
Contributor Author

@hbandura hbandura Apr 17, 2024

Choose a reason for hiding this comment

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

Correct, it is unchanged. But since the bad block I wanted to make sure everything was like before, so while this is a diff here, it makes it closer than what we had before the cip66 change in state_transition. The line 224 is exactly what we had, I wanted to preserve that line, even if, functionally, this block is the same

Comment on lines -381 to -390
var currencyFee *big.Int
if st.msg.MaxFeeInFeeCurrency() == nil {
// Normal feeCurrency tx
currencyFee = effectiveFee
if st.msg.MaxFeeInFeeCurrency() != nil {
st.erc20FeeDebited = denominatedCurrencyRate.FromBase(effectiveFee)
} else {
// Celo denominated tx
currencyFee = feeCurrencyRate.FromBase(effectiveFee)
st.erc20FeeDebited = effectiveFee
}
st.erc20FeeDebited = currencyFee
return erc20gas.DebitFees(st.evm, from, currencyFee, feeCurrency)
Copy link
Contributor

Choose a reason for hiding this comment

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

This block also seems to be functionally unchanged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just removing an unnecessary local variable.

denominatedCurrencyRate, err = currency.GetExchangeRate(st.vmRunner, st.msg.FeeCurrency())
if err != nil {
return nil, err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is the actual fix right? Only setting denominatedCurrencyRate for celo denominated transactions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. The rest of the changes are: variable renames for (in my opinion) more explicit names, and changing a few ifblocks to be exactly like they were before the previous change (a mini revert if you will).

@hbandura hbandura requested a review from piersy April 17, 2024 14:33
Copy link
Contributor

@piersy piersy left a comment

Choose a reason for hiding this comment

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

Hey @hbandura thanks for answering my questions. It's all looking good!

@hbandura
Copy link
Contributor Author

A full sync is currently running, may take a few days. When it finishes we can merge this

@piersy piersy merged commit 06eee2c into master May 15, 2024
27 checks passed
@piersy piersy deleted the hbandura/fix_st branch May 15, 2024 10:50
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.

None yet

2 participants