MCPcopy Create free account
hub / github.com/ethstorage/es-node / startL1

Method startL1

ethstorage/node/node.go:179–220  ·  view source on GitHub ↗
(cfg *Config)

Source from the content-addressed store, hash-verified

177}
178
179func (n *EsNode) startL1(cfg *Config) {
180 // Keep subscribed to the L1 heads, which keeps the L1 maintainer pointing to the best headers to sync
181 n.l1HeadsSub = event.ResubscribeErr(time.Second*10, func(ctx context.Context, err error) (event.Subscription, error) {
182 if err != nil {
183 n.lg.Warn("Resubscribing after failed L1 subscription", "err", err)
184 }
185 return eth.WatchHeadChanges(n.resourcesCtx, n.l1Source, n.OnNewL1Head)
186 })
187 go func() {
188 err, ok := <-n.l1HeadsSub.Err()
189 if !ok {
190 return
191 }
192 n.lg.Error("L1 heads subscription error", "err", err)
193 }()
194 if n.miner != nil {
195 // Keep subscribed to the randao heads, which helps miner to get proper random seeds
196 n.randaoHeadsSub = event.ResubscribeErr(time.Second*10, func(ctx context.Context, err error) (event.Subscription, error) {
197 if err != nil {
198 n.lg.Warn("Resubscribing after failed randao head subscription", "err", err)
199 }
200 if n.randaoSource != nil {
201 return eth.WatchHeadChanges(n.resourcesCtx, n.randaoSource, n.OnNewRandaoSourceHead)
202 } else {
203 return eth.WatchHeadChanges(n.resourcesCtx, n.l1Source, n.OnNewRandaoSourceHead)
204 }
205 })
206 go func() {
207 err, ok := <-n.randaoHeadsSub.Err()
208 if !ok {
209 return
210 }
211 n.lg.Error("Randao heads subscription error", "err", err)
212 }()
213 }
214 // Poll for the safe L1 block and finalized block,
215 // which only change once per epoch at most and may be delayed.
216 n.l1SafeSub = eth.PollBlockChanges(n.resourcesCtx, n.lg, n.l1Source, n.OnNewL1Safe, ethRPC.SafeBlockNumber,
217 cfg.L1EpochPollInterval, time.Second*10)
218 n.l1FinalizedSub = eth.PollBlockChanges(n.resourcesCtx, n.lg, n.l1Source, n.OnNewL1Finalized, ethRPC.FinalizedBlockNumber,
219 cfg.L1EpochPollInterval, time.Second*10)
220}
221
222func (n *EsNode) initP2P(ctx context.Context, cfg *Config) error {
223 if cfg.P2P != nil {

Callers 1

StartMethod · 0.95

Calls 3

WatchHeadChangesFunction · 0.92
PollBlockChangesFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected