Skip to content

Commit

Permalink
fix gasPrice for special network
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Jul 31, 2024
1 parent c3f6def commit 71626d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
41 changes: 5 additions & 36 deletions src/dataworker/dataworker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ export interface HistoryRecord {
messageNonce: number;
}

export interface ValidInfo {
gasPrice: GasPrice | null;
feeUsed: bigint | null;
isValid: boolean;
}

export interface TransferRecord {
lastTransferId: string;
record: HistoryRecord;
Expand Down Expand Up @@ -339,13 +333,11 @@ export class DataworkerService implements OnModuleInit {
fromBridge: LnBridgeContract | Lnv3BridgeContract,
toBridge: LnBridgeContract | Lnv3BridgeContract,
fromProvider: EthereumProvider,
toProvider: EthereumProvider,
reorgThreshold: number,
microReorgThreshold: number,
microThreshold: bigint,
notSupport1559: boolean,
wallet
): Promise<ValidInfo> {
): Promise<boolean> {
// 1. tx must be finalized
const transactionInfo = await fromProvider.checkPendingTransaction(
record.requestTxHash
Expand Down Expand Up @@ -383,11 +375,7 @@ export class DataworkerService implements OnModuleInit {
wallet
);
}
return {
gasPrice: null,
feeUsed: null,
isValid: false,
};
return false;
}
// 2. tx is not relayed
const transferId = this.getTransferId(record.id);
Expand All @@ -396,35 +384,16 @@ export class DataworkerService implements OnModuleInit {
this.logger.log(
`[${record.fromChain}>>${record.toChain}]tx has been relayed, waiting for sync, id ${transferId}, txHash ${record.requestTxHash}`
);
return {
gasPrice: null,
feeUsed: null,
isValid: false,
};
return false;
}
// 3. the lock info verify
const existInfo = await fromBridge.transferIdExist(transferId);
if (!existInfo[0]) {
this.logger.log(`lock info not exist, maybe reorged, id ${transferId}`);
return {
gasPrice: null,
feeUsed: null,
isValid: false,
};
return false;
} else {
this.logger.log(`transfer locked success, info ${existInfo[1]}`);
}
// 4. get current fee
let gasPrice = await toProvider.feeData(1, notSupport1559);
let feeUsed = this.relayFee(gasPrice);
let microHint = satisfyMicroThreshold
? `isMicro, send: ${record.sendAmount}, threshold: ${microThreshold}`
: "notMicro";
this.logger.log(`fee check passed, feeUsed ${feeUsed}, ${microHint}`);
return {
gasPrice,
feeUsed,
isValid: true,
};
return true;
}
}
18 changes: 8 additions & 10 deletions src/relayer/relayer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,28 +936,26 @@ export class RelayerService implements OnModuleInit {
continue;
}
const record = needRelayRecord.record;
const validInfo = await this.dataworkerService.checkValid(
const txValid = await this.dataworkerService.checkValid(
this.configureService.indexer,
record,
fromBridgeContract,
toBridgeContract,
fromChainInfo.provider,
toChainInfo.provider,
bridge.reorgThreshold,
bridge.microReorgThreshold,
new Any(lnProvider.microThreshold, srcDecimals).Number,
toChainInfo.notSupport1559,
bridge.toWallet
);

if (!validInfo.isValid) {
if (!txValid) {
continue;
}

if (validInfo.feeUsed > new Ether(bridge.feeLimit).Number) {
this.logger.log(
`fee is exceed limit, please check, fee ${validInfo.feeUsed}`
);
let gasPrice = await this.gasPrice(toChainInfo);
let feeUsed = this.dataworkerService.relayFee(gasPrice);
if (feeUsed > new Ether(bridge.feeLimit).Number) {
this.logger.log(`fee is exceed limit, please check, fee ${feeUsed}`);
continue;
}
let nonce: number | null = null;
Expand Down Expand Up @@ -1097,7 +1095,7 @@ export class RelayerService implements OnModuleInit {
txInfo.value,
txInfo.operation,
txInfo.signatures,
validInfo.gasPrice
gasPrice
);
await this.store.savePendingTransaction(
toChainInfo.chainName,
Expand Down Expand Up @@ -1132,7 +1130,7 @@ export class RelayerService implements OnModuleInit {
// relay and return
const tx = await toBridgeContract.relay(
args,
validInfo.gasPrice,
gasPrice,
nonce,
relayGasLimit
);
Expand Down

0 comments on commit 71626d7

Please sign in to comment.