Skip to content

Commit

Permalink
relayer's signer heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Sep 11, 2024
1 parent 0c3a4ea commit 6b1aeae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions apollo/src/aggregation/aggregation.history.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type LnBridgeRelayInfo {
dynamicFee: String
dynamicFeeExpire: String
dynamicFeeSignature: String
signers: String
}

type LnBridgeRelayInfos {
Expand Down
22 changes: 22 additions & 0 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AggregationResolver {
'0x2fdec62e57e1a77db6984424c01a3c13fbca7cc1': '0x00000c377b096e0c904d7736be14e653e500481c',
};
private invalidRelayerHeartbeat = new Map();
private signerHeartbeatTimestamp = [];
constructor(private aggregationService: AggregationService) {}

private ecrecover(hash: string, sig: string): string {
Expand Down Expand Up @@ -57,6 +58,19 @@ export class AggregationResolver {
{ value: messageHash, type: 'bytes' }
);
const signer = this.ecrecover(dataHash, sig);
// cache the signer heartbeat timestamp
if (this.relayerProxy[signer] === relayer.toLowerCase()) {
const heartBeatSigner = this.signerHeartbeatTimestamp.find((s) => s.address === signer);
if (heartBeatSigner) {
heartBeatSigner.timestamp = timestamp;
} else {
this.signerHeartbeatTimestamp.push({
address: signer,
proxy: relayer.toLowerCase(),
timestamp: timestamp,
});
}
}
return signer === relayer || this.relayerProxy[signer] === relayer;
} catch {
return false;
Expand Down Expand Up @@ -400,6 +414,14 @@ export class AggregationResolver {
take,
where,
});
for (const record of records.records) {
const signers = this.signerHeartbeatTimestamp.filter(
(s) => s.proxy === record.relayer.toLowerCase()
);
if (signers.length > 0) {
record.signers = signers.map((s) => `${s.address}-${s.timestamp}`).join(',');
}
}
return records;
}

Expand Down
1 change: 1 addition & 0 deletions apollo/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class LnBridgeRelayInfo {
dynamicFee?: Nullable<string>;
dynamicFeeExpire?: Nullable<string>;
dynamicFeeSignature?: Nullable<string>;
signers?: Nullable<string>;
}

export class LnBridgeRelayInfos {
Expand Down

0 comments on commit 6b1aeae

Please sign in to comment.