Validate transactions by consensus rules#323
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
e4d094d to
ffc4131
Compare
ffc4131 to
0e712e1
Compare
| head := &types.Header{ | ||
| Number: big.NewInt(20_182_324), | ||
| Time: uint64(time.Now().Unix()), | ||
| GasLimit: 30_000_000, | ||
| } | ||
| chainConfig := emulator.DefaultChainConfig | ||
| chainConfig.ChainID = e.config.EVMNetworkID | ||
| signer := types.MakeSigner( | ||
| chainConfig, | ||
| head.Number, | ||
| head.Time, | ||
| ) | ||
| opts := &txpool.ValidationOptions{ | ||
| Config: chainConfig, | ||
| Accept: 0 | | ||
| 1<<types.LegacyTxType | | ||
| 1<<types.AccessListTxType | | ||
| 1<<types.DynamicFeeTxType | | ||
| 1<<types.BlobTxType, | ||
| MaxSize: models.TxMaxSize, | ||
| MinTip: new(big.Int), | ||
| } |
There was a problem hiding this comment.
can we move this inside the ValidateConsensusRules
There was a problem hiding this comment.
Ideally, this is something that we should have cached somewhere, maybe in our implementation of TxPool.
So that we don't create all these objects for every request to eth_sendRawTransaction.
There was a problem hiding this comment.
Let's just have these defined as variables in the models where validate transaction is, not sure why would we need to have them defined in a function.
There was a problem hiding this comment.
I have updated this in 4ad00ea .
We can't define them as variable in the top-level scope, as we need access to the Gateway config, for fetching the current EVM Networkd ID (chain ID).
| MinTip: new(big.Int), | ||
| } | ||
|
|
||
| if err := models.ValidateConsensusRules(tx, head, signer, opts); err != nil { |
There was a problem hiding this comment.
can we call this inside the ValidateTransaction
There was a problem hiding this comment.
We could add this logic to the existing ValidateTransaction method. I just introduced a different method, to be able to test it in isolation.
| return nil | ||
| } | ||
|
|
||
| func ValidateConsensusRules( |
There was a problem hiding this comment.
why is defining this here needed? can't this just be called in the existing ValidateTransaction
There was a problem hiding this comment.
I can merge the two functions. I just wanted to keep them apart, so that they can be composed in other parts of the code-base. But maybe that was a premature thinking 👍
|
|
||
| } | ||
|
|
||
| func TestValidateConsensusRules(t *testing.T) { |
There was a problem hiding this comment.
this feels to me like it's testing txpool.ValidateTransaction which is test in go-ethereum so I don't feel like we should add tests here
There was a problem hiding this comment.
Unfortunately the test cases on go-ethereum were very little. And because that method is a rather black-box for us, I wanted to make sure that we validate transaction properly, without false positives / false negatives.
There was a problem hiding this comment.
Sorry, I don't exactly understand, aren't all this test existing in go-ethereum already? is there any bellow you added yourself? If not, I don't understand why would we want to have them here.
There was a problem hiding this comment.
I feel the same, I think this test for Ethereum, we don't need to test this logic.
There was a problem hiding this comment.
@sideninja @ramtinms These tests do not exist in the go-ethereum repository.
The rationale behind them is not to test the logic of txpool.ValidateTransaction(tx, head, signer, opts) .
I have added these tests mainly as a safeguard, against future upgrades of the go-ethereum package.
And the reason is that this method accepts several parameters.
Suppose that the method is updated and makes use of extra fields from the head or opts arguments.
Without the tests, any such changes will go unnoticed, and might result in crashes on production.
head := &types.Header{
Number: big.NewInt(20_182_324),
Time: uint64(time.Now().Unix()),
GasLimit: 30_000_000,
}For example, right now we only populate the above fields for the head argument.
0e712e1 to
afa0980
Compare
| chainConfig := emulator.DefaultChainConfig | ||
| chainConfig.ChainID = e.config.EVMNetworkID |
There was a problem hiding this comment.
maybe just rewrite this to this way
emulator.NewConfig(WithChainID(chainID))
afa0980 to
592a7d9
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- services/requester/requester.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- services/requester/requester.go
There was a problem hiding this comment.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- models/transaction.go (3 hunks)
- models/transaction_test.go (3 hunks)
- services/requester/requester.go (4 hunks)
Files not reviewed due to errors (1)
- models/transaction_test.go (no review received)
Files skipped from review as they are similar to previous changes (1)
- models/transaction.go
Additional comments not posted (1)
services/requester/requester.go (1)
194-194: Ensure error handling for validation.The validation logic is a good addition. Ensure that the error messages provide sufficient context for debugging.
| head := &types.Header{ | ||
| Number: big.NewInt(20_182_324), | ||
| Time: uint64(time.Now().Unix()), | ||
| GasLimit: 30_000_000, | ||
| } | ||
| emulatorConfig := emulator.NewConfig( | ||
| emulator.WithChainID(config.EVMNetworkID), | ||
| emulator.WithBlockNumber(head.Number), | ||
| emulator.WithBlockTime(head.Time), | ||
| ) | ||
| evmSigner := emulator.GetSigner(emulatorConfig) | ||
| validationOptions := &txpool.ValidationOptions{ | ||
| Config: emulatorConfig.ChainConfig, | ||
| Accept: 0 | | ||
| 1<<types.LegacyTxType | | ||
| 1<<types.AccessListTxType | | ||
| 1<<types.DynamicFeeTxType | | ||
| 1<<types.BlobTxType, | ||
| MaxSize: models.TxMaxSize, | ||
| MinTip: new(big.Int), | ||
| } |
There was a problem hiding this comment.
Ensure head values are configurable.
The head values such as Number, Time, and GasLimit are hard-coded. Consider making these configurable to enhance flexibility and testing.
head := &types.Header{
Number: big.NewInt(config.BlockNumber),
Time: uint64(time.Now().Unix()),
GasLimit: config.GasLimit,
}There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- models/transaction.go (3 hunks)
- models/transaction_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- models/transaction.go
- models/transaction_test.go
| head := &types.Header{ | ||
| Number: big.NewInt(20_182_324), | ||
| Time: uint64(time.Now().Unix()), | ||
| GasLimit: 30_000_000, | ||
| } | ||
| emulatorConfig := emulator.NewConfig( | ||
| emulator.WithChainID(config.EVMNetworkID), | ||
| emulator.WithBlockNumber(head.Number), | ||
| emulator.WithBlockTime(head.Time), | ||
| ) | ||
| evmSigner := emulator.GetSigner(emulatorConfig) | ||
| validationOptions := &txpool.ValidationOptions{ | ||
| Config: emulatorConfig.ChainConfig, | ||
| Accept: 0 | | ||
| 1<<types.LegacyTxType | | ||
| 1<<types.AccessListTxType | | ||
| 1<<types.DynamicFeeTxType | | ||
| 1<<types.BlobTxType, | ||
| MaxSize: models.TxMaxSize, | ||
| MinTip: new(big.Int), | ||
| } |
There was a problem hiding this comment.
why do we want to have these config here in the requester? I think it would be better if we just place it in the models/transaction with the ValidateTransaction function on the top as a variable
There was a problem hiding this comment.
Because we need access to config.EVMNetworkID. This means that even if we pass the config as a parameter, we will have to construct all these objects every time we call the ValidateTransaction function.
| ) | ||
| evmSigner := emulator.GetSigner(emulatorConfig) | ||
| validationOptions := &txpool.ValidationOptions{ | ||
| Config: emulatorConfig.ChainConfig, |
There was a problem hiding this comment.
There was a problem hiding this comment.
It was suggested by Ramtin (#323 (comment)), to construct a new config, with the desired options applied. This also facilitates fetching the signer, based on the created config. Note that we do not need the default config for all networks, as the default config is hardcoded to PreviewNet.
cb82dc6 to
d5906af
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- models/transaction.go (3 hunks)
- models/transaction_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- models/transaction.go
- models/transaction_test.go
Closes: #117
Description
Performs the same validation rules as the Geth TxPool
For contributor use:
masterbranchFiles changedin the Github PR explorerSummary by CodeRabbit
New Features
Tests
Chores