You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Attempt to produce SPV proofs in the valid history window (#2280)
When an SPV proof would have a root outside of the valid history window,
i.e. the proof would be expired, attempt to produce a proof which has a
root inside the valid history window instead if possible.
Co-authored-by: Lars Kuhtz <lars@kadena.io>
-- You have to wait at least N blocks before attempting to run the continuation,
366
+
-- You have to wait at least a diameter to get the block.
367
367
-- where N is the diameter of the graph + some constant. Here, we just run 10 blocks,
368
368
-- because it is less than the minimumBlockHeaderHistory of the test version, but
369
369
-- more than sufficient for the target chain to be aware of the source xchain transfer.
370
370
let waitBlocks ::Integrala=>a
371
-
waitBlocks =10
371
+
waitBlocks =int $ diameter (chainGraphAt v maxBound) +1
372
372
let expirationWindow = fromMaybe (error"missing minimumBlockHeaderHistory") (minimumBlockHeaderHistory v maxBound)
373
373
when (int expirationWindow < waitBlocks + diameter (chainGraphAt v maxBound)) $ assertFailure "test version has a minimumBlockHeaderHistory that is too short to test"
374
374
375
375
replicateM_ waitBlocks $ advanceAllChains_ fx
376
+
376
377
[Just sendCr] <- pollWithDepth fx v srcChain [initiatorReqKey] (Just (ConfirmationDepth0))
377
378
let cont = fromMaybe (error"missing continuation") (_crContinuation sendCr)
378
-
TransactionOutputProofB64 spvProof <- spvTxOutProof fx v targetChain srcChain initiatorReqKey
379
-
let contMsg =ContMsg
379
+
380
+
TransactionOutputProofB64 expiringSpvProof <- spvTxOutProof fx v targetChain srcChain initiatorReqKey
-- We have already run an extra 10 blocks since initiating the transfer.
388
389
-- We need to wait for the full window to expire.
389
-
390
390
-- still accessible at remainingWindow + diameter + 1 so we have to go one beyond
391
391
let remainingWindow = int @_@Int (int expirationWindow - waitBlocks + diameter (chainGraphAt v maxBound) +2)
392
392
replicateM_ remainingWindow $ advanceAllChains_ fx
393
393
394
+
expiringRecv <- buildTextCmd v
395
+
$ set cbRPC (mkCont expiringContMsg)
396
+
$ defaultCmd targetChain
397
+
send fx v targetChain [expiringRecv]
398
+
let expiringRecvReqKey = cmdToRequestKey expiringRecv
399
+
advanceAllChains_ fx
400
+
poll fx v targetChain [expiringRecvReqKey]
401
+
>>=P.match (_head . _Just)
402
+
?P.checkAll
403
+
[ P.fun _crResult ?P.match _PactResultErr ?P.fun _peMsg ?P.equals "Continuation error: spv verification failed: target header is not in the chain or is out of bounds"
404
+
]
405
+
406
+
TransactionOutputProofB64 spvWorkingProof <- spvTxOutProof fx v targetChain srcChain initiatorReqKey
[ P.fun _crResult ?P.match _PactResultErr ?P.fun _peMsg ?P.equals "Continuation error: spv verification failed: target header is not in the chain or is out of bounds"
0 commit comments