Skip to content

Commit

Permalink
Merge pull request #4809 from Guitarheroua/guitarheroua/4506-cff-enco…
Browse files Browse the repository at this point in the history
…ding-optional

[Access] 4506 - Make CCF encoded events optional via request parameter
  • Loading branch information
durkmurder authored Oct 27, 2023
2 parents 692969b + 36c93d8 commit 87af80f
Show file tree
Hide file tree
Showing 29 changed files with 913 additions and 354 deletions.
10 changes: 5 additions & 5 deletions access/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type API interface {
SendTransaction(ctx context.Context, tx *flow.TransactionBody) error
GetTransaction(ctx context.Context, id flow.Identifier) (*flow.TransactionBody, error)
GetTransactionsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.TransactionBody, error)
GetTransactionResult(ctx context.Context, id flow.Identifier, blockID flow.Identifier, collectionID flow.Identifier) (*TransactionResult, error)
GetTransactionResultByIndex(ctx context.Context, blockID flow.Identifier, index uint32) (*TransactionResult, error)
GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*TransactionResult, error)
GetTransactionResult(ctx context.Context, id flow.Identifier, blockID flow.Identifier, collectionID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) (*TransactionResult, error)
GetTransactionResultByIndex(ctx context.Context, blockID flow.Identifier, index uint32, requiredEventEncodingVersion entities.EventEncodingVersion) (*TransactionResult, error)
GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) ([]*TransactionResult, error)

GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)
GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)
Expand All @@ -41,8 +41,8 @@ type API interface {
ExecuteScriptAtBlockHeight(ctx context.Context, blockHeight uint64, script []byte, arguments [][]byte) ([]byte, error)
ExecuteScriptAtBlockID(ctx context.Context, blockID flow.Identifier, script []byte, arguments [][]byte) ([]byte, error)

GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64) ([]flow.BlockEvents, error)
GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier) ([]flow.BlockEvents, error)
GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64, requiredEventEncodingVersion entities.EventEncodingVersion) ([]flow.BlockEvents, error)
GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) ([]flow.BlockEvents, error)

GetLatestProtocolStateSnapshot(ctx context.Context) ([]byte, error)

Expand Down
19 changes: 14 additions & 5 deletions access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ func (h *Handler) GetTransactionResult(
}
}

result, err := h.api.GetTransactionResult(ctx, transactionID, blockId, collectionId)
eventEncodingVersion := req.GetEventEncodingVersion()
result, err := h.api.GetTransactionResult(ctx, transactionID, blockId, collectionId, eventEncodingVersion)
if err != nil {
return nil, err
}
Expand All @@ -296,7 +297,9 @@ func (h *Handler) GetTransactionResultsByBlockID(
return nil, err
}

results, err := h.api.GetTransactionResultsByBlockID(ctx, id)
eventEncodingVersion := req.GetEventEncodingVersion()

results, err := h.api.GetTransactionResultsByBlockID(ctx, id, eventEncodingVersion)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -342,7 +345,9 @@ func (h *Handler) GetTransactionResultByIndex(
return nil, err
}

result, err := h.api.GetTransactionResultByIndex(ctx, blockID, req.GetIndex())
eventEncodingVersion := req.GetEventEncodingVersion()

