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

Release/v0.0.1 alpha.57 #51

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.57](https://github.com/DIG-Network/dig-incentive-server/compare/v0.0.1-alpha.56...v0.0.1-alpha.57) (2024-10-07)


### Features

* update logging for payouts ([3a7e888](https://github.com/DIG-Network/dig-incentive-server/commit/3a7e8886d8acd1c5eb89fdf286f0df2c414eb941))

### [0.0.1-alpha.56](https://github.com/DIG-Network/dig-incentive-server/compare/v0.0.1-alpha.55...v0.0.1-alpha.56) (2024-10-05)

### [0.0.1-alpha.55](https://github.com/DIG-Network/dig-incentive-server/compare/v0.0.1-alpha.54...v0.0.1-alpha.55) (2024-10-05)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dig-incentive-server",
"version": "0.0.1-alpha.56",
"version": "0.0.1-alpha.57",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand All @@ -24,7 +24,7 @@
"LICENSE"
],
"dependencies": {
"@dignetwork/dig-sdk": "^0.0.1-alpha.142",
"@dignetwork/dig-sdk": "^0.0.1-alpha.161",
"async-mutex": "^0.5.0",
"datalayer-driver": "^0.1.21",
"express": "^4.19.2",
Expand Down
43 changes: 13 additions & 30 deletions src/tasks/payouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,14 @@ const runIncentiveProgram = async (
const rootHistory = await dataStore.getRootHistory();
const rootHash = rootHistory[rootHistory.length - 1].root_hash;

console.log(`Root hash for current epoch: ${rootHash}`);

const rewardThisRound =
(BigInt(program.xchRewardPerEpoch) * mojosPerXch) /
BigInt(roundsPerEpoch);

console.log(`Reward for this round: ${rewardThisRound} mojos`);

const peerBlackList = await program.getBlacklist();
console.log(`Peer blacklist retrieved: ${peerBlackList.length} peers`);
console.log(`DIG Peer blacklist retrieved: ${peerBlackList.length} peers`);

const serverCoin = new ServerCoin(program.storeId);
const storeKeys = dataStore.Tree.listKeys(rootHash);
Expand All @@ -180,23 +178,20 @@ const runIncentiveProgram = async (
const pendingRequests: Promise<boolean>[] = [];

while (!payoutMade) {
console.log("Sampling up to 50 peers from the current epoch...");

const serverCoins = await serverCoin.sampleCurrentEpoch(
500,
peerBlackList
);
const serverCoins = await serverCoin.getActiveEpochPeers(peerBlackList);

if (serverCoins.length === 0) {
console.log(`No more peers available for storeId ${program.storeId}`);
console.log(
`No more dig peers available for storeId ${program.storeId}`
);
break;
}

console.log(`Sampled ${serverCoins.length} peers for challenge.`);
console.log(`Requesting ${serverCoins.length} DIG Peers for challenge proof.`);

// Add network requests (headStore and getKey) to the shared request queue
for (const peerIp of serverCoins) {
console.log(`Initiating challenge for peer: ${peerIp}`);
console.log(`Initiating challenge for DIG peer: ${peerIp}`);
const digPeer = new DigPeer(peerIp, program.storeId);

// Track request results in the current run
Expand All @@ -209,15 +204,12 @@ const runIncentiveProgram = async (
const response = await withTimeout(
digPeer.contentServer.headStore(),
60000,
`headStore timed out for peer ${peerIp}`
`headStore timed out for Dig peer ${peerIp}`
);
console.log(`Peer ${peerIp} responded to headStore request`);

const peerGenerationHash =
response.headers?.["x-generation-hash"];
if (peerGenerationHash === rootHash) {
console.log(`Peer ${peerIp} has correct generation hash.`);

// Use Promise.all so that any failure immediately marks the peer as invalid
await Promise.all(
randomKeysHex.map(async (hexKey) => {
Expand All @@ -241,19 +233,13 @@ const runIncentiveProgram = async (
serializedChallenge
),
10000,
`getKey timed out for peer ${peerIp}`
`getKey timed out for dig peer ${peerIp}`
);

// Create the expected challenge response locally
const expectedChallengeResponse =
await digChallenge.createChallengeResponse(challenge);

console.log(
`${peerIp} - ${hexToUtf8(
hexKey
)} - ${peerChallengeResponse} - ${expectedChallengeResponse}`
);

// Compare the peer's response with the expected response
if (
peerChallengeResponse !== expectedChallengeResponse
Expand All @@ -267,12 +253,12 @@ const runIncentiveProgram = async (

validPeers.push(digPeer);
console.log(
`Peer ${peerIp} passed all challenges and is valid.`
`DIG Peer ${peerIp} passed all challenge proofs and is valid.`
);
resolve(true);
} else {
console.log(
`Peer ${peerIp} has an incorrect generation hash.`
`DIG Peer ${peerIp} has failed one or more challenges proofs.`
);
resolve(false);
}
Expand Down Expand Up @@ -325,7 +311,7 @@ const runIncentiveProgram = async (
const memos = [paymentHint, message];

console.log(
`Sending equal bulk payments to ${paymentAddresses.length} valid peers...`
`Sending equal bulk payments to ${paymentAddresses.length} valid DIG peers...`
);
await DigPeer.sendEqualBulkPayments(
program.walletName,
Expand Down Expand Up @@ -366,13 +352,10 @@ const runPayouts = async (): Promise<void> => {

// Use asyncPool to process stores concurrently (with a limit of 5 stores at a time)
await asyncPool(5, storeList, async (storeId) => {
console.log(`Starting payouts for storeId: ${storeId}`);
const program = await IncentiveProgram.from(storeId);
if (program?.active) {
console.log(`Program active for storeId: ${storeId}`);
console.log(`Starting payouts for storeId: ${storeId}`);
await runIncentiveProgram(program, currentEpoch);
} else {
console.log(`Program inactive for storeId: ${storeId}`);
}
});
};
Expand Down
Loading