The Staking API Service is a critical component of the Babylon Phase-1 system, focused on serving information about the state of the network and receiving unbonding requests for further processing. The API can be utilised by user facing applications, such as staking dApps.
This architecture is centered around a message-driven approach, utilizing RabbitMQ queues for inter-service communication. Such a design facilitates high concurrency and enhances fault tolerance by allowing for horizontal scaling and leveraging RabbitMQ's message retry features. The primary infrastructure components include:
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:
For more detailed rules applied to message processing, refer to the queue handler documentation.
The standard staking path encompasses user-initiated staking through CLI/UI, followed by waiting for the staking period (timelock) to expire.
ActiveStakingEvent
messages
to the Active Event Queue for the staking API service to process.timelock_queue
collection.timelock_queue
for
records with expired Bitcoin Staking timelocks and signals the staking API service
to update the staking delegation status to unbonded
.
This status displays to the user that the staking transaction is ready for withdrawal.The early unbonding path enables users to on-demand unlock their staked Bitcoin before the timelock of the staking transaction expires.
timelock_queue
.timelock_queue
in
MongoDB and emits an expired event
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.git clone git@github.com:babylonlabs-io/staking-api-service.git
make run-local
OR, you can run as a docker container
make start-staking-api-service
http://localhost
to see the api server running.The service only contains integration tests so far, run below:
make tests
DBClient
is up to datemockery
: https://vektra.github.io/mockery/latest/make generate-mock-interface
Feel free to submit a pull request or open an issue.