Skip to content

Commit 327e7d9

Browse files
AlexeyAkhunovAskAlexSharovGiulio2002awskiimandrigin
authored
[alpha] Move header stuck fix from devel (#4226)
* allow --syncmode=snap for bor-mainnnet (#4206) * save * save * allow --syncmode=snap for bor-mainnnet #4206 * allow snap sync for mumbai chain (#4208) * save * mumbai * Bor: GetTransactionReceipt (#4209) * fixed miner.sigfile option (#4210) * Snap: reduced memory footprint on building huffman table (#4214) * save * save * save * save * Remove dependency on leveldb (#4213) * save * save * save * save * save * save * methods to read single txn by txnID (#4215) * It's safe now to open snapshots at app start (#4216) * removed obsolete trie variant (#4172) * up gods lib version (#4217) * Fix `rpc.BlockNumberOrHash` unmarshaling (#4218) * add test * fix unmarshaling bug Co-authored-by: Igor Mandrigin <i@mandrigin.ru> * return err on invalid syncmode (#4219) * save * save * save * fixed kiln bug (#4221) * Clean headers pointers when removing links (#4222) * Clean headers pointers when removing links * Replace the lock Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> * Makefile: pass docker build arguments (#4212) Dockerfile requires some --build-arg options. Fix "docker" target to pass them. Fix GIT_TAG to reflect the most recent tag related to HEAD, instead of an unrelated most recent tag. Use it as the image VERSION. Image tags need to be passed explicitly if needed: DOCKER_FLAGS='-t erigon:latest' make docker * More header download diagnostics (#4224) Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> * Clean anchors, forward sort of headers (#4225) Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com> Co-authored-by: Giulio rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Artem Tsebrovskiy <awskii@users.noreply.github.com> Co-authored-by: Igor Mandrigin <mandrigin@users.noreply.github.com> Co-authored-by: Igor Mandrigin <i@mandrigin.ru> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: battlmonstr <battlmonstr@users.noreply.github.com>
1 parent ad822cf commit 327e7d9

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

cmd/sentry/sentry/sentry_multy_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func (cs *MultyClient) blockHeaders(ctx context.Context, pkt eth.BlockHeadersPac
488488
})
489489
}
490490
if cs.Hd.POSSync() {
491-
sort.Sort(headerdownload.HeadersByHeightAndHash(csHeaders)) // Sorting by reverse order of block heights
491+
sort.Sort(headerdownload.HeadersReverseSort(csHeaders)) // Sorting by reverse order of block heights
492492
tx, err := cs.db.BeginRo(ctx)
493493
defer tx.Rollback()
494494
if err != nil {
@@ -502,6 +502,7 @@ func (cs *MultyClient) blockHeaders(ctx context.Context, pkt eth.BlockHeadersPac
502502
cs.Penalize(ctx, penalties)
503503
}
504504
} else {
505+
sort.Sort(headerdownload.HeadersSort(csHeaders)) // Sorting by order of block heights
505506
canRequestMore := cs.Hd.ProcessHeaders(csHeaders, false /* newBlock */, ConvertH512ToPeerID(peerID))
506507

507508
if canRequestMore {

eth/stagedsync/stage_headers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ Loop:
821821
log.Info("Req/resp stats", "req", reqCount, "reqMin", reqMin, "reqMax", reqMax,
822822
"skel", skeletonReqCount, "skelMin", skeletonReqMin, "skelMax", skeletonReqMax,
823823
"resp", respCount, "respMin", respMin, "respMax", respMax)
824-
824+
cfg.hd.LogAnchorState()
825825
if noProgressCounter >= 5 && wasProgress {
826826
log.Warn("Looks like chain is not progressing, moving to the next stage")
827827
break Loop

turbo/stages/headerdownload/header_algos.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,40 @@ const POSPandaBanner = `
5656
`
5757

5858
// Implements sort.Interface so we can sort the incoming header in the message by block height
59-
type HeadersByHeightAndHash []ChainSegmentHeader
59+
type HeadersReverseSort []ChainSegmentHeader
6060

61-
func (h HeadersByHeightAndHash) Len() int {
61+
func (h HeadersReverseSort) Len() int {
6262
return len(h)
6363
}
6464

65-
func (h HeadersByHeightAndHash) Less(i, j int) bool {
65+
func (h HeadersReverseSort) Less(i, j int) bool {
6666
// Note - the ordering is the inverse ordering of the block heights
6767
if h[i].Number != h[j].Number {
6868
return h[i].Number > h[j].Number
6969
}
7070
return bytes.Compare(h[i].Hash[:], h[j].Hash[:]) > 0
7171
}
7272

73-
func (h HeadersByHeightAndHash) Swap(i, j int) {
73+
func (h HeadersReverseSort) Swap(i, j int) {
74+
h[i], h[j] = h[j], h[i]
75+
}
76+
77+
// Implements sort.Interface so we can sort the incoming header in the message by block height
78+
type HeadersSort []ChainSegmentHeader
79+
80+
func (h HeadersSort) Len() int {
81+
return len(h)
82+
}
83+
84+
func (h HeadersSort) Less(i, j int) bool {
85+
// Note - the ordering is the inverse ordering of the block heights
86+
if h[i].Number != h[j].Number {
87+
return h[i].Number < h[j].Number
88+
}
89+
return bytes.Compare(h[i].Hash[:], h[j].Hash[:]) < 0
90+
}
91+
92+
func (h HeadersSort) Swap(i, j int) {
7493
h[i], h[j] = h[j], h[i]
7594
}
7695

@@ -208,17 +227,20 @@ func (hd *HeaderDownload) pruneLinkQueue() {
208227
} else {
209228
prevChild.next = link.next
210229
}
230+
if anchor.fLink == nil {
231+
hd.removeAnchor(anchor)
232+
}
211233
}
212234
}
213235
}
214236

215-
func (hd *HeaderDownload) AnchorState() string {
237+
func (hd *HeaderDownload) LogAnchorState() {
216238
hd.lock.RLock()
217239
defer hd.lock.RUnlock()
218-
return hd.anchorState()
240+
hd.logAnchorState()
219241
}
220242

221-
func (hd *HeaderDownload) anchorState() string {
243+
func (hd *HeaderDownload) logAnchorState() {
222244
//nolint:prealloc
223245
var ss []string
224246
for anchorParent, anchor := range hd.anchors {
@@ -276,7 +298,9 @@ func (hd *HeaderDownload) anchorState() string {
276298
ss = append(ss, sb.String())
277299
}
278300
sort.Strings(ss)
279-
return strings.Join(ss, "\n")
301+
for _, s := range ss {
302+
log.Info(s)
303+
}
280304
}
281305

282306
func (hd *HeaderDownload) RecoverFromDb(db kv.RoDB) error {
@@ -877,7 +901,7 @@ func (hd *HeaderDownload) ProcessHeader(sh ChainSegmentHeader, newBlock bool, pe
877901
return false
878902
}
879903
if len(hd.anchors) >= hd.anchorLimit {
880-
log.Debug(fmt.Sprintf("too many anchors: %d, limit %d, state: %s", len(hd.anchors), hd.anchorLimit, hd.anchorState()))
904+
log.Debug(fmt.Sprintf("too many anchors: %d, limit %d", len(hd.anchors), hd.anchorLimit))
881905
return false
882906
}
883907
}

0 commit comments

Comments
 (0)