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

Optimize sequencing procedure #2

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions op-service/sources/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,19 @@ func (s *EthClient) ReadStorageAt(ctx context.Context, address common.Address, s
return common.BytesToHash(value.Bytes()), nil
}

// GetTransactionByBlockHashAndIndex returns the transaction at the given index in the block with the given hash.
func (s *EthClient) TxByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index uint64) (*types.Transaction, error) {
var tx *types.Transaction
err := s.client.CallContext(ctx, &tx, "eth_getTransactionByBlockHashAndIndex", blockHash.Hex(), hexutil.EncodeUint64(index))
if err != nil {
return nil, fmt.Errorf("failed to fetch transaction in block %s at index %d: %w", blockHash, index, err)
}
if tx == nil {
return nil, ethereum.NotFound
}
return tx, nil
}

func (s *EthClient) Close() {
s.client.Close()
}
28 changes: 25 additions & 3 deletions op-service/sources/l2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-node/rollup"
Expand Down Expand Up @@ -158,12 +159,33 @@ func (s *L2Client) SystemConfigByL2Hash(ctx context.Context, hash common.Hash) (
return ref, nil
}

envelope, err := s.PayloadByHash(ctx, hash)
header, err := s.InfoByHash(ctx, hash)
if err != nil {
// w%: wrap to preserve ethereum.NotFound case
return eth.SystemConfig{}, fmt.Errorf("failed to determine block-hash of hash %v, could not get payload: %w", hash, err)
return eth.SystemConfig{}, fmt.Errorf("failed to determine block-hash of hash %v, could not get header: %w", hash, err)
}
txs := []hexutil.Bytes{}
first_tx, err := s.TxByBlockHashAndIndex(ctx, hash, 0)
if err == nil {
first_tx_binary, err := first_tx.MarshalBinary()
if err != nil {
return eth.SystemConfig{}, fmt.Errorf("failed to determine block-hash of hash %v, could not marshal first tx: %w", hash, err)
}
txs = append(txs, first_tx_binary)
} else if err != ethereum.NotFound {
// w%: wrap to preserve ethereum.NotFound case
return eth.SystemConfig{}, fmt.Errorf("failed to determine block-hash of hash %v, could not get first tx: %w", hash, err)
}
cfg, err := derive.PayloadToSystemConfig(s.rollupCfg, envelope.ExecutionPayload)

// PayloadToSystemConfig only needs this fields from the header
payload := eth.ExecutionPayload{}
payload.BlockNumber = hexutil.Uint64(header.NumberU64())
payload.BlockHash = header.Hash()
payload.Timestamp = hexutil.Uint64(header.Time())
payload.GasLimit = hexutil.Uint64(header.GasLimit())
payload.Transactions = txs

cfg, err := derive.PayloadToSystemConfig(s.rollupCfg, &payload)
if err != nil {
return eth.SystemConfig{}, err
}
Expand Down