Skip to content

Commit

Permalink
Flags and interfaces for historical RPC requests (ethereum#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurelian authored and protolambda committed Nov 4, 2022
1 parent 5351dc4 commit 0caa739
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,11 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re
func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
return b.eth.stateAtTransaction(block, txIndex, reexec)
}

func (b *EthAPIBackend) SequencerRPCService() *rpc.Client {
return b.eth.seqRPCService
}

func (b *EthAPIBackend) Genesis() *types.Block {
return b.eth.blockchain.Genesis()
}
2 changes: 2 additions & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type Backend interface {

ChainConfig() *params.ChainConfig
Engine() consensus.Engine
SequencerRPCService() *rpc.Client
Genesis() *types.Block

// eth/filters needs to be initialized from this backend type, so methods needed by
// it must also be included here.
Expand Down
4 changes: 3 additions & 1 deletion internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,6 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)
return nil
}

func (b *backendMock) Engine() consensus.Engine { return nil }
func (b *backendMock) Engine() consensus.Engine { return nil }
func (b *backendMock) SequencerRPCService() *rpc.Client { return nil }
func (b *backendMock) Genesis() *types.Block { return nil }
8 changes: 8 additions & 0 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,11 @@ func (b *LesApiBackend) StateAtBlock(ctx context.Context, block *types.Block, re
func (b *LesApiBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
return b.eth.stateAtTransaction(ctx, block, txIndex, reexec)
}

func (b *LesApiBackend) SequencerRPCService() *rpc.Client {
return b.eth.seqRPCService
}

func (b *LesApiBackend) Genesis() *types.Block {
return b.eth.blockchain.Genesis()
}
24 changes: 24 additions & 0 deletions les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package les

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -66,6 +67,9 @@ type LightEthereum struct {
pruner *pruner
merger *consensus.Merger

seqRPCService *rpc.Client
historicalRPCService *rpc.Client

bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports

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

if config.RollupSequencerHTTP != "" {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
client, err := rpc.DialContext(ctx, config.RollupSequencerHTTP)
cancel()
if err != nil {
return nil, err
}
leth.seqRPCService = client
}

if config.RollupHistoricalRPC != "" {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
client, err := rpc.DialContext(ctx, config.RollupHistoricalRPC)
cancel()
if err != nil {
return nil, err
}
leth.historicalRPCService = client
}

leth.netRPCService = ethapi.NewNetAPI(leth.p2pServer, leth.config.NetworkId)

// Register the backend on the node
Expand Down

0 comments on commit 0caa739

Please sign in to comment.