Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-1103] FNS subaccount WS support #2088

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 2 additions & 181 deletions .github/workflows/protocol-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,13 @@ name: Protocol Build & Push Image to AWS ECR
on: # yamllint disable-line rule:truthy
push:
branches:
- 'wl/fnsws'
- main
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x

jobs:
build-and-push-dev:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0' # without this, ignite fails.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_VALIDATOR_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_VALIDATOR_DEV }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev-validator
run: |
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$commit_hash \
-f testing/testnet-dev/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags

build-and-push-dev2:
build-and-push-dev2:
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -79,147 +44,3 @@ jobs:
-t $ECR_REGISTRY/$ECR_REPOSITORY:$commit_hash \
-f testing/testnet-dev/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags

build-and-push-dev3:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0' # without this, ignite fails.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_VALIDATOR_DEV3 }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_VALIDATOR_DEV3 }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev3-validator
run: |
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$commit_hash \
-f testing/testnet-dev/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags

build-and-push-dev4:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0' # without this, ignite fails.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_VALIDATOR_DEV4 }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_VALIDATOR_DEV4 }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev4-validator
run: |
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$commit_hash \
-f testing/testnet-dev/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags

build-and-push-dev5:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0' # without this, ignite fails.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_VALIDATOR_DEV5 }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_VALIDATOR_DEV5 }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev5-validator
run: |
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$commit_hash \
-f testing/testnet-dev/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags

build-and-push-staging:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./protocol
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0' # without this, ignite fails.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_VALIDATOR_STAGING }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_VALIDATOR_STAGING }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: staging-validator
run: |
make localnet-build-amd64
commit_hash=$(git rev-parse --short=7 HEAD)
docker build \
--platform amd64 \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$commit_hash \
-f testing/testnet-staging/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags
44 changes: 41 additions & 3 deletions protocol/streaming/ws/websocket_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Parse subaccountIds from query parameters
subaccountIds, err := parseSubaccountIds(r)
if err != nil {
ws.logger.Error(
"Error parsing subaccountIds",
"err", err,
)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

websocketMessageSender := &WebsocketMessageSender{
cdc: ws.cdc,
Expand All @@ -78,8 +88,7 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) {

err = ws.streamingManager.Subscribe(
clobPairIds,
// TODO@(wliu) add subaccount ids
[]*satypes.SubaccountId{},
subaccountIds,
websocketMessageSender,
)
if err != nil {
Expand All @@ -91,11 +100,40 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) {
}
}

// parseSubaccountIds is a helper function to parse the subaccountIds from the query parameters.
func parseSubaccountIds(r *http.Request) ([]*satypes.SubaccountId, error) {
subaccountIdsParam := r.URL.Query().Get("subaccountIds")
if subaccountIdsParam == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here, i think split on empty string probably returns empty array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, nil
}

idStrs := strings.Split(subaccountIdsParam, ",")
subaccountIds := make([]*satypes.SubaccountId, len(idStrs))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pref zero-initialize to reduce error situations where an empty array initialized with len X has length X and we might check len(subaccounts) to determine success of parsing subaccount ids

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for i, idStr := range idStrs {
parts := strings.Split(idStr, "/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid subaccountId format: %s, expected subaccount_id format: owner/number", idStr)
}

number, err := strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("invalid subaccount number: %s, expected subaccount_id format: owner/number", parts[1])
}

subaccountIds[i] = &satypes.SubaccountId{
Owner: parts[0],
Number: uint32(number),
}
}

return subaccountIds, nil
}

// parseClobPairIds is a helper function to parse the clobPairIds from the query parameters.
func parseClobPairIds(r *http.Request) ([]uint32, error) {
clobPairIdsParam := r.URL.Query().Get("clobPairIds")
if clobPairIdsParam == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we can remove this special case now that empty clobpair ids is valid, i think rest of code should result in nil, nil as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, fmt.Errorf("missing clobPairIds parameter")
return nil, nil
}

idStrs := strings.Split(clobPairIdsParam, ",")
Expand Down
Loading