Skip to content

Commit

Permalink
Merge pull request #163 from helix-bridge/xiaoch05-repair-relayer
Browse files Browse the repository at this point in the history
support filter confirming txs
  • Loading branch information
xiaoch05 authored Apr 17, 2024
2 parents 726d13b + bf122bc commit ccfecf1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
10 changes: 5 additions & 5 deletions apollo/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ SUB2ETH_INBOUND=https://thegraph.darwinia.network/ethv2/subgraphs/name/sub2ethin
GOERLI_A2E_LN_ENDPOINT=http://localhost:8000/subgraphs/name/arbi2ethln/ethereum
ARBITRUM_A2E_LN_ENDPOINT=http://localhost:8000/subgraphs/name/arbi2ethln/arbitrum

LN_ETHEREUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-sepolia/version/latest
LN_ETHEREUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-sepolia/version/latest
LN_ARBITRUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-arbisepolia/version/latest
LN_ARBITRUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-arbisepolia/version/latest
LN_ZKSYNC_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-zksepolia/version/latest
LN_ETHEREUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-sepolia/v1.0.1
LN_ETHEREUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-sepolia/v1.0.1
LN_ARBITRUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-arbisepolia/v1.0.1
LN_ARBITRUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-arbisepolia/v1.0.1
LN_ZKSYNC_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-zksepolia/v1.0.1

ETHEREUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-sepolia/v1.0.5
ARBITRUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-arbitrum-sepolia/v1.0.5
Expand Down
2 changes: 1 addition & 1 deletion apollo/src/aggregation/aggregation.history.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type HealthInfo {
type Query {
historyRecordById(id: String): HistoryRecord
historyRecordByTxHash(txHash: String): HistoryRecord
firstHistoryRecord(fromChain: String, toChain: String, bridge: String, results: [Int], relayer: String, token: String, order: String): HistoryRecord
firstHistoryRecord(fromChain: String, toChain: String, bridge: String, results: [Int], relayer: String, token: String, order: String, notsubmited: Boolean): HistoryRecord
queryDailyStatistics(timepast: Int!, first: Int, from: String, to: String, bridge: String, token: String): [DailyStatistics]
historyRecords(sender: String, recipient: String, relayer: String, needWithdrawLiquidity: Boolean, fromChains: [String], toChains: [String], bridges: [String], row: Int, page: Int, results: [Int], recvTokenAddress: String, order: String): HistoryRecords
checkLnBridgeExist(fromChainId: Int, toChainId: Int, fromToken: String, toToken: String, version: String): Boolean
Expand Down
21 changes: 13 additions & 8 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ export class AggregationResolver {
@Args('results') results: number[],
@Args('relayer') relayer: string,
@Args('token') token: string,
@Args('order') order: string
@Args('order') order: string,
@Args('notsubmited') notsubmited: boolean,
) {
const orderCondition = order?.split('_');
const orderBy =
orderCondition && orderCondition.length == 2
? { [orderCondition[0]]: orderCondition[1] }
: { startTime: Prisma.SortOrder.desc };
const resultCondition = results && results.length ? { result: { in: results } } : {};
const submitCondition = notsubmited ? { confirmedBlocks: { not: { contains: '0x' } } } : {};

return this.aggregationService.queryHistoryRecordFirst(
{
AND: {
Expand All @@ -47,6 +50,7 @@ export class AggregationResolver {
bridge: bridge,
relayer: relayer,
sendTokenAddress: token,
...submitCondition,
...resultCondition,
},
},
Expand Down Expand Up @@ -395,14 +399,18 @@ export class AggregationResolver {
console.log(`get softTransferLimit failed ${record.id}, exception: ${e}`);
continue;
}
const providerFee = BigInt(amount) * BigInt(record.liquidityFeeRate) / BigInt(100000) + BigInt(record.baseFee);
if (limit < BigInt(amount) + providerFee + BigInt(record.protocolFee) || record.paused) {
continue;
}
// offline
if (record.heartbeatTimestamp + this.heartbeatTimeout < now) {
continue;
}

if (limit > transferLimit) {
transferLimit = limit;
}
const providerFee = BigInt(amount) * BigInt(record.liquidityFeeRate) / BigInt(100000) + BigInt(record.baseFee);
if (limit < BigInt(amount) + providerFee + BigInt(record.protocolFee) || record.paused) {
continue;
}
const point = await this.aggregationService.calculateLnBridgeRelayerPoint(
sendToken,
BigInt(amount),
Expand All @@ -412,9 +420,6 @@ export class AggregationResolver {
if (point == null) {
continue;
}
if (limit > transferLimit) {
transferLimit = limit;
}
sortedRelayers.push({ record, point });
}
return {
Expand Down
2 changes: 1 addition & 1 deletion apollo/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export abstract class IQuery {

abstract historyRecordByTxHash(txHash?: Nullable<string>): Nullable<HistoryRecord> | Promise<Nullable<HistoryRecord>>;

abstract firstHistoryRecord(fromChain?: Nullable<string>, toChain?: Nullable<string>, bridge?: Nullable<string>, results?: Nullable<Nullable<number>[]>, relayer?: Nullable<string>, token?: Nullable<string>, order?: Nullable<string>): Nullable<HistoryRecord> | Promise<Nullable<HistoryRecord>>;
abstract firstHistoryRecord(fromChain?: Nullable<string>, toChain?: Nullable<string>, bridge?: Nullable<string>, results?: Nullable<Nullable<number>[]>, relayer?: Nullable<string>, token?: Nullable<string>, order?: Nullable<string>, notsubmited?: Nullable<boolean>): Nullable<HistoryRecord> | Promise<Nullable<HistoryRecord>>;

abstract queryDailyStatistics(timepast: number, first?: Nullable<number>, from?: Nullable<string>, to?: Nullable<string>, bridge?: Nullable<string>, token?: Nullable<string>): Nullable<Nullable<DailyStatistics>[]> | Promise<Nullable<Nullable<DailyStatistics>[]>>;

Expand Down
32 changes: 32 additions & 0 deletions apollo/src/guard/guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,38 @@ export class GuardService {
chainId: 46,
depositor: '0x2B496f19A420C02490dB859fefeCCD71eDc2c046',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'darwinia-dvm',
toChain: 'crab-dvm',
bridge: 'xtoken-darwinia-crab',
chainId: 44,
depositor: '0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'crab-dvm',
toChain: 'darwinia-dvm',
bridge: 'xtoken-darwinia-crab',
chainId: 46,
depositor: '0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'darwinia-dvm',
toChain: 'crab-dvm',
bridge: 'xtoken-crab-darwinia',
chainId: 44,
depositor: '0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'crab-dvm',
toChain: 'darwinia-dvm',
bridge: 'xtoken-crab-darwinia',
chainId: 46,
depositor: '0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
}
];

Expand Down

0 comments on commit ccfecf1

Please sign in to comment.