Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Dec 5, 2024
1 parent bcfa0b1 commit e65160b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
72 changes: 36 additions & 36 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,7 @@ func (bc *BabylonController) BTCCheckpointParams() (*BTCCheckpointParams, error)
return bc.btccheckpointParamsWithRetry()
}

func (bc *BabylonController) Params() (*StakingParams, error) {
bccParams, err := bc.btccheckpointParamsWithRetry()

if err != nil {
return nil, err
}

func (bc *BabylonController) queryStakingTrackerWithRetries() (*StakingTrackerResponse, error) {
var stakingTrackerParams *StakingTrackerResponse
if err := retry.Do(func() error {
trackerParams, err := bc.QueryStakingTracker()
Expand All @@ -189,6 +183,22 @@ func (bc *BabylonController) Params() (*StakingParams, error) {
return nil, err
}

return stakingTrackerParams, nil
}

func (bc *BabylonController) Params() (*StakingParams, error) {
bccParams, err := bc.btccheckpointParamsWithRetry()

if err != nil {
return nil, err
}

stakingTrackerParams, err := bc.queryStakingTrackerWithRetries()

if err != nil {
return nil, err
}

return &StakingParams{
ConfirmationTimeBlocks: bccParams.ConfirmationTimeBlocks,
FinalizationTimeoutBlocks: bccParams.FinalizationTimeoutBlocks,
Expand All @@ -207,13 +217,9 @@ func (bc *BabylonController) Params() (*StakingParams, error) {
}, nil
}

func (bc *BabylonController) ParamsByBtcHeight(btcHeight uint32) (*StakingParams, error) {
bccParams, err := bc.btccheckpointParamsWithRetry()

if err != nil {
return nil, err
}

func (bc *BabylonController) queryStakingTrackerByBtcHeightWithRetries(
btcHeight uint32,
) (*StakingTrackerResponse, error) {
var stakingTrackerParams *StakingTrackerResponse
if err := retry.Do(func() error {
trackerParams, err := bc.QueryStakingTrackerByBtcHeight(btcHeight)
Expand All @@ -232,6 +238,22 @@ func (bc *BabylonController) ParamsByBtcHeight(btcHeight uint32) (*StakingParams
return nil, err
}

return stakingTrackerParams, nil
}

func (bc *BabylonController) ParamsByBtcHeight(btcHeight uint32) (*StakingParams, error) {
bccParams, err := bc.btccheckpointParamsWithRetry()

if err != nil {
return nil, err
}

stakingTrackerParams, err := bc.queryStakingTrackerByBtcHeightWithRetries(btcHeight)

if err != nil {
return nil, err
}

return &StakingParams{
ConfirmationTimeBlocks: bccParams.ConfirmationTimeBlocks,
FinalizationTimeoutBlocks: bccParams.FinalizationTimeoutBlocks,
Expand All @@ -250,28 +272,6 @@ func (bc *BabylonController) ParamsByBtcHeight(btcHeight uint32) (*StakingParams
}, nil
}

func (bc *BabylonController) StakingTrackerByBtcHeight(btcHeight uint32) (*StakingTrackerResponse, error) {
var stakingTrackerParams *StakingTrackerResponse
if err := retry.Do(func() error {
trackerParams, err := bc.QueryStakingTrackerByBtcHeight(btcHeight)
if err != nil {
return err
}
stakingTrackerParams = trackerParams
return nil
}, RtyAtt, RtyDel, RtyErr, retry.OnRetry(func(n uint, err error) {
bc.logger.WithFields(logrus.Fields{
"attempt": n + 1,
"max_attempts": RtyAttNum,
"error": err,
}).Error("Failed to query babylon client for staking tracker params")
})); err != nil {
return nil, err
}

return stakingTrackerParams, nil
}

func (bc *BabylonController) GetKeyAddress() sdk.AccAddress {
// get key address, retrieves address based on key name which is configured in
// cfg *stakercfg.BBNConfig. If this fails, it means we have misconfiguration problem
Expand Down
7 changes: 1 addition & 6 deletions babylonclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type BabylonClient interface {
BTCCheckpointParams() (*BTCCheckpointParams, error)
Params() (*StakingParams, error)
ParamsByBtcHeight(btcHeight uint32) (*StakingParams, error)
StakingTrackerByBtcHeight(btcHeight uint32) (*StakingTrackerResponse, error)
Delegate(dg *DelegationData) (*pv.RelayerTxResponse, error)
QueryFinalityProviders(limit uint64, offset uint64) (*FinalityProvidersClientResponse, error)
QueryFinalityProvider(btcPubKey *btcec.PublicKey) (*FinalityProviderClientResponse, error)
Expand All @@ -101,7 +100,7 @@ func (m *MockBabylonClient) Params() (*StakingParams, error) {
return m.ClientParams, nil
}

func (m *MockBabylonClient) ParamsByBtcHeight(btcHeight uint32) (*StakingParams, error) {
func (m *MockBabylonClient) ParamsByBtcHeight(_ uint32) (*StakingParams, error) {
return m.ClientParams, nil
}

Expand All @@ -112,10 +111,6 @@ func (m *MockBabylonClient) BTCCheckpointParams() (*BTCCheckpointParams, error)
}, nil
}

func (m *MockBabylonClient) StakingTrackerByBtcHeight(btcHeight uint32) (*StakingTrackerResponse, error) {
return &StakingTrackerResponse{}, nil
}

func (m *MockBabylonClient) Sign(msg []byte) ([]byte, error) {
sig, err := m.babylonKey.Sign(msg)

Expand Down
1 change: 0 additions & 1 deletion staker/stakerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ func (app *App) retrieveExternalDelegationData(
}

params = p

} else {
p, err := app.babylonClient.ParamsByBtcHeight(inclusionInfo.inclusionBlockBtcHeight)

Expand Down

0 comments on commit e65160b

Please sign in to comment.