Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
address review comments
Browse files Browse the repository at this point in the history
kanishkatn committed Oct 6, 2023
1 parent ec48cc9 commit 6c0cbcf
Showing 2 changed files with 28 additions and 23 deletions.
38 changes: 20 additions & 18 deletions dot/parachain/dispute/scraping/inclusion.go
Original file line number Diff line number Diff line change
@@ -57,25 +57,27 @@ func (i *Inclusions) RemoveUpToHeight(blockNumber uint32, candidatesModified []c
func (i *Inclusions) Get(candidateHash common.Hash) []Inclusion {
var inclusionsAsSlice []Inclusion
blocksIncluding, ok := i.inner[candidateHash]
if ok {
// Convert the map to a sorted slice for iteration
var sortedKeys []uint32
for h := range blocksIncluding {
sortedKeys = append(sortedKeys, h)
}
sort.Slice(sortedKeys, func(i, j int) bool {
return sortedKeys[i] < sortedKeys[j]
})
if !ok {
return inclusionsAsSlice
}

// Extract inclusions as a slice of structs
for _, height := range sortedKeys {
blocksAtHeight := blocksIncluding[height]
for _, block := range blocksAtHeight {
inclusionsAsSlice = append(inclusionsAsSlice, Inclusion{
BlockNumber: height,
BlockHash: block,
})
}
// Convert the map to a sorted slice for iteration
var sortedKeys []uint32
for h := range blocksIncluding {
sortedKeys = append(sortedKeys, h)
}
sort.Slice(sortedKeys, func(i, j int) bool {
return sortedKeys[i] < sortedKeys[j]
})

// Extract inclusions as a slice of structs
for _, height := range sortedKeys {
blocksAtHeight := blocksIncluding[height]
for _, block := range blocksAtHeight {
inclusionsAsSlice = append(inclusionsAsSlice, Inclusion{
BlockNumber: height,
BlockHash: block,
})
}
}

13 changes: 8 additions & 5 deletions dot/parachain/dispute/scraping/scraping.go
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ func (cs *ChainScraper) ProcessActiveLeavesUpdate(
}

earliestBlockNumber := update.Activated.Number - uint32(len(ancestors))
var blockNumbers []uint32
blockNumbers := make([]uint32, 0, update.Activated.Number-earliestBlockNumber+1)
for i := update.Activated.Number; i >= earliestBlockNumber; i-- {
blockNumbers = append(blockNumbers, i)
}
@@ -129,6 +129,10 @@ func (cs *ChainScraper) ProcessCandidateEvents(
return nil, fmt.Errorf("getting candidate events: %w", err)
}

if events == nil {
return nil, nil
}

for _, event := range events.Types {
candidateEvents = append(candidateEvents, parachainTypes.CandidateEvent(event))
}
@@ -301,9 +305,8 @@ func getBlockAncestors(

// saturatingSub returns the result of a - b, saturating at 0.
func saturatingSub(a, b uint32) uint32 {
result := int(a) - int(b)
if result < 0 {
return 0
if a > b {
return a - b
}
return uint32(result)
return 0
}

0 comments on commit 6c0cbcf

Please sign in to comment.