From bf94b422dd000f2a0ad33383d6746c0b76c90c74 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 9 Jan 2026 12:11:17 +0800 Subject: [PATCH] fast polling --- ethstorage/node/node.go | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ethstorage/node/node.go b/ethstorage/node/node.go index 180ba628..bcae2d6e 100644 --- a/ethstorage/node/node.go +++ b/ethstorage/node/node.go @@ -147,7 +147,7 @@ func (n *EsNode) initL2(ctx context.Context, cfg *Config) error { } func (n *EsNode) initL1(ctx context.Context, cfg *Config) error { - client, err := eth.Dial(cfg.L1.L1NodeAddr, cfg.Storage.L1Contract, cfg.L1.L1BlockTime, n.lg) + client, err := eth.Dial(cfg.L1.L1NodeAddr, cfg.Storage.L1Contract, 1, n.lg) if err != nil { return fmt.Errorf("failed to create L1 source: %w", err) } @@ -166,7 +166,7 @@ func (n *EsNode) initL1(ctx context.Context, cfg *Config) error { return fmt.Errorf("no L1 beacon or DA URL provided") } if cfg.RandaoSourceURL != "" { - rc, err := eth.DialRandaoSource(ctx, cfg.RandaoSourceURL, cfg.L1.L1NodeAddr, cfg.L1.L1BlockTime, n.lg) + rc, err := eth.DialRandaoSource(ctx, cfg.RandaoSourceURL, cfg.L1.L1NodeAddr, 1, n.lg) if err != nil { return fmt.Errorf("failed to create randao source: %w", err) } @@ -191,26 +191,26 @@ func (n *EsNode) startL1(cfg *Config) { } n.lg.Error("L1 heads subscription error", "err", err) }() - - // Keep subscribed to the randao heads, which helps miner to get proper random seeds - n.randaoHeadsSub = event.ResubscribeErr(time.Second*10, func(ctx context.Context, err error) (event.Subscription, error) { - if err != nil { - n.lg.Warn("Resubscribing after failed randao head subscription", "err", err) - } - if n.randaoSource != nil { - return eth.WatchHeadChanges(n.resourcesCtx, n.randaoSource, n.OnNewRandaoSourceHead) - } else { - return eth.WatchHeadChanges(n.resourcesCtx, n.l1Source, n.OnNewRandaoSourceHead) - } - }) - go func() { - err, ok := <-n.randaoHeadsSub.Err() - if !ok { - return - } - n.lg.Error("Randao heads subscription error", "err", err) - }() - + if n.miner != nil { + // Keep subscribed to the randao heads, which helps miner to get proper random seeds + n.randaoHeadsSub = event.ResubscribeErr(time.Second*10, func(ctx context.Context, err error) (event.Subscription, error) { + if err != nil { + n.lg.Warn("Resubscribing after failed randao head subscription", "err", err) + } + if n.randaoSource != nil { + return eth.WatchHeadChanges(n.resourcesCtx, n.randaoSource, n.OnNewRandaoSourceHead) + } else { + return eth.WatchHeadChanges(n.resourcesCtx, n.l1Source, n.OnNewRandaoSourceHead) + } + }) + go func() { + err, ok := <-n.randaoHeadsSub.Err() + if !ok { + return + } + n.lg.Error("Randao heads subscription error", "err", err) + }() + } // Poll for the safe L1 block and finalized block, // which only change once per epoch at most and may be delayed. n.l1SafeSub = eth.PollBlockChanges(n.resourcesCtx, n.lg, n.l1Source, n.OnNewL1Safe, ethRPC.SafeBlockNumber,