Skip to content

Commit

Permalink
txsource: Add consensus GetEvents workload
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Apr 15, 2020
1 parent a058e37 commit 0b0241c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
3 changes: 3 additions & 0 deletions go/consensus/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type ClientBackend interface {
// NOTE: Any of these transactions could be invalid.
GetTransactions(ctx context.Context, height int64) ([][]byte, error)

// GetEvents returns the consensus protocol events at specified block height.
GetEvents(ctx context.Context, height int64) ([]roothash.Event, error)

// WatchBlocks returns a channel that produces a stream of consensus
// blocks as they are being finalized.
WatchBlocks(ctx context.Context) (<-chan *Block, pubsub.ClosableSubscription, error)
Expand Down
38 changes: 38 additions & 0 deletions go/consensus/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/oasislabs/oasis-core/go/consensus/api/transaction"
epochtime "github.com/oasislabs/oasis-core/go/epochtime/api"
genesis "github.com/oasislabs/oasis-core/go/genesis/api"
roothash "github.com/oasislabs/oasis-core/go/roothash/api"
)

var (
Expand All @@ -32,6 +33,8 @@ var (
methodGetBlock = serviceName.NewMethod("GetBlock", int64(0))
// methodGetTransactions is the GetTransactions method.
methodGetTransactions = serviceName.NewMethod("GetTransactions", int64(0))
// methodGetEvents is the GetEvents method.
methodGetEvents = serviceName.NewMethod("GetEvents", int64(0))

// methodWatchBlocks is the WatchBlocks method.
methodWatchBlocks = serviceName.NewMethod("WatchBlocks", nil)
Expand Down Expand Up @@ -73,6 +76,10 @@ var (
MethodName: methodGetTransactions.ShortName(),
Handler: handlerGetTransactions,
},
{
MethodName: methodGetEvents.ShortName(),
Handler: handlerGetEvents,
},
},
Streams: []grpc.StreamDesc{
{
Expand Down Expand Up @@ -268,6 +275,29 @@ func handlerGetTransactions( // nolint: golint
return interceptor(ctx, height, info, handler)
}

func handlerGetEvents( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(Backend).GetEvents(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetEvents.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(Backend).GetEvents(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}

func handlerWatchBlocks(srv interface{}, stream grpc.ServerStream) error {
if err := stream.RecvMsg(nil); err != nil {
return err
Expand Down Expand Up @@ -362,6 +392,14 @@ func (c *consensusClient) GetTransactions(ctx context.Context, height int64) ([]
return rsp, nil
}

func (c *consensusClient) GetEvents(ctx context.Context, height int64) ([]roothash.Event, error) {
var rsp []roothash.Event
if err := c.conn.Invoke(ctx, methodGetEvents.FullName(), height, &rsp); err != nil {
return nil, err
}
return rsp, nil
}

func (c *consensusClient) WatchBlocks(ctx context.Context) (<-chan *Block, pubsub.ClosableSubscription, error) {
ctx, sub := pubsub.NewContextSubscription(ctx)

Expand Down
4 changes: 4 additions & 0 deletions go/consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ func (t *tendermintService) GetBlockResults(height int64) (*tmrpctypes.ResultBlo
return result, nil
}

func (t *tendermintService) GetEvents(ctx context.Context, height int64) ([]roothashAPI.Event, error) {
return t.roothash.GetEvents(ctx, height)
}

func (t *tendermintService) WatchTendermintBlocks() (<-chan *tmtypes.Block, *pubsub.Subscription) {
typedCh := make(chan *tmtypes.Block)
sub := t.blockNotifier.Subscribe()
Expand Down
6 changes: 6 additions & 0 deletions go/oasis-node/cmd/debug/txsource/workload/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func (q *queries) doConsensusQueries(ctx context.Context, rng *rand.Rand, height
return fmt.Errorf("GetTransactions at height %d: %w", height, err)
}

// Events.
_, err = q.consensus.GetEvents(ctx, height)
if err != nil {
return fmt.Errorf("GetEvents error at height %d: %w", height, err)
}

q.logger.Debug("Consensus queries done",
"height", height,
"epoch", epoch,
Expand Down
4 changes: 2 additions & 2 deletions go/roothash/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ type MergeDiscrepancyDetectedEvent struct {

// Event is a protocol event.
type Event struct {
ExecutionDiscrepancyDetected *ExecutionDiscrepancyDetectedEvent
MergeDiscrepancyDetected *MergeDiscrepancyDetectedEvent
ExecutionDiscrepancyDetected *ExecutionDiscrepancyDetectedEvent `json:"execution_discrepancy,omitempty"`
MergeDiscrepancyDetected *MergeDiscrepancyDetectedEvent `json:"merge_discrepancy,omitempty"`
}

// MetricsMonitorable is the interface exposed by backends capable of
Expand Down

0 comments on commit 0b0241c

Please sign in to comment.