Skip to content

Commit 930568b

Browse files
committed
sync: remove step from sync client implementation
Deprecated in the spec: ethereum/consensus-specs#2856 - future PR:s will deprecate server support as well.
1 parent 85d0234 commit 930568b

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

beacon_chain/sync/sync_manager.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ proc getBlocks*[A, B](man: SyncManager[A, B], peer: A,
165165
try:
166166
let res =
167167
if peer.useSyncV2():
168-
await beaconBlocksByRange_v2(peer, req.slot, req.count, req.step)
168+
await beaconBlocksByRange_v2(peer, req.slot, req.count, 1)
169169
else:
170-
(await beaconBlocksByRange(peer, req.slot, req.count, req.step)).map(
170+
(await beaconBlocksByRange(peer, req.slot, req.count, 1)).map(
171171
proc(blcks: seq[phase0.SignedBeaconBlock]): auto =
172172
blcks.mapIt(newClone(ForkedSignedBeaconBlock.init(it))))
173173

beacon_chain/sync/sync_protocol.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ p2pProtocol BeaconSync(version = 1,
266266
# client call that returns `seq[ref SignedBeaconBlock]` will
267267
# will be generated by the libp2p macro - we guarantee that seq items
268268
# are `not-nil` in the implementation
269+
# TODO reqStep is deprecated - future versions can remove support for
270+
# values != 1: https://github.com/ethereum/consensus-specs/pull/2856
269271
trace "got range request", peer, startSlot,
270272
count = reqCount, step = reqStep
271273
if reqCount == 0'u64 or reqStep == 0'u64:
@@ -404,6 +406,8 @@ p2pProtocol BeaconSync(version = 1,
404406
# client call that returns `seq[ref ForkedSignedBeaconBlock]` will
405407
# will be generated by the libp2p macro - we guarantee that seq items
406408
# are `not-nil` in the implementation
409+
# TODO reqStep is deprecated - future versions can remove support for
410+
# values != 1: https://github.com/ethereum/consensus-specs/pull/2856
407411

408412
trace "got range request", peer, startSlot,
409413
count = reqCount, step = reqStep

beacon_chain/sync/sync_queue.nim

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type
3838
index*: uint64
3939
slot*: Slot
4040
count*: uint64
41-
step*: uint64
4241
item*: T
4342

4443
SyncResult*[T] = object
@@ -105,12 +104,12 @@ proc getShortMap*[T](req: SyncRequest[T],
105104
break
106105
else:
107106
res.add('.')
108-
slider = slider + req.step
107+
slider = slider + 1
109108
res
110109

111110
proc contains*[T](req: SyncRequest[T], slot: Slot): bool {.inline.} =
112-
slot >= req.slot and slot < req.slot + req.count * req.step and
113-
((slot - req.slot) mod req.step == 0)
111+
slot >= req.slot and slot < req.slot + req.count and
112+
((slot - req.slot) == 0)
114113

115114
proc cmp*[T](a, b: SyncRequest[T]): int =
116115
cmp(uint64(a.slot), uint64(b.slot))
@@ -137,7 +136,7 @@ proc checkResponse*[T](req: SyncRequest[T],
137136
inc(dindex)
138137
else:
139138
return false
140-
slot = slot + req.step
139+
slot = slot + 1
141140
rindex = rindex + 1'u64
142141

143142
if dindex == len(data):
@@ -153,26 +152,26 @@ proc getFullMap*[T](req: SyncRequest[T],
153152
proc init[T](t1: typedesc[SyncRequest], kind: SyncQueueKind, start: Slot,
154153
finish: Slot, t2: typedesc[T]): SyncRequest[T] =
155154
let count = finish - start + 1'u64
156-
SyncRequest[T](kind: kind, slot: start, count: count, step: 1'u64)
155+
SyncRequest[T](kind: kind, slot: start, count: count)
157156

158157
proc init[T](t1: typedesc[SyncRequest], kind: SyncQueueKind, slot: Slot,
159158
count: uint64, item: T): SyncRequest[T] =
160-
SyncRequest[T](kind: kind, slot: slot, count: count, item: item, step: 1'u64)
159+
SyncRequest[T](kind: kind, slot: slot, count: count, item: item)
161160

162161
proc init[T](t1: typedesc[SyncRequest], kind: SyncQueueKind, start: Slot,
163162
finish: Slot, item: T): SyncRequest[T] =
164163
let count = finish - start + 1'u64
165-
SyncRequest[T](kind: kind, slot: start, count: count, step: 1'u64, item: item)
164+
SyncRequest[T](kind: kind, slot: start, count: count, item: item)
166165

167166
proc empty*[T](t: typedesc[SyncRequest], kind: SyncQueueKind,
168167
t2: typedesc[T]): SyncRequest[T] {.inline.} =
169-
SyncRequest[T](kind: kind, step: 0'u64, count: 0'u64)
168+
SyncRequest[T](kind: kind, count: 0'u64)
170169

171170
proc setItem*[T](sr: var SyncRequest[T], item: T) =
172171
sr.item = item
173172

174173
proc isEmpty*[T](sr: SyncRequest[T]): bool {.inline.} =
175-
(sr.step == 0'u64) and (sr.count == 0'u64)
174+
(sr.count == 0'u64)
176175

177176
proc init*[T](t1: typedesc[SyncQueue], t2: typedesc[T],
178177
queueKind: SyncQueueKind,
@@ -263,8 +262,7 @@ proc `<`*[T](a, b: SyncResult[T]): bool =
263262
a.request.slot > b.request.slot
264263

265264
proc `==`*[T](a, b: SyncRequest[T]): bool =
266-
(a.kind == b.kind) and (a.slot == b.slot) and (a.count == b.count) and
267-
(a.step == b.step)
265+
(a.kind == b.kind) and (a.slot == b.slot) and (a.count == b.count)
268266

269267
proc lastSlot*[T](req: SyncRequest[T]): Slot =
270268
## Returns last slot for request ``req``.
@@ -808,12 +806,10 @@ func updateRequestForNewSafeSlot[T](sq: SyncQueue[T], sr: var SyncRequest[T]) =
808806
# Request is only partially relevant.
809807
let
810808
numSlotsDone = outSlot - lowSlot
811-
numStepsDone = (numSlotsDone + sr.step - 1) div sr.step
812-
sr.slot += numStepsDone * sr.step
813-
sr.count -= numStepsDone
809+
sr.slot += numSlotsDone
810+
sr.count -= numSlotsDone
814811
else:
815812
# Entire request is no longer relevant.
816-
sr.step = 0
817813
sr.count = 0
818814
of SyncQueueKind.Backward:
819815
if outSlot >= highSlot:
@@ -823,11 +819,9 @@ func updateRequestForNewSafeSlot[T](sq: SyncQueue[T], sr: var SyncRequest[T]) =
823819
# Request is only partially relevant.
824820
let
825821
numSlotsDone = highSlot - outSlot
826-
numStepsDone = (numSlotsDone + sr.step - 1) div sr.step
827-
sr.count -= numStepsDone
822+
sr.count -= numSlotsDone
828823
else:
829824
# Entire request is no longer relevant.
830-
sr.step = 0
831825
sr.count = 0
832826

833827
proc pop*[T](sq: SyncQueue[T], maxslot: Slot, item: T): SyncRequest[T] =

0 commit comments

Comments
 (0)