From 7b0562c0ad27c56de07658e6088cfd179efbbf65 Mon Sep 17 00:00:00 2001 From: Krzysztof Szostak Date: Wed, 26 Aug 2026 18:07:35 +0200 Subject: [PATCH] fix: sign solution result with domain and reward period --- src/polkadot/polka.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/polkadot/polka.ts b/src/polkadot/polka.ts index ee3d9cb..fcdcf9f 100644 --- a/src/polkadot/polka.ts +++ b/src/polkadot/polka.ts @@ -28,6 +28,8 @@ const polkaLogger = pino({ name: 'PolkaLogger', }); +const SUBMIT_SOLUTION_RESULT_SIGN_DOMAIN = 'EWX_WorkerSolution_submit_solution_result'; + export const createApi = async (palletEndpoint: string): Promise => { const api: ApiPromise = await ApiPromise.create({ provider: new HttpProvider(palletEndpoint), @@ -192,7 +194,25 @@ export const submitSolutionResult = async ( hashVote: boolean, ): Promise => { const finalVote = hashVote ? blake2AsHex(vote) : vote; - const signature = account.sign(finalVote as string | Uint8Array); + + const api = await txManager.getConnection(); + + const rewardPeriodInfo = await api.query.workerNodePallet.activeRewardPeriodInfo(); + const rewardPeriodIndex = ( + rewardPeriodInfo as unknown as { index: { toNumber: () => number } } + ).index.toNumber(); + + const payload = api + .createType('(Bytes, Bytes, Bytes, u32, Bytes)', [ + SUBMIT_SOLUTION_RESULT_SIGN_DOMAIN, + namespace, + votingRoundId, + rewardPeriodIndex, + finalVote, + ]) + .toU8a(); + + const signature = account.sign(payload); const { txHash } = await txManager.sendWithoutSigning((api) => api.tx.workerNodePallet.submitSolutionResult(