Skip to content

Commit

Permalink
rename to validation and collect stader tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed May 29, 2024
1 parent 14b052f commit c9b0e05
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
13 changes: 9 additions & 4 deletions packages/brain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,21 @@ export const reloadValidatorsCron = new CronJob(
).reloadValidators
);
reloadValidatorsCron.start();
const proofOfAttestationCron = new CronJob(shareCronInterval, () =>
sendProofsOfValidation(signerApi, brainDb, dappnodeSignerProoverApi)
const proofOfValidationCron = new CronJob(shareCronInterval, () =>
sendProofsOfValidation(
signerApi,
brainDb,
dappnodeSignerProoverApi,
shareDataWithDappnode
)
);
if (shareDataWithDappnode) proofOfAttestationCron.start();
proofOfValidationCron.start();

// Graceful shutdown
function handle(signal: string): void {
logger.info(`${signal} received. Shutting down...`);
reloadValidatorsCron.stop();
proofOfAttestationCron.stop();
proofOfValidationCron.stop();
brainDb.close();
uiServer.close();
launchpadServer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export class DappnodeSigningProover extends StandardApi {
}

public async sendProofsOfValidation(
proofOfAttestations: DappnodeSigningProoverPostRequest[]
proofOfValidations: DappnodeSigningProoverPostRequest[]
): Promise<void> {
await this.request({
method: "POST",
endpoint: `${path.join(
this.dappnodeSignEndpoint
)}?network=${encodeURIComponent(this.network.toString())}`,
body: JSON.stringify(proofOfAttestations),
body: JSON.stringify(proofOfValidations),
timeout: 10000,
});
}
Expand Down
45 changes: 26 additions & 19 deletions packages/brain/src/modules/cron/sendProofsOfValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,37 @@ import { BrainDataBase } from "../db/index.js";
import logger from "../logger/index.js";

/**
* Send the proof of attestation to the dappnode-signatures.io domain
* Send the proof of validation to the dappnode-signatures.io domain
*/
export async function sendProofsOfValidation(
signerApi: Web3SignerApi,
brainDb: BrainDataBase,
dappnodeSigningProoverApi: DappnodeSigningProover
dappnodeSigningProoverApi: DappnodeSigningProover,
shareDataWithDappnode: boolean
): Promise<void> {
try {
// Get the proofs of attestation from the signer
const proofsOfAttestations = await getProofsOfValidation(
// Get the proofs of validation from the signer
const proofsOfValidations = await getProofsOfValidation(
signerApi,
brainDb
);
if (proofsOfAttestations.length === 0) return;
logger.debug(
`Sending ${proofsOfAttestations.length} proofs of validations`
);
await dappnodeSigningProoverApi.sendProofsOfValidation(
proofsOfAttestations
brainDb,
shareDataWithDappnode
);
if (proofsOfValidations.length === 0) return;
logger.debug(`Sending ${proofsOfValidations.length} proofs of validations`);
await dappnodeSigningProoverApi.sendProofsOfValidation(proofsOfValidations);
} catch (e) {
logger.error(`Error sending proof of attestation: ${e.message}`);
logger.error(`Error sending proof of validation: ${e.message}`);
}
}

/**
* Get the proofs of attestation from the signer
* Get the proofs of validation from the signer
* for all the pubkeys in the db
*/
async function getProofsOfValidation(
signerApi: Web3SignerApi,
brainDb: BrainDataBase
brainDb: BrainDataBase,
shareDataWithDappnode: boolean
): Promise<DappnodeSigningProoverPostRequest[]> {
const signerDappnodeSignRequest: Web3signerPostSignDappnodeRequest = {
type: "PROOF_OF_VALIDATION",
Expand All @@ -48,8 +47,16 @@ async function getProofsOfValidation(
};
// get pubkeys detauls from db
const dbPubkeysDetails = brainDb.getData();
// For each pubkey, get the proof of attestation from the signer
const proofsOfAttestations = await Promise.all(

// only send proof of validation if the user has enabled it
// or if there is a stader pubkey
if (
!shareDataWithDappnode &&
!Object.values(dbPubkeysDetails).some((pubkey) => pubkey.tag === "stader")
)
return [];
// For each pubkey, get the proof of validation from the signer
const proofsOfValidations = await Promise.all(
Object.keys(dbPubkeysDetails).map(async (pubkey) => {
try {
const { payload, signature }: Web3signerPostSignDappnodeResponse =
Expand All @@ -65,14 +72,14 @@ async function getProofsOfValidation(
};
} catch (e) {
logger.error(
`Error getting proof of attestation for pubkey ${pubkey}. Error: ${e.message}`
`Error getting proof of validation for pubkey ${pubkey}. Error: ${e.message}`
);
return null;
}
})
);

return filterNotNullishFromArray(proofsOfAttestations);
return filterNotNullishFromArray(proofsOfValidations);
}

/**
Expand Down

0 comments on commit c9b0e05

Please sign in to comment.