Skip to content

Commit e43b9d5

Browse files
committed
chore: replace ttl scientific notation w/ constants 20_000
1 parent 352d498 commit e43b9d5

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

cardano/gateway/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OGMIOS_ENDPOINT=http://127.0.0.1:1337
1212
CARDANO_CHAIN_HOST=127.0.0.1
1313
CARDANO_CHAIN_PORT=3001
1414
CARDANO_NETWORK_MAGIC=42
15-
CARDANO_EPOCH_NONCE_GENESIS="1ded2ae250301711769f64e867307cc034a3f2c4b1f134cc71e53cb35c0f44b5"
15+
CARDANO_EPOCH_NONCE_GENESIS="41c48395859c96d1a431ee848a4d2795f65a4ab19ca37ceeb4d13824792f1fa5"
1616

1717
HANDLER_JSON_PATH=/usr/src/app/cardano/offchain/deployments/handler.json
1818

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const MinimumActiveEpoch = BigInt(2);
2+
3+
export const TRANSACTION_TIME_TO_LIVE = 20_000; // 20 seconds

cardano/gateway/src/tx/channel.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
import { ORDER_MAPPING_CHANNEL } from '~@/constant/channel';
6565
import { Order } from '~@/shared/types/channel/order';
6666
import { sleep } from '../shared/helpers/time';
67+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
6768

