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

Merge main into dev branch 3 #18

Merged
merged 9 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ on:

jobs:
lint_test:
uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.0
with:
run-unit-tests: true
run-integration-tests: false
run-lint: false

docker_pipeline:
uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.0
secrets: inherit
with:
publish: false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ on:

jobs:
lint_test:
uses: babylonchain/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.2.0
with:
run-unit-tests: true
run-integration-tests: false
run-lint: false

docker_pipeline:
needs: ["lint_test"]
uses: babylonchain/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.2.0
secrets: inherit
with:
publish: true
Expand Down
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.

Parameters

Licensor: Babylonchain, Inc.
Licensor: Babylon Labs, Ltd.

Licensed Work: staking-api-service
The Licensed Work is (c) 2024 Babylonchain, Inc.
The Licensed Work is (c) 2024 Babylon Labs, Ltd.

Additional Use Grant: None.

Change Date: 2027-05-15 (March 15th, 2027]
Change Date: 2027-05-15 (March 15th, 2027)

Change License: Apache 2.0

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ build-docker:
$(MAKE) BBN_PRIV_DEPLOY_KEY=${BBN_PRIV_DEPLOY_KEY} -C contrib/images staking-api-service

start-staking-api-service: build-docker stop-service
docker-compose up -d
docker compose up -d

stop-service:
docker-compose down
docker compose down

run-local:
./bin/local-startup.sh;
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ The primary infrastructure components include:
2. RabbitMQ
3. Redis cache (Work In Progress)

### Infra recommendation

Since the service is public-facing and exposes a set of endpoints,
it's crucial to apply additional protection mechanisms in front of the service.
Here are some recommendations beyond the basic configurations of request size
limit, header limit, request caching, and DDOS protection:

- Request size limit
- Header limit
- Request caching
- Rate limiting
- DDOS protection mechanism
- SSL/TLS
- ... other common API gateway setup for running with microservices.

### Key Features

- **Asynchronous Communication**: Enables decoupled, non-blocking inter-service
Expand All @@ -39,9 +54,9 @@ The standard staking path encompasses user-initiated staking through CLI/UI,
followed by waiting for the staking period (timelock) to expire.

