Skip to content

Commit 9fa3351

Browse files
authored
Use GroupRunner in eth-beacon (#3790)
1 parent b607cde commit 9fa3351

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

.changeset/nervous-clocks-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/eth-beacon-adapter': patch
3+
---
4+
5+
Refactor how RPCs are grouped

packages/sources/eth-beacon/src/transport/balance.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TransportDependencies } from '@chainlink/external-adapter-framework/transports'
2+
import { GroupRunner } from '@chainlink/external-adapter-framework/util/group-runner'
23
import { Requester } from '@chainlink/external-adapter-framework/util/requester'
34
import {
45
AdapterResponse,
@@ -125,18 +126,14 @@ export class BalanceTransport extends SubscriptionTransport<BalanceTransportType
125126
)
126127

127128
const groupSize = this.config.GROUP_SIZE
128-
const requestGroups = splitArrayIntoChunks(batchedAddresses, groupSize)
129+
const runner = new GroupRunner(groupSize)
130+
const queryBeaconChain = runner.wrapFunction((addresses: string[]) =>
131+
this.queryBeaconChain(url, addresses, statusList),
132+
)
133+
129134
// Make request to beacon API for every batch
130135
// Send requests in groups
131-
for (const group of requestGroups) {
132-
responses.push(
133-
...(await Promise.all(
134-
group.map((addresses) => {
135-
return this.queryBeaconChain(url, addresses, statusList)
136-
}),
137-
)),
138-
)
139-
}
136+
responses.push(...(await Promise.all(batchedAddresses.map(queryBeaconChain))))
140137
}
141138

142139
// Flatten the results into single array for validators and balances

0 commit comments

Comments
 (0)