Skip to content
Merged
Changes from all commits
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
85 changes: 43 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,38 @@ 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` is only useful to detect hard-forks which were
// activated with block numbers. However, Ethereum now
// activates hard-forks with timestamps, so the `Number`
// field is not really necessary. Anyway, we set it to
// the latest finalized block on Ethereum mainnet.
Number: big.NewInt(22_446_370),
// The `Time` field is what's actually used for detecting
// whether we're in a certain hard-fork, and what kind of
// tx validations to run.
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