|
8 | 8 | "strconv" |
9 | 9 |
|
10 | 10 | "github.com/ethereum/go-ethereum/common" |
| 11 | + "github.com/ethereum/go-ethereum/common/hexutil" |
11 | 12 | "github.com/ethereum/go-ethereum/core/types" |
12 | 13 | "github.com/ethereum/go-ethereum/ethclient" |
13 | 14 | "github.com/ethereum/go-ethereum/p2p" |
@@ -192,13 +193,26 @@ func (ec *ExecutionClient) UninstallBlockFilter(ctx context.Context, filterId Bl |
192 | 193 | return result, err |
193 | 194 | } |
194 | 195 |
|
195 | | -func (ec *ExecutionClient) GetLatestHeader(ctx context.Context) (*types.Header, error) { |
196 | | - header, err := ec.ethClient.HeaderByNumber(ctx, nil) |
| 196 | +// GetLatestHead returns the latest block's number and hash as reported by the |
| 197 | +// execution node. The hash is read from the node's response rather than |
| 198 | +// recomputed from the header locally, which would be wrong whenever the header |
| 199 | +// carries fields the local go-ethereum types do not know about. |
| 200 | +func (ec *ExecutionClient) GetLatestHead(ctx context.Context) (uint64, common.Hash, error) { |
| 201 | + var head struct { |
| 202 | + Number *hexutil.Big `json:"number"` |
| 203 | + Hash common.Hash `json:"hash"` |
| 204 | + } |
| 205 | + |
| 206 | + err := ec.rpcClient.CallContext(ctx, &head, "eth_getBlockByNumber", "latest", false) |
197 | 207 | if err != nil { |
198 | | - return nil, err |
| 208 | + return 0, common.Hash{}, err |
199 | 209 | } |
200 | 210 |
|
201 | | - return header, nil |
| 211 | + if head.Number == nil { |
| 212 | + return 0, common.Hash{}, fmt.Errorf("no latest block returned") |
| 213 | + } |
| 214 | + |
| 215 | + return head.Number.ToInt().Uint64(), head.Hash, nil |
202 | 216 | } |
203 | 217 |
|
204 | 218 | func (ec *ExecutionClient) GetLatestBlock(ctx context.Context) (*types.Block, error) { |
|
0 commit comments