File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,11 @@ func (api *PrivateAdminAPI) EtcdDeleteWork() error {
318
318
return metaapi .EtcdDeleteWork ()
319
319
}
320
320
321
+ // Synchronize with the given peer
322
+ func (api * PrivateAdminAPI ) SynchroniseWith (id enode.ID ) error {
323
+ return api .eth .handler .SynchroniseWith (id )
324
+ }
325
+
321
326
// PublicDebugAPI is the collection of Ethereum full node APIs exposed
322
327
// over the public debugging endpoint.
323
328
type PublicDebugAPI struct {
Original file line number Diff line number Diff line change @@ -552,3 +552,16 @@ func (h *handler) RequestEtcdAddMember(id enode.ID) error {
552
552
return ethereum .NotFound
553
553
}
554
554
}
555
+
556
+ func (h * handler ) SynchroniseWith (id enode.ID ) error {
557
+ if p := h .peers .peer (id .String ()); p != nil {
558
+ if op , err := h .chainSync .peerSyncOp (p .Peer ); err != nil {
559
+ return err
560
+ } else if op != nil {
561
+ return h .doSync (op )
562
+ }
563
+ return nil
564
+ } else {
565
+ return ethereum .NotFound
566
+ }
567
+ }
Original file line number Diff line number Diff line change 17
17
package eth
18
18
19
19
import (
20
+ "errors"
20
21
"math/big"
21
22
"math/rand"
22
23
"sync/atomic"
@@ -271,6 +272,27 @@ func (cs *chainSyncer) nextSyncOp() *chainSyncOp {
271
272
return op
272
273
}
273
274
275
+ func (cs * chainSyncer ) peerSyncOp (p * eth.Peer ) (* chainSyncOp , error ) {
276
+ if cs .doneCh != nil {
277
+ // Sync already running
278
+ return nil , errors .New ("sync already in progress" )
279
+ } else if metaminer .AmPartner () && ! metaminer .IsPartner (p .ID ()) {
280
+ return nil , errors .New ("not a miner" )
281
+ }
282
+
283
+ mode , ourTD := cs .modeAndLocalHead ()
284
+ if mode == downloader .FastSync && atomic .LoadUint32 (& cs .handler .snapSync ) == 1 {
285
+ // Fast sync via the snap protocol
286
+ mode = downloader .SnapSync
287
+ }
288
+ op := peerToSyncOp (mode , p )
289
+ if op .td .Cmp (ourTD ) <= 0 {
290
+ // We're in sync.
291
+ return nil , nil
292
+ }
293
+ return op , nil
294
+ }
295
+
274
296
func peerToSyncOp (mode downloader.SyncMode , p * eth.Peer ) * chainSyncOp {
275
297
peerHead , peerTD := p .Head ()
276
298
return & chainSyncOp {mode : mode , peer : p , td : peerTD , head : peerHead }
You can’t perform that action at this time.
0 commit comments