Sitelet https://github.com/ethereum-optimism/optimism/commit/fc8648775a03fbb4c532a03b50f0681d74bbc106
Skip to content

Commit fc86487

Browse files
sebastianstclaude
andauthored
op-service: make sources the OP-aware eth client (#21908)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent bef2a1d commit fc86487

71 files changed

Lines changed: 1143 additions & 217 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎op-acceptance-tests/tests/interop/loadtest/interop_load_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
messages "github.com/ethereum-optimism/optimism/op-core/interop/messages"
1515
"github.com/ethereum-optimism/optimism/op-core/predeploys"
16+
optypes "github.com/ethereum-optimism/optimism/op-core/types"
1617
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
1718
"github.com/ethereum-optimism/optimism/op-devstack/dsl"
1819
"github.com/ethereum-optimism/optimism/op-devstack/presets"
@@ -25,7 +26,6 @@ import (
2526
"github.com/ethereum-optimism/optimism/op-service/txintent"
2627
"github.com/ethereum-optimism/optimism/op-service/txplan"
2728
"github.com/ethereum/go-ethereum/common/hexutil"
28-
ethtypes "github.com/ethereum/go-ethereum/core/types"
2929
"github.com/ethereum/go-ethereum/params"
3030
"github.com/ethereum/go-ethereum/rpc"
3131
)
@@ -222,13 +222,13 @@ func newReliableEL(el txinclude.EL, blockTime time.Duration, observer txinclude.
222222
}
223223

224224
// initMsgFromReceipt turns the first log in the receipt into an inititiating message.
225-
func initMsgFromReceipt(t devtest.T, l2 *L2, receipt *ethtypes.Receipt) (*messages.Message, error) {
225+
func initMsgFromReceipt(t devtest.T, l2 *L2, receipt *optypes.Receipt) (*messages.Message, error) {
226226
ref, err := l2.EL.Escape().EthClient().BlockRefByHash(t.Ctx(), receipt.BlockHash)
227227
if err != nil {
228228
return nil, fmt.Errorf("get init msg block ref by hash: %w", err)
229229
}
230230
out := new(txintent.InteropOutput)
231-
if err := out.FromReceipt(t.Ctx(), receipt, ref, l2.EL.ChainID()); err != nil {
231+
if err := out.FromReceipt(t.Ctx(), &receipt.Receipt, ref, l2.EL.ChainID()); err != nil {
232232
return nil, fmt.Errorf("get init msg from receipt: %w", err)
233233
}
234234
t.Require().NotEmpty(out.Entries)

‎op-acceptance-tests/tests/interop/loadtest/invalid_msg_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestRelayWithInvalidMessagesSteady(gt *testing.T) {
9494
t.Require().NoError(err)
9595
ref := l2A.EL.BlockRefByNumber(bigs.Uint64Strict(initTx.Receipt.BlockNumber))
9696
out := new(txintent.InteropOutput)
97-
t.Require().NoError(out.FromReceipt(t.Ctx(), initTx.Receipt, ref.BlockRef(), l2A.EL.ChainID()))
97+
t.Require().NoError(out.FromReceipt(t.Ctx(), &initTx.Receipt.Receipt, ref.BlockRef(), l2A.EL.ChainID()))
9898
t.Require().Len(out.Entries, 1)
9999
validInitMsg := out.Entries[0]
100100

‎op-alt-da/damgr.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ethereum/go-ethereum/log"
1414

1515
"github.com/ethereum-optimism/optimism/op-alt-da/bindings"
16+
optypes "github.com/ethereum-optimism/optimism/op-core/types"
1617
"github.com/ethereum-optimism/optimism/op-service/bigs"
1718
"github.com/ethereum-optimism/optimism/op-service/eth"
1819
)
@@ -38,7 +39,7 @@ var ErrInvalidChallenge = errors.New("invalid challenge")
3839
// L1Fetcher is the required interface for syncing the DA challenge contract state.
3940
type L1Fetcher interface {
4041
InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error)
41-
FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error)
42+
FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, optypes.Receipts, error)
4243
L1BlockRefByNumber(context.Context, uint64) (eth.L1BlockRef, error)
4344
}
4445

‎op-alt-da/damgr_test.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"math/rand"
77
"testing"
88

9+
optypes "github.com/ethereum-optimism/optimism/op-core/types"
910
"github.com/ethereum-optimism/optimism/op-service/eth"
1011
"github.com/ethereum-optimism/optimism/op-service/testlog"
1112
"github.com/ethereum/go-ethereum/common"
@@ -209,12 +210,12 @@ func (m *mockL1Fetcher) ExpectInfoAndTxsByHash(hash common.Hash, info eth.BlockI
209210
m.Mock.On("InfoAndTxsByHash", hash).Once().Return(info, transactions, err)
210211
}
211212

212-
func (m *mockL1Fetcher) FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error) {
213+
func (m *mockL1Fetcher) FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, optypes.Receipts, error) {
213214
out := m.Mock.Called(blockHash)
214-
return *out.Get(0).(*eth.BlockInfo), out.Get(1).(types.Receipts), out.Error(2)
215+
return *out.Get(0).(*eth.BlockInfo), out.Get(1).(optypes.Receipts), out.Error(2)
215216
}
216217