6869
@Injectable()
6970
export class ChannelService {
@@ -82,7 +83,7 @@ export class ChannelService {
8283
channelOpenInitOperator,
8384
constructedAddress,
8485
);
85-
const validToTime = Date.now() + 2e4;
86+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
8687
const validToSlot = unixTimeToSlot(this.lucidService.lucid.config().network, Number(validToTime));
8788
const currentSlot = this.lucidService.lucid.currentSlot();
8889
if (currentSlot > validToSlot) {
@@ -126,7 +127,7 @@ export class ChannelService {
126127
channelOpenTryOperator,
127128
constructedAddress,
128129
);
129-
const validToTime = Date.now() + 2e4;
130+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
130131
const unsignedChannelOpenTryTxValidTo: TxBuilder = unsignedChannelOpenTryTx.validTo(validToTime);
131132
// TODO: signing should be done by the relayer in the future
132133
const signedChannelOpenTryTxCompleted = await (await unsignedChannelOpenTryTxValidTo.complete()).sign
@@ -160,7 +161,7 @@ export class ChannelService {
160161
channelOpenAckOperator,
161162
constructedAddress,
162163
);
163-
const validToTime = Date.now() + 2e4;
164+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
164165
const validToSlot = unixTimeToSlot(this.lucidService.lucid.config().network, Number(validToTime));
165166
const currentSlot = this.lucidService.lucid.currentSlot();
166167
if (currentSlot > validToSlot) {
@@ -201,7 +202,7 @@ export class ChannelService {
201202
channelOpenConfirmOperator,
202203
constructedAddress,
203204
);
204-
const validToTime = Date.now() + 2e4;
205+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
205206
const unsignedChannelConfirmInitTxValidTo: TxBuilder = unsignedChannelConfirmInitTx.validTo(validToTime);
206207

207208
// TODO: signing should be done by the relayer in the future
@@ -243,7 +244,7 @@ export class ChannelService {
243244
channelCloseInitOperator,
244245
constructedAddress,
245246
);
246-
const validToTime = Date.now() + 2e4;
247+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
247248
const unsignedChannelCloseInitTxValidTo: TxBuilder = unsignedChannelCloseInitTx.validTo(validToTime);
248249

249250
// TODO: signing should be done by the relayer in the future

cardano/gateway/src/tx/client.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import { checkForMisbehaviour } from '@shared/types/misbehaviour/misbehaviour';
3232
import { UpdateOnMisbehaviourOperatorDto, UpdateClientOperatorDto } from './dto/client/update-client-operator.dto';
3333
import { validateAndFormatCreateClientParams, validateAndFormatUpdateClientParams } from './helper/client.validate';
34+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
3435

3536
@Injectable()
3637
export class ClientService {
@@ -121,7 +122,7 @@ export class ClientService {
121122

122123
const unsignedUpdateClientTx: TxBuilder =
123124
await this.buildUnsignedUpdateOnMisbehaviour(updateOnMisbehaviourOperator);
124-
const validToTime = Date.now() + 2e4;
125+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
125126
const unSignedTxValidTo: TxBuilder = unsignedUpdateClientTx
126127
.validFrom(new Date().valueOf())
127128
.validTo(validToTime);
@@ -146,7 +147,7 @@ export class ClientService {
146147
BigInt(currentClientDatum.state.clientState.maxClockDrift || 0)) /
147148
10n ** 6n +
148149
100n * 10n ** 3n;
149-
const validToTime = Date.now() + 2e4;
150+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
150151
const updateClientHeaderOperator: UpdateClientOperatorDto = {
151152
clientId,
152153
header,
@@ -167,7 +168,7 @@ export class ClientService {
167168
}
168169

169170
const validFrom = Number(validFromTime);
170-
const validTo = new Date().valueOf() + 100 * 1e3;
171+
const validTo = Date.now() + TRANSACTION_TIME_TO_LIVE;
171172

172173
const unSignedTxValidTo: TxBuilder = unsignedUpdateClientTx.validFrom(validFrom).validTo(validTo);
173174

cardano/gateway/src/tx/connection.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { ClientState as CardanoClientState } from '@plus/proto-types/build/ibc/l
4747
import { Any } from '@plus/proto-types/build/google/protobuf/any';
4848
import { getMithrilClientStateForVerifyProofRedeemer } from '../shared/helpers/mithril-client';
4949
import { ClientState as MithrilClientState } from '@plus/proto-types/build/ibc/lightclients/mithril/mithril';
50+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
5051
@Injectable()
5152
export class ConnectionService {
5253
constructor(
@@ -68,7 +69,7 @@ export class ConnectionService {
6869
connectionOpenInitOperator,
6970
constructedAddress,
7071
);
71-
const validToTime = Date.now() + 2e4;
72+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
7273
const unsignedConnectionOpenInitTxValidTo: TxBuilder = unsignedConnectionOpenInitTx.validTo(validToTime);
7374

7475
// Todo: signing should be done by the relayer in the future
@@ -107,7 +108,7 @@ export class ConnectionService {
107108
connectionOpenTryOperator,
108109
constructedAddress,
109110
);
110-
const validToTime = Date.now() + 2e4;
111+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
111112
const unsignedConnectionOpenTryTxValidTo: TxBuilder = unsignedConnectionOpenTryTx.validTo(validToTime);
112113

113114
// Todo: signing should be done by the relayer in the future
@@ -146,7 +147,7 @@ export class ConnectionService {
146147
connectionOpenAckOperator,
147148
constructedAddress,
148149
);
149-
const validToTime = Date.now() + 2e4;
150+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
150151
const unsignedConnectionOpenAckTxValidTo: TxBuilder = unsignedConnectionOpenAckTx.validTo(validToTime);
151152
// Todo: signing should be done by the relayer in the future
152153
const signedConnectionOpenAckTxCompleted = await (await unsignedConnectionOpenAckTxValidTo.complete()).sign
@@ -188,7 +189,7 @@ export class ConnectionService {
188189
connectionOpenConfirmOperator,
189190
constructedAddress,
190191
);
191-
const validToTime = Date.now() + 2e4;
192+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
192193
const unsignedConnectionOpenConfirmTxValidTo: TxBuilder = unsignedConnectionOpenConfirmTx.validTo(validToTime);
193194

194195
// Todo: signing should be done by the relayer in the future

cardano/gateway/src/tx/packet.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { packetAcknowledgementPath, packetCommitmentPath, packetReceiptPath } fr
7171
import { Order as ChannelOrder } from '@plus/proto-types/build/ibc/core/channel/v1/channel';
7272
import { Order } from '~@/shared/types/channel/order';
7373
import { GrpcInternalException, GrpcInvalidArgumentException } from '~@/exception/grpc_exceptions';
74+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
7475

7576
@Injectable()
7677
export class PacketService {
@@ -133,7 +134,7 @@ export class PacketService {
133134
constructedAddress,
134135
);
135136

136-
const validToTime = Date.now() + 2e4;
137+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
137138
const validToSlot = this.lucidService.lucid.unixTimeToSlot(Number(validToTime));
138139
const currentSlot = this.lucidService.lucid.currentSlot();
139140
if (currentSlot > validToSlot) {
@@ -181,7 +182,7 @@ export class PacketService {
181182
const sendPacketOperator = validateAndFormatSendPacketParams(data);
182183

183184
const unsignedSendPacketTx: TxBuilder = await this.buildUnsignedSendPacketTx(sendPacketOperator);
184-
const validToTime = Date.now() + 2e4;
185+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
185186
const validToSlot = this.lucidService.lucid.unixTimeToSlot(Number(validToTime));
186187
const currentSlot = this.lucidService.lucid.currentSlot();
187188
if (currentSlot > validToSlot) {
@@ -227,7 +228,7 @@ export class PacketService {
227228
timeoutPacketOperator,
228229
constructedAddress,
229230
);
230-
const validToTime = Date.now() + 2e4;
231+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
231232
const unsignedSendPacketTxValidTo: TxBuilder = unsignedSendPacketTx.validTo(validToTime);
232233

233234
// Todo: signing should be done in the relayer in the future
@@ -281,7 +282,7 @@ export class PacketService {
281282
timeoutRefreshOperator,
282283
constructedAddress,
283284
);
284-
const validToTime = Date.now() + 2e4;
285+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
285286
const validToSlot = this.lucidService.lucid.unixTimeToSlot(Number(validToTime));
286287

287288
const currentSlot = this.lucidService.lucid.currentSlot();
@@ -330,7 +331,7 @@ export class PacketService {
330331
ackPacketOperator,
331332
constructedAddress,
332333
);
333-
const validToTime = Date.now() + 2e4;
334+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
334335
const unsignedAckPacketTxValidTo: TxBuilder = unsignedAckPacketTx.validTo(validToTime);
335336

336337
// Todo: signing should be done in the relayer in the future

0 commit comments

Comments
 (0)