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

Integration API for EIP-4337 bundler with an L2 validator/sequencer #1357

Merged
merged 5 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
internal/ethapi: cleaner designed and improved check
  • Loading branch information
MatusKysel committed Apr 14, 2023
commit 26c69a15bacb5a20c554d097c4fa3da80883f476
45 changes: 8 additions & 37 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2078,42 +2078,6 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
return tx.Hash(), nil
}

func SubmitConditionalTransaction(ctx context.Context, b Backend, tx *types.Transaction, options TransactionOpts) (common.Hash, error) {
// If the transaction fee cap is already specified, ensure the
// fee of the given transaction is _reasonable_.
if err := checkTxFee(tx.GasPrice(), tx.Gas(), b.RPCTxFeeCap()); err != nil {
return common.Hash{}, err
}
if !b.UnprotectedAllowed() && !tx.Protected() {
// Ensure only eip155 signed transactions are submitted if EIP155Required is set.
return common.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC")
}
state, _, err := b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(b.CurrentBlock().Number().Int64()))
if state == nil || err != nil {
return common.Hash{}, err
}
if err := options.Check(b.CurrentBlock().NumberU64(), b.CurrentBlock().Time(), state); err != nil {
return common.Hash{}, err
}
if err := b.SendTx(ctx, tx); err != nil {
return common.Hash{}, err
}
// Print a log with full tx details for manual investigations and interventions
signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())
from, err := types.Sender(signer, tx)
if err != nil {
return common.Hash{}, err
}

if tx.To() == nil {
addr := crypto.CreateAddress(from, tx.Nonce())
log.Info("Submitted contract creation", "hash", tx.Hash().Hex(), "from", from, "nonce", tx.Nonce(), "contract", addr.Hex(), "value", tx.Value())
} else {
log.Info("Submitted transaction", "hash", tx.Hash().Hex(), "from", from, "nonce", tx.Nonce(), "recipient", tx.To(), "value", tx.Value())
}
return tx.Hash(), nil
}

// SendTransaction creates a transaction for the given argument, sign it and submit it to the
// transaction pool.
func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args TransactionArgs) (common.Hash, error) {
Expand Down Expand Up @@ -2180,7 +2144,14 @@ func (s *PublicTransactionPoolAPI) SendRawTransactionConditional(ctx context.Con
if err := tx.UnmarshalBinary(input); err != nil {
return common.Hash{}, err
}
return SubmitConditionalTransaction(ctx, s.b, tx, opts)
state, _, err := s.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(s.b.CurrentBlock().Number().Int64()))
if state == nil || err != nil {
return common.Hash{}, err
}
if err := opts.Check(s.b.CurrentBlock().NumberU64(), s.b.CurrentBlock().Time(), state); err != nil {
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
return common.Hash{}, err
}
return SubmitTransaction(ctx, s.b, tx)
}

// Sign calculates an ECDSA signature for:
Expand Down
10 changes: 9 additions & 1 deletion internal/ethapi/transaction_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ func (o *TransactionOpts) Check(blockNumber uint64, timeStamp uint64, statedb *s
if o.TimestampMax != nil && timeStamp > uint64(*o.TimestampMax) {
return errors.New("TimestampMax condition not met")
}
if len(o.KnownAccounts) > 1000 {
counter := 0
for _, account := range o.KnownAccounts {
if account.RootHash != nil {
counter += 1
} else if account.SlotValue != nil {
counter += len(account.SlotValue)
MatusKysel marked this conversation as resolved.
Show resolved Hide resolved
}
}
if counter > 1000 {
MatusKysel marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("knownAccounts too large")
}
return o.CheckOnlyStorage(statedb)
Expand Down