Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions beacon/blsync/block_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,8 @@ func (s *beaconBlockSync) updateEventFeed() {
Finalized: finalizedHash,
})
}

func (s *beaconBlockSync) getBlock(blockRoot common.Hash) *types.BeaconBlock {
block, _ := s.recentBlocks.Get(blockRoot)
return block
}
18 changes: 14 additions & 4 deletions beacon/blsync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/restapi"
"github.com/ethereum/go-ethereum/rpc"
)

Expand All @@ -38,12 +39,13 @@ type Client struct {
scheduler *request.Scheduler
blockSync *beaconBlockSync
engineRPC *rpc.Client
apiServer *api.BeaconApiServer

chainHeadSub event.Subscription
engineClient *engineClient
}

func NewClient(config params.ClientConfig) *Client {
func NewClient(config params.ClientConfig, execChain api.ExecChain) *Client {
// create data structures
var (
db = memorydb.New()
Expand All @@ -55,12 +57,13 @@ func NewClient(config params.ClientConfig) *Client {
log.Error("Failed to save beacon checkpoint", "file", config.CheckpointFile, "checkpoint", checkpoint, "error", err)
}
})
checkpointStore = light.NewCheckpointStore(db, committeeChain)
)
headSync := sync.NewHeadSync(headTracker, committeeChain)

// set up scheduler and sync modules
scheduler := request.NewScheduler()
checkpointInit := sync.NewCheckpointInit(committeeChain, config.Checkpoint)
checkpointInit := sync.NewCheckpointInit(committeeChain, checkpointStore, config.Checkpoint)
forwardSync := sync.NewForwardUpdateSync(committeeChain)
beaconBlockSync := newBeaconBlockSync(headTracker)
scheduler.RegisterTarget(headTracker)
Expand All @@ -69,34 +72,41 @@ func NewClient(config params.ClientConfig) *Client {
scheduler.RegisterModule(forwardSync, "forwardSync")
scheduler.RegisterModule(headSync, "headSync")
scheduler.RegisterModule(beaconBlockSync, "beaconBlockSync")
apiServer := api.NewBeaconApiServer(scheduler, checkpointStore, committeeChain, headTracker, beaconBlockSync.getBlock, execChain)

return &Client{
scheduler: scheduler,
urls: config.Apis,
customHeader: config.CustomHeader,
config: &config,
blockSync: beaconBlockSync,
apiServer: apiServer,
}
}

func (c *Client) SetEngineRPC(engine *rpc.Client) {
c.engineRPC = engine
}

func (c *Client) RestAPI(server *restapi.Server) restapi.API {
return c.apiServer.RestAPI(server)
}

func (c *Client) Start() error {
headCh := make(chan types.ChainHeadEvent, 16)
c.chainHeadSub = c.blockSync.SubscribeChainHead(headCh)
c.engineClient = startEngineClient(c.config, c.engineRPC, headCh)

c.scheduler.Start()
for _, url := range c.urls {
beaconApi := api.NewBeaconLightApi(url, c.customHeader)
c.scheduler.RegisterServer(request.NewServer(api.NewApiServer(beaconApi), &mclock.System{}))
beaconApi := api.NewBeaconApiClient(url, c.customHeader)
c.scheduler.RegisterServer(request.NewServer(api.NewSyncServer(beaconApi), &mclock.System{}))
}
return nil
}

func (c *Client) Stop() error {
c.apiServer.Stop()
c.engineClient.stop()
c.chainHeadSub.Unsubscribe()
c.scheduler.Stop()
Expand Down
Loading
Loading