From 8f05fc97d3458169e1d1bebb9379d411bc172311 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 10:14:27 +0100 Subject: [PATCH 01/13] use human readable logs --- go.mod | 1 + go.sum | 2 ++ internal/logging/logging.go | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2e91a2c1a..9ccd303e5 100644 --- a/go.mod +++ b/go.mod @@ -84,6 +84,7 @@ require ( github.com/libp2p/go-netroute v0.2.1 // indirect github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect + github.com/lmittmann/tint v1.0.2 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect diff --git a/go.sum b/go.sum index 3851270fd..c6c029f79 100644 --- a/go.sum +++ b/go.sum @@ -507,6 +507,8 @@ github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQsc github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= +github.com/lmittmann/tint v1.0.2 h1:9XZ+JvEzjvd3VNVugYqo3j+dl0NRju8k9FquAusJExM= +github.com/lmittmann/tint v1.0.2/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= diff --git a/internal/logging/logging.go b/internal/logging/logging.go index aed19f889..cacd8e895 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -6,7 +6,9 @@ import ( "log/slog" "os" "path/filepath" + "time" + "github.com/lmittmann/tint" "github.com/statechannels/go-nitro/protocols" "github.com/statechannels/go-nitro/types" ) @@ -64,6 +66,9 @@ func SetupDefaultFileLogger(filename string, level slog.Level) { // SetupDefaultLogger sets up a default logger that writes to the specified writer func SetupDefaultLogger(w io.Writer, level slog.Level) { - h := slog.NewJSONHandler(w, &slog.HandlerOptions{Level: level}) + h := tint.NewHandler(w, &tint.Options{ + Level: level, + TimeFormat: time.Kitchen, + }) slog.SetDefault(slog.New(h)) } From 7a20ca597cf730f091855f5ae922fd484bd3cda6 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 10:14:36 +0100 Subject: [PATCH 02/13] add comment about existing issue --- .github/workflows/ts-rpc-test.yml | 4 ++-- packages/nitro-rpc-client/scripts/client-runner.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ts-rpc-test.yml b/.github/workflows/ts-rpc-test.yml index 6587ad9dd..13e91c601 100644 --- a/.github/workflows/ts-rpc-test.yml +++ b/.github/workflows/ts-rpc-test.yml @@ -29,11 +29,11 @@ jobs: run: make ui/build - name: Run go-nitro RPC servers with GUI - run: go run ./cmd/start-rpc-servers -ui=true &> output.log & + run: go run ./cmd/start-rpc-servers -ui=true &> output1.log & - name: Run Create Channels script # TODO: We could write a test specific script that creates channels and checks the results - run: npx ts-node ./scripts/client-runner.ts create-channels -w 300000 &> output.log + run: npx ts-node ./scripts/client-runner.ts create-channels -w 300000 &> output2.log working-directory: packages/nitro-rpc-client - name: Archive logs diff --git a/packages/nitro-rpc-client/scripts/client-runner.ts b/packages/nitro-rpc-client/scripts/client-runner.ts index b73881b3f..742afb7e6 100755 --- a/packages/nitro-rpc-client/scripts/client-runner.ts +++ b/packages/nitro-rpc-client/scripts/client-runner.ts @@ -177,6 +177,7 @@ yargs(hideBin(process.argv)) yargs.ledgerdeposit ); + // race condition means this may never resolve https://github.com/statechannels/go-nitro/issues/1749 await Promise.all([ aliceClient.WaitForObjective(aliceLedger.Id), bobClient.WaitForObjective(bobLedger.Id), From dd00ddd37c355620a9c5d48a5a29399341ec746b Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 10:47:02 +0100 Subject: [PATCH 03/13] Fix type mismatch between rpc client and server --- packages/nitro-rpc-client/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nitro-rpc-client/src/types.ts b/packages/nitro-rpc-client/src/types.ts index 46bfc7684..62986d2aa 100644 --- a/packages/nitro-rpc-client/src/types.ts +++ b/packages/nitro-rpc-client/src/types.ts @@ -259,4 +259,4 @@ export type AssetMetadata = { Metadata: null; }; -export type ChannelStatus = "Proposed" | "Ready" | "Closing" | "Complete"; +export type ChannelStatus = "Proposed" | "Open" | "Closing" | "Complete"; From be84db35b5c8ff077af7a3814598d57ec6d9d83d Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 10:47:31 +0100 Subject: [PATCH 04/13] replace WaitForObjective with WaitFor*ChannelToHaveStatus --- packages/nitro-rpc-client/src/interface.ts | 21 +++++++++-- packages/nitro-rpc-client/src/rpc-client.ts | 41 ++++++++++++++++++--- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/packages/nitro-rpc-client/src/interface.ts b/packages/nitro-rpc-client/src/interface.ts index 585865d9a..66ae21fa8 100644 --- a/packages/nitro-rpc-client/src/interface.ts +++ b/packages/nitro-rpc-client/src/interface.ts @@ -1,4 +1,5 @@ import { + ChannelStatus, LedgerChannelInfo, ObjectiveResponse, PaymentChannelInfo, @@ -100,11 +101,25 @@ interface paymentApi { interface syncAPI { /** - * WaitForObjective blocks until the objective with the given ID to complete. + * WaitForLedgerChannelToHaveStatus blocks until the ledger channel with the given ID to have the given status. * - * @param objectiveId - The id objective to wait for + * @param objectiveId - The channel id to wait for + * @param status - The channel id to wait for (e.g. Ready or Closing) + */ + WaitForLedgerChannelToHaveStatus( + objectiveId: string, + status: ChannelStatus + ): Promise; + /** + * WaitForPaymentChannelToHaveStatus blocks until the payment channel with the given ID to have the given status. + * + * @param objectiveId - The channel id to wait for + * @param status - The channel id to wait for (e.g. Ready or Closing) */ - WaitForObjective(objectiveId: string): Promise; + WaitForPaymentChannelToHaveStatus( + objectiveId: string, + status: ChannelStatus + ): Promise; /** * PaymentChannelUpdated attaches a callback which is triggered when the channel with supplied ID is updated. * Returns a cleanup function which can be used to remove the subscription. diff --git a/packages/nitro-rpc-client/src/rpc-client.ts b/packages/nitro-rpc-client/src/rpc-client.ts index 41cef4fba..4cc9d9abe 100644 --- a/packages/nitro-rpc-client/src/rpc-client.ts +++ b/packages/nitro-rpc-client/src/rpc-client.ts @@ -8,9 +8,11 @@ import { RequestMethod, RPCRequestAndResponses, ObjectiveResponse, - ObjectiveCompleteNotification, Voucher, ReceiveVoucherResult, + ChannelStatus, + LedgerChannelUpdatedNotification, + PaymentChannelUpdatedNotification, } from "./types"; import { Transport } from "./transport"; import { createOutcome, generateRequest } from "./utils"; @@ -57,13 +59,40 @@ export class NitroRpcClient implements RpcClientApi { return getAndValidateResult(res, "receive_voucher"); } - public async WaitForObjective(objectiveId: string): Promise { + public async WaitForLedgerChannelToHaveStatus( + channelId: string, + status: ChannelStatus + ): Promise { + const ledger = await this.GetLedgerChannel(channelId); + return new Promise((resolve) => { + if (ledger.Status == status) resolve(); + this.transport.Notifications.on( + "ledger_channel_updated", + (payload: LedgerChannelUpdatedNotification["params"]["payload"]) => { + if (payload.ID === channelId) { + this.GetLedgerChannel(channelId).then((l) => { + if (l.Status == status) resolve(); + }); + } + } + ); + }); + } + + public async WaitForPaymentChannelToHaveStatus( + channelId: string, + status: ChannelStatus + ): Promise { + const channel = await this.GetPaymentChannel(channelId); return new Promise((resolve) => { + if (channel.Status == status) resolve(); this.transport.Notifications.on( - "objective_completed", - (params: ObjectiveCompleteNotification["params"]) => { - if (params["payload"] === objectiveId) { - resolve(); + "payment_channel_updated", + (payload: PaymentChannelUpdatedNotification["params"]["payload"]) => { + if (payload.ID === channelId) { + this.GetLedgerChannel(channelId).then((l) => { + if (l.Status == status) resolve(); + }); } } ); From 4c8ee18bcfb3141ba87bab5052d425dc2fbc4ff4 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 10:47:58 +0100 Subject: [PATCH 05/13] use new client waiting logic (which is robust to race conditions) --- .../nitro-rpc-client/scripts/client-runner.ts | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/nitro-rpc-client/scripts/client-runner.ts b/packages/nitro-rpc-client/scripts/client-runner.ts index 742afb7e6..e66c06a36 100755 --- a/packages/nitro-rpc-client/scripts/client-runner.ts +++ b/packages/nitro-rpc-client/scripts/client-runner.ts @@ -177,11 +177,17 @@ yargs(hideBin(process.argv)) yargs.ledgerdeposit ); - // race condition means this may never resolve https://github.com/statechannels/go-nitro/issues/1749 await Promise.all([ - aliceClient.WaitForObjective(aliceLedger.Id), - bobClient.WaitForObjective(bobLedger.Id), + aliceClient.WaitForLedgerChannelToHaveStatus( + aliceLedger.ChannelId, + "Open" + ), + bobClient.WaitForLedgerChannelToHaveStatus( + bobLedger.ChannelId, + "Open" + ), ]); + console.log(`Ledger channel ${bobLedger.ChannelId} created`); console.log(`Ledger channel ${aliceLedger.ChannelId} created`); } @@ -195,7 +201,10 @@ yargs(hideBin(process.argv)) [ireneAddress], yargs.virtualdeposit ); - await aliceClient.WaitForObjective(res.Id); + await aliceClient.WaitForPaymentChannelToHaveStatus( + res.ChannelId, + "Open" + ); console.log(`Virtual channel ${res.ChannelId} created`); virtualChannels.push(res.ChannelId); } @@ -218,11 +227,12 @@ yargs(hideBin(process.argv)) break; } - const res = await aliceClient.ClosePaymentChannel(channelId); - await aliceClient.WaitForObjective(res); - console.log( - `Virtual channel ${getChannelIdFromObjectiveId(res)} closed` + await aliceClient.ClosePaymentChannel(channelId); + await aliceClient.WaitForPaymentChannelToHaveStatus( + channelId, + "Complete" ); + console.log(`Virtual channel ${channelId} closed`); closeCount++; } @@ -270,7 +280,10 @@ yargs(hideBin(process.argv)) rightAddress, 1_000_000 ); - await leftClient.WaitForObjective(ledger.Id); + await leftClient.WaitForLedgerChannelToHaveStatus( + ledger.ChannelId, + "Open" + ); console.log(`Ledger channel ${ledger.ChannelId} created`); await closeClients(clients); @@ -287,10 +300,6 @@ async function wait(ms: number) { await new Promise((res) => setTimeout(res, ms)); } -function getChannelIdFromObjectiveId(objectiveId: string): string { - return objectiveId.split("-")[1]; -} - // Waits for the RPC server to be available by sending a simple get_address POST request until we get a response async function waitForRPCServer( port: number, From 36a5208f00323ea19cbdf11cea901d6e3a87d0ce Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 10:48:30 +0100 Subject: [PATCH 06/13] remove todo --- packages/payment-proxy-client/src/App.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/payment-proxy-client/src/App.tsx b/packages/payment-proxy-client/src/App.tsx index e7aa9aee4..05a70dfdd 100644 --- a/packages/payment-proxy-client/src/App.tsx +++ b/packages/payment-proxy-client/src/App.tsx @@ -137,9 +137,6 @@ export default function App() { initialChannelBalance ); - // TODO: If the objective completes fast enough, we might start waiting after it's already done - // await nitroClient.WaitForObjective(result.Id); - setPaymentChannelId(result.ChannelId); nitroClient.onPaymentChannelUpdated( From ab07765d83cefad97eeffdc28a9c01ce804a3831 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 13:07:20 +0100 Subject: [PATCH 07/13] do not redirect ouput to a log file and be more selective in uploading logs --- .github/workflows/ts-rpc-test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ts-rpc-test.yml b/.github/workflows/ts-rpc-test.yml index 13e91c601..4f22af7aa 100644 --- a/.github/workflows/ts-rpc-test.yml +++ b/.github/workflows/ts-rpc-test.yml @@ -29,16 +29,16 @@ jobs: run: make ui/build - name: Run go-nitro RPC servers with GUI - run: go run ./cmd/start-rpc-servers -ui=true &> output1.log & + run: go run ./cmd/start-rpc-servers -ui=true &> output.log & - name: Run Create Channels script # TODO: We could write a test specific script that creates channels and checks the results - run: npx ts-node ./scripts/client-runner.ts create-channels -w 300000 &> output2.log + run: npx ts-node ./scripts/client-runner.ts create-channels -w 300000 working-directory: packages/nitro-rpc-client - name: Archive logs if: always() uses: actions/upload-artifact@v2 with: - name: logs - path: ./**/*.log + name: rpc server logs + path: ./output.log From f8b003b58b2b7c2cb524ee50eb67661190fc8d2a Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 13:15:07 +0100 Subject: [PATCH 08/13] fix up cli --- packages/nitro-rpc-client/src/cli.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/nitro-rpc-client/src/cli.ts b/packages/nitro-rpc-client/src/cli.ts index 19ab0adc5..c9e27912a 100755 --- a/packages/nitro-rpc-client/src/cli.ts +++ b/packages/nitro-rpc-client/src/cli.ts @@ -125,11 +125,11 @@ yargs(hideBin(process.argv)) yargs.counterparty, yargs.amount ); - const { Id } = dfObjective; + const { Id, ChannelId } = dfObjective; console.log(`Objective started ${Id}`); - await rpcClient.WaitForObjective(Id); - console.log(`Objective complete ${Id}`); + await rpcClient.WaitForLedgerChannelToHaveStatus(ChannelId, "Open"); + console.log(`Channel Open ${ChannelId}`); await rpcClient.Close(); process.exit(0); } @@ -154,8 +154,11 @@ yargs(hideBin(process.argv)) const id = await rpcClient.CloseLedgerChannel(yargs.channelId); console.log(`Objective started ${id}`); - await rpcClient.WaitForObjective(id); - console.log(`Objective complete ${id}`); + await rpcClient.WaitForPaymentChannelToHaveStatus( + yargs.channelId, + "Complete" + ); + console.log(`Channel Complete ${yargs.channelId}`); await rpcClient.Close(); process.exit(0); } @@ -200,10 +203,10 @@ yargs(hideBin(process.argv)) yargs.amount ); - const { Id } = vfObjective; + const { ChannelId, Id } = vfObjective; console.log(`Objective started ${Id}`); - await rpcClient.WaitForObjective(Id); - console.log(`Objective complete ${Id}`); + await rpcClient.WaitForPaymentChannelToHaveStatus(ChannelId, "Open"); + console.log(`Channel Open ${ChannelId}`); await rpcClient.Close(); process.exit(0); } @@ -230,8 +233,11 @@ yargs(hideBin(process.argv)) const id = await rpcClient.ClosePaymentChannel(yargs.channelId); console.log(`Objective started ${id}`); - await rpcClient.WaitForObjective(id); - console.log(`Objective complete ${id}`); + await rpcClient.WaitForPaymentChannelToHaveStatus( + yargs.channelId, + "Complete" + ); + console.log(`Channel complete ${yargs.channelId}`); await rpcClient.Close(); process.exit(0); } From c92dc4bb79e733b36e10c44a4c1eeb8fe0eed811 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 13:16:03 +0100 Subject: [PATCH 09/13] go mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9ccd303e5..565eb6c3b 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/BurntSushi/toml v1.3.2 github.com/golang-jwt/jwt/v5 v5.0.0 github.com/libp2p/go-libp2p-kad-dht v0.24.2 + github.com/lmittmann/tint v1.0.2 github.com/tidwall/buntdb v1.2.10 github.com/urfave/cli/v2 v2.25.3 @@ -84,7 +85,6 @@ require ( github.com/libp2p/go-netroute v0.2.1 // indirect github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.1 // indirect - github.com/lmittmann/tint v1.0.2 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect From a6e1ac0844a58621028a6643766866f747d07929 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 13:32:44 +0100 Subject: [PATCH 10/13] attach listener first, then do a "static" check for condition --- packages/nitro-rpc-client/src/rpc-client.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/nitro-rpc-client/src/rpc-client.ts b/packages/nitro-rpc-client/src/rpc-client.ts index 4cc9d9abe..8d207a757 100644 --- a/packages/nitro-rpc-client/src/rpc-client.ts +++ b/packages/nitro-rpc-client/src/rpc-client.ts @@ -63,9 +63,7 @@ export class NitroRpcClient implements RpcClientApi { channelId: string, status: ChannelStatus ): Promise { - const ledger = await this.GetLedgerChannel(channelId); - return new Promise((resolve) => { - if (ledger.Status == status) resolve(); + const promise = new Promise((resolve) => { this.transport.Notifications.on( "ledger_channel_updated", (payload: LedgerChannelUpdatedNotification["params"]["payload"]) => { @@ -77,14 +75,16 @@ export class NitroRpcClient implements RpcClientApi { } ); }); + const ledger = await this.GetLedgerChannel(channelId); + if (ledger.Status == status) return; + return promise; } public async WaitForPaymentChannelToHaveStatus( channelId: string, status: ChannelStatus ): Promise { - const channel = await this.GetPaymentChannel(channelId); - return new Promise((resolve) => { + const promise = new Promise((resolve) => { if (channel.Status == status) resolve(); this.transport.Notifications.on( "payment_channel_updated", @@ -97,6 +97,10 @@ export class NitroRpcClient implements RpcClientApi { } ); }); + + const channel = await this.GetPaymentChannel(channelId); + if (channel.Status == status) return; + return promise; } public onPaymentChannelUpdated( From 0ee63bea4bebfe21993148486676206deeb698cd Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 13:39:37 +0100 Subject: [PATCH 11/13] remove line --- packages/nitro-rpc-client/src/rpc-client.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nitro-rpc-client/src/rpc-client.ts b/packages/nitro-rpc-client/src/rpc-client.ts index 8d207a757..7a44a0d8e 100644 --- a/packages/nitro-rpc-client/src/rpc-client.ts +++ b/packages/nitro-rpc-client/src/rpc-client.ts @@ -85,7 +85,6 @@ export class NitroRpcClient implements RpcClientApi { status: ChannelStatus ): Promise { const promise = new Promise((resolve) => { - if (channel.Status == status) resolve(); this.transport.Notifications.on( "payment_channel_updated", (payload: PaymentChannelUpdatedNotification["params"]["payload"]) => { From 94d291e465e111df7c3586b2f2d2b25648a79065 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 14:52:04 +0100 Subject: [PATCH 12/13] fix typo --- packages/nitro-rpc-client/src/rpc-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nitro-rpc-client/src/rpc-client.ts b/packages/nitro-rpc-client/src/rpc-client.ts index 7a44a0d8e..0be993b0c 100644 --- a/packages/nitro-rpc-client/src/rpc-client.ts +++ b/packages/nitro-rpc-client/src/rpc-client.ts @@ -89,7 +89,7 @@ export class NitroRpcClient implements RpcClientApi { "payment_channel_updated", (payload: PaymentChannelUpdatedNotification["params"]["payload"]) => { if (payload.ID === channelId) { - this.GetLedgerChannel(channelId).then((l) => { + this.GetPaymentChannel(channelId).then((l) => { if (l.Status == status) resolve(); }); } From 6e0658447119880bdc2243e0251e422d8a408113 Mon Sep 17 00:00:00 2001 From: George Knee Date: Thu, 12 Oct 2023 14:53:26 +0100 Subject: [PATCH 13/13] use shorter names --- .../nitro-rpc-client/scripts/client-runner.ts | 25 ++++--------------- packages/nitro-rpc-client/src/cli.ts | 14 +++-------- packages/nitro-rpc-client/src/interface.ts | 8 +++--- packages/nitro-rpc-client/src/rpc-client.ts | 4 +-- 4 files changed, 15 insertions(+), 36 deletions(-) diff --git a/packages/nitro-rpc-client/scripts/client-runner.ts b/packages/nitro-rpc-client/scripts/client-runner.ts index e66c06a36..af8925a5f 100755 --- a/packages/nitro-rpc-client/scripts/client-runner.ts +++ b/packages/nitro-rpc-client/scripts/client-runner.ts @@ -178,14 +178,8 @@ yargs(hideBin(process.argv)) ); await Promise.all([ - aliceClient.WaitForLedgerChannelToHaveStatus( - aliceLedger.ChannelId, - "Open" - ), - bobClient.WaitForLedgerChannelToHaveStatus( - bobLedger.ChannelId, - "Open" - ), + aliceClient.WaitForLedgerChannelStatus(aliceLedger.ChannelId, "Open"), + bobClient.WaitForLedgerChannelStatus(bobLedger.ChannelId, "Open"), ]); console.log(`Ledger channel ${bobLedger.ChannelId} created`); @@ -201,10 +195,7 @@ yargs(hideBin(process.argv)) [ireneAddress], yargs.virtualdeposit ); - await aliceClient.WaitForPaymentChannelToHaveStatus( - res.ChannelId, - "Open" - ); + await aliceClient.WaitForPaymentChannelStatus(res.ChannelId, "Open"); console.log(`Virtual channel ${res.ChannelId} created`); virtualChannels.push(res.ChannelId); } @@ -228,10 +219,7 @@ yargs(hideBin(process.argv)) } await aliceClient.ClosePaymentChannel(channelId); - await aliceClient.WaitForPaymentChannelToHaveStatus( - channelId, - "Complete" - ); + await aliceClient.WaitForPaymentChannelStatus(channelId, "Complete"); console.log(`Virtual channel ${channelId} closed`); closeCount++; } @@ -280,10 +268,7 @@ yargs(hideBin(process.argv)) rightAddress, 1_000_000 ); - await leftClient.WaitForLedgerChannelToHaveStatus( - ledger.ChannelId, - "Open" - ); + await leftClient.WaitForLedgerChannelStatus(ledger.ChannelId, "Open"); console.log(`Ledger channel ${ledger.ChannelId} created`); await closeClients(clients); diff --git a/packages/nitro-rpc-client/src/cli.ts b/packages/nitro-rpc-client/src/cli.ts index c9e27912a..a48ce990f 100755 --- a/packages/nitro-rpc-client/src/cli.ts +++ b/packages/nitro-rpc-client/src/cli.ts @@ -128,7 +128,7 @@ yargs(hideBin(process.argv)) const { Id, ChannelId } = dfObjective; console.log(`Objective started ${Id}`); - await rpcClient.WaitForLedgerChannelToHaveStatus(ChannelId, "Open"); + await rpcClient.WaitForLedgerChannelStatus(ChannelId, "Open"); console.log(`Channel Open ${ChannelId}`); await rpcClient.Close(); process.exit(0); @@ -154,10 +154,7 @@ yargs(hideBin(process.argv)) const id = await rpcClient.CloseLedgerChannel(yargs.channelId); console.log(`Objective started ${id}`); - await rpcClient.WaitForPaymentChannelToHaveStatus( - yargs.channelId, - "Complete" - ); + await rpcClient.WaitForPaymentChannelStatus(yargs.channelId, "Complete"); console.log(`Channel Complete ${yargs.channelId}`); await rpcClient.Close(); process.exit(0); @@ -205,7 +202,7 @@ yargs(hideBin(process.argv)) const { ChannelId, Id } = vfObjective; console.log(`Objective started ${Id}`); - await rpcClient.WaitForPaymentChannelToHaveStatus(ChannelId, "Open"); + await rpcClient.WaitForPaymentChannelStatus(ChannelId, "Open"); console.log(`Channel Open ${ChannelId}`); await rpcClient.Close(); process.exit(0); @@ -233,10 +230,7 @@ yargs(hideBin(process.argv)) const id = await rpcClient.ClosePaymentChannel(yargs.channelId); console.log(`Objective started ${id}`); - await rpcClient.WaitForPaymentChannelToHaveStatus( - yargs.channelId, - "Complete" - ); + await rpcClient.WaitForPaymentChannelStatus(yargs.channelId, "Complete"); console.log(`Channel complete ${yargs.channelId}`); await rpcClient.Close(); process.exit(0); diff --git a/packages/nitro-rpc-client/src/interface.ts b/packages/nitro-rpc-client/src/interface.ts index 66ae21fa8..8ad3376ab 100644 --- a/packages/nitro-rpc-client/src/interface.ts +++ b/packages/nitro-rpc-client/src/interface.ts @@ -101,22 +101,22 @@ interface paymentApi { interface syncAPI { /** - * WaitForLedgerChannelToHaveStatus blocks until the ledger channel with the given ID to have the given status. + * WaitForLedgerChannelStatus blocks until the ledger channel with the given ID to have the given status. * * @param objectiveId - The channel id to wait for * @param status - The channel id to wait for (e.g. Ready or Closing) */ - WaitForLedgerChannelToHaveStatus( + WaitForLedgerChannelStatus( objectiveId: string, status: ChannelStatus ): Promise; /** - * WaitForPaymentChannelToHaveStatus blocks until the payment channel with the given ID to have the given status. + * WaitForPaymentChannelStatus blocks until the payment channel with the given ID to have the given status. * * @param objectiveId - The channel id to wait for * @param status - The channel id to wait for (e.g. Ready or Closing) */ - WaitForPaymentChannelToHaveStatus( + WaitForPaymentChannelStatus( objectiveId: string, status: ChannelStatus ): Promise; diff --git a/packages/nitro-rpc-client/src/rpc-client.ts b/packages/nitro-rpc-client/src/rpc-client.ts index 0be993b0c..f5f91d023 100644 --- a/packages/nitro-rpc-client/src/rpc-client.ts +++ b/packages/nitro-rpc-client/src/rpc-client.ts @@ -59,7 +59,7 @@ export class NitroRpcClient implements RpcClientApi { return getAndValidateResult(res, "receive_voucher"); } - public async WaitForLedgerChannelToHaveStatus( + public async WaitForLedgerChannelStatus( channelId: string, status: ChannelStatus ): Promise { @@ -80,7 +80,7 @@ export class NitroRpcClient implements RpcClientApi { return promise; } - public async WaitForPaymentChannelToHaveStatus( + public async WaitForPaymentChannelStatus( channelId: string, status: ChannelStatus ): Promise {