From 5a27f1a3688e4f6ebe59d66a8dc0c0fafccb55a0 Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 15:41:04 +0100 Subject: [PATCH 1/8] test: add e2e test for data commitment window change --- e2e/Dockerfile_e2e | 2 +- e2e/celestia-app/config.toml | 14 +-- e2e/celestia-app/genesis.json | 10 +- e2e/celestia-app/genesis_template.json | 10 +- e2e/orchestrator_test.go | 35 ++++-- e2e/qgb_network.go | 154 +++++++++++++++++++++---- e2e/relayer_test.go | 108 ++++++++++++++++- 7 files changed, 282 insertions(+), 51 deletions(-) diff --git a/e2e/Dockerfile_e2e b/e2e/Dockerfile_e2e index 7ada6614..b1935e78 100644 --- a/e2e/Dockerfile_e2e +++ b/e2e/Dockerfile_e2e @@ -16,6 +16,6 @@ RUN apk update && apk --no-cache add bash jq coreutils curl COPY --from=builder /orchestrator-relayer/build/qgb /bin/qgb # p2p port -EXPOSE 30000 +EXPOSE 30000 9090 26657 CMD [ "/bin/qgb" ] diff --git a/e2e/celestia-app/config.toml b/e2e/celestia-app/config.toml index 0f61e6e7..eb236f16 100644 --- a/e2e/celestia-app/config.toml +++ b/e2e/celestia-app/config.toml @@ -383,21 +383,21 @@ version = "v0" wal_file = "data/cs.wal/wal" # How long we wait for a proposal block before prevoting nil -timeout_propose = "50s" +timeout_propose = "500ms" # How much timeout_propose increases with each round -timeout_propose_delta = "10ms" +timeout_propose_delta = "5ms" # How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil) -timeout_prevote = "100ms" +timeout_prevote = "5ms" # How much the timeout_prevote increases with each round -timeout_prevote_delta = "10ms" +timeout_prevote_delta = "1ms" # How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil) -timeout_precommit = "100ms" +timeout_precommit = "5ms" # How much the timeout_precommit increases with each round -timeout_precommit_delta = "10ms" +timeout_precommit_delta = "1ms" # How long we wait after committing a block, before starting on the new # height (this gives us a chance to receive some more precommits, even # though we already have +2/3). -timeout_commit = "50ms" +timeout_commit = "1ms" # How many blocks to look back to check existence of the node's consensus votes before joining consensus # When non-zero, the node will panic upon restart diff --git a/e2e/celestia-app/genesis.json b/e2e/celestia-app/genesis.json index 8828557c..779ece17 100644 --- a/e2e/celestia-app/genesis.json +++ b/e2e/celestia-app/genesis.json @@ -255,18 +255,18 @@ "min_deposit": [ { "denom": "utia", - "amount": "10000000" + "amount": "100" } ], "max_deposit_period": "172800s" }, "voting_params": { - "voting_period": "172800s" + "voting_period": "30s" }, "tally_params": { - "quorum": "0.334000000000000000", - "threshold": "0.500000000000000000", - "veto_threshold": "0.334000000000000000" + "quorum": "0.000001", + "threshold": "0.000001", + "veto_threshold": "0.001" } }, "ibc": { diff --git a/e2e/celestia-app/genesis_template.json b/e2e/celestia-app/genesis_template.json index d3c47561..6dbfae0e 100644 --- a/e2e/celestia-app/genesis_template.json +++ b/e2e/celestia-app/genesis_template.json @@ -255,18 +255,18 @@ "min_deposit": [ { "denom": "utia", - "amount": "10000000" + "amount": "100" } ], "max_deposit_period": "172800s" }, "voting_params": { - "voting_period": "172800s" + "voting_period": "30s" }, "tally_params": { - "quorum": "0.334000000000000000", - "threshold": "0.500000000000000000", - "veto_threshold": "0.334000000000000000" + "quorum": "0.000001", + "threshold": "0.000001", + "veto_threshold": "0.001" } }, "ibc": { diff --git a/e2e/orchestrator_test.go b/e2e/orchestrator_test.go index 60bc7962..3edef212 100644 --- a/e2e/orchestrator_test.go +++ b/e2e/orchestrator_test.go @@ -34,7 +34,12 @@ func TestOrchestratorWithOneValidator(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+50)) + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) + + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+50)) HandleNetworkError(t, network, err, false) // create dht for querying @@ -53,7 +58,7 @@ func TestOrchestratorWithOneValidator(t *testing.T) { // give the orchestrators some time to catchup time.Sleep(time.Second) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+height)) + err = network.WaitForBlock(ctx, int64(window+height)) HandleNetworkError(t, network, err, false) dcConfirm, err := network.GetDataCommitmentConfirmByHeight(ctx, dht, height, CORE0EVMADDRESS) @@ -93,8 +98,12 @@ func TestOrchestratorWithTwoValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+50)) + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+50)) HandleNetworkError(t, network, err, false) // create dht for querying @@ -127,7 +136,7 @@ func TestOrchestratorWithTwoValidators(t *testing.T) { // assert that it carries the right evm address assert.Equal(t, CORE0EVMADDRESS, core0ValsetConfirm.EthAddress) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+c0Height)) + err = network.WaitForBlock(ctx, int64(window+c0Height)) HandleNetworkError(t, network, err, false) // check core0 submitted the data commitment confirm @@ -143,7 +152,7 @@ func TestOrchestratorWithTwoValidators(t *testing.T) { // assert that it carries the right evm address assert.Equal(t, CORE0EVMADDRESS, core0DataCommitmentConfirm.EthAddress) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+c1Height)) + err = network.WaitForBlock(ctx, int64(window+c1Height)) HandleNetworkError(t, network, err, false) // check core1 submitted the data commitment confirm @@ -168,8 +177,12 @@ func TestOrchestratorWithMultipleValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+50)) + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+50)) HandleNetworkError(t, network, err, false) // create dht for querying @@ -208,7 +221,7 @@ func TestOrchestratorWithMultipleValidators(t *testing.T) { // assert that it carries the right evm address assert.Equal(t, CORE0EVMADDRESS, core0ValsetConfirm.EthAddress) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+c0Height)) + err = network.WaitForBlock(ctx, int64(window+c0Height)) HandleNetworkError(t, network, err, false) // check core0 submitted the data commitment confirm @@ -260,8 +273,12 @@ func TestOrchestratorReplayOld(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) - err = network.WaitForBlock(ctx, int64(2*network.DataCommitmentWindow)) + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(2*window)) HandleNetworkError(t, network, err, false) // add core0 orchestrator @@ -273,7 +290,7 @@ func TestOrchestratorReplayOld(t *testing.T) { HandleNetworkError(t, network, err, false) // give time for the orchestrators to submit confirms - err = network.WaitForBlock(ctx, int64(2*network.DataCommitmentWindow+50)) + err = network.WaitForBlock(ctx, int64(2*window+50)) HandleNetworkError(t, network, err, false) // create dht for querying diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index 7a53abc8..14ab4ef2 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -10,6 +10,15 @@ import ( "strings" "time" + "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + sdk "github.com/cosmos/cosmos-sdk/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + qgbwrapper "github.com/celestiaorg/quantum-gravity-bridge/v2/wrappers/QuantumGravityBridge.sol" "github.com/celestiaorg/celestia-app/app" @@ -28,16 +37,15 @@ import ( ) type QGBNetwork struct { - ComposePaths []string - Identifier string - Instance *testcontainers.LocalDockerCompose - EVMRPC string - TendermintRPC string - CelestiaGRPC string - P2PAddr string - EncCfg encoding.Config - DataCommitmentWindow uint64 - Logger tmlog.Logger + ComposePaths []string + Identifier string + Instance *testcontainers.LocalDockerCompose + EVMRPC string + TendermintRPC string + CelestiaGRPC string + P2PAddr string + EncCfg encoding.Config + Logger tmlog.Logger // used by the moderator to notify all the workers. stopChan <-chan struct{} @@ -54,17 +62,16 @@ func NewQGBNetwork() (*QGBNetwork, error) { // and wanted to notify the moderator. toStopChan := make(chan struct{}, 10) network := &QGBNetwork{ - Identifier: id, - ComposePaths: paths, - Instance: instance, - EVMRPC: "http://localhost:8545", - TendermintRPC: "tcp://localhost:26657", - CelestiaGRPC: "localhost:9090", - P2PAddr: "localhost:30000", - EncCfg: encoding.MakeConfig(app.ModuleEncodingRegisters...), - DataCommitmentWindow: 101, // If this one is changed, make sure to change also the genesis file - stopChan: stopChan, - toStopChan: toStopChan, + Identifier: id, + ComposePaths: paths, + Instance: instance, + EVMRPC: "http://localhost:8545", + TendermintRPC: "tcp://localhost:26657", + CelestiaGRPC: "localhost:9090", + P2PAddr: "localhost:30000", + EncCfg: encoding.MakeConfig(app.ModuleEncodingRegisters...), + stopChan: stopChan, + toStopChan: toStopChan, } // moderate stop notifications from waiters. @@ -882,6 +889,97 @@ func (network QGBNetwork) WaitForEventNonce(ctx context.Context, bridge *qgbwrap } } +func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWindow uint64) error { + network.Logger.Info("updating data commitment window", "new_window", newWindow) + kr, err := keyring.New( + "qgb-tests", + "test", + "celestia-app/core0", + nil, + encoding.MakeConfig(app.ModuleEncodingRegisters...).Codec, + ) + if err != nil { + return err + } + qgbGRPC, err := grpc.Dial("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return err + } + defer qgbGRPC.Close() + + signer, err := user.SetupSingleSigner(ctx, kr, qgbGRPC, encoding.MakeConfig(app.ModuleEncodingRegisters...)) + if err != nil { + return err + } + + // create and submit a new param change proposal for the data commitment window + change := proposal.NewParamChange( + types.ModuleName, + string(types.ParamsStoreKeyDataCommitmentWindow), + fmt.Sprintf("\"%d\"", newWindow), + ) + content := proposal.NewParameterChangeProposal( + "data commitment window update", + "description", + []proposal.ParamChange{change}, + ) + + msg, err := v1beta1.NewMsgSubmitProposal( + content, + sdk.NewCoins( + sdk.NewCoin(app.BondDenom, sdk.NewInt(5000000))), + signer.Address(), + ) + if err != nil { + return err + } + + _, err = signer.SubmitTx(ctx, []sdk.Msg{msg}, user.SetGasLimitAndFee(3000000, 300000)) + if err != nil { + return err + } + + // query the proposal to get the id + gqc := v1.NewQueryClient(qgbGRPC) + gresp, err := gqc.Proposals( + ctx, + &v1.QueryProposalsRequest{ + ProposalStatus: v1.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD, + }, + ) + if err != nil { + return err + } + if len(gresp.Proposals) != 1 { + return fmt.Errorf("expected to have only one proposal in voting period") + } + + // create and submit a new vote + vote := v1.NewMsgVote( + signer.Address(), + gresp.Proposals[0].Id, + v1.VoteOption_VOTE_OPTION_YES, + "", + ) + + _, err = signer.SubmitTx(ctx, []sdk.Msg{vote}, user.SetGasLimitAndFee(3000000, 300000)) + if err != nil { + return err + } + + // wait for the voting period to finish + time.Sleep(25 * time.Second) + + // check that the parameters got updated as expected + currentWindow, err := network.GetCurrentDataCommitmentWindow(ctx) + if currentWindow != newWindow { + return fmt.Errorf("data commitment window was not updated successfuly. %d vs %d", currentWindow, newWindow) + } + + network.Logger.Info("updated data commitment window successfully") + return nil +} + func (network QGBNetwork) PrintLogs() { _ = network.Instance. WithCommand([]string{"logs"}). @@ -903,3 +1001,17 @@ func (network QGBNetwork) GetLatestValset(ctx context.Context) (*types.Valset, e } return valset, nil } + +func (network QGBNetwork) GetCurrentDataCommitmentWindow(ctx context.Context) (uint64, error) { + qgbGRPC, err := grpc.Dial("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return 0, err + } + defer qgbGRPC.Close() + bqc := types.NewQueryClient(qgbGRPC) + presp, err := bqc.Params(ctx, &types.QueryParamsRequest{}) + if err != nil { + return 0, err + } + return presp.Params.DataCommitmentWindow, nil +} diff --git a/e2e/relayer_test.go b/e2e/relayer_test.go index 809bb4c5..e34eaec7 100644 --- a/e2e/relayer_test.go +++ b/e2e/relayer_test.go @@ -32,7 +32,12 @@ func TestRelayerWithOneValidator(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+50)) + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) + + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+50)) HandleNetworkError(t, network, err, false) // create dht for querying @@ -90,8 +95,12 @@ func TestRelayerWithTwoValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) - err = network.WaitForBlock(ctx, int64(network.DataCommitmentWindow+50)) + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+50)) HandleNetworkError(t, network, err, false) // create dht for querying @@ -147,7 +156,12 @@ func TestRelayerWithMultipleValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(2*network.DataCommitmentWindow)) + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) + + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(2*window)) HandleNetworkError(t, network, err, false) // create dht for querying @@ -200,3 +214,91 @@ func TestRelayerWithMultipleValidators(t *testing.T) { assert.NoError(t, err) assert.GreaterOrEqual(t, dcNonce, latestValset.Nonce) } + +func TestUpdatingTheDataCommitmentWindow(t *testing.T) { + if os.Getenv("QGB_INTEGRATION_TEST") != TRUE { + t.Skip("Skipping QGB integration tests") + } + + network, err := NewQGBNetwork() + HandleNetworkError(t, network, err, false) + + // to release resources after tests + defer network.DeleteAll() //nolint:errcheck + + // start full network with four validators + err = network.StartAll() + HandleNetworkError(t, network, err, false) + + ctx := context.Background() + err = network.WaitForBlock(ctx, int64(100)) + HandleNetworkError(t, network, err, false) + + window, err := network.GetCurrentDataCommitmentWindow(ctx) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window)) + HandleNetworkError(t, network, err, false) + + // update the data commitment window to 200 + err = network.UpdateDataCommitmentWindow(ctx, 200) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+200+100)) + + // shrink the data commitment window to 150 + err = network.UpdateDataCommitmentWindow(ctx, 150) + require.NoError(t, err) + err = network.WaitForBlock(ctx, int64(window+200+150+150+50)) + + nonceAfterTheWindowChanges, err := network.GetLatestAttestationNonce(ctx) + require.NoError(t, err) + + // create dht for querying + bootstrapper, err := helpers.ParseAddrInfos(network.Logger, BOOTSTRAPPERS) + HandleNetworkError(t, network, err, false) + host, _, dht := qgbtesting.NewTestDHT(ctx, bootstrapper) + defer dht.Close() + + // force the connection to the DHT to start the orchestrator + err = ConnectToDHT(ctx, host, dht, bootstrapper[0]) + HandleNetworkError(t, network, err, false) + + _, _, err = network.WaitForOrchestratorToStart(ctx, dht, CORE0EVMADDRESS) + HandleNetworkError(t, network, err, false) + + _, _, err = network.WaitForOrchestratorToStart(ctx, dht, CORE1EVMADDRESS) + HandleNetworkError(t, network, err, false) + + _, _, err = network.WaitForOrchestratorToStart(ctx, dht, CORE2EVMADDRESS) + HandleNetworkError(t, network, err, false) + + _, _, err = network.WaitForOrchestratorToStart(ctx, dht, CORE3EVMADDRESS) + HandleNetworkError(t, network, err, false) + + // give the orchestrators some time to catchup + time.Sleep(time.Second) + + // check whether the four validators are up and running + appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg) + HandleNetworkError(t, network, err, false) + err = appQuerier.Start() + HandleNetworkError(t, network, err, false) + defer appQuerier.Stop() //nolint:errcheck + + latestValset, err := appQuerier.QueryLatestValset(ctx) + assert.NoError(t, err) + assert.Equal(t, 4, len(latestValset.Members)) + + bridge, err := network.GetLatestDeployedQGBContract(ctx) + HandleNetworkError(t, network, err, false) + + err = network.WaitForRelayerToStart(ctx, bridge) + HandleNetworkError(t, network, err, false) + + evmClient := evm.NewClient(nil, bridge, nil, nil, network.EVMRPC, evm.DefaultEVMGasLimit) + + err = network.WaitForEventNonce(ctx, bridge, nonceAfterTheWindowChanges) + HandleNetworkError(t, network, err, false) + dcNonce, err := evmClient.StateLastEventNonce(&bind.CallOpts{Context: ctx}) + assert.NoError(t, err) + assert.GreaterOrEqual(t, dcNonce, nonceAfterTheWindowChanges) +} From 06e1d6983d4f22e9e2da3efe105ff05a386f6071 Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 15:44:52 +0100 Subject: [PATCH 2/8] chore: typo --- e2e/qgb_network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index 14ab4ef2..79494400 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -973,7 +973,7 @@ func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWin // check that the parameters got updated as expected currentWindow, err := network.GetCurrentDataCommitmentWindow(ctx) if currentWindow != newWindow { - return fmt.Errorf("data commitment window was not updated successfuly. %d vs %d", currentWindow, newWindow) + return fmt.Errorf("data commitment window was not updated successfully. %d vs %d", currentWindow, newWindow) } network.Logger.Info("updated data commitment window successfully") From 401861ced5ed5860bc33a66f1b972a022b6df03d Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 15:47:29 +0100 Subject: [PATCH 3/8] chore: lint --- e2e/qgb_network.go | 3 +++ e2e/relayer_test.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index 79494400..ffe9c1a2 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -972,6 +972,9 @@ func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWin // check that the parameters got updated as expected currentWindow, err := network.GetCurrentDataCommitmentWindow(ctx) + if err != nil { + return err + } if currentWindow != newWindow { return fmt.Errorf("data commitment window was not updated successfully. %d vs %d", currentWindow, newWindow) } diff --git a/e2e/relayer_test.go b/e2e/relayer_test.go index e34eaec7..6f1c9028 100644 --- a/e2e/relayer_test.go +++ b/e2e/relayer_test.go @@ -243,11 +243,13 @@ func TestUpdatingTheDataCommitmentWindow(t *testing.T) { err = network.UpdateDataCommitmentWindow(ctx, 200) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+200+100)) + require.NoError(t, err) // shrink the data commitment window to 150 err = network.UpdateDataCommitmentWindow(ctx, 150) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+200+150+150+50)) + require.NoError(t, err) nonceAfterTheWindowChanges, err := network.GetLatestAttestationNonce(ctx) require.NoError(t, err) From db6fc2a6ebc8e04e66b5fb432103f9c4627ac563 Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 16:20:52 +0100 Subject: [PATCH 4/8] chore: better data commitment window query --- e2e/orchestrator_test.go | 12 ----------- e2e/qgb_network.go | 43 +++++++++++++++++++++++++++++++--------- e2e/relayer_test.go | 12 ----------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/e2e/orchestrator_test.go b/e2e/orchestrator_test.go index 3edef212..6898ffa7 100644 --- a/e2e/orchestrator_test.go +++ b/e2e/orchestrator_test.go @@ -34,9 +34,6 @@ func TestOrchestratorWithOneValidator(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+50)) @@ -98,9 +95,6 @@ func TestOrchestratorWithTwoValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+50)) @@ -177,9 +171,6 @@ func TestOrchestratorWithMultipleValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+50)) @@ -273,9 +264,6 @@ func TestOrchestratorReplayOld(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(2*window)) diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index ffe9c1a2..9f99d6d3 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -1006,15 +1006,40 @@ func (network QGBNetwork) GetLatestValset(ctx context.Context) (*types.Valset, e } func (network QGBNetwork) GetCurrentDataCommitmentWindow(ctx context.Context) (uint64, error) { - qgbGRPC, err := grpc.Dial("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - return 0, err + var window uint64 + queryFun := func() error { + qgbGRPC, err := grpc.Dial("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return err + } + defer qgbGRPC.Close() + bqc := types.NewQueryClient(qgbGRPC) + presp, err := bqc.Params(ctx, &types.QueryParamsRequest{}) + if err != nil { + return err + } + window = presp.Params.DataCommitmentWindow + return nil } - defer qgbGRPC.Close() - bqc := types.NewQueryClient(qgbGRPC) - presp, err := bqc.Params(ctx, &types.QueryParamsRequest{}) - if err != nil { - return 0, err + ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) + for { + select { + case <-network.stopChan: + cancel() + return 0, ErrNetworkStopped + case <-ctx.Done(): + cancel() + if errors.Is(ctx.Err(), context.DeadlineExceeded) { + return 0, fmt.Errorf("couldn't query data commitment window") + } + return 0, ctx.Err() + default: + err := queryFun() + if err == nil { + cancel() + return window, nil + } + time.Sleep(2 * time.Second) + } } - return presp.Params.DataCommitmentWindow, nil } diff --git a/e2e/relayer_test.go b/e2e/relayer_test.go index 6f1c9028..7401cf50 100644 --- a/e2e/relayer_test.go +++ b/e2e/relayer_test.go @@ -32,9 +32,6 @@ func TestRelayerWithOneValidator(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+50)) @@ -95,9 +92,6 @@ func TestRelayerWithTwoValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window+50)) @@ -156,9 +150,6 @@ func TestRelayerWithMultipleValidators(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(2*window)) @@ -231,9 +222,6 @@ func TestUpdatingTheDataCommitmentWindow(t *testing.T) { HandleNetworkError(t, network, err, false) ctx := context.Background() - err = network.WaitForBlock(ctx, int64(100)) - HandleNetworkError(t, network, err, false) - window, err := network.GetCurrentDataCommitmentWindow(ctx) require.NoError(t, err) err = network.WaitForBlock(ctx, int64(window)) From 82c7c9b5ec6f936ded2403a89b30b403bc1605fe Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 16:41:06 +0100 Subject: [PATCH 5/8] chore: use printf instead of logger --- e2e/qgb_network.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index 9f99d6d3..ec45f81f 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -890,7 +890,7 @@ func (network QGBNetwork) WaitForEventNonce(ctx context.Context, bridge *qgbwrap } func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWindow uint64) error { - network.Logger.Info("updating data commitment window", "new_window", newWindow) + fmt.Println(fmt.Printf("updating data commitment window %s", newWindow)) kr, err := keyring.New( "qgb-tests", "test", @@ -979,7 +979,7 @@ func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWin return fmt.Errorf("data commitment window was not updated successfully. %d vs %d", currentWindow, newWindow) } - network.Logger.Info("updated data commitment window successfully") + fmt.Println("updated data commitment window successfully") return nil } From 4f2757d46fcf7f66fa6745aa31db7252e7bcd997 Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 16:42:17 +0100 Subject: [PATCH 6/8] chore: use printf instead of logger --- e2e/qgb_network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index ec45f81f..efa895db 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -890,7 +890,7 @@ func (network QGBNetwork) WaitForEventNonce(ctx context.Context, bridge *qgbwrap } func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWindow uint64) error { - fmt.Println(fmt.Printf("updating data commitment window %s", newWindow)) + fmt.Println(fmt.Printf("updating data commitment window %d", newWindow)) kr, err := keyring.New( "qgb-tests", "test", From 7b42c35b4841ac0e7e4bd4c3c5befadfc66054bc Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 21:10:04 +0100 Subject: [PATCH 7/8] chore: order dockerfile ports --- e2e/Dockerfile_e2e | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/Dockerfile_e2e b/e2e/Dockerfile_e2e index b1935e78..b11af384 100644 --- a/e2e/Dockerfile_e2e +++ b/e2e/Dockerfile_e2e @@ -16,6 +16,6 @@ RUN apk update && apk --no-cache add bash jq coreutils curl COPY --from=builder /orchestrator-relayer/build/qgb /bin/qgb # p2p port -EXPOSE 30000 9090 26657 +EXPOSE 9090 26657 30000 CMD [ "/bin/qgb" ] From 77289e1431edfbb10a8396c7665342349ce5dd2f Mon Sep 17 00:00:00 2001 From: rachid Date: Thu, 21 Sep 2023 21:54:34 +0100 Subject: [PATCH 8/8] fix: print --- e2e/qgb_network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/qgb_network.go b/e2e/qgb_network.go index efa895db..3618e5ea 100644 --- a/e2e/qgb_network.go +++ b/e2e/qgb_network.go @@ -890,7 +890,7 @@ func (network QGBNetwork) WaitForEventNonce(ctx context.Context, bridge *qgbwrap } func (network QGBNetwork) UpdateDataCommitmentWindow(ctx context.Context, newWindow uint64) error { - fmt.Println(fmt.Printf("updating data commitment window %d", newWindow)) + fmt.Printf("updating data commitment window %d\n", newWindow) kr, err := keyring.New( "qgb-tests", "test",