@@ -34,7 +34,6 @@ import (
3434// directed by the skeleton sync's head/tail events.
3535type beaconBackfiller struct {
3636 downloader * Downloader // Downloader to direct via this callback implementation
37- syncMode SyncMode // Sync mode to use for backfilling the skeleton chains
3837 success func () // Callback to run on successful sync cycle completion
3938 filling bool // Flag whether the downloader is backfilling or not
4039 filled * types.Header // Last header filled by the last terminated sync loop
@@ -92,7 +91,6 @@ func (b *beaconBackfiller) resume() {
9291 b .filling = true
9392 b .filled = nil
9493 b .started = make (chan struct {})
95- mode := b .syncMode
9694 b .lock .Unlock ()
9795
9896 // Start the backfilling on its own thread since the downloader does not have
@@ -107,7 +105,7 @@ func (b *beaconBackfiller) resume() {
107105 }()
108106 // If the downloader fails, report an error as in beacon chain mode there
109107 // should be no errors as long as the chain we're syncing to is valid.
110- if err := b .downloader .synchronise (mode , b .started ); err != nil {
108+ if err := b .downloader .synchronise (b .started ); err != nil {
111109 log .Error ("Beacon backfilling failed" , "err" , err )
112110 return
113111 }
@@ -119,27 +117,6 @@ func (b *beaconBackfiller) resume() {
119117 }()
120118}
121119
122- // setMode updates the sync mode from the current one to the requested one. If
123- // there's an active sync in progress, it will be cancelled and restarted.
124- func (b * beaconBackfiller ) setMode (mode SyncMode ) {
125- // Update the old sync mode and track if it was changed
126- b .lock .Lock ()
127- oldMode := b .syncMode
128- updated := oldMode != mode
129- filling := b .filling
130- b .syncMode = mode
131- b .lock .Unlock ()
132-
133- // If the sync mode was changed mid-sync, restart. This should never ever
134- // really happen, we just handle it to detect programming errors.
135- if ! updated || ! filling {
136- return
137- }
138- log .Error ("Downloader sync mode changed mid-run" , "old" , oldMode .String (), "new" , mode .String ())
139- b .suspend ()
140- b .resume ()
141- }
142-
143120// SetBadBlockCallback sets the callback to run when a bad block is hit by the
144121// block processor. This method is not thread safe and should be set only once
145122// on startup before system events are fired.
@@ -153,8 +130,8 @@ func (d *Downloader) SetBadBlockCallback(onBadBlock badBlockFn) {
153130//
154131// Internally backfilling and state sync is done the same way, but the header
155132// retrieval and scheduling is replaced.
156- func (d * Downloader ) BeaconSync (mode SyncMode , head * types.Header , final * types.Header ) error {
157- return d .beaconSync (mode , head , final , true )
133+ func (d * Downloader ) BeaconSync (head * types.Header , final * types.Header ) error {
134+ return d .beaconSync (head , final , true )
158135}
159136
160137// BeaconExtend is an optimistic version of BeaconSync, where an attempt is made
@@ -163,8 +140,8 @@ func (d *Downloader) BeaconSync(mode SyncMode, head *types.Header, final *types.
163140//
164141// This is useful if a beacon client is feeding us large chunks of payloads to run,
165142// but is not setting the head after each.
166- func (d * Downloader ) BeaconExtend (mode SyncMode , head * types.Header ) error {
167- return d .beaconSync (mode , head , nil , false )
143+ func (d * Downloader ) BeaconExtend (head * types.Header ) error {
144+ return d .beaconSync (head , nil , false )
168145}
169146
170147// beaconSync is the post-merge version of the chain synchronization, where the
@@ -173,20 +150,9 @@ func (d *Downloader) BeaconExtend(mode SyncMode, head *types.Header) error {
173150//
174151// Internally backfilling and state sync is done the same way, but the header
175152// retrieval and scheduling is replaced.
176- func (d * Downloader ) beaconSync (mode SyncMode , head * types.Header , final * types.Header , force bool ) error {
177- // When the downloader starts a sync cycle, it needs to be aware of the sync
178- // mode to use (full, snap). To keep the skeleton chain oblivious, inject the
179- // mode into the backfiller directly.
180- //
181- // Super crazy dangerous type cast. Should be fine (TM), we're only using a
182- // different backfiller implementation for skeleton tests.
183- d .skeleton .filler .(* beaconBackfiller ).setMode (mode )
184-
153+ func (d * Downloader ) beaconSync (head * types.Header , final * types.Header , force bool ) error {
185154 // Signal the skeleton sync to switch to a new head, however it wants
186- if err := d .skeleton .Sync (head , final , force ); err != nil {
187- return err
188- }
189- return nil
155+ return d .skeleton .Sync (head , final , force )
190156}
191157
192158// findBeaconAncestor tries to locate the common ancestor link of the local chain
0 commit comments