result, err := h.api.GetTransactionResultByIndex(ctx, blockID, req.GetIndex(), eventEncodingVersion)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -513,7 +518,9 @@ func (h *Handler) GetEventsForHeightRange(
startHeight := req.GetStartHeight()
endHeight := req.GetEndHeight()

results, err := h.api.GetEventsForHeightRange(ctx, eventType, startHeight, endHeight)
eventEncodingVersion := req.GetEventEncodingVersion()

results, err := h.api.GetEventsForHeightRange(ctx, eventType, startHeight, endHeight, eventEncodingVersion)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -545,7 +552,9 @@ func (h *Handler) GetEventsForBlockIDs(
return nil, err
}

results, err := h.api.GetEventsForBlockIDs(ctx, eventType, blockIDs)
eventEncodingVersion := req.GetEventEncodingVersion()

results, err := h.api.GetEventsForBlockIDs(ctx, eventType, blockIDs, eventEncodingVersion)
if err != nil {
return nil, err
}
Expand Down
13 changes: 10 additions & 3 deletions access/legacy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"

"github.com/onflow/flow/protobuf/go/flow/entities"
accessproto "github.com/onflow/flow/protobuf/go/flow/legacy/access"
entitiesproto "github.com/onflow/flow/protobuf/go/flow/legacy/entities"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -189,7 +190,13 @@ func (h *Handler) GetTransactionResult(
) (*accessproto.TransactionResultResponse, error) {
id := convert.MessageToIdentifier(req.GetId())

result, err := h.api.GetTransactionResult(ctx, id, flow.ZeroID, flow.ZeroID)
result, err := h.api.GetTransactionResult(
ctx,
id,
flow.ZeroID,
flow.ZeroID,
entities.EventEncodingVersion_JSON_CDC_V0,
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -313,7 +320,7 @@ func (h *Handler) GetEventsForHeightRange(
startHeight := req.GetStartHeight()
endHeight := req.GetEndHeight()

results, err := h.api.GetEventsForHeightRange(ctx, eventType, startHeight, endHeight)
results, err := h.api.GetEventsForHeightRange(ctx, eventType, startHeight, endHeight, entities.EventEncodingVersion_JSON_CDC_V0)
if err != nil {
return nil, err
}
Expand All @@ -331,7 +338,7 @@ func (h *Handler) GetEventsForBlockIDs(
eventType := req.GetType()
blockIDs := convert.MessagesToIdentifiers(req.GetBlockIds())

results, err := h.api.GetEventsForBlockIDs(ctx, eventType, blockIDs)
results, err := h.api.GetEventsForBlockIDs(ctx, eventType, blockIDs, entities.EventEncodingVersion_JSON_CDC_V0)
if err != nil {
return nil, err
}
Expand Down
92 changes: 47 additions & 45 deletions access/mock/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions engine/access/rest/apiproxy/rest_proxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/onflow/flow-go/module/metrics"

accessproto "github.com/onflow/flow/protobuf/go/flow/access"
"github.com/onflow/flow/protobuf/go/flow/entities"
)

// RestProxyHandler is a structure that represents the proxy algorithm for observer node.
Expand Down Expand Up @@ -147,17 +148,24 @@ func (r *RestProxyHandler) GetTransaction(ctx context.Context, id flow.Identifie
}

// GetTransactionResult returns transaction result by the transaction ID.
func (r *RestProxyHandler) GetTransactionResult(ctx context.Context, id flow.Identifier, blockID flow.Identifier, collectionID flow.Identifier) (*access.TransactionResult, error) {
func (r *RestProxyHandler) GetTransactionResult(
ctx context.Context,
id flow.Identifier,
blockID flow.Identifier,
collectionID flow.Identifier,
requiredEventEncodingVersion entities.EventEncodingVersion,
) (*access.TransactionResult, error) {
upstream, err := r.FaultTolerantClient()
if err != nil {

return nil, err
}

getTransactionResultRequest := &accessproto.GetTransactionRequest{
Id: id[:],
BlockId: blockID[:],
CollectionId: collectionID[:],
Id: id[:],
BlockId: blockID[:],
CollectionId: collectionID[:],
EventEncodingVersion: requiredEventEncodingVersion,
}

transactionResultResponse, err := upstream.GetTransactionResult(ctx, getTransactionResultRequest)
Expand Down Expand Up @@ -258,16 +266,22 @@ func (r *RestProxyHandler) ExecuteScriptAtBlockID(ctx context.Context, blockID f
}

// GetEventsForHeightRange returns events by their name in the specified blocks heights.
func (r *RestProxyHandler) GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64) ([]flow.BlockEvents, error) {
func (r *RestProxyHandler) GetEventsForHeightRange(
ctx context.Context,
eventType string,
startHeight, endHeight uint64,
requiredEventEncodingVersion entities.EventEncodingVersion,
) ([]flow.BlockEvents, error) {
upstream, err := r.FaultTolerantClient()
if err != nil {
return nil, err
}

getEventsForHeightRangeRequest := &accessproto.GetEventsForHeightRangeRequest{
Type: eventType,
StartHeight: startHeight,
EndHeight: endHeight,
Type: eventType,
StartHeight: startHeight,
EndHeight: endHeight,
EventEncodingVersion: requiredEventEncodingVersion,
}
eventsResponse, err := upstream.GetEventsForHeightRange(ctx, getEventsForHeightRangeRequest)
r.log("upstream", "GetEventsForHeightRange", err)
Expand All @@ -280,7 +294,12 @@ func (r *RestProxyHandler) GetEventsForHeightRange(ctx context.Context, eventTyp
}

// GetEventsForBlockIDs returns events by their name in the specified block IDs.
func (r *RestProxyHandler) GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier) ([]flow.BlockEvents, error) {
func (r *RestProxyHandler) GetEventsForBlockIDs(
ctx context.Context,
eventType string,
blockIDs []flow.Identifier,
requiredEventEncodingVersion entities.EventEncodingVersion,
) ([]flow.BlockEvents, error) {
upstream, err := r.FaultTolerantClient()
if err != nil {
return nil, err
Expand All @@ -289,8 +308,9 @@ func (r *RestProxyHandler) GetEventsForBlockIDs(ctx context.Context, eventType s
blockIds := convert.IdentifiersToMessages(blockIDs)

getEventsForBlockIDsRequest := &accessproto.GetEventsForBlockIDsRequest{
Type: eventType,
BlockIds: blockIds,
Type: eventType,
BlockIds: blockIds,
EventEncodingVersion: requiredEventEncodingVersion,
}
eventsResponse, err := upstream.GetEventsForBlockIDs(ctx, getEventsForBlockIDsRequest)
r.log("upstream", "GetEventsForBlockIDs", err)
Expand Down
Loading

0 comments on commit 87af80f

Please sign in to comment.