Skip to content

Commit 1bf5ca3

Browse files
authored
Beacon sync maint update (#3867)
* Un-export `helpers` from `worker_desc` source why Exporting `helpers` makes the import logic too brittle when imported by the upcoming `snap` syncer. This is due to the fact that the latter will use a similar basic framework so that a clash of similar functions would be cumbersome to avoid. * Update `stand-by` mode why Setting `stand-by` mode as `start()` function argument seems top make more sense than using it as a general config option.
1 parent 95041a6 commit 1bf5ca3

File tree

11 files changed

+26
-16
lines changed

11 files changed

+26
-16
lines changed

execution_chain/sync/beacon.nim

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ proc config*(
8686
ethNode: EthereumNode;
8787
chain: ForkedChainRef;
8888
maxPeers: int;
89-
standByMode = false;
9089
) =
9190
## Complete `BeaconSyncRef` descriptor initialisation.
9291
##
@@ -103,8 +102,6 @@ proc config*(
103102
desc.addBeaconSyncProtocol(eth68)
104103

105104
desc.ctx.pool.chain = chain
106-
if standByMode:
107-
desc.ctx.pool.syncState = SyncState.standByMode
108105

109106
if not desc.lazyConfigHook.isNil:
110107
desc.lazyConfigHook(desc)
@@ -128,10 +125,23 @@ proc activate*(desc: BeaconSyncRef) =
128125
if desc.ctx.pool.syncState == SyncState.standByMode:
129126
desc.ctx.pool.syncState = SyncState.idle
130127

131-
proc start*(desc: BeaconSyncRef): bool =
128+
proc start*(desc: BeaconSyncRef; standByMode = false): bool =
129+
## This function returns `true` exactly if the run state could be changed.
130+
## The following expressions are equivalent:
131+
## * desc.start(true)
132+
## * desc.start(false) and desc.start(true)
133+
##
132134
doAssert not desc.ctx.isNil
133-
if not desc.isRunning and desc.startSync():
134-
return true
135+
if desc.isRunning:
136+
# Correct state to stand-by mode if possible
137+
if standByMode and desc.ctx.pool.syncState == SyncState.idle:
138+
desc.ctx.pool.syncState = SyncState.standByMode
139+
return true
140+
else:
141+
if standByMode:
142+
desc.ctx.pool.syncState = SyncState.standByMode
143+
if desc.startSync():
144+
return true
135145
# false
136146

137147
proc stop*(desc: BeaconSyncRef) {.async.} =

execution_chain/sync/beacon/worker.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import
1717
../../common,
1818
../../networking/p2p,
1919
./worker/headers/headers_target,
20-
./worker/[blocks, classify, headers, start_stop, update, worker_desc]
20+
./worker/[blocks, classify, headers, helpers, start_stop, update, worker_desc]
2121

2222
# ------------------------------------------------------------------------------
2323
# Public start/stop and admin functions

execution_chain/sync/beacon/worker/blocks.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import
1616
pkg/stew/[interval_set, sorted_set],
1717
../../../networking/p2p,
1818
./blocks/[blocks_blocks, blocks_helpers, blocks_queue, blocks_unproc],
19-
./worker_desc
19+
./[helpers, worker_desc]
2020

2121
export
2222
blocks_queue, blocks_unproc

execution_chain/sync/beacon/worker/blocks/blocks_blocks.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import
1616
pkg/stew/interval_set,
1717
../../../../networking/p2p,
1818
../../../wire_protocol/types,
19-
../[update, worker_desc],
19+
../[helpers, update, worker_desc],
2020
./[blocks_fetch, blocks_helpers, blocks_import, blocks_unproc]
2121

2222
# ------------------------------------------------------------------------------

execution_chain/sync/beacon/worker/blocks/blocks_fetch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import
1515
pkg/eth/[common, rlp],
1616
pkg/stew/interval_set,
1717
../../../wire_protocol,
18-
../worker_desc,
18+
../[helpers, worker_desc],
1919
./blocks_helpers
2020

2121
# ------------------------------------------------------------------------------

execution_chain/sync/beacon/worker/blocks/blocks_helpers.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import
1414
pkg/chronos,
1515
../update/update_eta,
16-
../worker_desc
16+
../[helpers, worker_desc]
1717

1818
# ------------------------------------------------------------------------------
1919
# Public functions

execution_chain/sync/beacon/worker/headers.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import
1616
pkg/eth/common,
1717
pkg/stew/[interval_set, sorted_set],
1818
./headers/[headers_headers, headers_helpers, headers_queue, headers_unproc],
19-
./worker_desc
19+
./[helpers, worker_desc]
2020

2121
export
2222
headers_queue, headers_unproc

execution_chain/sync/beacon/worker/headers/headers_fetch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import
1515
pkg/eth/[common, rlp],
1616
pkg/stew/interval_set,
1717
../../../wire_protocol,
18-
../worker_desc,
18+
../[helpers, worker_desc],
1919
./headers_helpers
2020

2121
# ------------------------------------------------------------------------------

execution_chain/sync/beacon/worker/headers/headers_headers.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import
1616
pkg/stew/interval_set,
1717
../../../../networking/p2p,
1818
../update/update_eta,
19-
../worker_desc,
19+
../[helpers, worker_desc],
2020
./[headers_fetch, headers_helpers, headers_unproc]
2121

2222
# ------------------------------------------------------------------------------

execution_chain/sync/beacon/worker/headers/headers_helpers.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import
1414
pkg/chronos,
1515
../update/update_eta,
16-
../worker_desc
16+
../[helpers, worker_desc]
1717

1818
# ------------------------------------------------------------------------------
1919
# Private helpers

0 commit comments

Comments
 (0)