Skip to content

Commit

Permalink
loop over multiple signatures for address
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Nov 18, 2024
1 parent c589bc0 commit 1721e13
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions pkg/solana/logpoller/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,54 @@ func (c *EncodedLogCollector) BackfillForAddress(ctx context.Context, address st
return err
}

sigs, err := c.client.GetSignaturesForAddressWithOpts(ctx, pubKey, &rpc.GetSignaturesForAddressOpts{
Commitment: rpc.CommitmentFinalized,
MinContextSlot: &fromSlot,
})
if err != nil {
return err
}
var (
lowestSlotRead uint64
lowestSlotSig solana.Signature
)

slots := make(map[uint64]struct{})
for lowestSlotRead > fromSlot {
opts := rpc.GetSignaturesForAddressOpts{
Commitment: rpc.CommitmentFinalized,
MinContextSlot: &fromSlot,
}

for _, sig := range sigs {
_, ok := slots[sig.Slot]
if !ok {
if err := c.workers.Do(ctx, &getTransactionsFromBlockJob{
slotNumber: sig.Slot,
client: c.client,
parser: c.parser,
chJobs: c.chJobs,
}); err != nil {
return err
if lowestSlotRead > 0 {
opts.Before = lowestSlotSig
}

sigs, err := c.client.GetSignaturesForAddressWithOpts(ctx, pubKey, &opts)
if err != nil {
return err
}

slots := make(map[uint64]struct{})

var newSigsFound bool

for _, sig := range sigs {
if sig.Slot < lowestSlotRead {
lowestSlotRead = sig.Slot
lowestSlotSig = sig.Signature
}

slots[sig.Slot] = struct{}{}
_, ok := slots[sig.Slot]
if !ok {
if err := c.workers.Do(ctx, &getTransactionsFromBlockJob{
slotNumber: sig.Slot,
client: c.client,
parser: c.parser,
chJobs: c.chJobs,
}); err != nil {
return err
}

slots[sig.Slot] = struct{}{}
newSigsFound = true
}
}

if !newSigsFound {
break
}
}

Expand Down

0 comments on commit 1721e13

Please sign in to comment.