Skip to content

Commit

Permalink
chore(listenForStakingEvents): fix listener bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Aug 9, 2024
1 parent 3c3b35e commit 27c3f56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/handler/evm/utils/listenForStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ const listenForStakingEvents = (
for (const log of logs) {
const decoded = stakerInt.parseLog(log);
if (!decoded) continue;
logger.info(`found event at ${lastBlock} - ${latestBlock}`);
await cb(builder.staked(decoded.args.validatorAddressAndChainType));
}
lastBlock = latestBlockNumber;
lastBlock = latestBlock;
await em.upsert(Block, {
chain: chainIdent,
contractAddress: staker,
Expand Down
35 changes: 11 additions & 24 deletions src/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function listenEvents(
if (err_.shortMessage?.includes("Signature already used")) {
return null;
}
log.error(err_.shortMessage, "Error while approving");
log.error(err_, "Error while approving lock");
throw err;
}
};
Expand Down Expand Up @@ -172,23 +172,13 @@ export async function listenStakeEvents(

async function poolEvents(chain: TStakingHandler) {
log.info("Listening for Staking Events");
const currentValidatorAddress: string =
// @ts-ignore
await deps.storage.runner?.getAddress();
const currentValidatorEpoch = await deps.storage.validatorEpoch(
currentValidatorAddress,
);

const currentValidatorVotes = await deps.storage.validatorStatusChangeVotes(
currentValidatorAddress,
true,
currentValidatorEpoch,
);
const storageValidators = await deps.storage.validatorCount();

log.info({ currentValidatorVotes, storageValidators });

chain.listenForStakingEvents(builder, async (ev) => {
const stakerAddress = ev.find(
(item) => item.chainType === "evm",
)?.validatorAddress;
if (!stakerAddress) return;

const signatures: {
validatorAddress: string;
signerAndSignature: {
Expand All @@ -213,12 +203,9 @@ export async function listenStakeEvents(

const approvalFn = async () => {
try {
const tx = Promise.race([
const tx = await Promise.race([
(
await deps.storage.approveStake(
currentValidatorAddress,
signatures,
)
await deps.storage.approveStake(stakerAddress, signatures)
).wait(),
setTimeout(10 * 1000),
]);
Expand All @@ -233,7 +220,7 @@ export async function listenStakeEvents(
) {
return null;
}
log.error(err_.shortMessage, "Error while approving");
log.error(err_, "Error while approving stake");
throw err;
}
};
Expand All @@ -245,8 +232,8 @@ export async function listenStakeEvents(
);
log.info(
approved
? `Approved and Signed Data for Staking Chain at TX: ${approved.hash}`
: `Already approved for ${currentValidatorAddress}`,
? `Approved and Signed Data for Staking Chain at TX: ${approved.hash} for user ${stakerAddress}`
: `Already approved for ${stakerAddress}`,
);
}
});
Expand Down

0 comments on commit 27c3f56

Please sign in to comment.