Skip to content

Commit 1acef32

Browse files
authored
fix: add health check on startup, increase gas adjustment and update docs (#117)
* fix: add health check on startup, increase gas adjustment and update docs * CHANGELOG * fix: set default gas adjustment to 5
1 parent e5b6f4f commit 1acef32

File tree

5 files changed

+89
-20
lines changed

5 files changed

+89
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3939

4040
### Improvements
4141

42+
* [#117](https://github.com/babylonlabs-io/covenant-emulator/pull/117) Add health check on startup, increase gas adjustment and update docs.
43+
4244
## v0.14.0
4345

4446
* [#114](https://github.com/babylonlabs-io/covenant-emulator/pull/114) bump babylon to v1.0.0-rc.8

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ duty or power. If it has a dishonest super majority, then
3535

3636
* it cannot:
3737

38-
* steal the stakers bitcoins, because all the spending transactions
38+
* steal the staker's bitcoins, because all the spending transactions
3939
require the staker's signature;
4040

41-
* slash the stakers bitcoins by itself, because slashing requires the
41+
* slash the staker's bitcoins by itself, because slashing requires the
4242
secret key of the finality provider, which the covenant committee does
4343
not know in advance, and
4444

@@ -47,8 +47,8 @@ duty or power. If it has a dishonest super majority, then
4747

4848
In other words, there is no way the committee can act against the stakers,
4949
except rejecting their staking requests. Furthermore, the dishonest actions
50-
of the covenant committee can be contained by 1) including the stakers
51-
counterparty in the committee, such as the PoS systems foundation, or 2)
50+
of the covenant committee can be contained by 1) including the staker's
51+
counterparty in the committee, such as the PoS system's foundation, or 2)
5252
implementing a governance proposal to re-elect the committee.
5353

5454
This rule-enforcing committee is necessary for now because the current BTC
@@ -110,6 +110,21 @@ This flow ensures that all private key operations remain isolated within the
110110
secure Covenant Signer while the emulator handles the blockchain interaction
111111
and validation logic.
112112

113+
## Boot Order and Dependencies
114+
115+
The Covenant Emulator requires the Covenant Signer to be running and unlocked
116+
before it can start. This is because the emulator performs a health check
117+
during startup to ensure the signer is accessible and ready to handle signing requests.
118+
If the signer is not running or is locked, the emulator will fail to start with a clear error message.
119+
120+
The required boot sequence is:
121+
1. Start and unlock the Covenant Signer
122+
2. Verify the signer is running and accessible
123+
3. Start the Covenant Emulator
124+
125+
The emulator will automatically verify the signer's availability
126+
during startup and will not proceed if the signer is not ready.
127+
113128
![Covenant Architecture](./static/covenant.png)
114129

115130
## Covenant Emulator Stack Setup
@@ -118,3 +133,10 @@ please follow the instructions in the following documents
118133
(in sequence):
119134
1. [Covenant Signer Setup](./docs/covenant-signer-setup.md)
120135
2. [Covenant Emulator Setup](./docs/covenant-emulator-setup.md)
136+
137+
## Important Limitations
138+
139+
**Keyring Backend**: The covenant emulator only supports the `test`
140+
keyring backend. This limitation exists because the emulator requires automated
141+
signing capabilities without manual passphrase entry. Other keyring backends
142+
will cause the emulator to fail at startup.

cmd/covd/start.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func start(ctx *cli.Context) error {
4545
}
4646

4747
if cfg.BabylonConfig.KeyringBackend != keyring.BackendTest {
48-
return fmt.Errorf("the keyring backend in config must be `test` for automatic signing, got %s", cfg.BabylonConfig.KeyringBackend)
48+
return fmt.Errorf("the keyring backend in config must be `test` for automatic signing, got %s. Other keyring backends are not supported as they require manual passphrase entry", cfg.BabylonConfig.KeyringBackend)
4949
}
5050

