Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 35 additions & 42 deletions services/requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ type EVM struct {
mux sync.Mutex
keystore *keystore.KeyStore

head *types.Header
evmSigner types.Signer
validationOptions *txpool.ValidationOptions
collector metrics.Collector
rateLimiter limiter.Store
collector metrics.Collector
rateLimiter limiter.Store
}

func NewEVM(
Expand Down Expand Up @@ -153,30 +150,6 @@ func NewEVM(
}
}

head := &types.Header{
Number: big.NewInt(20_182_324),
Time: uint64(time.Now().Unix()),
GasLimit: blockGasLimit,
Difficulty: big.NewInt(0),
}
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 |
1<<types.SetCodeTxType,
MaxSize: models.TxMaxSize,
MinTip: new(big.Int),
}

rateLimiter, err := memorystore.New(
&memorystore.Config{
Tokens: config.TxRequestLimit,
Expand All @@ -188,18 +161,15 @@ func NewEVM(
}

return &EVM{
registerStore: registerStore,
client: client,
config: config,
logger: logger,
blocks: blocks,
txPool: txPool,
head: head,
evmSigner: evmSigner,
validationOptions: validationOptions,
collector: collector,
keystore: keystore,
rateLimiter: rateLimiter,
registerStore: registerStore,
client: client,
config: config,
logger: logger,
blocks: blocks,
txPool: txPool,
collector: collector,
keystore: keystore,
rateLimiter: rateLimiter,
}, nil
}

Expand All @@ -213,7 +183,30 @@ func (e *EVM) SendRawTransaction(ctx context.Context, data []byte) (common.Hash,
return common.Hash{}, errs.NewTxGasLimitTooHighError(txMaxGasLimit)
}

if err := models.ValidateTransaction(tx, e.head, e.evmSigner, e.validationOptions); err != nil {
head := &types.Header{
Number: big.NewInt(20_182_324),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this block number hardcoded?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This one is not really important, as it's no longer used for hard-forks. Ethereum does upgrades with timestamps, instead of block numbers. But this is there for backwards-compatibility. I think this was the Ethereum mainnet latest block number, when we launched Flow EVM on mainnet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@m-Peter please add that as a comment, magic numbers not good :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@j1010001 Good point 👍
I added some comments which better describe the intent, in this commit: 45de8d3 .

Time: uint64(time.Now().Unix()),
GasLimit: blockGasLimit,
Difficulty: big.NewInt(0),
}
emulatorConfig := emulator.NewConfig(
emulator.WithChainID(e.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 |
1<<types.SetCodeTxType,
MaxSize: models.TxMaxSize,
MinTip: new(big.Int),
}
if err := models.ValidateTransaction(tx, head, evmSigner, validationOptions); err != nil {
return common.Hash{}, err
}

Expand Down