Skip to content

Commit b27e568

Browse files
committed
Add query for poa chains
1 parent b68af8f commit b27e568

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

relayer/chains/cosmos/provider.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,9 @@ func (cc *CosmosProvider) Address() (string, error) {
220220
}
221221

222222
func (cc *CosmosProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) {
223-
res, err := cc.QueryStakingParams(ctx)
224-
225-
var unbondingTime time.Duration
223+
unbondingTime, err := cc.QueryUnbondingPeriod(ctx)
226224
if err != nil {
227-
// Attempt ICS query
228-
consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx)
229-
if consumerErr != nil {
230-
return 0,
231-
fmt.Errorf("failed to query unbonding period as both standard and consumer chain: %s: %w", err.Error(), consumerErr)
232-
}
233-
unbondingTime = consumerUnbondingPeriod
234-
} else {
235-
unbondingTime = res.UnbondingTime
225+
return 0, err
236226
}
237227

238228
// We want the trusting period to be 85% of the unbonding time.

relayer/chains/cosmos/query.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,47 +178,51 @@ func (cc *CosmosProvider) QueryBalanceWithAddress(ctx context.Context, address s
178178
return coins, nil
179179
}
180180

181-
func (cc *CosmosProvider) queryConsumerUnbondingPeriod(ctx context.Context) (time.Duration, error) {
181+
func (cc *CosmosProvider) querySubspaceUnbondingPeriod(subspace string, ctx context.Context) (time.Duration, error) {
182182
queryClient := proposal.NewQueryClient(cc)
183183

184-
params := proposal.QueryParamsRequest{Subspace: "ccvconsumer", Key: "UnbondingPeriod"}
184+
params := proposal.QueryParamsRequest{Subspace: subspace, Key: "UnbondingPeriod"}
185185

186186
resICS, err := queryClient.Params(ctx, &params)
187187

188188
if err != nil {
189-
return 0, fmt.Errorf("failed to make ccvconsumer params request: %w", err)
189+
return 0, fmt.Errorf("failed to make %s params request: %w", subspace, err)
190190
}
191191

192192
if resICS.Param.Value == "" {
193-
return 0, fmt.Errorf("ccvconsumer unbonding period is empty")
193+
return 0, fmt.Errorf("%s unbonding period is empty", subspace)
194194
}
195195

196196
unbondingPeriod, err := strconv.ParseUint(strings.ReplaceAll(resICS.Param.Value, `"`, ""), 10, 64)
197197
if err != nil {
198-
return 0, fmt.Errorf("failed to parse unbonding period from ccvconsumer param: %w", err)
198+
return 0, fmt.Errorf("failed to parse unbonding period from %s param: %w", subspace, err)
199199
}
200200

201201
return time.Duration(unbondingPeriod), nil
202202
}
203203

204204
// QueryUnbondingPeriod returns the unbonding period of the chain
205205
func (cc *CosmosProvider) QueryUnbondingPeriod(ctx context.Context) (time.Duration, error) {
206-
req := stakingtypes.QueryParamsRequest{}
207-
queryClient := stakingtypes.NewQueryClient(cc)
208-
209-
res, err := queryClient.Params(ctx, &req)
210-
if err != nil {
211-
// Attempt ICS query
212-
consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx)
213-
if consumerErr != nil {
214-
return 0,
215-
fmt.Errorf("failed to query unbonding period as both standard and consumer chain: %s: %w", err.Error(), consumerErr)
216-
}
206+
res, err := cc.QueryStakingParams(ctx)
207+
if err == nil {
208+
return res.UnbondingTime, nil
209+
}
217210

211+
// Attempt ICS query
212+
consumerUnbondingPeriod, consumerErr := cc.querySubspaceUnbondingPeriod("ccvconsumer", ctx)
213+
if consumerErr == nil {
218214
return consumerUnbondingPeriod, nil
219215
}
220216

221-
return res.Params.UnbondingTime, nil
217+
poaUnbondingPeriod, poaErr := cc.querySubspaceUnbondingPeriod("poa", ctx)
218+
if poaErr == nil {
219+
return poaUnbondingPeriod, nil
220+
}
221+
222+
return 0, fmt.Errorf(
223+
"failed to query unbonding period as both standard, consumer, and poa chain: %s, %s, %s",
224+
err.Error(), consumerErr.Error(), poaErr.Error(),
225+
)
222226
}
223227

224228
// QueryTendermintProof performs an ABCI query with the given key and returns

0 commit comments

Comments
 (0)