Skip to content

Commit

Permalink
feat: use new pings table
Browse files Browse the repository at this point in the history
  • Loading branch information
mo4islona committed Jul 15, 2024
1 parent 041e1dd commit 6e6a15e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/contracts/scripts/createMerkleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ for (const leaf of leaves) {
total += BigInt(leaf[2]);
}

fs.mkdirSync('airdrop-data', { recursive: true });
fs.writeFileSync("airdrop-data/leaves.json", JSON.stringify(walletMap));
console.log(`Finished generating leaves.json.`);
console.log(`Total distribution: ${total}`);
console.log(`Total distribution: ${total} (${total / (10n ** 18n)} SQD)`);

const tree = StandardMerkleTree.of(leaves, ["uint32", "address", "uint256"]);

Expand Down
24 changes: 15 additions & 9 deletions packages/rewards-calculator/src/clickhouseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ export class ClickhouseClient {
}

public async getPings(from = this.from, to = this.to) {
const query = `select workerId,arrayConcat([toUnixTimestamp('${formatDate(from)}')],arraySort(groupArray(toUnixTimestamp(timestamp))),[toUnixTimestamp('${formatDate(to)}')]) as timestamps from ${
config.clickhouse.pingsTableName
} where timestamp >= '${formatDate(from)}' and timestamp <= '${formatDate(
to,
)}' group by workerId`;
const query = `select
worker_id,
arrayConcat(
[toUnixTimestamp('${formatDate(from)}')],
arraySort(groupArray(toUnixTimestamp(timestamp))),
[toUnixTimestamp('${formatDate(to)}')]
) as timestamps
from ${config.clickhouse.pingsTableName}
where timestamp >= '${formatDate(from)}' and timestamp <= '${formatDate(to)}'
group by worker_id
`;
const pings: Record<string, number[]> = {};
for await (const row of clickhouse.query(query).stream()) {
pings[row.workerId] = row.timestamps;
pings[row.worker_id] = row.timestamps;
}
return pings;
}
Expand Down Expand Up @@ -114,14 +120,14 @@ export async function livenessFactor(clickhouseClient: ClickhouseClient) {
dayjs(clickhouseClient.from),
"second",
);
const netwotkStats: Record<string, NetworkStatsEntry> = {};
const res: Record<string, NetworkStatsEntry> = {};
for (const workersKey in pings) {
netwotkStats[workersKey] = networkStats(
res[workersKey] = networkStats(
pings[workersKey],
totalPeriodSeconds,
);
}
return netwotkStats;
return res;
}

function networkStats(pingTimestamps: number[], epochLength: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rewards-calculator/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const config = {
password: env("CLICKHOUSE_PASSWORD"),
url: env("CLICKHOUSE_URL", "https://clickhouse.subsquid.io/"),
logsTableName: env("CLICKHOUSE_LOGS_TABLE", "testnet.worker_query_logs"),
pingsTableName: env("CLICKHOUSE_PINGS_TABLE", "testnet.worker_pings"),
pingsTableName: env("CLICKHOUSE_PINGS_TABLE", "testnet.worker_pings_v2"),
},
fordefi: {
accessToken: env("FORDEFI_ACCESS_TOKEN"),
Expand Down
4 changes: 1 addition & 3 deletions packages/rewards-calculator/src/reward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export async function epochStats(
const to = await getBlockTimestamp(toBlock);
logger.log(from, "-", to);
const clickhouse = new ClickhouseClient(from, to);
const workers = await clickhouse.getActiveWorkers(
shouldSkipSignatureValidation,
);
const workers = await clickhouse.getActiveWorkers(shouldSkipSignatureValidation);
if (workers.count() === 0) {
return workers;
}
Expand Down

2 comments on commit 6e6a15e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.