Skip to content

Commit

Permalink
Move round robin call to inside SQLX callback
Browse files Browse the repository at this point in the history
  • Loading branch information
vreff committed Mar 8, 2023
1 parent 5db7a84 commit 8a21518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 6 additions & 7 deletions core/services/vrf/listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,6 @@ func (lsn *listenerV2) processRequestsPerSub(
return processed
}

fromAddress, err := lsn.gethks.GetRoundRobinAddress(lsn.chainID, fromAddresses...)
if err != nil {
l.Errorw("Couldn't get next from address", "err", err)
continue
}
ll = ll.With("fromAddress", fromAddress)

ll.Infow("Enqueuing fulfillment")
var ethTX txmgr.EthTx
err = lsn.q.Transaction(func(tx pg.Queryer) error {
Expand All @@ -815,6 +808,12 @@ func (lsn *listenerV2) processRequestsPerSub(
maxLinkString := p.maxLink.String()
requestID := common.BytesToHash(p.req.req.RequestId.Bytes())
coordinatorAddress := lsn.coordinator.Address()

fromAddress, err := lsn.gethks.GetRoundRobinAddress(lsn.chainID, fromAddresses...)
if err != nil {
return errors.Wrap(err, "Couldn't get next from address")
}

ethTX, err = lsn.txm.CreateEthTransaction(txmgr.NewTx{
FromAddress: fromAddress,
ToAddress: lsn.coordinator.Address(),
Expand Down
15 changes: 7 additions & 8 deletions core/services/vrf/listener_v2_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,9 @@ func (lsn *listenerV2) processBatch(
float64(lsn.job.VRFSpec.BatchFulfillmentGasMultiplier),
)

fromAddresses := lsn.fromAddresses()
fromAddress, err := lsn.gethks.GetRoundRobinAddress(lsn.chainID, fromAddresses...)
if err != nil {
l.Errorw("Couldn't get next from address", "err", err)
return
}

ll := l.With("numRequestsInBatch", len(batch.reqIDs),
"requestIDs", batch.reqIDs,
"batchSumGasLimit", batch.totalGasLimit,
"fromAddress", fromAddresses,
"linkBalance", startBalanceNoReserveLink,
"totalGasLimitBumped", totalGasLimitBumped,
"gasMultiplier", lsn.job.VRFSpec.BatchFulfillmentGasMultiplier,
Expand All @@ -158,6 +150,13 @@ func (lsn *listenerV2) processBatch(
for _, reqID := range batch.reqIDs {
reqIDHashes = append(reqIDHashes, common.BytesToHash(reqID.Bytes()))
}

fromAddresses := lsn.fromAddresses()
fromAddress, err := lsn.gethks.GetRoundRobinAddress(lsn.chainID, fromAddresses...)
if err != nil {
return errors.Wrap(err, "Couldn't get next from address")
}

ethTX, err = lsn.txm.CreateEthTransaction(txmgr.NewTx{
FromAddress: fromAddress,
ToAddress: lsn.batchCoordinator.Address(),
Expand Down

0 comments on commit 8a21518

Please sign in to comment.