Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate results in /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}/stackers #2022

Open
aryzing opened this issue Jun 29, 2024 · 1 comment
Assignees

Comments

@aryzing
Copy link

aryzing commented Jun 29, 2024

Describe the bug
The results from /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}/stackers contain some stackers more than once.

To Reproduce

The following script gets dupes. You can try it with cycle 86 and signer public key 02877ce29ba35458b827a6ea18510b9058ae4c30e2c33d288f2982c13497caec6e

async function getDupes(cycleNumber: number, signerPublicKey: string) {
  function makeEndpoint(
    cycleNumber: number,
    signerPublicKey: string,
    offset: number,
    limit: number,
  ) {
    const baseUrl = "https://api.mainnet.hiro.so";
    const path = `/extended/v2/pox/cycles/${cycleNumber}/signers/0x${signerPublicKey}/stackers?offset=${offset}&limit=${limit}`;
    const endpoint = `${baseUrl}${path}`;
    return endpoint;
  }

  type GetStackersForSignerInPoxCycleResponse = {
    limit: number;
    offset: number;
    total: number;
    results: Array<{
      stacker_address: string;
      stacked_amount: string;
      pox_address: string;
      stacker_type: "pooled" | "solo";
    }>;
  };

  const stackersMap = new Map<string, bigint>();

  let hasMore = true;
  let offset = 0;
  const limit = 200;
  while (hasMore) {
    const res = await fetch(
      makeEndpoint(cycleNumber, signerPublicKey, offset, limit),
      {
        headers: {
          "x-hiro-api-key": hiroApiKey,
        },
      },
    );

    const data = (await res.json()) as GetStackersForSignerInPoxCycleResponse;

    const stackers = data.results;
    for (const stacker of stackers) {
      const stacksAddress = stacker.stacker_address;
      const lockAmount = BigInt(stacker.stacked_amount);

      if (stackersMap.get(stacksAddress)) {
        console.log("Found repeat result from API");
        console.log("  Existing entry:", stackersMap.get(stacksAddress));
        console.log("  New entry:", stacksAddress, lockAmount);
      } else {
        stackersMap.set(stacksAddress, lockAmount);
      }
    }

    offset += data.results.length;
    hasMore = offset < data.total;
  }
}

Expected behavior
No dupes

@aryzing
Copy link
Author

aryzing commented Oct 28, 2024

Hey there, just checking whether it's worth brining this issue out of the backlog since it's still happening? For this last cycle 95, getting a few repeat entries still:

Found repeat result from API
  Existing entry: 1499000000n
  New entry: SP3Y40Y7KSVNAGAV4AEACET8WC2CH5ZS1TN436H0A 1499000000n
Found repeat result from API
  Existing entry: 1499000000n
  New entry: SP3GKWW70RNNXHCYHF8S93NSSV9GPR6N6XEX0CRV 1499000000n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants