Skip to content

Commit

Permalink
Checking if the block exists in the DB before requesting from Peer
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Sep 23, 2023
1 parent 1081fda commit 209c0b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
14 changes: 10 additions & 4 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (c *Core) serviceBlocks(hashNumberList []types.HashAndNumber) {
// ram, we are using the header
c.InsertChain([]*types.Block{types.NewBlockWithHeader(header)})
} else {
if !c.HasHeader(header.ParentHash(), header.NumberU64()-1) {
if c.GetHeaderOrCandidateByHash(header.ParentHash()) == nil {
c.sl.missingParentFeed.Send(header.ParentHash())
}
}
Expand All @@ -256,7 +256,9 @@ func (c *Core) RequestDomToAppendOrFetch(hash common.Hash, order int) {
_, exists := c.appendQueue.Get(hash)
if !exists {
log.Warn("Block sub asked doesnt exist in append queue, so request the peers for it", "Hash", hash, "Order", order)
c.sl.missingParentFeed.Send(hash) // Using the missing parent feed to ask for the block
if c.GetHeaderOrCandidateByHash(hash) == nil {
c.sl.missingParentFeed.Send(hash) // Using the missing parent feed to ask for the block
}
}
} else if nodeCtx == common.REGION_CTX {
if order < nodeCtx { // Prime block
Expand All @@ -267,7 +269,9 @@ func (c *Core) RequestDomToAppendOrFetch(hash common.Hash, order int) {
_, exists := c.appendQueue.Get(hash)
if !exists {
log.Warn("Block sub asked doesnt exist in append queue, so request the peers for it", "Hash", hash, "Order", order)
c.sl.missingParentFeed.Send(hash) // Using the missing parent feed to ask for the block
if c.GetHeaderOrCandidateByHash(hash) == nil {
c.sl.missingParentFeed.Send(hash) // Using the missing parent feed to ask for the block
}
}
}

Expand Down Expand Up @@ -430,7 +434,9 @@ func (c *Core) Append(header *types.Header, domPendingHeader *types.Header, domT
newPendingEtxs, subReorg, err := c.sl.Append(header, domPendingHeader, domTerminus, domOrigin, newInboundEtxs)
if err != nil {
if err.Error() == ErrBodyNotFound.Error() || err.Error() == consensus.ErrUnknownAncestor.Error() || err.Error() == ErrSubNotSyncedToDom.Error() {
c.sl.missingParentFeed.Send(header.ParentHash())
if c.GetHeaderOrCandidateByHash(header.ParentHash()) == nil {
c.sl.missingParentFeed.Send(header.ParentHash())
}
}
}
return newPendingEtxs, subReorg, err
Expand Down
12 changes: 2 additions & 10 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,8 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64) error {
}
}

// If no more headers are inbound, notify the content fetchers and return
if packet.Items() == 0 {
// No more headers, terminate the process
p.log.Debug("No more headers available")
select {
case d.headerProcCh <- nil:
return nil
case <-d.cancelCh:
return errCanceled
}
if len(headers) == 0 {
continue
}

// Prepare the resultStore to fill the skeleton.
Expand Down
2 changes: 1 addition & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
}
h.core.WriteBlock(block)
}
h.blockFetcher = fetcher.NewBlockFetcher(h.core.GetBlockByHash, writeBlock, validator, h.BroadcastBlock, heighter, h.removePeer, h.core.IsBlockHashABadHash)
h.blockFetcher = fetcher.NewBlockFetcher(h.core.GetBlockOrCandidateByHash, writeBlock, validator, h.BroadcastBlock, heighter, h.removePeer, h.core.IsBlockHashABadHash)

// Only initialize the Tx fetcher in zone
if nodeCtx == common.ZONE_CTX && h.core.ProcessingState() {
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (

// maxKnownBlocks is the maximum block hashes to keep in the known list
// before starting to randomly evict them.
maxKnownBlocks = 1024
maxKnownBlocks = 10000

// maxQueuedTxs is the maximum number of transactions to queue up before dropping
// older broadcasts.
Expand Down

0 comments on commit 209c0b2

Please sign in to comment.