Skip to content

Commit 3db12f4

Browse files
committed
consensus: identifying header by both number and hash for consensus
1 parent 6f29b02 commit 3db12f4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

consensus/dccs/2_dccs.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ func (c *Context) verifySeal2() error {
277277
return nil
278278
}
279279

280+
func (c *Context) getHeader(hash common.Hash, number uint64) *types.Header {
281+
header := c.getHeaderByNumber(number)
282+
if header != nil && header.Hash() == hash {
283+
return header
284+
}
285+
header = c.getHeaderByHash(hash)
286+
if header != nil && header.Number.Uint64() == number {
287+
return header
288+
}
289+
return nil
290+
}
291+
280292
// getHeaderByNumber returns either:
281293
// + the context head, if number == head.Number
282294
// + the header in parents if available (nessesary for batch headers processing)

consensus/dccs/2_queue.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func (c *Context) getSealingQueue(parentHash common.Hash) (*SealingQueue, error)
257257
}
258258

259259
var maxDiff uint64
260+
hash := parentHash
260261

261262
// scan backward atmost LeakDurations blocks from number
262263
for i := uint64(0); i < c.engine.config.LeakDuration; i++ {
@@ -275,9 +276,9 @@ func (c *Context) getSealingQueue(parentHash common.Hash) (*SealingQueue, error)
275276
// TODO: optimization for leakage case
276277

277278
n := number - i
278-
header := c.getHeaderByNumber(n)
279+
header := c.getHeader(hash, n)
279280
if header == nil {
280-
log.Error("getSealingQueue: getHeaderByNumber returns nil", "n", n, "len(parents)", len(c.parents))
281+
log.Error("Header not found", "number", n, "hash", hash, "len(parents)", len(c.parents))
281282
return nil, errUnknownBlock
282283
}
283284
sealer, err := c.ecrecover(header)
@@ -295,6 +296,9 @@ func (c *Context) getSealingQueue(parentHash common.Hash) (*SealingQueue, error)
295296
if i < minBlockToScan || len(recents) < int(maxDiff)/2 {
296297
addRecent(sealer)
297298
}
299+
300+
// next parent in the hash chain
301+
hash = header.ParentHash
298302
}
299303

300304
apps, err := c.crawlSealerApplications(parent)

0 commit comments

Comments
 (0)