Skip to content

Commit

Permalink
adjusted subscriptions as well as the handling of workObjectHeaderVie…
Browse files Browse the repository at this point in the history
…ws in handler
  • Loading branch information
kiltsonfire authored and Djadih committed May 20, 2024
1 parent 9bf807d commit e0e597c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 10 additions & 6 deletions cmd/utils/hierarchical_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@ func (hc *HierarchicalCoordinator) startNode(logPath string, quaiBackend quai.Co
quaiBackend.SetApiBackend(&apiBackend, location)

// Only subscribe to block and transaction data if processing state
if quaiBackend.ProcessingState(location) {
hc.p2p.Subscribe(location, &types.WorkObjectBlockView{})
hc.p2p.Subscribe(location, &types.Transactions{})
if !quaiBackend.ProcessingState(location) && location.Context() == common.ZONE_CTX {
hc.p2p.Subscribe(location, &types.WorkObjectHeaderView{})
}

if quaiBackend.ProcessingState(location) && location.Context() == common.ZONE_CTX {
// Subscribe to the new topics after setting the api backend
hc.p2p.Subscribe(location, &types.WorkObjectHeader{})
hc.p2p.Subscribe(location, &types.Transactions{})
}

// Subscribe to the new topics after setting the api backend
hc.p2p.Subscribe(location, &types.WorkObjectHeaderView{})
hc.p2p.Subscribe(location, &types.WorkObjectHeader{})
if location.Context() == common.PRIME_CTX || location.Context() == common.REGION_CTX || quaiBackend.ProcessingState(location) {
hc.p2p.Subscribe(location, &types.WorkObjectBlockView{})
}

StartNode(stack)

Expand Down
16 changes: 12 additions & 4 deletions quai/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,18 @@ func (h *handler) missingBlockLoop() {
}).Fatal("Go-Quai Panicked")
}
}()
resultCh := h.p2pBackend.Request(h.nodeLocation, blockRequest.Hash, &types.WorkObjectBlockView{})
block := <-resultCh
if block != nil {
h.core.WriteBlock(block.(*types.WorkObjectBlockView).WorkObject)
if !h.core.ProcessingState() && h.nodeLocation.Context() == common.ZONE_CTX {
resultCh := h.p2pBackend.Request(h.nodeLocation, blockRequest.Hash, &types.WorkObjectHeaderView{})
block := <-resultCh
if block != nil {
h.core.WriteBlock(block.(*types.WorkObjectHeaderView).WorkObject)
}
} else {
resultCh := h.p2pBackend.Request(h.nodeLocation, blockRequest.Hash, &types.WorkObjectBlockView{})
block := <-resultCh
if block != nil {
h.core.WriteBlock(block.(*types.WorkObjectBlockView).WorkObject)
}
}
h.recentBlockReqCache.Remove(blockRequest.Hash)
}()
Expand Down

0 comments on commit e0e597c

Please sign in to comment.