@@ -7,10 +7,34 @@ import (
7
7
8
8
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
9
9
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"
10
+ "github.com/ethereum-optimism/optimism/op-service/eth"
10
11
"github.com/ethereum/go-ethereum/common"
11
12
"github.com/ethereum/go-ethereum/common/hexutil"
13
+ "github.com/ethereum/go-ethereum/rpc"
12
14
)
13
15
16
+ type l1BlockRefJSON struct {
17
+ Hash common.Hash `json:"hash"`
18
+ Number hexutil.Uint64 `json:"number"`
19
+ ParentHash common.Hash `json:"parentHash"`
20
+ Time hexutil.Uint64 `json:"timestamp"`
21
+ }
22
+
23
+ func blockRefFromRpc (ctx context.Context , l1Client * rpc.Client , numberArg string ) (eth.BlockRef , error ) {
24
+ var l1BRJ l1BlockRefJSON
25
+ if err := l1Client .CallContext (ctx , & l1BRJ , "eth_getBlockByNumber" , numberArg , false ); err != nil {
26
+ return eth.BlockRef {}, fmt .Errorf ("failed to get L1 block header for block: %w" , err )
27
+ }
28
+
29
+ headerBlockRef := eth.BlockRef {
30
+ Number : uint64 (l1BRJ .Number ),
31
+ Hash : l1BRJ .Hash ,
32
+ ParentHash : l1BRJ .ParentHash ,
33
+ Time : uint64 (l1BRJ .Time ),
34
+ }
35
+ return headerBlockRef , nil
36
+ }
37
+
14
38
func SetStartBlockLiveStrategy (ctx context.Context , env * Env , st * state.State , chainID common.Hash ) error {
15
39
lgr := env .Logger .New ("stage" , "set-start-block" , "strategy" , "live" )
16
40
lgr .Info ("setting start block" , "id" , chainID .Hex ())
@@ -20,11 +44,12 @@ func SetStartBlockLiveStrategy(ctx context.Context, env *Env, st *state.State, c
20
44
return fmt .Errorf ("failed to get chain state: %w" , err )
21
45
}
22
46
23
- startHeader , err := env .L1Client .HeaderByNumber ( ctx , nil )
47
+ headerBlockRef , err := blockRefFromRpc ( ctx , env .L1Client .Client (), "latest" )
24
48
if err != nil {
25
- return fmt .Errorf ("failed to get start block: %w" , err )
49
+ return fmt .Errorf ("failed to get L1 block header : %w" , err )
26
50
}
27
- thisChainState .StartBlock = startHeader
51
+
52
+ thisChainState .StartBlock = & headerBlockRef
28
53
29
54
return nil
30
55
}
@@ -57,7 +82,7 @@ func SetStartBlockGenesisStrategy(env *Env, st *state.State, chainID common.Hash
57
82
if err != nil {
58
83
return fmt .Errorf ("failed to build L1 developer genesis: %w" , err )
59
84
}
60
- thisChainState .StartBlock = devGenesis .ToBlock ().Header ()
85
+ thisChainState .StartBlock = eth . BlockRefFromHeader ( devGenesis .ToBlock ().Header () )
61
86
62
87
return nil
63
88
}
0 commit comments