- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8
Dev Branch - staking backend docs + audit section update #65
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
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a5d60bb
              
                moved staking backend content locally
              
              
                web3jenks 37aac6b
              
                Update docusaurus.config.js
              
              
                web3jenks 3093d2d
              
                moved content
              
              
                web3jenks 92df527
              
                Jenks/move staking backend docs (#64)
              
              
                web3jenks bfc8f60
              
                updated as per vitalis fieedback
              
              
                web3jenks f539dcb
              
                Update audit_reports.mdx
              
              
                web3jenks 1b5f00e
              
                Restructruing of wallet integration (#67)
              
              
                web3jenks 738eaf4
              
                Jenks/move wallet integration (#68)
              
              
                web3jenks c2d0474
              
                fix: remove useless auth code
              
              
                 fb9796c
              
                feat: adjust the crawling method
              
              
                 97e919c
              
                fix: Card style disorder
              
              
                 03f0556
              
                fix: move the backend to developer part
              
              
                 8a4dbc8
              
                chore: del useless code & optimization build warning (#70)
              
              
                kkkk666 7b0bc3e
              
                moved Staking Backend sidebar position up
              
              
                web3jenks File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| title: Staking Backend | ||
| sidebar_label: Staking Backend | ||
| sidebar_position: 4 | ||
| --- | ||
|  | ||
| # Staking Backend | ||
|  | ||
| import { Redirect } from '@docusaurus/router'; | ||
|  | ||
| <Redirect to="/guides/networks/phase-2/testnet/staking_backend/" /> | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "position": 4, | ||
| "label": "Staking Backend", | ||
| "collapsible": true, | ||
| "collapsed": true, | ||
| "className": "staking_backend_sidebar" | ||
| } | 
            File renamed without changes.
          
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| title: Global Configuration | ||
| sidebar_label: Global Configuration | ||
| sidebar_position: 4 | ||
| --- | ||
|  | ||
| # Global Configuration | ||
|  | ||
| {/* TODO */} | 
        
          
          
            209 changes: 209 additions & 0 deletions
          
          209 
        
  docs/developers/staking_backend/services/staking_api_service.mdx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| --- | ||
| title: Staking API Service | ||
| sidebar_label: Staking API Service | ||
| sidebar_position: 1 | ||
| --- | ||
|  | ||
| # Babylon Staking API Service | ||
|  | ||
| The Babylon Staking API Service provides a performant interface between Babylon | ||
| Phase-2 and application layers. It transforms blockchain data for efficient | ||
| access by dApps, serves network state information, and processes unbonding | ||
| requests for Phase-1 delegations. | ||
|  | ||
| > **Note:** Phase-1 delegations are now in maintenance mode. | ||
|  | ||
| ## Hardware Requirements | ||
|  | ||
| - **CPU:** Multicore processor (4 cores minimum) | ||
| - **Memory:** Minimum 1GB RAM | ||
|  | ||
| ## Configuration | ||
|  | ||
| ### 1. Create Home Directory | ||
| ```bash | ||
| mkdir -p ~/.staking-api-service/ | ||
| ``` | ||
|  | ||
| ### 2. Copy the Default Configuration | ||
| ```bash | ||
| cp ~/staking-api-service/config/config-local.yml ~/.staking-api-service/config.yml | ||
| ``` | ||
|  | ||
| ### 3. Update Default Configurations | ||
|  | ||
| Edit the `config.yml` file to match your environment: | ||
|  | ||
| #### MongoDB Cluster Connection | ||
| Set the MongoDB connection address (`address`) and credentials (`username`, | ||
| `password`, and `db-name`) to match the information from your installed MongoDB | ||
| cluster. | ||
|  | ||
| ```yaml | ||
| db: | ||
| address: "mongodb://localhost:27017/?directConnection=true" | ||
| username: "<username>" | ||
| password: "<password>" | ||
| db-name: "<db-name>" | ||
| ``` | ||
|  | ||
| #### RabbitMQ Cluster Connection | ||
| Set the RabbitMQ connection address (`url`) and credentials (`queue_user` and | ||
| `queue_password`) to match the information from your installed RabbitMQ cluster. | ||
|  | ||
| ```yaml | ||
| queue: | ||
| queue_user: admin | ||
| queue_password: password | ||
| url: "localhost:5672" | ||
| ``` | ||
|  | ||
| #### Prometheus Metrics Configuration | ||
| Set the host and port to customize how the metrics are exposed. | ||
|  | ||
| ```yaml | ||
| metrics: | ||
| host: 0.0.0.0 | ||
| port: 2112 | ||
| ``` | ||
|  | ||
| ### 4. Download Global Parameters | ||
|  | ||
| To run the Staking API, a `global-params.json` file that defines all the | ||
| staking parameters is needed. | ||
|  | ||
| To download the global parameters, follow the instructions at: | ||
| [Staking Parameters Documentation](https://docs.babylonlabs.io/docs/user-guides/bitcoin-staking-phase1/backend-deployment/global-params#staking-parameters) | ||
|  | ||
| ### 5. Download Finality Providers | ||
|  | ||
| To run the Staking API, a `finality-provider.json` file that associates finality | ||
| provider BTC public keys with additional information about them such as their | ||
| moniker and commission is needed. | ||
|  | ||
| To generate the concatenated finality providers information from Babylon | ||
| registry, follow the instructions at: | ||
| [Finality Providers Documentation](https://docs.babylonlabs.io/docs/user-guides/bitcoin-staking-phase1/backend-deployment/global-params#22-generating-concatenated-finality-provider-information) | ||
|  | ||
| ## Start the Service | ||
|  | ||
| ### Method A: Docker Deployment (Recommended) | ||
|  | ||
| Runs the Staking API Service image from the official Babylon Docker Hub repository: | ||
|  | ||
| ```bash | ||
| docker run -d --name staking-api-service \ | ||
| -v ~/.staking-api-service/config.yml:/app/config.yml \ | ||
| -v ~/.staking-api-service/global-params.json:/app/global-params.json \ | ||
| -v ~/.staking-api-service/finality-providers.json:/app/finality-providers.json \ | ||
| babylonlabs/staking-api-service:v1.0.0 \ | ||
| --config /app/config.yml \ | ||
| --params /app/global-params.json \ | ||
| --finality-providers /app/finality-providers.json | ||
| ``` | ||
|  | ||
| This approach is recommended for production environments as it provides better | ||
| isolation and simplified deployment. | ||
|  | ||
| ### Method B: Local Binary Execution | ||
|  | ||
| #### 1. Clone the Repository | ||
| ```bash | ||
| git clone https://github.com/babylonlabs-io/staking-api-service.git | ||
| ``` | ||
|  | ||
| #### 2. Check Out the Desired Version | ||
| You can find the latest release | ||
| [here](https://github.com/babylonlabs-io/staking-api-service/releases). | ||
|  | ||
| ```bash | ||
| cd staking-api-service | ||
| git checkout tags/{VERSION} | ||
| ``` | ||
|  | ||
| #### 3. Install the Binary | ||
| ```bash | ||
| make install | ||
| ``` | ||
| This command will build and install the binary to your GOPATH. | ||
|  | ||
| #### 4. Start the Staking API Service | ||
| You can start the Staking API Service by running: | ||
|  | ||
| ```bash | ||
| staking-api-service --config ~/.staking-api-service/config.yml \ | ||
| --params ~/.staking-api-service/global-params.json \ | ||
| --finality-providers ~/.staking-api-service/finality-providers.json | ||
| ``` | ||
|  | ||
| ## Create Systemd Service (Linux Only) | ||
|  | ||
| #### 1. Create Systemd Service Definition | ||
| Run the following command, replacing `system_username` with the appropriate | ||
| system user or service account name: | ||
|  | ||
| ```bash | ||
| cat <<EOF | sudo tee /etc/systemd/system/staking-api-service.service | ||
| [Unit] | ||
| Description=Staking API Service | ||
| After=network.target | ||
|  | ||
| [Service] | ||
| Type=simple | ||
| ExecStart=$(which staking-api-service) \ | ||
| --config /home/system_username/.staking-api-service/config.yml \ | ||
| --params /home/system_username/.staking-api-service/global-params.json \ | ||
| --finality-providers /home/system_username/.staking-api-service/finality-providers.json | ||
| Restart=on-failure | ||
| User=system_username | ||
|  | ||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
| ``` | ||
|  | ||
| #### 2. Reload Systemd Configuration | ||
| ```bash | ||
| sudo systemctl daemon-reload | ||
| ``` | ||
|  | ||
| #### 3. Enable the Service at Boot | ||
| ```bash | ||
| sudo systemctl enable staking-api-service.service | ||
| ``` | ||
|  | ||
| #### 4. Start the Service | ||
| ```bash | ||
| sudo systemctl start staking-api-service.service | ||
| ``` | ||
|  | ||
| #### 5. Verify the Service | ||
| Check service status: | ||
| ```bash | ||
| sudo systemctl status staking-api-service.service | ||
| ``` | ||
|  | ||
| Expected log output: | ||
| ``` | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"debug","time":"2024-07-04T03:36:05Z","message":"Index created successfully on collection: unbonding_queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","time":"2024-07-04T03:36:05Z","message":"Collections and Indexes created successfully."} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","queueName":"active_staking_queue","time":"2024-07-04T03:36:05Z","message":"start receiving messages from queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","queueName":"expired_staking_queue","time":"2024-07-04T03:36:05Z","message":"start receiving messages from queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","queueName":"unbonding_staking_queue","time":"2024-07-04T03:36:05Z","message":"start receiving messages from queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","queueName":"withdraw_staking_queue","time":"2024-07-04T03:36:05Z","message":"start receiving messages from queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","queueName":"staking_stats_queue","time":"2024-07-04T03:36:05Z","message":"start receiving messages from queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","queueName":"btc_info_queue","time":"2024-07-04T03:36:05Z","message":"start receiving messages from queue"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","time":"2024-07-04T03:36:05Z","message":"Initiated Health Check Cron"} | ||
| Jul 04 03:36:05 system_username staking-api-service[824224]: {"level":"info","time":"2024-07-04T03:36:05Z","message":"Starting server on 0.0.0.0:8092"} | ||
| ``` | ||
|  | ||
| ## Monitoring | ||
|  | ||
| The service exposes Prometheus metrics through a Prometheus server. By default, | ||
| it is available at the address configured in the metrics configuration section | ||
| (0.0.0.0:2112). Configure the metrics endpoint in your configuration file as | ||
| needed. | ||
|  | ||
| ## Backup | ||
|  | ||
| The Staking API Service is stateless, so no backups are needed. | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.