Skip to content

Commit 262e7c6

Browse files
author
Daisuke Kanda
committed
remove prove option from query functions
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
1 parent 2c397bd commit 262e7c6

File tree

4 files changed

+52
-120
lines changed

4 files changed

+52
-120
lines changed

core/channel-upgrade.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func InitChannelUpgrade(ctx context.Context, chain, cp *ProvableChain, upgradeFi
9696
NewQueryContext(ctx, cpH),
9797
chain,
9898
cp,
99-
false,
10099
); err != nil {
101100
logger.ErrorContext(ctx, "failed to query for the channel pair", err)
102101
span.SetStatus(codes.Error, err.Error())
@@ -212,7 +211,7 @@ func CancelChannelUpgrade(ctx context.Context, chain, cp *ProvableChain, settlem
212211
queryCtx := sh.GetQueryContext(ctx, chain.ChainID())
213212
cpQueryCtx := sh.GetQueryContext(ctx, cp.ChainID())
214213

215-
chann, _, settled, err := querySettledChannelPair(queryCtx, cpQueryCtx, chain, cp, false)
214+
chann, _, settled, err := querySettledChannelPair(queryCtx, cpQueryCtx, chain, cp)
216215
if err != nil {
217216
logger.ErrorContext(ctx, "failed to query for settled channel pair", err)
218217
return false, err
@@ -221,7 +220,7 @@ func CancelChannelUpgrade(ctx context.Context, chain, cp *ProvableChain, settlem
221220
return false, nil
222221
}
223222

224-
if _, _, settled, err := querySettledChannelUpgradePair(queryCtx, cpQueryCtx, chain, cp, false); err != nil {
223+
if _, _, settled, err := querySettledChannelUpgradePair(queryCtx, cpQueryCtx, chain, cp); err != nil {
225224
logger.ErrorContext(ctx, "failed to query for settled channel upgrade pair", err)
226225
return false, err
227226
} else if !settled {
@@ -235,7 +234,7 @@ func CancelChannelUpgrade(ctx context.Context, chain, cp *ProvableChain, settlem
235234
return false, err
236235
}
237236

238-
upgErr, err := QueryChannelUpgradeError(cpQueryCtx, cp, true)
237+
upgErr, err := QueryChannelUpgradeError(cpQueryCtx, cp)
239238
if err != nil {
240239
logger.ErrorContext(ctx, "failed to query the channel upgrade error receipt", err)
241240
return false, err
@@ -255,6 +254,8 @@ func CancelChannelUpgrade(ctx context.Context, chain, cp *ProvableChain, settlem
255254
// If the sender is authority and the channel state is anything other than FLUSHCOMPLETE,
256255
// the cancellation will be successful.
257256
upgErr = &chantypes.QueryUpgradeErrorResponse{}
257+
} else if err = ProveChannelUpgradeError(cpQueryCtx, cp, upgErr); err != nil {
258+
return false, err
258259
}
259260

260261
addr, err := chain.GetAddress()
@@ -325,7 +326,7 @@ func upgradeChannelStep(ctx context.Context, src, dst *ProvableChain, targetSrcS
325326
dstCtx := sh.GetQueryContext(ctx, dst.ChainID())
326327

327328
// query finalized channels with proofs
328-
srcChan, dstChan, settled, err := querySettledChannelPair(srcCtx, dstCtx, src, dst, false)
329+
srcChan, dstChan, settled, err := querySettledChannelPair(srcCtx, dstCtx, src, dst)
329330
if err != nil {
330331
logger.ErrorContext(ctx, "failed to query the channel pair with proofs", err)
331332
return nil, err
@@ -339,7 +340,6 @@ func upgradeChannelStep(ctx context.Context, src, dst *ProvableChain, targetSrcS
339340
dstCtx,
340341
src,
341342
dst,
342-
false,
343343
)
344344
if err != nil {
345345
logger.ErrorContext(ctx, "failed to query the channel upgrade pair with proofs", err)
@@ -661,17 +661,15 @@ func querySettledChannelUpgradePair(
661661
Chain
662662
StateProver
663663
},
664-
prove bool,
665664
) (*chantypes.QueryUpgradeResponse, *chantypes.QueryUpgradeResponse, bool, error) {
666665
logger := GetChannelPairLogger(src, dst)
667666
logger = &log.RelayLogger{Logger: logger.With(
668667
"src_height", srcCtx.Height().String(),
669668
"dst_height", dstCtx.Height().String(),
670-
"prove", prove,
671669
)}
672670

673671
// query channel upgrade pair at latest finalized heights
674-
srcChanUpg, dstChanUpg, err := QueryChannelUpgradePair(srcCtx, dstCtx, src, dst, prove)
672+
srcChanUpg, dstChanUpg, err := QueryChannelUpgradePair(srcCtx, dstCtx, src, dst)
675673
if err != nil {
676674
logger.ErrorContext(srcCtx.Context(), "failed to query a channel upgrade pair at the latest finalized heights", err)
677675
return nil, nil, false, err
@@ -693,7 +691,7 @@ func querySettledChannelUpgradePair(
693691
}
694692

695693
// query channel upgrade pair at latest heights
696-
srcLatestChanUpg, dstLatestChanUpg, err := QueryChannelUpgradePair(srcLatestCtx, dstLatestCtx, src, dst, false)
694+
srcLatestChanUpg, dstLatestChanUpg, err := QueryChannelUpgradePair(srcLatestCtx, dstLatestCtx, src, dst)
697695
if err != nil {
698696
logger.ErrorContext(srcCtx.Context(), "failed to query a channel upgrade pair at the latest heights", err)
699697
return nil, nil, false, err
@@ -799,27 +797,34 @@ func buildActionMsg(
799797
}
800798
return pathEnd.ChanUpgradeOpen(cpChan, addr), nil
801799
case UPGRADE_ACTION_CANCEL:
802-
upgErr, err := QueryChannelUpgradeError(cpCtx, cp, true)
800+
upgErr, err := QueryChannelUpgradeError(cpCtx, cp)
803801
if err != nil {
804802
return nil, err
805803
} else if upgErr == nil {
806804
// NOTE: Even if an error receipt is not found, anyway try to execute ChanUpgradeCancel.
807805
// If the sender is authority and the channel state is anything other than FLUSHCOMPLETE,
808806
// the cancellation will be successful.
809807
upgErr = &chantypes.QueryUpgradeErrorResponse{}
808+
} else if err := ProveChannelUpgradeError(cpCtx, cp, upgErr); err != nil {
809+
return nil, err
810810
}
811+
811812
return pathEnd.ChanUpgradeCancel(upgErr, addr), nil
812813
case UPGRADE_ACTION_CANCEL_FLUSHCOMPLETE:
813-
upgErr, err := QueryChannelUpgradeError(cpCtx, cp, true)
814+
upgErr, err := QueryChannelUpgradeError(cpCtx, cp)
814815
if err != nil {
815816
return nil, err
816817
} else if upgErr == nil {
817818
return nil, fmt.Errorf("upgrade error receipt not found")
818-
} else if upgErr.ErrorReceipt.Sequence != selfChan.Channel.UpgradeSequence {
819+
}
820+
if upgErr.ErrorReceipt.Sequence != selfChan.Channel.UpgradeSequence {
819821
return nil, fmt.Errorf(
820822
"upgrade sequences don't match: channel.upgrade_sequence=%d, error_receipt.sequence=%d",
821823
selfChan.Channel.UpgradeSequence, upgErr.ErrorReceipt.Sequence)
822824
}
825+
if err = ProveChannelUpgradeError(cpCtx, cp, upgErr); err != nil {
826+
return nil, err
827+
}
823828
return pathEnd.ChanUpgradeCancel(upgErr, addr), nil
824829
case UPGRADE_ACTION_TIMEOUT:
825830
if err := ProveChannel(cpCtx, cp, cpChan); err != nil {

core/channel.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func resolveCreateChannelFutureProofs(
158158
return err
159159
}
160160

161-
if fromProofs.chanRes != nil {
161+
if fromProofs.chanRes != nil && fromProofs.chanRes.Channel.State != chantypes.UNINITIALIZED {
162162
err = ProveChannel(queryCtx, from, fromProofs.chanRes)
163163
if err != nil {
164164
return err
@@ -244,7 +244,6 @@ func createChannelStep(ctx context.Context, src, dst *ProvableChain) (*RelayMsgs
244244
sh.GetQueryContext(ctx, dst.ChainID()),
245245
src,
246246
dst,
247-
false,
248247
)
249248
if err != nil {
250249
return nil, err
@@ -369,16 +368,14 @@ func querySettledChannelPair(
369368
Chain
370369
StateProver
371370
},
372-
prove bool,
373371
) (*chantypes.QueryChannelResponse, *chantypes.QueryChannelResponse, bool, error) {
374372
logger := GetChannelPairLogger(src, dst)
375373
logger = &log.RelayLogger{Logger: logger.With(
376374
"src_height", srcCtx.Height().String(),
377375
"dst_height", dstCtx.Height().String(),
378-
"prove", prove,
379376
)}
380377

381-
srcChan, dstChan, err := QueryChannelPair(srcCtx, dstCtx, src, dst, prove)
378+
srcChan, dstChan, err := QueryChannelPair(srcCtx, dstCtx, src, dst)
382379
if err != nil {
383380
logger.ErrorContext(srcCtx.Context(), "failed to query channel pair at the latest finalized height", err)
384381
return nil, nil, false, err
@@ -398,7 +395,7 @@ func querySettledChannelPair(
398395
dstLatestCtx = NewQueryContext(dstCtx.Context(), h)
399396
}
400397

401-
srcLatestChan, dstLatestChan, err := QueryChannelPair(srcLatestCtx, dstLatestCtx, src, dst, false)
398+
srcLatestChan, dstLatestChan, err := QueryChannelPair(srcLatestCtx, dstLatestCtx, src, dst)
402399
if err != nil {
403400
logger.ErrorContext(srcCtx.Context(), "failed to query channel pair at the latest height", err)
404401
return nil, nil, false, err

core/connection.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func resolveCreateConnectionFutureProofs(
168168
return err
169169
}
170170

171-
if fromProofs.connRes != nil {
171+
if fromProofs.connRes != nil && fromProofs.connRes.Connection.State != conntypes.UNINITIALIZED {
172172
err = ProveConnection(queryCtx, fromChain, fromProofs.connRes)
173173
if err != nil {
174174
return err
@@ -279,7 +279,6 @@ func createConnectionStep(ctx context.Context, src, dst *ProvableChain) (*RelayM
279279
sh.GetQueryContext(ctx, dst.ChainID()),
280280
src,
281281
dst,
282-
false,
283282
)
284283
if err != nil {
285284
return nil, err
@@ -289,7 +288,7 @@ func createConnectionStep(ctx context.Context, src, dst *ProvableChain) (*RelayM
289288

290289
if !(srcProofs.connRes.Connection.State == conntypes.UNINITIALIZED && dstProofs.connRes.Connection.State == conntypes.UNINITIALIZED) {
291290
// Query client state from each chain's client
292-
srcProofs.csRes, dstProofs.csRes, err = QueryClientStatePair(sh.GetQueryContext(ctx, src.ChainID()), sh.GetQueryContext(ctx, dst.ChainID()), src, dst, false)
291+
srcProofs.csRes, dstProofs.csRes, err = QueryClientStatePair(sh.GetQueryContext(ctx, src.ChainID()), sh.GetQueryContext(ctx, dst.ChainID()), src, dst)
293292
if err != nil {
294293
return nil, err
295294
}
@@ -304,7 +303,7 @@ func createConnectionStep(ctx context.Context, src, dst *ProvableChain) (*RelayM
304303
srcConsH, dstConsH = srcCS.GetLatestHeight(), dstCS.GetLatestHeight()
305304
srcProofs.consRes, dstProofs.consRes, err = QueryClientConsensusStatePair(
306305
sh.GetQueryContext(ctx, src.ChainID()), sh.GetQueryContext(ctx, dst.ChainID()),
307-
src, dst, srcConsH, dstConsH, false)
306+
src, dst, srcConsH, dstConsH)
308307
if err != nil {
309308
return nil, err
310309
}
@@ -481,16 +480,14 @@ func querySettledConnectionPair(
481480
Chain
482481
StateProver
483482
},
484-
prove bool,
485483
) (*conntypes.QueryConnectionResponse, *conntypes.QueryConnectionResponse, bool, error) {
486484
logger := GetConnectionPairLogger(src, dst)
487485
logger = &log.RelayLogger{Logger: logger.With(
488486
"src_height", srcCtx.Height().String(),
489487
"dst_height", dstCtx.Height().String(),
490-
"prove", prove,
491488
)}
492489

493-
srcConn, dstConn, err := QueryConnectionPair(srcCtx, dstCtx, src, dst, prove)
490+
srcConn, dstConn, err := QueryConnectionPair(srcCtx, dstCtx, src, dst)
494491
if err != nil {
495492
logger.ErrorContext(srcCtx.Context(), "failed to query connection pair at the latest finalized height", err)
496493
return nil, nil, false, err
@@ -510,7 +507,7 @@ func querySettledConnectionPair(
510507
dstLatestCtx = NewQueryContext(dstCtx.Context(), h)
511508
}
512509

513-
srcLatestConn, dstLatestConn, err := QueryConnectionPair(srcLatestCtx, dstLatestCtx, src, dst, false)
510+
srcLatestConn, dstLatestConn, err := QueryConnectionPair(srcLatestCtx, dstLatestCtx, src, dst)
514511
if err != nil {
515512
logger.ErrorContext(srcCtx.Context(), "failed to query connection pair at the latest height", err)
516513
return nil, nil, false, err

0 commit comments

Comments
 (0)