217-
func (m *mockL1Fetcher) ExpectFetchReceipts(hash common.Hash, info eth.BlockInfo, receipts types.Receipts, err error) {
218+
func (m *mockL1Fetcher) ExpectFetchReceipts(hash common.Hash, info eth.BlockInfo, receipts optypes.Receipts, err error) {
218219
m.Mock.On("FetchReceipts", hash).Once().Return(&info, receipts, err)
219220
}
220221

@@ -392,7 +393,7 @@ func TestAdvanceChallengeOrigin(t *testing.T) {
392393

393394
da := NewAltDAWithState(logger, pcfg, storage, &NoopMetrics{}, state)
394395

395-
receipts := types.Receipts{&types.Receipt{
396+
receipts := optypes.Receipts{{Receipt: types.Receipt{
396397
Type: 2,
397398
Status: 1,
398399
Logs: []*types.Log{
@@ -414,7 +415,7 @@ func TestAdvanceChallengeOrigin(t *testing.T) {
414415
},
415416
},
416417
BlockNumber: big.NewInt(int64(bn)),
417-
}}
418+
}}}
418419
id := eth.BlockID{
419420
Number: bn,
420421
Hash: bhash,

‎op-chain-ops/cmd/check-karst/karsttest/checks.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func NewBasePlan(cl *ethclient.Client, key *ecdsa.PrivateKey) txplan.Option {
123123
txplan.WithAgainstLatestBlockEthClient(cl),
124124
txplan.WithEstimator(cl, true),
125125
txplan.WithRetrySubmission(cl, 5, retry.Exponential()),
126-
txplan.WithRetryInclusion(cl, 5, retry.Exponential()),
126+
txplan.WithRetryInclusion(txplan.FromGethReceipts(cl), 5, retry.Exponential()),
127127
)
128128
}
129129

@@ -419,7 +419,7 @@ func CheckEIP7825DepositBypass(
419419

420420
l2DepositHash := l2DepositTx.Hash()
421421
logger.Info("EIP-7825-deposit: waiting for L2 deposit receipt", "tx", l2DepositHash)
422-
var l2Receipt *types.Receipt
422+
var l2Receipt *optypes.Receipt
423423
for {
424424
var err error
425425
l2Receipt, err = l2.TransactionReceipt(ctx, l2DepositHash)

‎op-chain-ops/cmd/check-karst/main.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/ethereum/go-ethereum/log"
1919

2020
"github.com/ethereum-optimism/optimism/op-chain-ops/cmd/check-karst/karsttest"
21+
optypes "github.com/ethereum-optimism/optimism/op-core/types"
2122
op_service "github.com/ethereum-optimism/optimism/op-service"
2223
"github.com/ethereum-optimism/optimism/op-service/apis"
2324
"github.com/ethereum-optimism/optimism/op-service/cliapp"
@@ -177,6 +178,17 @@ func makeAllCommand() *cli.Command {
177178
// aren't needed by the EIP-7934 check.
178179
type ethclientLatestBlockAdapter struct{ *ethclient.Client }
179180

181+
// TransactionReceipt adapts the go-ethereum receipt to the optypes shape the
182+
// karst checks consume; the OP extension fields stay nil (the checks read only
183+
// standard fields).
184+
func (a *ethclientLatestBlockAdapter) TransactionReceipt(ctx context.Context, txHash common.Hash) (*optypes.Receipt, error) {
185+
receipt, err := a.Client.TransactionReceipt(ctx, txHash)
186+
if err != nil || receipt == nil {
187+
return nil, err
188+
}
189+
return &optypes.Receipt{Receipt: *receipt}, nil
190+
}
191+
180192
func (a *ethclientLatestBlockAdapter) InfoAndTxsByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, types.Transactions, error) {
181193
if label != eth.Unsafe {
182194
return nil, nil, fmt.Errorf("unsupported block label %q (only %q is supported)", label, eth.Unsafe)
@@ -248,7 +260,7 @@ func makeDepositCommand() *cli.Command {
248260
}
249261

250262
if _, err := karsttest.CheckEIP7825DepositBypass(
251-
env.ctx, env.logger, env.l2,
263+
env.ctx, env.logger, &ethclientLatestBlockAdapter{env.l2},
252264
common.HexToAddress(portalHex),
253265
crypto.PubkeyToAddress(l1Key.PublicKey),
254266
karsttest.NewBasePlan(l1Cl, l1Key),

‎op-chain-ops/cmd/receipt-reference-builder/pull.go‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/ethereum-optimism/optimism/op-service/bigs"
1111
"github.com/ethereum-optimism/optimism/op-service/dial"
12-
"github.com/ethereum-optimism/optimism/op-service/sources"
1312
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
13+
"github.com/ethereum/go-ethereum/common/hexutil"
1414
"github.com/ethereum/go-ethereum/core/types"
1515
"github.com/ethereum/go-ethereum/ethclient"
1616
"github.com/ethereum/go-ethereum/log"
@@ -291,7 +291,7 @@ func processBlockRange(
291291
for i := 0; i < len(blocks); i++ {
292292
b := blocks[i]
293293
matches := 0
294-
blockNumber := b.BlockID().Number
294+
blockNumber := uint64(b.Number)
295295
res := result{
296296
BlockNumber: blockNumber,
297297
Nonces: []uint64{},
@@ -319,16 +319,24 @@ func processBlockRange(
319319
// batchBlockByNumber will batch a list of block numbers into a single batch rpc request
320320
// it uses the iterative batch call to make the request
321321
// and returns the results
322-
func batchBlockByNumber(ctx context.Context, c *ethclient.Client, blockNumbers []rpc.BlockNumber) ([]*sources.RPCBlock, error) {
323-
makeBlockByNumberRequest := func(blockNumber rpc.BlockNumber) (*sources.RPCBlock, rpc.BatchElem) {
324-
out := new(sources.RPCBlock)
322+
// rpcBlock is a minimal eth_getBlockBy* result carrying what this tool reads.
323+
// Transactions decode as op-geth typed transactions: the tool extracts the
324+
// effective deposit nonce, JSON-only data that op-geth's decoder captures.
325+
type rpcBlock struct {
326+
Number hexutil.Uint64 `json:"number"`
327+
Transactions []*types.Transaction `json:"transactions"`
328+
}
329+
330+
func batchBlockByNumber(ctx context.Context, c *ethclient.Client, blockNumbers []rpc.BlockNumber) ([]*rpcBlock, error) {
331+
makeBlockByNumberRequest := func(blockNumber rpc.BlockNumber) (*rpcBlock, rpc.BatchElem) {
332+
out := new(rpcBlock)
325333
return out, rpc.BatchElem{
326334
Method: "eth_getBlockByNumber",
327335
Args: []any{blockNumber, true},
328336
Result: &out,
329337
}
330338
}
331-
batchReq := batching.NewIterativeBatchCall[rpc.BlockNumber, *sources.RPCBlock](
339+
batchReq := batching.NewIterativeBatchCall[rpc.BlockNumber, *rpcBlock](
332340
blockNumbers,
333341
makeBlockByNumberRequest,
334342
c.Client().BatchCallContext,

‎op-challenger/game/keccak/fetcher/fetcher.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (f *InputFetcher) FetchInputs(ctx context.Context, blockHash common.Hash, o
5353
return nil, fmt.Errorf("failed to retrieve receipts for block %v: %w", blockNum, err)
5454
}
5555
for _, rcpt := range receipts {
56-
inputData, err := f.extractRelevantLeavesFromReceipt(rcpt, oracle, ident)
56+
inputData, err := f.extractRelevantLeavesFromReceipt(&rcpt.Receipt, oracle, ident)
5757
if err != nil {
5858
return nil, err
5959
}

‎op-challenger/game/keccak/fetcher/fetcher_test.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
1212
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
13+
optypes "github.com/ethereum-optimism/optimism/op-core/types"
1314
"github.com/ethereum-optimism/optimism/op-service/eth"
1415
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
1516
"github.com/ethereum-optimism/optimism/op-service/testlog"
@@ -287,7 +288,7 @@ func setupFetcherTest(t *testing.T) (*InputFetcher, *stubOracle, *stubL1Source)
287288
}
288289
l1Source := &stubL1Source{
289290
blocks: make(map[uint64]common.Hash),
290-
rcpts: make(map[common.Hash]types.Receipts),
291+
rcpts: make(map[common.Hash]optypes.Receipts),
291292
txs: make(map[uint64]types.Transactions),
292293
rcptStatus: make(map[common.Hash]uint64),
293294
logs: make(map[common.Hash][]*types.Log),
@@ -358,7 +359,7 @@ type stubL1Source struct {
358359
// Map block number to block hash
359360
blocks map[uint64]common.Hash
360361
// Map block hash to receipts
361-
rcpts map[common.Hash]types.Receipts
362+
rcpts map[common.Hash]optypes.Receipts
362363
// Map block number to tx
363364
txs map[uint64]types.Transactions
364365
// Map txHash to receipt
@@ -378,7 +379,7 @@ func (s *stubL1Source) BlockRefByNumber(_ context.Context, num uint64) (eth.Bloc
378379
}, nil
379380
}
380381

381-
func (s *stubL1Source) FetchReceipts(_ context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error) {
382+
func (s *stubL1Source) FetchReceipts(_ context.Context, blockHash common.Hash) (eth.BlockInfo, optypes.Receipts, error) {
382383
rcpts, ok := s.rcpts[blockHash]
383384
if !ok {
384385
return nil, nil, errors.New("not found")
@@ -392,7 +393,7 @@ func uint64ToHash(num uint64) common.Hash {
392393
return crypto.Keccak256Hash(data)
393394
}
394395

395-
func (s *stubL1Source) createReceipt(blockNum uint64, status uint64, proposals ...*proposalConfig) *types.Receipt {
396+
func (s *stubL1Source) createReceipt(blockNum uint64, status uint64, proposals ...*proposalConfig) *optypes.Receipt {
396397
// Make the block exist
397398
s.blocks[blockNum] = uint64ToHash(blockNum)
398399

@@ -420,7 +421,7 @@ func (s *stubL1Source) createReceipt(blockNum uint64, status uint64, proposals .
420421
}
421422
logs[i] = txLog
422423
}
423-
rcpt := &types.Receipt{TxHash: uint64ToHash(txId), Status: status, Logs: logs}
424+
rcpt := &optypes.Receipt{Receipt: types.Receipt{TxHash: uint64ToHash(txId), Status: status, Logs: logs}}
424425
blockHash := s.blocks[blockNum]
425426
rcpts := s.rcpts[blockHash]
426427
s.rcpts[blockHash] = append(rcpts, rcpt)

‎op-core/types/receipt_consensus.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ type Receipts []*Receipt
2525

2626
var _ types.DerivableList = (Receipts)(nil)
2727

28+
// FromGethReceipts wraps go-ethereum receipts into Receipts. The receipt
29+
// structs are shallow-copied (reference fields like Logs still alias the
30+
// source). While go-ethereum resolves to op-geth, the deposit receipt fields
31+
// are mirrored to the authoritative outer copies so consensus encoding stays
32+
// correct; those two assignments stop compiling at the final cutover and are
33+
// removed then.
34+
func FromGethReceipts(rs types.Receipts) Receipts {
35+
out := make(Receipts, len(rs))
36+
for i, r := range rs {
37+
wrapped := &Receipt{Receipt: *r}
38+
wrapped.DepositNonce = r.DepositNonce
39+
wrapped.DepositReceiptVersion = r.DepositReceiptVersion
40+
out[i] = wrapped
41+
}
42+
return out
43+
}
44+
2845
// Geth returns a view of the embedded go-ethereum receipts, for boundaries
2946
// that operate on standard receipt fields only. The elements alias the
3047
// receivers' embedded structs — mutations are visible in both.

0 commit comments

Comments
 (0)