Skip to content

Commit

Permalink
fix: decoding issues in unbonding tx (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 authored Dec 27, 2024
1 parent e130b17 commit 710451a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 111 deletions.
10 changes: 5 additions & 5 deletions cmd/staking-expiry-checker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"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/services"
"github.com/babylonlabs-io/staking-expiry-checker/internal/types"
"github.com/babylonlabs-io/staking-expiry-checker/params"
)

func init() {
Expand All @@ -36,11 +36,11 @@ func main() {
log.Fatal().Err(err).Msg(fmt.Sprintf("error while loading config file: %s", cfgPath))
}

paramsPath := cli.GetGlobalParamsPath()
params, err := types.NewGlobalParams(paramsPath)
paramsRetriever, err := params.NewGlobalParamsRetriever(cli.GetGlobalParamsPath())
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("error while loading global params file: %s", paramsPath))
log.Fatal().Err(err).Msg("failed to initialize params retriever")
}
versionedParams := paramsRetriever.VersionedParams()

// Create context with signal handling
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
Expand Down Expand Up @@ -68,7 +68,7 @@ func main() {
}

// Create service
service := services.NewService(cfg, params, dbClient, btcNotifier, btcClient)
service := services.NewService(cfg, versionedParams, dbClient, btcNotifier, btcClient)
if err := service.RunUntilShutdown(ctx); err != nil {
log.Fatal().Err(err).Msg("failed to start service")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.1

require (
github.com/babylonlabs-io/babylon v0.18.1
github.com/babylonlabs-io/networks/parameters v0.2.2
github.com/btcsuite/btcd v0.24.3-0.20241011125836-24eb815168f4
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.6
Expand Down Expand Up @@ -33,7 +34,6 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/babylonlabs-io/networks/parameters v0.2.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcutil/psbt v1.1.8 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/aws/aws-sdk-go v1.49.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3Tju
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.18.1 h1:ID8BDDHc+snOnW2nqjP7OMf3a//5mvjbEmiAoJAtZlc=
github.com/babylonlabs-io/babylon v0.18.1/go.mod h1:sT+KG2U+M0tDMNZZ2L5CwlXX0OpagGEs56BiWXqaZFw=
github.com/babylonlabs-io/networks/parameters v0.2.3 h1:T1nigYrU61GWSpJZko3Gylt3T3eHHoxXLWkhw7s3uz0=
github.com/babylonlabs-io/networks/parameters v0.2.3/go.mod h1:iEJVOzaLsE33vpP7J4u+CRGfkSIfErUAwRmgCFCBpyI=
github.com/babylonlabs-io/networks/parameters v0.2.2 h1:TCu39fZvjX5f6ZZrjhYe54M6wWxglNewuKu56yE+zrc=
github.com/babylonlabs-io/networks/parameters v0.2.2/go.mod h1:iEJVOzaLsE33vpP7J4u+CRGfkSIfErUAwRmgCFCBpyI=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
20 changes: 0 additions & 20 deletions internal/services/params.go

This file was deleted.

3 changes: 0 additions & 3 deletions internal/services/pollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func (s *Service) processBTCSubscriber(ctx context.Context) *types.Error {
// Process each delegation
for _, delegation := range delegations {
if s.trackedSubs.IsSubscribed(delegation.StakingTxHashHex) {
log.Debug().
Str("stakingTxHash", delegation.StakingTxHashHex).
Msg("Delegation already subscribed, skipping")
continue
}

Expand Down
20 changes: 15 additions & 5 deletions internal/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"
"time"

"github.com/babylonlabs-io/networks/parameters/parser"
"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"
Expand All @@ -19,9 +20,9 @@ type Service struct {
wg sync.WaitGroup
quit chan struct{}

cfg *config.Config
btcNotifier notifier.ChainNotifier
params *types.GlobalParams
cfg *config.Config
btcNotifier notifier.ChainNotifier
paramsVersions *parser.ParsedGlobalParams

// interfaces
db db.DbInterface
Expand All @@ -37,7 +38,7 @@ type Service struct {

func NewService(
cfg *config.Config,
params *types.GlobalParams,
paramsVersions *parser.ParsedGlobalParams,
db db.DbInterface,
btcNotifier notifier.ChainNotifier,
btc btcclient.BtcInterface,
Expand All @@ -46,7 +47,7 @@ func NewService(
quit: make(chan struct{}),
cfg: cfg,
btcNotifier: btcNotifier,
params: params,
paramsVersions: paramsVersions,
db: db,
btc: btc,
trackedSubs: NewTrackedSubscriptions(),
Expand Down Expand Up @@ -138,3 +139,12 @@ func (s *Service) startBTCSubscriberPoller(ctx context.Context) {
}
}
}

func (s *Service) getVersionedParams(height uint64) (*parser.ParsedVersionedGlobalParams, error) {
params := s.paramsVersions.GetVersionedGlobalParamsByHeight(height)
if params == nil {
return nil, fmt.Errorf("the params for height %d does not exist", height)
}

return params, nil
}
Loading

0 comments on commit 710451a

Please sign in to comment.