Skip to content

Commit

Permalink
Merge pull request #27 from dmccartney/daniel-gentler-loading
Browse files Browse the repository at this point in the history
fix: ease off the details loading to avoid stalling out
  • Loading branch information
dmccartney authored Oct 17, 2023
2 parents 788c5e9 + f0e0686 commit a278820
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions web/src/hooks/useMinipoolDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ export default function useMinipoolDetails(nodeAddress) {
let mpDelegateInterface = new ethers.utils.Interface(
contracts.RocketMinipoolDelegate.abi
);
let loadingWindowMs = 15 * 1000;

// For very large nodes we can't load all minipools at once without hitting rate limits.
// But most nodes are smaller and they can be loaded at once.
// So we aggressively load the first minipools for a node and then spread out the remainder.
// Thus, most nodes load right away and larger nodes load over a predictable loading window.

// Note: these numbers are experimentally derived and may need tweaking as the `queryFn` changes.
// Load this many minipools immediately without spreading out the load.
let loadingWindowBypassCount = 50;
// Spread out any remaining minipool loads over this-sized window of time.
let loadingWindowMs = 25 * 1000; // 25 seconds

let details = useQueries(
minipoolAddresses.map((minipoolAddress, i) => ({
queryKey: ["MinipoolDetails", minipoolAddress],
queryFn: async () => {
if (i > 50) {
// Spread out load for large nodes.
if (i > loadingWindowBypassCount) {
await new Promise((resolve) =>
setTimeout(resolve, loadingWindowMs * Math.random())
);
Expand All @@ -33,14 +45,14 @@ export default function useMinipoolDetails(nodeAddress) {
mpDelegateInterface,
provider?.signer || provider
);
let [version, status, isFinalized, balance, nodeRefundBalance] =
await Promise.all([
mp.version(),
mp.getStatus(),
mp.getFinalised(),
provider.getBalance(minipoolAddress),
mp.getNodeRefundBalance(),
]);
// Note: we don't Promise.all these reads to be gentler on the rate-limit.
// TODO: issue a multi-read call instead.
let isFinalized = await mp.getFinalised();
let nodeRefundBalance = await mp.getNodeRefundBalance();
let version = await mp.version();
let status = await mp.getStatus();
let balance = await provider.getBalance(minipoolAddress);

let balanceLessRefund = balance.sub(nodeRefundBalance);
let calculatedNodeShare = ethers.constants.Zero;
if (balanceLessRefund.gt(ethers.constants.Zero)) {
Expand Down

0 comments on commit a278820

Please sign in to comment.