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

feat: support phase1 unbonding #23

Merged
merged 35 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5ad178b
fix
gusin13 Dec 10, 2024
badc1fc
fix
gusin13 Dec 10, 2024
e96599b
fix
gusin13 Dec 10, 2024
aac2260
improve config
gusin13 Dec 10, 2024
27130c4
fix
gusin13 Dec 10, 2024
859b9b5
fix mocks and processes
gusin13 Dec 10, 2024
03d3f9b
tracked subs
gusin13 Dec 10, 2024
061a808
fix config
gusin13 Dec 10, 2024
8224971
fix funcs
gusin13 Dec 10, 2024
d387f35
push to channels
gusin13 Dec 10, 2024
9cc16cb
chan handlers
gusin13 Dec 10, 2024
d173d61
mocks
gusin13 Dec 10, 2024
31d3dcd
add metrics
gusin13 Dec 11, 2024
61a6bbe
handling withdrawn delegations
gusin13 Dec 11, 2024
52ef5ab
fix msgs
gusin13 Dec 11, 2024
fa8f269
fix methods
gusin13 Dec 11, 2024
5f7a1a9
fix channel handlers
gusin13 Dec 11, 2024
6cf69f1
bump workflows
gusin13 Dec 11, 2024
8eb710e
fix gh wf
gusin13 Dec 11, 2024
3859f30
global params
gusin13 Dec 11, 2024
8c1b5ce
fix global params
gusin13 Dec 11, 2024
1c84059
deps
gusin13 Dec 11, 2024
797b134
fix
gusin13 Dec 11, 2024
6e064fa
fix
gusin13 Dec 11, 2024
01bb56d
fix notifier start
gusin13 Dec 11, 2024
c3ff260
fix docker
gusin13 Dec 12, 2024
5443ca7
start clean
gusin13 Dec 12, 2024
25df15d
imrpove pollers
gusin13 Dec 12, 2024
8a664db
fix cfg
gusin13 Dec 12, 2024
750ca47
fix lint
gusin13 Dec 12, 2024
c91514c
fix cmnts
gusin13 Dec 12, 2024
f84a9fe
pr comment: rm unneeded fields in delegation document
gusin13 Dec 13, 2024
d881e4f
pr comment: set fetch limit in mongo to avoid fetching too many results
gusin13 Dec 13, 2024
a89b298
pr comment: update delegation document to include unbonding tx data
gusin13 Dec 13, 2024
6b60e28
fix docker config
gusin13 Dec 13, 2024
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
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ on:

jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.6.0
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.7.0
with:
run-unit-tests: true
run-integration-tests: false
run-lint: true
run-build: true
run-gosec: true
gosec-args: "-no-fail ./..."

go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: false
run-lint: true
run-build: true
run-gosec: true
gosec-args: "-no-fail ./..."

docker_pipeline:
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.6.0
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.7.0
secrets: inherit
with:
publish: false
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: false
run-lint: true
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ stop-service:

run-local:
./bin/local-startup.sh;
go run cmd/staking-expiry-checker/main.go --config config/config-local.yml
go run cmd/staking-expiry-checker/main.go \
--config config/config-local.yml \
--params config/global-params.json

generate-mock-interface:
cd internal/db && mockery --name=DbInterface --output=../../tests/mocks --outpkg=mocks --filename=mock_db_client.go
Expand Down
15 changes: 12 additions & 3 deletions cmd/staking-expiry-checker/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
)

const (
defaultConfigFileName = "config.yml"
defaultConfigFileName = "config.yml"
defaultGlobalParamsFileName = "global_params.json"
)

var (
cfgPath string
rootCmd = &cobra.Command{
cfgPath string
globalParamsPath string
rootCmd = &cobra.Command{
Use: "start-server",
}
)
Expand All @@ -26,8 +28,11 @@ func Setup() error {
}

defaultConfigPath := getDefaultConfigFile(homePath, defaultConfigFileName)
defaultGlobalParamsPath := getDefaultConfigFile(homePath, defaultGlobalParamsFileName)

rootCmd.PersistentFlags().StringVar(&cfgPath, "config", defaultConfigPath, fmt.Sprintf("config file (default %s)", defaultConfigPath))
rootCmd.PersistentFlags().StringVar(&globalParamsPath, "params", defaultGlobalParamsPath, fmt.Sprintf("global params file (default %s)", defaultGlobalParamsPath))

if err := rootCmd.Execute(); err != nil {
return err
}
Expand All @@ -42,3 +47,7 @@ func getDefaultConfigFile(homePath, filename string) string {
func GetConfigPath() string {
return cfgPath
}

func GetGlobalParamsPath() string {
return globalParamsPath
}
42 changes: 26 additions & 16 deletions cmd/staking-expiry-checker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"os/signal"
"syscall"

"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
Expand All @@ -11,9 +13,8 @@ import (
"github.com/babylonlabs-io/staking-expiry-checker/internal/btcclient"
"github.com/babylonlabs-io/staking-expiry-checker/internal/config"
"github.com/babylonlabs-io/staking-expiry-checker/internal/db"
"github.com/babylonlabs-io/staking-expiry-checker/internal/observability/metrics"
"github.com/babylonlabs-io/staking-expiry-checker/internal/poller"
"github.com/babylonlabs-io/staking-expiry-checker/internal/services"
"github.com/babylonlabs-io/staking-expiry-checker/internal/types"
)

func init() {
Expand All @@ -23,43 +24,52 @@ func init() {
}

func main() {
ctx := context.Background()

// setup cli commands and flags
// Setup CLI commands and flags
if err := cli.Setup(); err != nil {
log.Fatal().Err(err).Msg("error while setting up cli")
}

// load config
// Load config
cfgPath := cli.GetConfigPath()
cfg, err := config.New(cfgPath)
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("error while loading config file: %s", cfgPath))
}

// initialize metrics with the metrics port from config
metricsPort := cfg.Metrics.GetMetricsPort()
metrics.Init(metricsPort)
paramsPath := cli.GetGlobalParamsPath()
params, err := types.NewGlobalParams(paramsPath)
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("error while loading global params file: %s", paramsPath))
}

