Skip to content

Commit

Permalink
Merge pull request #4204 from oasisprotocol/kostko/fix/rt-client-chec…
Browse files Browse the repository at this point in the history
…ksupp

go/runtime/client: Fail SubmitTx early for unsupported runtimes
  • Loading branch information
kostko authored Aug 16, 2021
2 parents 33aeee6 + 5384f06 commit f609998
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/4202.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/runtime/client: Fail SubmitTx early for unsupported runtimes

Make sure that the runtime is actually among the supported runtimes as
otherwise we will not be able to actually get any results back.
6 changes: 6 additions & 0 deletions go/runtime/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (c *runtimeClient) submitTx(ctx context.Context, request *api.SubmitTxReque
return nil, fmt.Errorf("client: cannot submit transaction, p2p disabled")
}

// Make sure that the runtime is actually among the supported runtimes for this node as
// otherwise we will not be able to actually get any results back.
if _, err := c.common.runtimeRegistry.GetRuntime(request.RuntimeID); err != nil {
return nil, fmt.Errorf("client: cannot resolve runtime: %w", err)
}

// Make sure consensus is synced.
select {
case <-c.common.consensus.Synced():
Expand Down
9 changes: 9 additions & 0 deletions go/runtime/client/tests/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func testFailSubmitTransaction(
c api.RuntimeClient,
input string,
) {
// Failures during CheckTx.
resp, err := c.SubmitTxMeta(ctx, &api.SubmitTxRequest{Data: mock.CheckTxFailInput, RuntimeID: runtimeID})
require.NoError(t, err, "SubmitTxMeta")
require.EqualValues(t, &protocol.Error{
Expand All @@ -90,6 +91,14 @@ func testFailSubmitTransaction(

_, err = c.SubmitTx(ctx, &api.SubmitTxRequest{Data: mock.CheckTxFailInput, RuntimeID: runtimeID})
require.Error(t, err, "SubmitTx should fail check tx")

// Failures for unsupported runtimes.
var unsupportedRuntimeID common.Namespace
err = unsupportedRuntimeID.UnmarshalHex("0000000000000000BADF00BADF00BADF00BADF00BADF00BADF00BADF00BADF00")
require.NoError(t, err, "UnmarshalHex")

_, err = c.SubmitTx(ctx, &api.SubmitTxRequest{Data: []byte("irrelevant"), RuntimeID: unsupportedRuntimeID})
require.Error(t, err, "SubmitTx should fail for unsupported runtime")
}

func testQuery(
Expand Down

0 comments on commit f609998

Please sign in to comment.