Skip to content

Commit 7667e63

Browse files
author
Park Juhyung
committed
Send transactions together
If we send transactions without waiting for inclusion, Foundy can create a block that has more than one transaction.
1 parent ac419b8 commit 7667e63

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

ibc.ts/src/common/chain.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,34 @@ export class Chain {
5454
}
5555

5656
public async submitDatagram(datagram: Datagram): Promise<void> {
57-
const ibcAction = new IBC(this.sdk.networkId, datagram.rlpBytes());
57+
await this.submitDatagrams([datagram]);
58+
}
5859

60+
public async submitDatagrams(datagrams: Datagram[]): Promise<void> {
61+
const txHashes = [];
5962
const seq = await this.sdk.rpc.chain.getSeq(this.faucetAddress);
60-
const signedTx = await this.sdk.key.signTransaction(ibcAction, {
61-
account: this.faucetAddress,
62-
fee: 100,
63-
seq
64-
});
6563

66-
const txHash = await this.sdk.rpc.chain.sendSignedTransaction(signedTx);
67-
await waitForTx(this.sdk, txHash);
64+
for (let i = 0; i < datagrams.length; i += 1) {
65+
const datagram = datagrams[i];
66+
const ibcAction = new IBC(this.sdk.networkId, datagram.rlpBytes());
67+
68+
const signedTx = await this.sdk.key.signTransaction(ibcAction, {
69+
account: this.faucetAddress,
70+
fee: 100,
71+
seq: seq + i
72+
});
73+
74+
debug(`Send tx with seq ${seq + i}`);
75+
const txHash = await this.sdk.rpc.chain.sendSignedTransaction(
76+
signedTx
77+
);
78+
txHashes.push(txHash);
79+
}
80+
81+
for (const txHash of txHashes) {
82+
debug(`Wait for tx ${txHash}`);
83+
await waitForTx(this.sdk, txHash);
84+
}
6885
}
6986

7087
public async latestHeight(): Promise<number> {

ibc.ts/src/relayer/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ async function relayFromTo({
6161
counterpartyChain
6262
});
6363

64-
for (const localDiagram of localDatagrams) {
65-
await chain.submitDatagram(localDiagram);
66-
}
64+
await chain.submitDatagrams(localDatagrams);
6765

68-
for (const counterpartyDatagram of counterpartyDatagrams) {
69-
await counterpartyChain.submitDatagram(counterpartyDatagram);
70-
}
66+
await counterpartyChain.submitDatagrams(counterpartyDatagrams);
7167
}
7268

7369
async function pendingDatagrams({

0 commit comments

Comments
 (0)