5151
logger, err := log.NewRootLoggerWithFile(covcfg.LogFile(homePath), cfg.LogLevel)
@@ -63,6 +63,13 @@ func start(ctx *cli.Context) error {
6363
return fmt.Errorf("failed to create remote signer from config: %w", err)
6464
}
6565

66+
// Perform health check on the remote signer
67+
logger.Info("Performing health check on remote signer...")
68+
if _, err := signer.PubKey(); err != nil {
69+
return fmt.Errorf("remote signer health check failed - ensure the signer is running and unlocked: %w", err)
70+
}
71+
logger.Info("Remote signer health check passed")
72+
6673
ce, err := covenant.NewCovenantEmulator(cfg, bbnClient, logger, signer)
6774
if err != nil {
6875
return fmt.Errorf("failed to start the covenant emulator: %w", err)

config/babylon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type BBNConfig struct {
1212
RPCAddr string `long:"rpc-address" description:"address of the rpc server to connect to"`
1313
GRPCAddr string `long:"grpc-address" description:"address of the grpc server to connect to"`
1414
AccountPrefix string `long:"acc-prefix" description:"account prefix to use for addresses"`
15-
KeyringBackend string `long:"keyring-type" description:"type of keyring to use"`
15+
KeyringBackend string `long:"keyring-type" description:"type of keyring to use"` // IMPORTANT: Only 'test' backend is supported due to automated signing requirements
1616
GasAdjustment float64 `long:"gas-adjustment" description:"adjustment factor when using gas estimation"`
1717
GasPrices string `long:"gas-prices" description:"comma separated minimum gas prices to accept for transactions"`
1818
KeyDirectory string `long:"key-dir" description:"directory to store keys in"`
@@ -33,7 +33,7 @@ func DefaultBBNConfig() BBNConfig {
3333
GRPCAddr: dc.GRPCAddr,
3434
AccountPrefix: dc.AccountPrefix,
3535
KeyringBackend: dc.KeyringBackend,
36-
GasAdjustment: dc.GasAdjustment,
36+
GasAdjustment: 5, // Increased from default to ensure sufficient gas
3737
GasPrices: dc.GasPrices,
3838
Debug: dc.Debug,
3939
Timeout: dc.Timeout,

docs/covenant-emulator-setup.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ daemon program.
66
## Table of Contents
77

88
1. [Prerequesites](#1-prerequisites)
9-
2. [Install Covenant Emulator Binary](#2-install-covenant-emulator-binary)
10-
3. [Setting up the Covenant Emulator Program](#3-setting-up-the-covenant-emulator-program)
11-
1. [Initialize directories](#31-initialize-directories)
12-
2. [Configure the covenant emulator](#32-configure-the-covenant-emulator)
13-
4. [Generate key pairs](#4-generate-key-pairs)
14-
5. [Start the emulator daemon](#5-start-the-emulator-daemon)
9+
2. [Boot Order and Signer Dependency](#2-boot-order-and-signer-dependency)
10+
3. [Install Covenant Emulator Binary](#3-install-covenant-emulator-binary)
11+
4. [Setting up the Covenant Emulator Program](#4-setting-up-the-covenant-emulator-program)
12+
1. [Initialize directories](#41-initialize-directories)
13+
2. [Configure the covenant emulator](#42-configure-the-covenant-emulator)
14+
5. [Generate key pairs](#5-generate-key-pairs)
15+
6. [Start the emulator daemon](#6-start-the-emulator-daemon)
1516

1617
## 1. Prerequisites
1718

@@ -26,7 +27,36 @@ To successfully complete this guide, you will need:
2627
2. A connection to a Babylon node. To run your own node, please refer to the
2728
[Babylon Node Setup Guide](https://github.com/babylonlabs-io/networks/blob/main/bbn-test-5/bbn-test-5/babylon-node/README.md).
2829

29-
## 2. Install covenant emulator binary
30+
## 2. Boot Order and Signer Dependency
31+
32+
The Covenant Emulator requires the Covenant Signer to be running and
33+
unlocked before it can start. This is a critical dependency that is enforced
34+
through a health check during the emulator's startup process.
35+
36+
### Required Boot Sequence
37+
38+
1. Start the Covenant Signer:
39+
2. Unlock the Covenant Signer:
40+
3. Verify the signer is running and accessible:
41+
4. Start the Covenant Emulator:
42+
43+
### Health Check Behavior
44+
45+
The emulator performs an automatic health check during startup by attempting
46+
to fetch the signer's public key. If this check fails, the emulator will:
47+
- Log an error message indicating the signer is not accessible
48+
- Provide guidance to ensure the signer is running and unlocked
49+
- Exit with a non-zero status code
50+
51+
### Troubleshooting
52+
53+
If the emulator fails to start with a signer-related error:
54+
1. Verify the signer is running and accessible at the configured URL
55+
2. Check if the signer is locked and needs to be unlocked
56+
3. Verify the HMAC key in the emulator's configuration matches the signer's configuration
57+
4. Check the signer's logs for any errors or issues
58+
59+
## 3. Install covenant emulator binary
3060

3161
If you haven't already, download [Golang 1.23](https://go.dev/dl).
3262

@@ -65,9 +95,9 @@ export PATH=$HOME/go/bin:$PATH
6595
echo 'export PATH=$HOME/go/bin:$PATH' >> ~/.profile
6696
```
6797

68-
## 3. Setting up the covenant emulator program
98+
## 4. Setting up the covenant emulator program
6999

70-
### 3.1. Initialize directories
100+
### 4.1. Initialize directories
71101

72102
Next, initialize the node and home directory by generating all of the
73103
necessary files such as `covd.conf`. These files will live in the `<path>`
@@ -85,7 +115,7 @@ $ ls <path>
85115
├── logs # Covd logs
86116
```
87117

88-
### 3.2. Configure the covenant emulator
118+
### 4.2. Configure the covenant emulator
89119

90120
Use the following parameters to configure the `covd.conf` file.
91121

@@ -140,11 +170,19 @@ Below are brief explanations of the configuration entries:
140170
- `GRPCAddr` - gRPC endpoint for connecting to a Babylon node
141171
- `Key` - Name of the key in the keyring used for transaction signing
142172
- `KeyringBackend` - Storage backend for the keyring (os, file, kwallet, pass, test, memory)
173+
174+
> **IMPORTANT LIMITATION**: The covenant emulator only supports the `test`
175+
keyring backend. This limitation exists because the emulator requires automated
176+
signing capabilities and the test backend is the only one that supports this
177+
feature without manual passphrase entry. Other keyring backends
178+
(os, file, kwallet, pass, memory) will not work and will
179+
cause the emulator to fail at startup.
180+
143181
- `URL` - Endpoint where the remote signing service is running
144182
- `Timeout` - Maximum time to wait for remote signer responses
145183
- `HMACKey` - Secret key for HMAC authentication with the covenant-signer
146184

147-
### 3.3. Configure HMAC Authentication (Recommended for Production)
185+
### 4.3. Configure HMAC Authentication (Recommended for Production)
148186

149187
HMAC (Hash-based Message Authentication Code) authentication provides an additional layer of security for the communication between the covenant-emulator and covenant-signer by ensuring that only authenticated requests are processed.
150188

@@ -174,7 +212,7 @@ HMAC (Hash-based Message Authentication Code) authentication provides an additio
174212
When HMAC authentication is properly configured, all requests between the covenant-emulator and covenant-signer will include an authentication header. If there's a key mismatch or other authentication issues, you'll see error messages in the logs.
175213

176214

177-
## 4. Generate key pairs
215+
## 5. Generate key pairs
178216

179217
The covenant emulator daemon requires the existence of a Babylon keyring that
180218
signs signatures and interacts with Babylon. Use the following command to generate
@@ -209,7 +247,7 @@ To check your balance, View your account on the
209247
address.
210248

211249

212-
## 5. Start the emulator daemon
250+
## 6. Start the emulator daemon
213251

214252
You can start the covenant emulator daemon using the following command:
215253

0 commit comments

Comments
 (0)