Skip to content

Commit 0caa739

Browse files
maurelianprotolambda
authored andcommitted
Flags and interfaces for historical RPC requests (ethereum#12)
1 parent 5351dc4 commit 0caa739

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

eth/api_backend.go

+8
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,11 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re
382382
func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
383383
return b.eth.stateAtTransaction(block, txIndex, reexec)
384384
}
385+
386+
func (b *EthAPIBackend) SequencerRPCService() *rpc.Client {
387+
return b.eth.seqRPCService
388+
}
389+
390+
func (b *EthAPIBackend) Genesis() *types.Block {
391+
return b.eth.blockchain.Genesis()
392+
}

internal/ethapi/backend.go

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ type Backend interface {
8686

8787
ChainConfig() *params.ChainConfig
8888
Engine() consensus.Engine
89+
SequencerRPCService() *rpc.Client
90+
Genesis() *types.Block
8991

9092
// eth/filters needs to be initialized from this backend type, so methods needed by
9193
// it must also be included here.

internal/ethapi/transaction_args_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,6 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)
339339
return nil
340340
}
341341

342-
func (b *backendMock) Engine() consensus.Engine { return nil }
342+
func (b *backendMock) Engine() consensus.Engine { return nil }
343+
func (b *backendMock) SequencerRPCService() *rpc.Client { return nil }
344+
func (b *backendMock) Genesis() *types.Block { return nil }

les/api_backend.go

+8
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,11 @@ func (b *LesApiBackend) StateAtBlock(ctx context.Context, block *types.Block, re
330330
func (b *LesApiBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
331331
return b.eth.stateAtTransaction(ctx, block, txIndex, reexec)
332332
}
333+
334+
func (b *LesApiBackend) SequencerRPCService() *rpc.Client {
335+
return b.eth.seqRPCService
336+
}
337+
338+
func (b *LesApiBackend) Genesis() *types.Block {
339+
return b.eth.blockchain.Genesis()
340+
}

les/client.go

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package les
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"strings"
2324
"time"
@@ -66,6 +67,9 @@ type LightEthereum struct {
6667
pruner *pruner
6768
merger *consensus.Merger
6869

70+
seqRPCService *rpc.Client
71+
historicalRPCService *rpc.Client
72+
6973
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
7074
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
7175

@@ -195,6 +199,26 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
195199
leth.blockchain.DisableCheckFreq()
196200
}
197201

202+
if config.RollupSequencerHTTP != "" {
203+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
204+
client, err := rpc.DialContext(ctx, config.RollupSequencerHTTP)
205+
cancel()
206+
if err != nil {
207+
return nil, err
208+
}
209+
leth.seqRPCService = client
210+
}
211+
212+
if config.RollupHistoricalRPC != "" {
213+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
214+
client, err := rpc.DialContext(ctx, config.RollupHistoricalRPC)
215+
cancel()
216+
if err != nil {
217+
return nil, err
218+
}
219+
leth.historicalRPCService = client
220+
}
221+
198222
leth.netRPCService = ethapi.NewNetAPI(leth.p2pServer, leth.config.NetworkId)
199223

200224
// Register the backend on the node

0 commit comments

Comments
 (0)