From abc6d203b8863877115cca744fe141525731f115 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 16 Jan 2025 09:47:47 +0400 Subject: [PATCH 1/2] Replace .Str()+strconv.Format() in logs with .Uint32 for uint32 types --- internal/services/delegation.go | 6 +++--- internal/services/expiry_checker.go | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/services/delegation.go b/internal/services/delegation.go index 70d4cdf..d2ce3df 100644 --- a/internal/services/delegation.go +++ b/internal/services/delegation.go @@ -154,7 +154,7 @@ func (s *Service) processCovenantQuorumReachedEvent( if newState == types.StateActive { log.Debug(). Str("staking_tx", covenantQuorumReachedEvent.StakingTxHash). - Str("staking_start_height", strconv.FormatUint(uint64(delegation.StartHeight), 10)). + Uint32("staking_start_height", delegation.StartHeight). Stringer("event_type", EventCovenantQuorumReached). Msg("handling active state") @@ -338,8 +338,8 @@ func (s *Service) processBTCDelegationUnbondedEarlyEvent( Str("staking_tx", unbondedEarlyEvent.StakingTxHash). Stringer("new_state", types.StateUnbonding). Str("early_unbonding_start_height", unbondedEarlyEvent.StartHeight). - Str("unbonding_time", strconv.FormatUint(uint64(delegation.UnbondingTime), 10)). - Str("unbonding_expire_height", strconv.FormatUint(uint64(unbondingExpireHeight), 10)). + Uint32("unbonding_time", delegation.UnbondingTime). + Uint32("unbonding_expire_height", unbondingExpireHeight). Stringer("sub_state", subState). Stringer("event_type", EventBTCDelgationUnbondedEarly). Msg("updating delegation state") diff --git a/internal/services/expiry_checker.go b/internal/services/expiry_checker.go index af1ac90..f8db35e 100644 --- a/internal/services/expiry_checker.go +++ b/internal/services/expiry_checker.go @@ -4,8 +4,6 @@ import ( "context" "fmt" "net/http" - "strconv" - "github.com/babylonlabs-io/babylon-staking-indexer/internal/db" "github.com/babylonlabs-io/babylon-staking-indexer/internal/types" "github.com/babylonlabs-io/babylon-staking-indexer/internal/utils/poller" @@ -49,7 +47,7 @@ func (s *Service) checkExpiry(ctx context.Context) *types.Error { Str("staking_tx", delegation.StakingTxHashHex). Stringer("current_state", delegation.State). Stringer("new_sub_state", tlDoc.DelegationSubState). - Str("expire_height", strconv.FormatUint(uint64(tlDoc.ExpireHeight), 10)). + Uint32("expire_height", tlDoc.ExpireHeight). Msg("checking if delegation is expired") stateUpdateErr := s.db.UpdateBTCDelegationState( From 7c32007e70714e92fe1eea4057d5f9bb39fa5659 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 16 Jan 2025 11:06:12 +0400 Subject: [PATCH 2/2] Remove unused types.IndexedBlock, types.TimeLockTxType --- internal/types/block.go | 47 ------------------------------ internal/types/timelock_tx_type.go | 12 -------- 2 files changed, 59 deletions(-) delete mode 100644 internal/types/block.go delete mode 100644 internal/types/timelock_tx_type.go diff --git a/internal/types/block.go b/internal/types/block.go deleted file mode 100644 index 6b7d220..0000000 --- a/internal/types/block.go +++ /dev/null @@ -1,47 +0,0 @@ -package types - -import ( - "github.com/btcsuite/btcd/btcutil" - "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/wire" - - "github.com/babylonlabs-io/babylon-staking-indexer/internal/utils" -) - -// IndexedBlock is a BTC block with some extra information compared to wire.MsgBlock, including: -// - block height -// - txHash, txHashWitness, txIndex for each Tx -// These are necessary for generating Merkle proof (and thus the `MsgInsertBTCSpvProof` message in babylon) of a certain tx -type IndexedBlock struct { - Height int32 - Header *wire.BlockHeader - Txs []*btcutil.Tx -} - -func NewIndexedBlock(height int32, header *wire.BlockHeader, txs []*btcutil.Tx) *IndexedBlock { - return &IndexedBlock{height, header, txs} -} - -func NewIndexedBlockFromMsgBlock(height int32, block *wire.MsgBlock) *IndexedBlock { - return &IndexedBlock{ - height, - &block.Header, - utils.GetWrappedTxs(block), - } -} - -func (ib *IndexedBlock) MsgBlock() *wire.MsgBlock { - msgTxs := []*wire.MsgTx{} - for _, tx := range ib.Txs { - msgTxs = append(msgTxs, tx.MsgTx()) - } - - return &wire.MsgBlock{ - Header: *ib.Header, - Transactions: msgTxs, - } -} - -func (ib *IndexedBlock) BlockHash() chainhash.Hash { - return ib.Header.BlockHash() -} diff --git a/internal/types/timelock_tx_type.go b/internal/types/timelock_tx_type.go deleted file mode 100644 index 4b78509..0000000 --- a/internal/types/timelock_tx_type.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -type TimeLockTxType string - -const ( - ExpiredTxType TimeLockTxType = "EXPIRED" - EarlyUnbondingTxType TimeLockTxType = "EARLY_UNBONDING" -) - -func (t TimeLockTxType) String() string { - return string(t) -}