1. **Transaction Submission**: User-submitted staking transactions are
confirmed and picked up by the [indexer](https://github.com/babylonchain/staking-indexer)
confirmed and picked up by the [indexer](https://github.com/babylonlabs-io/staking-indexer)
after receiving sufficient Bitcoin block confirmations.
2. **Event Queuing**: The indexer sends `ActiveStakingEvent` [messages](https://github.com/babylonchain/staking-queue-client/blob/main/client/schema.go#L24)
2. **Event Queuing**: The indexer sends `ActiveStakingEvent` [messages](https://github.com/babylonlabs-io/staking-queue-client/blob/main/client/schema.go#L24)
to the Active Event Queue for the staking API service to process.
3. **Processing and State Management**: The staking API service executes statistical calculations,
data transformation, and staking state management, inserting records into the `timelock_queue` collection.
Expand All @@ -64,12 +79,12 @@ stores it for further processing by the unbonding pipeline.
3. **Committee Co-Signing**: The unbonding pipeline collects additional signatures
from the covenant committee and submits the unbonding transaction to the Bitcoin network.
4. **Transaction Detection**: The unbonding transaction is detected by the staking-indexer
once it receives a sufficient number of confirmations and a corresponding [unbonding event](https://github.com/babylonchain/staking-queue-client/blob/main/client/schema.go#L70)
once it receives a sufficient number of confirmations and a corresponding [unbonding event](https://github.com/babylonlabs-io/staking-queue-client/blob/main/client/schema.go#L70)
is placed into the RabbitMQ queue.
5. **Processing and State Management**: Similar to the standard path, the staking API service
handles statistical updates, adjusts the staking state, and inserts a record into the `timelock_queue`.
6. **Finalization**: The expire-service processes items from the `timelock_queue` in
MongoDB and emits an [expired event](https://github.com/babylonchain/staking-queue-client/blob/main/client/schema.go#L130)
MongoDB and emits an [expired event](https://github.com/babylonlabs-io/staking-queue-client/blob/main/client/schema.go#L130)
to RabbitMQ for the staking-api-service to process. This marks completed staking
transactions as `unbonded`. This status displays to the user that the staking transaction is ready for withdrawal.

Expand All @@ -85,7 +100,7 @@ transactions as `unbonded`. This status displays to the user that the staking tr
1. Clone the repository:

```bash
git clone [email protected]:babylonchain/staking-api-service.git
git clone [email protected]:babylonlabs-io/staking-api-service.git
```

2. Run the service:
Expand Down
4 changes: 2 additions & 2 deletions bin/local-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ $(docker ps -q -f name=^/${MONGO_CONTAINER_NAME}$) ]; then
else
echo "Starting MongoDB"
# Start MongoDB
docker-compose up -d mongodb
docker compose up -d mongodb
fi

# Check if the RabbitMQ container is already running
Expand All @@ -17,6 +17,6 @@ if [ $(docker ps -q -f name=^/${RABBITMQ_CONTAINER_NAME}$) ]; then
else
echo "Starting RabbitMQ"
# Start RabbitMQ
docker-compose up -d rabbitmq
docker compose up -d rabbitmq
sleep 10
fi
22 changes: 11 additions & 11 deletions cmd/staking-api-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
"context"
"fmt"

"github.com/babylonchain/staking-api-service/cmd/staking-api-service/cli"
"github.com/babylonchain/staking-api-service/cmd/staking-api-service/scripts"
"github.com/babylonchain/staking-api-service/internal/api"
"github.com/babylonchain/staking-api-service/internal/clients"
"github.com/babylonchain/staking-api-service/internal/config"
"github.com/babylonchain/staking-api-service/internal/db/model"
"github.com/babylonchain/staking-api-service/internal/observability/healthcheck"
"github.com/babylonchain/staking-api-service/internal/observability/metrics"
"github.com/babylonchain/staking-api-service/internal/queue"
"github.com/babylonchain/staking-api-service/internal/services"
"github.com/babylonchain/staking-api-service/internal/types"
"github.com/babylonlabs-io/staking-api-service/cmd/staking-api-service/cli"
"github.com/babylonlabs-io/staking-api-service/cmd/staking-api-service/scripts"
"github.com/babylonlabs-io/staking-api-service/internal/api"
"github.com/babylonlabs-io/staking-api-service/internal/clients"
"github.com/babylonlabs-io/staking-api-service/internal/config"
"github.com/babylonlabs-io/staking-api-service/internal/db/model"
"github.com/babylonlabs-io/staking-api-service/internal/observability/healthcheck"
"github.com/babylonlabs-io/staking-api-service/internal/observability/metrics"
"github.com/babylonlabs-io/staking-api-service/internal/queue"
"github.com/babylonlabs-io/staking-api-service/internal/services"
"github.com/babylonlabs-io/staking-api-service/internal/types"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
)
Expand Down
10 changes: 5 additions & 5 deletions cmd/staking-api-service/scripts/replay_unprocessed_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"errors"
"fmt"

"github.com/babylonchain/staking-api-service/internal/config"
"github.com/babylonchain/staking-api-service/internal/db"
"github.com/babylonchain/staking-api-service/internal/queue"
queueClient "github.com/babylonchain/staking-queue-client/client"
"github.com/babylonlabs-io/staking-api-service/internal/config"
"github.com/babylonlabs-io/staking-api-service/internal/db"
"github.com/babylonlabs-io/staking-api-service/internal/queue"
queueClient "github.com/babylonlabs-io/staking-queue-client/client"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -83,4 +83,4 @@ func processEventMessage(ctx context.Context, queues *queue.Queues, event Generi
fmt.Printf("Error: unknown event type: %v\n", event.EventType)
return fmt.Errorf("unknown event type: %v", event.EventType)
}
}
}
4 changes: 2 additions & 2 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ DOCKER = $(shell which docker)
.PHONY: staking-api-service staking-api-service-rmi

staking-api-service:
$(DOCKER) build --tag babylonchain/staking-api-service -f staking-api-service/Dockerfile \
$(DOCKER) build --tag babylonlabs-io/staking-api-service -f staking-api-service/Dockerfile \
$(shell git rev-parse --show-toplevel)

staking-api-service-rmi:
$(DOCKER) rmi babylonchain/staking-api-service 2>/dev/null; true
$(DOCKER) rmi babylonlabs-io/staking-api-service 2>/dev/null; true
12 changes: 6 additions & 6 deletions contrib/images/staking-api-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
openssh

# Build
WORKDIR /go/src/github.com/babylonchain/staking-api-service
WORKDIR /go/src/github.com/babylonlabs-io/staking-api-service
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonchain/staking-api-service/
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/staking-api-service/

# Copy the rest of the files
COPY ./ /go/src/github.com/babylonchain/staking-api-service/
COPY ./ /go/src/github.com/babylonlabs-io/staking-api-service/


RUN LDFLAGS='-extldflags "-static" -v' \
Expand All @@ -31,18 +31,18 @@
make build

# Final minimal image with binary only
FROM alpine:3.16 as run

Check warning on line 34 in contrib/images/staking-api-service/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN addgroup --gid 1138 -S staking-api-service && adduser --uid 1138 -S staking-api-service -G staking-api-service
RUN apk add bash curl jq

# Label should match your github repo
LABEL org.opencontainers.image.source="https://github.com/babylonchain/staking-api-service:${VERSION}"
LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/staking-api-service:${VERSION}"

Check warning on line 40 in contrib/images/staking-api-service/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$VERSION' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/


# Copy over binaries from the build-env
COPY --from=builder /go/src/github.com/babylonchain/staking-api-service/build/staking-api-service /bin/staking-api-service
COPY --from=builder /go/src/github.com/babylonchain/staking-api-service/contrib/images/staking-api-service/entrypoint.sh /bin/entrypoint.sh
COPY --from=builder /go/src/github.com/babylonlabs-io/staking-api-service/build/staking-api-service /bin/staking-api-service
COPY --from=builder /go/src/github.com/babylonlabs-io/staking-api-service/contrib/images/staking-api-service/entrypoint.sh /bin/entrypoint.sh

WORKDIR /home/staking-api-service
RUN chown -R staking-api-service /home/staking-api-service
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.9"
services:
staking-api-service:
image: babylonchain/staking-api-service:latest
image: babylonlabs-io/staking-api-service:latest
container_name: staking-api-service
ports:
- "80:8090"
Expand Down
14 changes: 7 additions & 7 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const docTemplate = `{
"400": {
"description": "Error: Bad Request",
"schema": {
"$ref": "#/definitions/github_com_babylonchain_staking-api-service_internal_types.Error"
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_types.Error"
}
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ const docTemplate = `{
"400": {
"description": "Error: Bad Request",
"schema": {
"$ref": "#/definitions/github_com_babylonchain_staking-api-service_internal_types.Error"
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_types.Error"
}
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ const docTemplate = `{
"400": {
"description": "Error: Bad Request",
"schema": {
"$ref": "#/definitions/github_com_babylonchain_staking-api-service_internal_types.Error"
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_types.Error"
}
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ const docTemplate = `{
"400": {
"description": "Error: Bad Request",
"schema": {
"$ref": "#/definitions/github_com_babylonchain_staking-api-service_internal_types.Error"
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_types.Error"
}
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ const docTemplate = `{
"400": {
"description": "Invalid request payload",
"schema": {
"$ref": "#/definitions/github_com_babylonchain_staking-api-service_internal_types.Error"
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_types.Error"
}
}
}
Expand Down Expand Up @@ -287,15 +287,15 @@ const docTemplate = `{
"400": {
"description": "Missing or invalid 'staking_tx_hash_hex' query parameter",
"schema": {
"$ref": "#/definitions/github_com_babylonchain_staking-api-service_internal_types.Error"
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_types.Error"
}
}
}
}
}
},
"definitions": {
"github_com_babylonchain_staking-api-service_internal_types.Error": {
"github_com_babylonlabs-io_staking-api-service_internal_types.Error": {
"type": "object",
"properties": {
"err": {},
Expand Down
Loading
Loading