Skip to content

Commit

Permalink
go/worker/executor: batch CheckTx transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jul 13, 2021
1 parent 11876d1 commit d721f15
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 112 deletions.
15 changes: 7 additions & 8 deletions go/runtime/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
"github.com/oasisprotocol/oasis-core/go/runtime/client/api"
enclaverpc "github.com/oasisprotocol/oasis-core/go/runtime/enclaverpc/api"
"github.com/oasisprotocol/oasis-core/go/runtime/host"
runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry"
"github.com/oasisprotocol/oasis-core/go/runtime/tagindexer"
"github.com/oasisprotocol/oasis-core/go/runtime/transaction"
Expand Down Expand Up @@ -198,15 +197,15 @@ func (c *runtimeClient) CheckTx(ctx context.Context, request *api.CheckTxRequest
return fmt.Errorf("client: failed to get current epoch: %w", err)
}

_, err = rt.CheckTx(ctx, rs.CurrentBlock, lb, epoch, request.Data)
switch {
case err == nil:
return nil
case errors.Is(err, host.ErrCheckTxFailed):
return errors.WithContext(api.ErrCheckTxFailed, errors.Context(err))
default:
resp, err := rt.CheckTx(ctx, rs.CurrentBlock, lb, epoch, transaction.RawBatch{request.Data})
if err != nil {
return fmt.Errorf("client: local transaction check failed: %w", err)
}
if !resp[0].IsSuccess() {
return errors.WithContext(api.ErrCheckTxFailed, resp[0].Error.String())
}

return nil
}

// Implements api.RuntimeClient.
Expand Down
4 changes: 2 additions & 2 deletions go/runtime/client/tests/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func testQuery(
// Check that indexer has indexed txn keys (check the mock worker for key/values).
tx, err = c.QueryTx(ctx, &api.QueryTxRequest{RuntimeID: runtimeID, Key: []byte("txn_foo"), Value: []byte("txn_bar")})
require.NoError(t, err, "QueryTx")
require.EqualValues(t, 2, tx.Block.Header.Round)
require.EqualValues(t, 3, tx.Block.Header.Round)
require.EqualValues(t, 0, tx.Index)
// Check for values from TestNode/ExecutorWorker/QueueTx
require.True(t, strings.HasPrefix(string(tx.Input), "hello world"))
Expand All @@ -161,7 +161,7 @@ func testQuery(
require.EqualValues(t, testInput, txns[0])

// Check events query (see mock worker for emitted events).
events, err := c.GetEvents(ctx, &api.GetEventsRequest{RuntimeID: runtimeID, Round: 2})
events, err := c.GetEvents(ctx, &api.GetEventsRequest{RuntimeID: runtimeID, Round: 3})
require.NoError(t, err, "GetEvents")
require.Len(t, events, 1)
require.EqualValues(t, []byte("txn_foo"), events[0].Key)
Expand Down
21 changes: 7 additions & 14 deletions go/runtime/host/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type RichRuntime interface {
rb *block.Block,
lb *consensus.LightBlock,
epoch beacon.EpochTime,
tx []byte,
) (*transaction.CheckedTransaction, error)
batch transaction.RawBatch,
) ([]protocol.CheckTxResult, error)

// Query requests the runtime to answer a runtime-specific query.
Query(
Expand Down Expand Up @@ -64,16 +64,16 @@ func (r *richRuntime) CheckTx(
rb *block.Block,
lb *consensus.LightBlock,
epoch beacon.EpochTime,
tx []byte,
) (*transaction.CheckedTransaction, error) {
batch transaction.RawBatch,
) ([]protocol.CheckTxResult, error) {
if rb == nil || lb == nil {
return nil, ErrInvalidArgument
}

resp, err := r.Call(ctx, &protocol.Body{
RuntimeCheckTxBatchRequest: &protocol.RuntimeCheckTxBatchRequest{
ConsensusBlock: *lb,
Inputs: transaction.RawBatch{tx},
Inputs: batch,
Block: *rb,
Epoch: epoch,
},
Expand All @@ -83,17 +83,10 @@ func (r *richRuntime) CheckTx(
return nil, errors.WithContext(ErrInternal, err.Error())
case resp.RuntimeCheckTxBatchResponse == nil:
return nil, errors.WithContext(ErrInternal, "malformed runtime response")
case len(resp.RuntimeCheckTxBatchResponse.Results) != 1:
case len(resp.RuntimeCheckTxBatchResponse.Results) != len(batch):
return nil, errors.WithContext(ErrInternal, "malformed runtime response: incorrect number of results")
}

// Interpret CheckTx result.
result := resp.RuntimeCheckTxBatchResponse.Results[0]
if !result.IsSuccess() {
return nil, errors.WithContext(ErrCheckTxFailed, result.Error.String())
}

return result.ToCheckedTransaction(tx), nil
return resp.RuntimeCheckTxBatchResponse.Results, nil
}

// Implements RichRuntime.
Expand Down
1 change: 1 addition & 0 deletions go/worker/compute/executor/committee/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ func (ub *unresolvedBatch) resolve(ctx context.Context, sb storage.Backend) (tra
if err != nil {
return nil, fmt.Errorf("failed to fetch inputs from storage: %w", err)
}
ub.batch = batch
return batch, nil
}
Loading

0 comments on commit d721f15

Please sign in to comment.