-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Side load snapshot #1864
Open
ffakenz
wants to merge
10
commits into
master
Choose a base branch
from
side-load-snapshot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,746
−20
Open
Side load snapshot #1864
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
705ff3a
draft e2e scenario for head getting stuck
ffakenz d02543a
add GET /snapshot
ffakenz c57219f
add new client input for side load snapshot
ffakenz 1d6a4f9
introduce server output, outcome event and aggregate handle in logic
ffakenz bddd59e
draft logic handle
ffakenz 298b6e4
add POST /snapshot and POST /snapshot/latest
ffakenz 85ccea9
fix head stuck
ffakenz 7a3a2ef
Update CHANGELOG
ffakenz d9451f2
update docs
ffakenz 9f6a7ea
fixes after rebase
ffakenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -26,10 +26,10 @@ import CardanoClient ( | |||||
) | ||||||
import CardanoNode (NodeLog) | ||||||
import Control.Concurrent.Async (mapConcurrently_) | ||||||
import Control.Lens ((.~), (^.), (^..), (^?)) | ||||||
import Control.Lens ((.~), (?~), (^.), (^..), (^?)) | ||||||
import Data.Aeson (Value, object, (.=)) | ||||||
import Data.Aeson qualified as Aeson | ||||||
import Data.Aeson.Lens (key, values, _JSON, _String) | ||||||
import Data.Aeson.Lens (atKey, key, values, _JSON, _String) | ||||||
import Data.Aeson.Types (parseMaybe) | ||||||
import Data.ByteString (isInfixOf) | ||||||
import Data.ByteString qualified as B | ||||||
|
@@ -104,10 +104,12 @@ import Hydra.Tx.Utils (dummyValidatorScript, verificationKeyToOnChainId) | |||||
import HydraNode ( | ||||||
HydraClient (..), | ||||||
HydraNodeLog, | ||||||
getSnapshotConfirmed, | ||||||
getSnapshotUTxO, | ||||||
input, | ||||||
output, | ||||||
postDecommit, | ||||||
prepareHydraNode, | ||||||
requestCommitTx, | ||||||
send, | ||||||
waitFor, | ||||||
|
@@ -116,6 +118,7 @@ import HydraNode ( | |||||
waitMatch, | ||||||
withHydraCluster, | ||||||
withHydraNode, | ||||||
withPreparedHydraNode, | ||||||
) | ||||||
import Network.HTTP.Conduit (parseUrlThrow) | ||||||
import Network.HTTP.Conduit qualified as L | ||||||
|
@@ -1305,6 +1308,112 @@ canDecommit tracer workDir node hydraScriptsTxId = | |||||
|
||||||
RunningNode{networkId, nodeSocket, blockTime} = node | ||||||
|
||||||
-- | Can side load snapshot and resume agreement after a peer comes back online with healthy configuration | ||||||
canSideLoadSnapshot :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [TxId] -> IO () | ||||||
canSideLoadSnapshot tracer workDir cardanoNode hydraScriptsTxId = do | ||||||
let clients = [Alice, Bob, Carol] | ||||||
[(aliceCardanoVk, aliceCardanoSk), (bobCardanoVk, _), (carolCardanoVk, _)] <- forM clients keysFor | ||||||
seedFromFaucet_ cardanoNode aliceCardanoVk 100_000_000 (contramap FromFaucet tracer) | ||||||
seedFromFaucet_ cardanoNode bobCardanoVk 100_000_000 (contramap FromFaucet tracer) | ||||||
seedFromFaucet_ cardanoNode carolCardanoVk 100_000_000 (contramap FromFaucet tracer) | ||||||
|
||||||
let contestationPeriod = UnsafeContestationPeriod 1 | ||||||
let depositDeadline = UnsafeDepositDeadline 200 | ||||||
aliceChainConfig <- | ||||||
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob, Carol] contestationPeriod depositDeadline | ||||||
<&> setNetworkId networkId | ||||||
bobChainConfig <- | ||||||
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice, Carol] contestationPeriod depositDeadline | ||||||
<&> setNetworkId networkId | ||||||
carolChainConfig <- | ||||||
chainConfigFor Carol workDir nodeSocket hydraScriptsTxId [Alice, Bob] contestationPeriod depositDeadline | ||||||
<&> setNetworkId networkId | ||||||
|
||||||
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk, carolVk] [1, 2, 3] $ \n1 -> do | ||||||
aliceUTxO <- seedFromFaucet cardanoNode aliceCardanoVk 1_000_000 (contramap FromFaucet tracer) | ||||||
withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk, carolVk] [1, 2, 3] $ \n2 -> do | ||||||
-- Carol starts its node missconfigured | ||||||
let pparamsDecorator = atKey "maxTxSize" ?~ toJSON (Aeson.Number 0) | ||||||
wrongOptions <- prepareHydraNode carolChainConfig workDir 3 carolSk [aliceVk, bobVk] [1, 2, 3] pparamsDecorator | ||||||
tx <- withPreparedHydraNode hydraTracer workDir 3 wrongOptions $ \n3 -> do | ||||||
-- Init | ||||||
send n1 $ input "Init" [] | ||||||
headId <- waitForAllMatch (10 * blockTime) [n1, n2, n3] $ headIsInitializingWith (Set.fromList [alice, bob, carol]) | ||||||
|
||||||
-- Alice commits something | ||||||
requestCommitTx n1 aliceUTxO >>= submitTx cardanoNode | ||||||
|
||||||
-- Everyone else commits nothing | ||||||
mapConcurrently_ (\n -> requestCommitTx n mempty >>= submitTx cardanoNode) [n2, n3] | ||||||
|
||||||
-- Observe open with the relevant UTxOs | ||||||
waitFor hydraTracer (20 * blockTime) [n1, n2, n3] $ | ||||||
output "HeadIsOpen" ["utxo" .= toJSON aliceUTxO, "headId" .= headId] | ||||||
|
||||||
-- Alice submits a new transaction | ||||||
utxo <- getSnapshotUTxO n1 | ||||||
tx <- mkTransferTx testNetworkId utxo aliceCardanoSk aliceCardanoVk | ||||||
send n1 $ input "NewTx" ["transaction" .= tx] | ||||||
|
||||||
-- Alice and Bob accept it | ||||||
waitForAllMatch (200 * blockTime) [n1, n2] $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "TxValid" | ||||||
guard $ v ^? key "transactionId" == Just (toJSON $ txId tx) | ||||||
|
||||||
-- Carol does not because of its node being missconfigured | ||||||
waitMatch 3 n3 $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "TxInvalid" | ||||||
guard $ v ^? key "transaction" . key "txId" == Just (toJSON $ txId tx) | ||||||
|
||||||
pure tx | ||||||
|
||||||
-- Carol disconnects and the others observe it | ||||||
waitForAllMatch (100 * blockTime) [n1, n2] $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "PeerDisconnected" | ||||||
|
||||||
-- Carol reconnects with healthy reconfigured node | ||||||
withHydraNode hydraTracer carolChainConfig workDir 3 carolSk [aliceVk, bobVk] [1, 2, 3] $ \n3 -> do | ||||||
-- Carol re-submits the same transaction | ||||||
send n3 $ input "NewTx" ["transaction" .= tx] | ||||||
-- Carol accepts it | ||||||
waitMatch 3 n3 $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "TxValid" | ||||||
guard $ v ^? key "transactionId" == Just (toJSON $ txId tx) | ||||||
-- But now Alice and Bob does not because they already applied it | ||||||
waitForAllMatch (200 * blockTime) [n1, n2] $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "TxInvalid" | ||||||
guard $ v ^? key "transaction" . key "txId" == Just (toJSON $ txId tx) | ||||||
|
||||||
-- \| Up to this point the head became stuck and no further SnapshotConfirmed | ||||||
-- including above tx will be seen signed by everyone. | ||||||
|
||||||
-- The party side-loads latest confirmed snapshot (which is the initial) | ||||||
-- This also prunes local txs, and discards any signing round inflight | ||||||
snapshotConfirmed <- getSnapshotConfirmed n1 | ||||||
flip mapConcurrently_ [n1, n2, n3] $ \n -> do | ||||||
send n $ input "SideLoadSnapshot" ["snapshot" .= snapshotConfirmed] | ||||||
waitMatch (200 * blockTime) n $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "SnapshotSideLoaded" | ||||||
guard $ v ^? key "confirmedSnapshot" == Just (toJSON snapshotConfirmed) | ||||||
|
||||||
-- Carol re-submits the same transaction (but anyone can at this point) | ||||||
send n3 $ input "NewTx" ["transaction" .= tx] | ||||||
|
||||||
-- Everyone confirms it | ||||||
-- Note: We can't use `waitForAlMatch` here as it expects them to | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-- emit the exact same datatype; but Carol will be behind in sequence | ||||||
-- numbers as she was offline. | ||||||
flip mapConcurrently_ [n1, n2, n3] $ \n -> | ||||||
waitMatch (200 * blockTime) n $ \v -> do | ||||||
guard $ v ^? key "tag" == Just "SnapshotConfirmed" | ||||||
guard $ v ^? key "snapshot" . key "number" == Just (toJSON (1 :: Integer)) | ||||||
-- Just check that everyone signed it. | ||||||
let sigs = v ^.. key "signatures" . key "multiSignature" . values | ||||||
guard $ length sigs == 3 | ||||||
where | ||||||
RunningNode{nodeSocket, networkId, blockTime} = cardanoNode | ||||||
hydraTracer = contramap FromHydraNode tracer | ||||||
|
||||||
-- * L2 scenarios | ||||||
|
||||||
-- | Finds UTxO owned by given key in the head and creates transactions | ||||||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the changelog you mention
POST /snapshot
but here the route is different, herePOST /snapshot/latest endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... there are two routes actually.