Skip to content

Commit

Permalink
use container/list for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Dec 18, 2024
1 parent 28e8dea commit c54eb2a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pkg/solana/logpoller/loader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logpoller

import (
"container/list"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -326,15 +327,15 @@ type orderedParser struct {
// internal state
parser ProgramEventProcessor
mu sync.Mutex
blocks []uint64
blocks *list.List
expect map[uint64]int
actual map[uint64][]ProgramEvent
}

func newOrderedParser(parser ProgramEventProcessor, lggr logger.Logger) *orderedParser {
op := &orderedParser{
parser: parser,
blocks: make([]uint64, 0),
blocks: list.New(),
expect: make(map[uint64]int),
actual: make(map[uint64][]ProgramEvent),
}
Expand All @@ -353,7 +354,7 @@ func (p *orderedParser) ExpectBlock(block uint64) {
p.mu.Lock()
defer p.mu.Unlock()

p.blocks = append(p.blocks, block)
p.blocks.PushBack(block)
}

func (p *orderedParser) ExpectTxs(block uint64, quantity int) {
Expand Down Expand Up @@ -430,7 +431,8 @@ func (p *orderedParser) run(_ context.Context) {

func (p *orderedParser) sendReadySlots() error {
// start at the lowest block and find ready blocks
for _, block := range p.blocks {
for element := p.blocks.Front(); element != nil; element = element.Next() {
block := element.Value.(uint64)
// if no expectations are set, we are still waiting on information for the block.
// if expectations set and not met, we are still waiting on information for the block
// no other block data should be sent until this is resolved
Expand All @@ -442,7 +444,14 @@ func (p *orderedParser) sendReadySlots() error {
// if expectations are 0 -> remove and continue
if exp == 0 {
p.clearExpectations(block)
p.blocks = p.blocks[1:]

temp := element.Prev()
p.blocks.Remove(element)
if temp == nil {
break
}

element = temp

continue
}
Expand All @@ -462,7 +471,14 @@ func (p *orderedParser) sendReadySlots() error {
return errs
}

p.blocks = p.blocks[1:]
temp := element.Prev()
p.blocks.Remove(element)

if temp == nil {
break
}

element = temp

p.clearExpectations(block)
}
Expand Down

0 comments on commit c54eb2a

Please sign in to comment.