// create new db client
// Create context with signal handling
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

// Create DB client
dbClient, err := db.New(ctx, cfg.Db)
if err != nil {
log.Fatal().Err(err).Msg("error while creating db client")
}

// Create BTC client
btcClient, err := btcclient.NewBtcClient(&cfg.Btc)
if err != nil {
log.Fatal().Err(err).Msg("error while creating btc client")
}

delegationService := services.NewService(dbClient, btcClient)
// Create BTC notifier
btcNotifier, err := btcclient.NewBTCNotifier(
&cfg.Btc,
&btcclient.EmptyHintCache{},
)
if err != nil {
log.Fatal().Err(err).Msg("error while creating delegation service")
log.Fatal().Err(err).Msg("error while creating btc notifier")
}

p, err := poller.NewPoller(cfg.Poller, delegationService)
if err != nil {
log.Fatal().Err(err).Msg("error while creating poller")
// Create service
service := services.NewService(cfg, params, dbClient, btcNotifier, btcClient)
if err := service.RunUntilShutdown(ctx); err != nil {
log.Fatal().Err(err).Msg("failed to start service")
}
p.Start(ctx)
}
20 changes: 12 additions & 8 deletions config/config-docker.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
poller:
interval: 5s
pollers:
log-level: debug
timeout: 10s
expiry-checker:
interval: 5s
timeout: 10s
btc-subscriber:
interval: 5s
timeout: 10s
db:
username: root
password: example
address: "mongodb://localhost:27017"
db-name: staking-api-service
btc:
endpoint: localhost:18332
disable-tls: false
net-params: testnet
rpc-user: rpcuser
rpc-pass: rpcpass
endpoint: localhost:38332 # signet endpoint
disable-tls: true # should be disabled for local testing
net-params: signet # signet network params
rpc-user: rpcuser # rpc user
rpc-pass: rpcpass # rpc pass
metrics:
host: 0.0.0.0
port: 2112
20 changes: 12 additions & 8 deletions config/config-local.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
poller:
interval: 5s
pollers:
log-level: debug
timeout: 10s
expiry-checker:
interval: 5s
timeout: 1000s
btc-subscriber:
interval: 5s
timeout: 1000s
db:
username: root
password: example
address: "mongodb://localhost:27017"
db-name: staking-api-service
btc:
endpoint: localhost:18332
disable-tls: false
net-params: testnet
rpc-user: rpcuser
rpc-pass: rpcpass
endpoint: 127.0.0.1:38332 # signet endpoint
disable-tls: true # should be disabled for local testing
net-params: signet # signet network params
rpc-user: rpcuser # rpc user
rpc-pass: rpcpass # rpc pass
metrics:
host: 0.0.0.0
port: 2112
25 changes: 25 additions & 0 deletions config/global-params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"versions": [
{
"version": 0,
"activation_height": 192840,
"staking_cap": 50000000000,
"tag": "01020304",
"covenant_pks": [
"0381b70c01535f5153a8039c21150c53f3e49a083555b57930103db8a7272ff336",
"02159f46467124f6bbba77060520571ddb07c7e95ff54d8b9958ec0b0d59d86c03",
"039705be04f3a3eb5c3d0dd61e648e06ea8170975744594fe702e8088bcceff375",
"02ce138027bfdfb4dd631e9cecf097082c8a505ab16de36f5e3eb816d105ba7575",
"03e15dba250612e79e22abf28a1828ba5e6bdfaaa6ed2d87462b046994c33fa46f"
],
"covenant_quorum": 3,
"unbonding_time": 1000,
"unbonding_fee": 20000,
"max_staking_amount": 1000000000,
"min_staking_amount": 1000000,
"max_staking_time": 65000,
"min_staking_time": 64000,
"confirmation_depth": 10
}
]
}
8 changes: 7 additions & 1 deletion contrib/images/staking-expiry-checker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -x

BINARY=${BINARY:-/bin/staking-expiry-checker}
CONFIG=${CONFIG:-/home/staking-expiry-checker/config.yml}
PARAMS=${PARAMS:-/home/staking-expiry-checker/global-params.json}

if ! [ -f "${BINARY}" ]; then
echo "The binary $(basename "${BINARY}") cannot be found."
Expand All @@ -15,4 +16,9 @@ if ! [ -f "${CONFIG}" ]; then
exit 1
fi

$BINARY --config "$CONFIG" 2>&1
if ! [ -f "${PARAMS}" ]; then
echo "The global parameters file $(basename "${PARAMS}") cannot be found. Please add the global parameters file to the shared folder. Use the PARAMS environment variable if the name of the global parameters file is not 'global-params.json'"
exit 1
fi

$BINARY --config "$CONFIG" --params "$PARAMS" 2>&1
Loading
Loading