-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add check if the covenant is the covenant committee (#91)
* fix: add check if the covenant is the covenant committee of that btc delegation based on the params version * chore: refactory sanitize delegations * chore: add #91 to changelog * chore: add godoc to funcs * chore: add client controller and logger directly to param cache * chore: refactory to remove delegations in a single loop over dels * chore: add check for del copy * chore: removed delCopy * fix: test check endheight modified * chore: add test that verifies if all the delegations pointers wasn't pointing to the last one * chore: return error in func IsKeyInCommittee and log if there is a error * chore: stop the loop if there is an error in sanitize delegations * chore: address pr comments, transform err from %s to %w and add check if sanitized dels returns some delegation
- Loading branch information
1 parent
dd54041
commit 37d715e
Showing
4 changed files
with
306 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package covenant | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/avast/retry-go/v4" | ||
"github.com/babylonlabs-io/covenant-emulator/clientcontroller" | ||
"github.com/babylonlabs-io/covenant-emulator/types" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type ( | ||
ParamsGetter interface { | ||
Get(version uint32) (*types.StakingParams, error) | ||
} | ||
CacheVersionedParams struct { | ||
sync.Mutex | ||
paramsByVersion map[uint32]*types.StakingParams | ||
|
||
cc clientcontroller.ClientController | ||
logger *zap.Logger | ||
} | ||
) | ||
|
||
func NewCacheVersionedParams(cc clientcontroller.ClientController, logger *zap.Logger) ParamsGetter { | ||
return &CacheVersionedParams{ | ||
paramsByVersion: make(map[uint32]*types.StakingParams), | ||
cc: cc, | ||
logger: logger, | ||
} | ||
} | ||
|
||
// Get returns the staking parameter from the | ||
func (v *CacheVersionedParams) Get(version uint32) (*types.StakingParams, error) { | ||
v.Lock() | ||
defer v.Unlock() | ||
|
||
params, ok := v.paramsByVersion[version] | ||
if ok { | ||
return params, nil | ||
} | ||
|
||
params, err := v.getParamsByVersion(version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
v.paramsByVersion[version] = params | ||
return params, nil | ||
} | ||
|
||
func (v *CacheVersionedParams) getParamsByVersion(version uint32) (*types.StakingParams, error) { | ||
var ( | ||
err error | ||
params *types.StakingParams | ||
) | ||
|
||
if err := retry.Do(func() error { | ||
params, err = v.cc.QueryStakingParamsByVersion(version) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, RtyAtt, RtyDel, RtyErr, retry.OnRetry(func(n uint, err error) { | ||
v.logger.Debug( | ||
"failed to query the consumer chain for the staking params", | ||
zap.Uint("attempt", n+1), | ||
zap.Uint("max_attempts", RtyAttNum), | ||
zap.Error(err), | ||
) | ||
})); err != nil { | ||
return nil, err | ||
} | ||
|
||
return params, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.