Skip to content

Commit

Permalink
CR fix
Browse files Browse the repository at this point in the history
  • Loading branch information
novosandara committed Nov 3, 2024
1 parent 220e43e commit cb2a91f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
34 changes: 14 additions & 20 deletions jsonrpc/debug_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"runtime"
"runtime/debug"
"strings"
"sync"
"time"

"github.com/0xPolygon/polygon-edge/helper/hex"
Expand Down Expand Up @@ -690,6 +689,7 @@ func (d *Debug) GetRawReceipts(filter BlockNumberOrHash) (interface{}, error) {
)
}

// TraceChain traces a range of blocks from `start` to `end` and returns their trace results or an error.
func (d *Debug) TraceChain(start, end BlockNumber, config *TraceConfig) (interface{}, error) {
return d.throttling.AttemptRequest(
context.Background(),
Expand All @@ -710,21 +710,12 @@ func (d *Debug) TraceChain(start, end BlockNumber, config *TraceConfig) (interfa

blocks := int(endNum-startNum) + 1
results := make([]BlockTraceResult, blocks)
resultCh := make(chan BlockTraceResult, blocks)
maxConcurrency := runtime.NumCPU() - 1
semaphore := make(chan struct{}, maxConcurrency)
resultCh := make(chan *BlockTraceResult, blocks)

var wg sync.WaitGroup
for i := 0; i < blocks; i++ {
wg.Add(1)
semaphore <- struct{}{}

go func(i int) {
defer wg.Done()
defer func() { <-semaphore }()

blockNum := startNum + uint64(i)
traceResult := BlockTraceResult{Block: blockNum}
traceResult := &BlockTraceResult{Block: blockNum}

block, ok := d.store.GetBlockByNumber(blockNum, true)
if !ok {
Expand All @@ -744,16 +735,19 @@ func (d *Debug) TraceChain(start, end BlockNumber, config *TraceConfig) (interfa
}(i)
}

go func() {
wg.Wait()
close(resultCh)
}()
traceResults := 0

for traceResult := range resultCh {
results[traceResult.Block-startNum] = traceResult
}
for {
select {
case traceResult := <-resultCh:
results[traceResult.Block-startNum] = *traceResult

return results, nil
traceResults++
if traceResults == blocks {
return results, nil
}
}
}
},
)
}
Expand Down
1 change: 1 addition & 0 deletions output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Compactions\n Level | Tables | Size(MB) | Time(sec) | Read(MB) | Write(MB)\n-------+------------+---------------+---------------+---------------+---------------\n-------+------------+---------------+---------------+---------------+---------------\n Total | 0 | 0.00000 | 0.00000 | 0.00000 | 0.00000\n"
2 changes: 1 addition & 1 deletion state/immutable-trie/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (m *memStorage) Has(p []byte) (bool, error) {

// Stat returns a particular internal stat of the database.
func (m *memStorage) Stat(property string) (string, error) {
return "", fmt.Errorf("unknown property")
return "", fmt.Errorf("not implemented for in-memory storage")
}

// Compact is not supported on a memory database, but there's no need either as
Expand Down

0 comments on commit cb2a91f

Please sign in to comment.