From 99e153f95928f82b79d06aa4b1b54b938272efb5 Mon Sep 17 00:00:00 2001 From: zkao Date: Mon, 11 Jul 2022 13:49:54 +0200 Subject: [PATCH] sequence diagram: update --- doc/sequencediagram.svg | 2 +- doc/sequencediagram.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/sequencediagram.svg b/doc/sequencediagram.svg index e36f0277c..d1f806334 100644 --- a/doc/sequencediagram.svg +++ b/doc/sequencediagram.svg @@ -1 +1 @@ -title%20Farcaster%20node%0A%2F%2F%20to%20display%20the%20diagram%2C%20go%20to%20sequencediagram.org%0A%2F%2F%20dashed%20lines%2C%20not%20yet%20implemented%0A%0Aparticipant%20t_syncer%0Aparticipant%20t_wallet%0Aparticipant%20t_swap%0Aparticipant%20t_checkpoint%0Aparticipant%20t_farcasterd%0Aparticipant%20t_cli%0Aparticipant%20peerd%0Aparticipant%20m_cli%0Aparticipant%20m_farcasterd%0Aparticipant%20m_checkpoint%0Aparticipant%20m_swap%0Aparticipant%20m_wallet%0Aparticipant%20m_syncer%0A%0A%3D%3DSetup%20and%20Commit-Reveal%3A%20Bob%20and%20Alice%20can%20be%20on%20both%20sides%3D%3D%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20launch%20farcasterd%5Cnmanually%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20launch%20walletd%0Am_farcasterd%20%3C-%20m_wallet%20%3A%20Ctl%20Hello%0Am_cli%20-%3E%20m_farcasterd%20%3A%20MakeOffer%20(deferred)%0Am_farcasterd%20-%3E%20m_wallet%20%3A%20Ctl%20GetKeys%0Am_farcasterd%20%3C-%20m_wallet%20%3A%20Ctl%20Keys%20(not%20to%20be%20held%20on%20state)%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20MakeOffer%20(continues)%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20launch%5Cnpeerd%20listen%0At_farcasterd%20-%3E%20t_farcasterd%20%3A%20launch%20farcasterd%5Cnmanually%0At_farcasterd%20-%3E%20t_farcasterd%20%3A%20launch%20walletd%0At_wallet%20-%3E%20t_farcasterd%20%3A%20Ctl%20Hello%0At_cli%20-%3E%20t_farcasterd%20%3A%20Ctl%20TakeOffer%20(deferred)%0At_wallet%20%3C-%20t_farcasterd%20%3A%20Ctl%20GetKeys%0At_wallet%20-%3E%20t_farcasterd%20%3A%20Ctl%20Keys%20(not%20to%20be%20held%20on%20state)%0At_farcasterd%20%3C-%20t_farcasterd%20%3A%20Ctl%20TakeOffer%20(continues)%0At_farcasterd%20-%3E%20t_farcasterd%20%3A%20launch%5Cnpeerd%20connect%0At_wallet%20%3C-%20t_farcasterd%20%3A%20Ctl%20TakeOffer%0At_wallet%20-%3E%20t_wallet%20%3A%20create%20taker%20wallet%0At_wallet%20-%3E%20t_farcasterd%20%3A%20Ctl%20LaunchSwap%0At_swap%20-%3E%20t_farcasterd%20%3A%20Ctl%20Hello%0At_swap%20-%3E%20t_wallet%20%3A%20Ctl%20Hello%0At_farcasterd%20-%3E%20t_farcasterd%3Alaunch%20syncer%0At_swap%20%3C-%20t_farcasterd%20%3A%20Ctl%20TakeSwap%0At_swap%20-%3E%20peerd%20%3A%20Msg%20TakerCommit%0Apeerd%20-%3E%20m_farcasterd%20%3A%20Msg%20TakerCommit%0Am_farcasterd%20-%3E%20m_wallet%20%3A%20Ctl%20BitcoinAddress%0Am_farcasterd%20-%3E%20m_wallet%20%3A%20Msg%20TakerCommit%0Am_wallet%20-%3E%20m_wallet%20%3A%20create%20maker%20wallet%0Am_wallet%20-%3E%20m_farcasterd%20%3A%20Ctl%20LaunchSwap%0Am_swap%20-%3E%20m_farcasterd%20%3A%20Ctl%20Hello%0Am_swap%20-%3E%20m_wallet%20%3A%20Ctl%20Hello%0Am_farcasterd%20-%3E%20m_farcasterd%3Alaunch%20syncer%0Am_farcasterd%20-%3E%20m_swap%20%3A%20Ctl%20MakeSwap%0A%0Am_swap%20-%3E%20peerd%20%3A%20Msg%20MakerCommit%0At_swap%20%3C-%20peerd%20%3A%20Msg%20MakerCommit%0A%2F%2F%20TODO%3A%20verify%20that%20swapd%20launches%20no%20matter%20what%0At_syncer%20%3C-%20t_swap%20%3A%20Ctl%20WatchHeight%0At_syncer%20%3C-%20t_swap%20%3A%20if%20Bob%2C%20Watch%20Arbitrating%20Funding%20Address%0At_swap%20-%3E%20t_wallet%20%3A%20Msg%20MakerCommit%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20RevealProof%20(taker%20is%20sender)%0At_swap%20-%3E%20peerd%20%3A%20Msg%20RevealProof%20(taker%20is%20sender)%0At_swap%20-%3E%20peerd%20%3A%20Msg%20Reveal%20(taker%20is%20sender)%0Apeerd%20-%3E%20m_swap%20%3A%20Msg%20RevealProof%20(taker%20is%20sender)%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Alice%2C%20Msg%20RevealProof%20(taker%20is%20sender)%20%0Am_swap%20-%3E%20m_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20RevealProof%0Apeerd%20-%3E%20m_swap%20%3A%20Msg%20Reveal%20(taker%20is%20sender)%0Am_swap%20-%3E%20m_farcasterd%20%3A%20if%20Bob%2C%20ask%20for%20funding%0Am_swap%20-%3E%20m_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20Reveal%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Alice%2C%20Msg%20Reveal%20(taker%20is%20sender)%0A%0Am_swap-%3Em_syncer%3ACtl%20WatchHeight%0Am_swap%20-%3E%20m_syncer%3Aif%20Bob%2C%20Watch%20Arbitrating%20Funding%20Address%0Am_swap%20%3C-%20m_syncer%3AIf%20Bob%2C%20Arbitrating%20Funding%20event%0Am_swap-%3Em_wallet%3Aif%20Bob%2C%20Ctl%20Tx%3A%3AFunding%0Am_swap%3C-m_wallet%3AIf%20Bob%2C%20Ctl%20FundingUpdated%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20RevealProof%20(taker%20is%20sender)%20%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20Reveal%20(taker%20is%20sender)%0Am_wallet%20-%3E%20m_swap%20%3A%20Ctl%20RevealProof%20(maker%20is%20sender)%0Apeerd%20%3C-%20m_swap%20%3A%20Msg%20RevealProof%20(maker%20is%20sender)%0Apeerd%20%3C-%20m_swap%20%3A%20Msg%20Reveal%20(maker%20is%20sender)%0Apeerd%20-%3E%20t_swap%20%3A%20Msg%20RevealProof%20(maker%20is%20sender)%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Alice%2C%20Msg%20RevealProof%20(maker%20is%20sender)%0At_swap%20-%3E%20t_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20RevealProof%0Apeerd%20-%3E%20t_swap%20%3A%20Msg%20Reveal%20(maker%20is%20sender)%0At_swap%20-%3E%20t_farcasterd%20%3A%20if%20Bob%2C%20ask%20for%20funding%0At_swap%20-%3E%20t_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20Reveal%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Alice%2C%20Msg%20Reveal%20(maker%20is%20sender)%0At_syncer%20-%3E%20t_swap%3AIf%20Bob%2C%20Arbitrating%20Funding%20event%0At_swap-%3Et_wallet%3Aif%20Bob%2C%20Ctl%20Tx%3A%3AFunding%0At_swap%3C-t_wallet%3AIf%20Bob%2C%20Ctl%20FundingUpdated%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20RevealProof%20(maker%20is%20sender)%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20Reveal%20(maker%20is%20sender)%0A%3D%3DCommit-Reveal%20Complete%3D%3D%0A%3D%3DChanging%20semantics%3A%20On%20Commit-Reveal%2C%20Maker%20and%20Taker%20were%20the%20key%20roles.%20From%20now%20on%20Bob%20or%20Alice%20are%20the%20key%20roles.%20Now%20t_%20is%20bob_%20on%20the%20left%20and%20m_%20is%20alice_%20on%20the%20right.%3D%3D%0A%3D%3DSwap%20setup%3A%20Bob%20is%20left%2C%20Alice%20right%3D%3D%0At_wallet%20-%3E%20t_checkpoint%3A%20Ctl%20CheckpointWalletBobPrelockBob%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20CoreArbitratingSetup%0At_swap%20-%3E%20t_checkpoint%3A%20Ctl%20CheckpointSwapBobPrelockBob%0A%2F%2F%20TODO%3A%20During%20replay%20of%20CheckpointSwapBobPrelockBob%2C%20Bob%20has%20to%20rewatch%20these%203%20txs%0At_syncer%20%3C-%20t_swap%20%3A%20Watch%20Arbitrating%20Lock%0At_syncer%20%3C-%20t_swap%20%3A%20Watch%20Cancel%0At_syncer%20%3C-%20t_swap%20%3A%20Watch%20Refund%0Apeerd%20%3C-%20t_swap%20%3A%20Msg%20CoreArbitratingSetup%0Am_swap%20%3C-%20peerd%20%3A%20Msg%20CoreArbitratingSetup%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Arbitrating%20Lock%0A%2F%2F%20TODO%3A%20During%20replay%20of%20CheckpointWalletAlicePrelockBob%2C%20Alice%20has%20to%20rewatch%20these%202%20txs%20(arbitrating%20already%20final%20then)%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Cancel%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Refund%0A%0Am_wallet%20%3C-%20m_swap%20%3A%20Msg%20CoreArbitratingSetup%0Am_wallet%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointWalletAlicePrelockBob%0Am_wallet%20-%3E%20m_swap%20%3A%20Ctl%20RefundProcedureSignatures%0Am_swap%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointSwapAlicePrelockBob%0Am_swap%20-%3E%20peerd%20%3A%20Msg%20RefundProcedureSignatures%0Apeerd%20-%3E%20t_swap%20%3A%20Msg%20RefundProcedureSignatures%0At_wallet%20%3C-%20t_swap%20%3A%20Msg%20RefundProcedureSignatures%0At_wallet%20-%3E%20t_swap%3ACtl%20Datum%3A%3ASignedArbitratingLock%0A%2F%2F%20DONE%3A%20do%20we%20know%20that%20same%20inputs%20are%20being%20used%20in%20case%20of%20replay%3F%0A%2F%2F%20-%3E%20yes%2C%20but%20create%20different%20sig%0At_wallet%20-%3E%20t_checkpoint%20%3A%20Ctl%20CheckpointWalletBobPreBuySig%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20Tx%3A%3ALock%0At_swap%20-%3E%20t_syncer%3A%20Ctl%20Broadcast%20Arbitrating%20Lock%0At_swap%20-%3E%20t_syncer%20%3A%20Watch%20Accordant%20Lock%0At_wallet%20-%3E%20t_swap%3A%20Ctl%20Tx%3A%3ACancel%0At_wallet%20-%3E%20t_swap%3A%20Ctl%20Tx%3A%3ARefund%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20BuyProcedureSignature%0At_swap%20-%3E%20t_checkpoint%20%3A%20Ctl%20CheckpointSwapBobPreBuySig%0At_swap%20-%3E%20t_syncer%20%3A%20Watch%20Buy%0A%0Aparallel%0At_syncer%20-%3E%20%20t_swap%20%3A%20Arbitrating%20Lock%20final%0A%2F%2F%20TODO%3A%20maybe%20instead%20of%20checkpointing%20earlier%2C%20reach%20this%20stage%20via%20a%20message%20from%20walletd%20in%20lieu%20of%20the%20syncer%0Am_swap%20%3C-%20m_syncer%20%3A%20Arbitrating%20Lock%20final%0Aparallel%20off%0A%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Accordant%20Lock%0A%0Aparallel%0Am_swap%20%3C-%20m_syncer%20%3A%20Accordant%20Lock%20final%0At_swap%20%3C-%20t_syncer%20%3A%20Accordant%20Lock%20final%0Aparallel%20off%0A%0Apeerd%20%3C-%20t_swap%20%3A%20Msg%20BuyProcedureSignature%0Am_swap%20%3C-%20peerd%20%3A%20Msg%20BuyProcedureSignature%0Am_swap%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointSwapAlicePreBuy%0Am_swap%20-%3E%20m_syncer%3AWatch%20Buy%0Am_swap%20-%3E%20m_wallet%20%3A%20Msg%20BuyProcedureSignature%0Am_wallet%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointWalletAlicePreBuy%0A%3D%3DSwap%20Setup%20Complete%3D%3D%0A%3D%3DBuy%20Procedure%3A%20Bob%20is%20left%2C%20Alice%20right%3D%3D%0A%0Am_swap%20%3C-%20m_wallet%20%3A%20Fully%20signed%20buy%0Am_swap%20-%3E%20m_syncer%20%3A%20Broadcast%20buy%0Aparallel%0Am_swap%20%3C-%20m_syncer%20%3A%20Event%3A%20buy%20seen%20on%20mempool%0At_swap%20%3C-%20t_syncer%20%3A%20Event%3A%20buy%20seen%20on%20mempool%0Aparallel%20off%0At_wallet%20%3C-%20t_swap%20%3A%20Ctl%20Buy%20signature%0At_wallet%20-%3E%20t_wallet%20%3A%20recover%20accordant%20keys%0A%0A%3D%3DCancel%20Init%20t%20%3E%20t0%3A%20Bob%20is%20left%2C%20Alice%20right%2C%20either%20have%20a%20fully%20signed%20and%20valid%20cancel%20tx%2C%20and%20can%20publish%3D%3D%0A%2F%2F%20TODO%3A%20insert%20Ctl%20Tx%3A%3ACancel%20from%20wallet%20to%20swap%20(or%20do%20it%20after%20CoreArbitratingSetup%2C%20as%20in%20the%20code%20atm)%0Aparallel%0At_swap%20%3C-%20t_syncer%20%3A%20Ctl%20Cancel%20valid%0Am_swap%20%3C-%20m_syncer%20%3A%20Ctl%20Cancel%20valid%0Aparallel%20off%0Aparallel%0Am_swap%20-%3E%20m_syncer%20%3A%20Broadcast%20cancel%20(Alice%20inits)%0At_swap%20-%3E%20t_syncer%20%3A%20Broadcast%20cancel%20(Bob%20inits)%0Aparallel%20off%0A%3D%3DCancel%20detected%20t%20%3E%20t0%3A%20Bob%20is%20left%2C%20Alice%20right%3D%3D%0At_swap%20%3C-%20t_syncer%3A%20Event%20cancel%20final%0At_swap%20-%3E%20t_syncer%20%3A%20Broadcast%20refund%0Aparallel%0At_syncer%20-%3E%20t_swap%20%3A%20Event%3A%20refund%20seen%0Am_syncer%20-%3E%20m_swap%20%3A%20Event%3A%20refund%20seen%0Aparallel%20off%0Am_swap%20-%3E%20m_wallet%20%3A%20Ctl%20Tx%3A%3ARefund%20tx%0Am_wallet%20-%3E%20m_wallet%20%3A%20recover%20accordant%20keys%0A%0A%3D%3D%20Punish%20process%20t%20%3E%20t1%20%3E%20t0%20%3D%3D%0A%2F%2F%20TODO%3A%20none%20of%20this%20is%20true%20except%20last%20step%0Am_swap%3C-m_syncer%3ACtl%20Event%3A%20punish%20valid%0Am_swap-%3Em_wallet%3ACtl%20Event%3A%20punish%20valid%0Am_wallet-%3Em_wallet%3Afully%20sign%20punish%0A%2F%2F%20TODO%3A%20in%20the%20code%2C%20this%20actually%20already%20happens%20after%20CoreArbitratingSetup%20-%20think%20about%20this%20and%20move%20either%20this%20or%20that%0Am_swap%3C-m_wallet%3ACtl%20Tx%3A%3APunish%0Am_swap-%3Em_syncer%3ACtl%20Broadcast%20punish%20txFarcaster nodet_syncert_wallett_swapt_checkpointt_farcasterdt_clipeerdm_clim_farcasterdm_checkpointm_swapm_walletm_syncerSetup and Commit-Reveal: Bob and Alice can be on both sideslaunch farcasterdmanuallylaunch walletdCtl HelloMakeOffer (deferred)Ctl GetKeysCtl Keys (not to be held on state)MakeOffer (continues)launchpeerd listenlaunch farcasterdmanuallylaunch walletdCtl HelloCtl TakeOffer (deferred)Ctl GetKeysCtl Keys (not to be held on state)Ctl TakeOffer (continues)launchpeerd connectCtl TakeOffercreate taker walletCtl LaunchSwapCtl HelloCtl Hellolaunch syncerCtl TakeSwapMsg TakerCommitMsg TakerCommitCtl BitcoinAddressMsg TakerCommitcreate maker walletCtl LaunchSwapCtl HelloCtl Hellolaunch syncerCtl MakeSwapMsg MakerCommitMsg MakerCommitCtl WatchHeightif Bob, Watch Arbitrating Funding AddressMsg MakerCommitCtl RevealProof (taker is sender)Msg RevealProof (taker is sender)Msg Reveal (taker is sender)Msg RevealProof (taker is sender)if Alice, Msg RevealProof (taker is sender) if Bob, ADD PENDING Msg RevealProofMsg Reveal (taker is sender)if Bob, ask for fundingif Bob, ADD PENDING Msg Revealif Alice, Msg Reveal (taker is sender)Ctl WatchHeightif Bob, Watch Arbitrating Funding AddressIf Bob, Arbitrating Funding eventif Bob, Ctl Tx::FundingIf Bob, Ctl FundingUpdatedif Bob, SEND PENDING Msg RevealProof (taker is sender) if Bob, SEND PENDING Msg Reveal (taker is sender)Ctl RevealProof (maker is sender)Msg RevealProof (maker is sender)Msg Reveal (maker is sender)Msg RevealProof (maker is sender)if Alice, Msg RevealProof (maker is sender)if Bob, ADD PENDING Msg RevealProofMsg Reveal (maker is sender)if Bob, ask for fundingif Bob, ADD PENDING Msg Revealif Alice, Msg Reveal (maker is sender)If Bob, Arbitrating Funding eventif Bob, Ctl Tx::FundingIf Bob, Ctl FundingUpdatedif Bob, SEND PENDING Msg RevealProof (maker is sender)if Bob, SEND PENDING Msg Reveal (maker is sender)Commit-Reveal CompleteChanging semantics: On Commit-Reveal, Maker and Taker were the key roles. From now on Bob or Alice are the key roles. Now t_ is bob_ on the left and m_ is alice_ on the right.Swap setup: Bob is left, Alice rightCtl CheckpointWalletBobPrelockBobCtl CoreArbitratingSetupCtl CheckpointSwapBobPrelockBobWatch Arbitrating LockWatch CancelWatch RefundMsg CoreArbitratingSetupMsg CoreArbitratingSetupWatch Arbitrating LockWatch CancelWatch RefundMsg CoreArbitratingSetupCtl CheckpointWalletAlicePrelockBobCtl RefundProcedureSignaturesCtl CheckpointSwapAlicePrelockBobMsg RefundProcedureSignaturesMsg RefundProcedureSignaturesMsg RefundProcedureSignaturesCtl Datum::SignedArbitratingLockCtl CheckpointWalletBobPreBuySigCtl Tx::LockCtl Broadcast Arbitrating LockWatch Accordant LockCtl Tx::CancelCtl Tx::RefundCtl BuyProcedureSignatureCtl CheckpointSwapBobPreBuySigWatch BuyArbitrating Lock finalArbitrating Lock finalWatch Accordant LockAccordant Lock finalAccordant Lock finalMsg BuyProcedureSignatureMsg BuyProcedureSignatureCtl CheckpointSwapAlicePreBuyWatch BuyMsg BuyProcedureSignatureCtl CheckpointWalletAlicePreBuySwap Setup CompleteBuy Procedure: Bob is left, Alice rightFully signed buyBroadcast buyEvent: buy seen on mempoolEvent: buy seen on mempoolCtl Buy signaturerecover accordant keysCancel Init t > t0: Bob is left, Alice right, either have a fully signed and valid cancel tx, and can publishCtl Cancel validCtl Cancel validBroadcast cancel (Alice inits)Broadcast cancel (Bob inits)Cancel detected t > t0: Bob is left, Alice rightEvent cancel finalBroadcast refundEvent: refund seenEvent: refund seenCtl Tx::Refund txrecover accordant keys Punish process t > t1 > t0 Ctl Event: punish validCtl Event: punish validfully sign punishCtl Tx::PunishCtl Broadcast punish tx \ No newline at end of file +title%20Farcaster%20node%0A%2F%2F%20to%20display%20the%20diagram%2C%20go%20to%20sequencediagram.org%0A%2F%2F%20dashed%20lines%2C%20not%20yet%20implemented%0A%0Aparticipant%20t_syncer%0Aparticipant%20t_wallet%0Aparticipant%20t_swap%0Aparticipant%20t_checkpoint%0Aparticipant%20t_farcasterd%0Aparticipant%20t_cli%0Aparticipant%20peerd%0Aparticipant%20m_cli%0Aparticipant%20m_farcasterd%0Aparticipant%20m_checkpoint%0Aparticipant%20m_swap%0Aparticipant%20m_wallet%0Aparticipant%20m_syncer%0A%0A%3D%3DSetup%20and%20Commit-Reveal%3A%20Bob%20and%20Alice%20can%20be%20on%20both%20sides%3D%3D%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20launch%20farcasterd%5Cnmanually%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20launch%20walletd%0Am_farcasterd%20%3C-%20m_wallet%20%3A%20Ctl%20Hello%0Am_cli%20-%3E%20m_farcasterd%20%3A%20MakeOffer%20(deferred)%0Am_farcasterd%20-%3E%20m_wallet%20%3A%20Ctl%20GetKeys%0Am_farcasterd%20%3C-%20m_wallet%20%3A%20Ctl%20Keys%20(not%20to%20be%20held%20on%20state)%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20MakeOffer%20(continues)%0Am_farcasterd%20-%3E%20m_farcasterd%20%3A%20launch%5Cnpeerd%20listen%0At_farcasterd%20-%3E%20t_farcasterd%20%3A%20launch%20farcasterd%5Cnmanually%0At_farcasterd%20-%3E%20t_farcasterd%20%3A%20launch%20walletd%0At_wallet%20-%3E%20t_farcasterd%20%3A%20Ctl%20Hello%0At_cli%20-%3E%20t_farcasterd%20%3A%20Ctl%20TakeOffer%20(deferred)%0At_wallet%20%3C-%20t_farcasterd%20%3A%20Ctl%20GetKeys%0At_wallet%20-%3E%20t_farcasterd%20%3A%20Ctl%20Keys%20(not%20to%20be%20held%20on%20state)%0At_farcasterd%20%3C-%20t_farcasterd%20%3A%20Ctl%20TakeOffer%20(continues)%0At_farcasterd%20-%3E%20t_farcasterd%20%3A%20launch%5Cnpeerd%20connect%0At_wallet%20%3C-%20t_farcasterd%20%3A%20Ctl%20TakeOffer%0At_wallet%20-%3E%20t_wallet%20%3A%20create%20taker%20wallet%0At_wallet%20-%3E%20t_farcasterd%20%3A%20Ctl%20LaunchSwap%0At_swap%20-%3E%20t_farcasterd%20%3A%20Ctl%20Hello%0At_swap%20-%3E%20t_wallet%20%3A%20Ctl%20Hello%0At_farcasterd%20-%3E%20t_farcasterd%3Alaunch%20syncer%0At_swap%20%3C-%20t_farcasterd%20%3A%20Ctl%20TakeSwap%0At_swap%20-%3E%20peerd%20%3A%20Msg%20TakerCommit%0Apeerd%20-%3E%20m_farcasterd%20%3A%20Msg%20TakerCommit%0Am_farcasterd%20-%3E%20m_wallet%20%3A%20Ctl%20BitcoinAddress%0Am_farcasterd%20-%3E%20m_wallet%20%3A%20Msg%20TakerCommit%0Am_wallet%20-%3E%20m_wallet%20%3A%20create%20maker%20wallet%0Am_wallet%20-%3E%20m_farcasterd%20%3A%20Ctl%20LaunchSwap%0Am_swap%20-%3E%20m_farcasterd%20%3A%20Ctl%20Hello%0Am_swap%20-%3E%20m_wallet%20%3A%20Ctl%20Hello%0Am_farcasterd%20-%3E%20m_farcasterd%3Alaunch%20syncer%0Am_farcasterd%20-%3E%20m_swap%20%3A%20Ctl%20MakeSwap%0A%0Am_swap%20-%3E%20peerd%20%3A%20Msg%20MakerCommit%0At_swap%20%3C-%20peerd%20%3A%20Msg%20MakerCommit%0A%2F%2F%20TODO%3A%20verify%20that%20swapd%20launches%20no%20matter%20what%0At_syncer%20%3C-%20t_swap%20%3A%20Ctl%20WatchHeight%0At_syncer%20%3C-%20t_swap%20%3A%20if%20Bob%2C%20Watch%20Arbitrating%20Funding%20Address%0At_syncer%3C-t_swap%3AIf%20Bob%2C%20Ctl%20EstimateFee%20(btc)%0At_swap%20-%3E%20t_wallet%20%3A%20Msg%20MakerCommit%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20RevealProof%20(taker%20is%20sender)%0At_swap%20-%3E%20peerd%20%3A%20Msg%20RevealProof%20(taker%20is%20sender)%0At_swap%20-%3E%20peerd%20%3A%20Msg%20Reveal%20(taker%20is%20sender)%0Apeerd%20-%3E%20m_swap%20%3A%20Msg%20RevealProof%20(taker%20is%20sender)%0Am_swap-%3Em_syncer%3AIf%20Bob%2C%20Ctl%20EstimateFee%20(btc)%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Alice%2C%20Msg%20RevealProof%20(taker%20is%20sender)%20%0Am_swap%20-%3E%20m_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20RevealProof%0Apeerd%20-%3E%20m_swap%20%3A%20Msg%20Reveal%20(taker%20is%20sender)%0Am_swap%20-%3E%20m_farcasterd%20%3A%20if%20Bob%2C%20ask%20for%20funding%0Am_swap%20-%3E%20m_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20Reveal%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Alice%2C%20Msg%20Reveal%20(taker%20is%20sender)%0A%0Am_swap-%3Em_syncer%3ACtl%20WatchHeight%0Am_swap%20-%3E%20m_syncer%3Aif%20Bob%2C%20Watch%20Arbitrating%20Funding%20Address%0Am_swap%20%3C-%20m_syncer%3AIf%20Bob%2C%20Arbitrating%20Funding%20event%0Am_swap-%3Em_wallet%3Aif%20Bob%2C%20Ctl%20Tx%3A%3AFunding%0Am_swap%3C-m_wallet%3AIf%20Bob%2C%20Ctl%20FundingUpdated%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20RevealProof%20(taker%20is%20sender)%20%0Am_swap%20-%3E%20m_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20Reveal%20(taker%20is%20sender)%0Am_wallet%20-%3E%20m_swap%20%3A%20Ctl%20RevealProof%20(maker%20is%20sender)%0Apeerd%20%3C-%20m_swap%20%3A%20Msg%20RevealProof%20(maker%20is%20sender)%0Apeerd%20%3C-%20m_swap%20%3A%20Msg%20Reveal%20(maker%20is%20sender)%0Apeerd%20-%3E%20t_swap%20%3A%20Msg%20RevealProof%20(maker%20is%20sender)%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Alice%2C%20Msg%20RevealProof%20(maker%20is%20sender)%0At_swap%20-%3E%20t_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20RevealProof%0Apeerd%20-%3E%20t_swap%20%3A%20Msg%20Reveal%20(maker%20is%20sender)%0At_swap%20-%3E%20t_farcasterd%20%3A%20if%20Bob%2C%20ask%20for%20funding%0At_swap%20-%3E%20t_swap%20%3A%20if%20Bob%2C%20ADD%20PENDING%20Msg%20Reveal%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Alice%2C%20Msg%20Reveal%20(maker%20is%20sender)%0At_syncer%20-%3E%20t_swap%3AIf%20Bob%2C%20Arbitrating%20Funding%20event%0At_swap-%3Et_wallet%3Aif%20Bob%2C%20Ctl%20Tx%3A%3AFunding%0At_swap%3C-t_wallet%3AIf%20Bob%2C%20Ctl%20FundingUpdated%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20RevealProof%20(maker%20is%20sender)%0At_swap%20-%3E%20t_wallet%20%3A%20if%20Bob%2C%20SEND%20PENDING%20Msg%20Reveal%20(maker%20is%20sender)%0A%3D%3DCommit-Reveal%20Complete%3D%3D%0A%3D%3DChanging%20semantics%3A%20On%20Commit-Reveal%2C%20Maker%20and%20Taker%20were%20the%20key%20roles.%20From%20now%20on%20Bob%20or%20Alice%20are%20the%20key%20roles.%20Now%20t_%20is%20bob_%20on%20the%20left%20and%20m_%20is%20alice_%20on%20the%20right.%3D%3D%0A%3D%3DSwap%20setup%3A%20Bob%20is%20left%2C%20Alice%20right%3D%3D%0At_wallet%20-%3E%20t_checkpoint%3A%20Ctl%20CheckpointWalletBobPrelockBob%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20CoreArbitratingSetup%0At_swap%20-%3E%20t_checkpoint%3A%20Ctl%20CheckpointSwapBobPrelockBob%0A%2F%2F%20TODO%3A%20During%20replay%20of%20CheckpointSwapBobPrelockBob%2C%20Bob%20has%20to%20rewatch%20these%203%20txs%0At_syncer%20%3C-%20t_swap%20%3A%20Watch%20Arbitrating%20Lock%0At_syncer%20%3C-%20t_swap%20%3A%20Watch%20Cancel%0At_syncer%20%3C-%20t_swap%20%3A%20Watch%20Refund%0Apeerd%20%3C-%20t_swap%20%3A%20Msg%20CoreArbitratingSetup%0Am_swap%20%3C-%20peerd%20%3A%20Msg%20CoreArbitratingSetup%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Arbitrating%20Lock%0A%2F%2F%20TODO%3A%20During%20replay%20of%20CheckpointWalletAlicePrelockBob%2C%20Alice%20has%20to%20rewatch%20these%202%20txs%20(arbitrating%20already%20final%20then)%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Cancel%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Refund%0A%0Am_wallet%20%3C-%20m_swap%20%3A%20Msg%20CoreArbitratingSetup%0Am_wallet%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointWalletAlicePrelockBob%0Am_wallet%20-%3E%20m_swap%20%3A%20Ctl%20RefundProcedureSignatures%0Am_swap%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointSwapAlicePrelockBob%0Am_swap%20-%3E%20peerd%20%3A%20Msg%20RefundProcedureSignatures%0Apeerd%20-%3E%20t_swap%20%3A%20Msg%20RefundProcedureSignatures%0At_wallet%20%3C-%20t_swap%20%3A%20Msg%20RefundProcedureSignatures%0At_wallet%20-%3E%20t_swap%3ACtl%20Datum%3A%3ASignedArbitratingLock%0A%2F%2F%20DONE%3A%20do%20we%20know%20that%20same%20inputs%20are%20being%20used%20in%20case%20of%20replay%3F%0A%2F%2F%20-%3E%20yes%2C%20but%20create%20different%20sig%0At_wallet%20-%3E%20t_checkpoint%20%3A%20Ctl%20CheckpointWalletBobPreBuySig%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20Tx%3A%3ALock%0At_swap%20-%3E%20t_syncer%3A%20Ctl%20Broadcast%20Arbitrating%20Lock%0At_swap%20-%3E%20t_syncer%20%3A%20Watch%20Accordant%20Lock%0At_wallet%20-%3E%20t_swap%3A%20Ctl%20Tx%3A%3ACancel%0At_wallet%20-%3E%20t_swap%3A%20Ctl%20Tx%3A%3ARefund%0At_wallet%20-%3E%20t_swap%20%3A%20Ctl%20BuyProcedureSignature%0At_swap%20-%3E%20t_checkpoint%20%3A%20Ctl%20CheckpointSwapBobPreBuySig%0At_swap%20-%3E%20t_syncer%20%3A%20Watch%20Buy%0A%0Aparallel%0At_syncer%20-%3E%20%20t_swap%20%3A%20Arbitrating%20Lock%20final%0A%2F%2F%20TODO%3A%20maybe%20instead%20of%20checkpointing%20earlier%2C%20reach%20this%20stage%20via%20a%20message%20from%20walletd%20in%20lieu%20of%20the%20syncer%0Am_swap%20%3C-%20m_syncer%20%3A%20Arbitrating%20Lock%20final%0Aparallel%20off%0A%0Am_swap%20-%3E%20m_syncer%20%3A%20Watch%20Accordant%20Lock%0A%0Aparallel%0Am_swap%20%3C-%20m_syncer%20%3A%20Accordant%20Lock%20final%0At_swap%20%3C-%20t_syncer%20%3A%20Accordant%20Lock%20final%0Aparallel%20off%0A%0Am_swap-%3Em_syncer%3ACtl%20EstimateFee%20(btc)%0Apeerd%20%3C-%20t_swap%20%3A%20Msg%20BuyProcedureSignature%0Am_swap%20%3C-%20peerd%20%3A%20Msg%20BuyProcedureSignature%0Am_swap%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointSwapAlicePreBuy%0Am_swap%20-%3E%20m_syncer%3AWatch%20Buy%0Am_swap%20-%3E%20m_wallet%20%3A%20Msg%20BuyProcedureSignature%0Am_wallet%20-%3E%20m_checkpoint%20%3A%20Ctl%20CheckpointWalletAlicePreBuy%0A%3D%3DSwap%20Setup%20Complete%3D%3D%0A%3D%3DBuy%20Procedure%3A%20Bob%20is%20left%2C%20Alice%20right%3D%3D%0A%0Am_swap%20%3C-%20m_wallet%20%3A%20Fully%20signed%20buy%0Am_swap%20-%3E%20m_syncer%20%3A%20Broadcast%20buy%0Aparallel%0Am_swap%20%3C-%20m_syncer%20%3A%20Event%3A%20buy%20seen%20on%20mempool%0At_swap%20%3C-%20t_syncer%20%3A%20Event%3A%20buy%20seen%20on%20mempool%0Aparallel%20off%0At_wallet%20%3C-%20t_swap%20%3A%20Ctl%20Buy%20signature%0At_wallet%20-%3E%20t_wallet%20%3A%20recover%20accordant%20keys%0A%0A%3D%3DCancel%20Init%20t%20%3E%20t0%3A%20Bob%20is%20left%2C%20Alice%20right%2C%20either%20have%20a%20fully%20signed%20and%20valid%20cancel%20tx%2C%20and%20can%20publish%3D%3D%0Aparallel%0At_swap%20%3C-%20t_syncer%20%3A%20Ctl%20Cancel%20valid%0Am_swap%20%3C-%20m_syncer%20%3A%20Ctl%20Cancel%20valid%0Aparallel%20off%0Aparallel%0Am_swap%20-%3E%20m_syncer%20%3A%20Broadcast%20cancel%20(Alice%20inits)%0At_swap%20-%3E%20t_syncer%20%3A%20Broadcast%20cancel%20(Bob%20inits)%0Aparallel%20off%0A%3D%3DCancel%20detected%20t%20%3E%20t0%3A%20Bob%20is%20left%2C%20Alice%20right%3D%3D%0At_swap%20%3C-%20t_syncer%3A%20Event%20cancel%20final%0At_swap%20-%3E%20t_syncer%20%3A%20Broadcast%20refund%0Aparallel%0At_syncer%20-%3E%20t_swap%20%3A%20Event%3A%20refund%20seen%0Am_syncer%20-%3E%20m_swap%20%3A%20Event%3A%20refund%20seen%0Aparallel%20off%0Am_swap%20-%3E%20m_wallet%20%3A%20Ctl%20Tx%3A%3ARefund%20tx%0Am_wallet%20-%3E%20m_wallet%20%3A%20recover%20accordant%20keys%0A%0A%3D%3D%20Punish%20process%20t%20%3E%20t1%20%3E%20t0%20%3D%3D%0A%2F%2F%20TODO%3A%20none%20of%20this%20is%20true%20except%20last%20step%0Am_swap%3C-m_syncer%3ACtl%20Event%3A%20punish%20valid%0Am_swap-%3Em_wallet%3ACtl%20Event%3A%20punish%20valid%0Am_wallet-%3Em_wallet%3Afully%20sign%20punish%0A%2F%2F%20TODO%3A%20in%20the%20code%2C%20this%20actually%20already%20happens%20after%20CoreArbitratingSetup%20-%20think%20about%20this%20and%20move%20either%20this%20or%20that%0Am_swap%3C-m_wallet%3ACtl%20Tx%3A%3APunish%0Am_swap-%3Em_syncer%3ACtl%20Broadcast%20punish%20tx%0AFarcaster nodet_syncert_wallett_swapt_checkpointt_farcasterdt_clipeerdm_clim_farcasterdm_checkpointm_swapm_walletm_syncerSetup and Commit-Reveal: Bob and Alice can be on both sideslaunch farcasterdmanuallylaunch walletdCtl HelloMakeOffer (deferred)Ctl GetKeysCtl Keys (not to be held on state)MakeOffer (continues)launchpeerd listenlaunch farcasterdmanuallylaunch walletdCtl HelloCtl TakeOffer (deferred)Ctl GetKeysCtl Keys (not to be held on state)Ctl TakeOffer (continues)launchpeerd connectCtl TakeOffercreate taker walletCtl LaunchSwapCtl HelloCtl Hellolaunch syncerCtl TakeSwapMsg TakerCommitMsg TakerCommitCtl BitcoinAddressMsg TakerCommitcreate maker walletCtl LaunchSwapCtl HelloCtl Hellolaunch syncerCtl MakeSwapMsg MakerCommitMsg MakerCommitCtl WatchHeightif Bob, Watch Arbitrating Funding AddressIf Bob, Ctl EstimateFee (btc)Msg MakerCommitCtl RevealProof (taker is sender)Msg RevealProof (taker is sender)Msg Reveal (taker is sender)Msg RevealProof (taker is sender)If Bob, Ctl EstimateFee (btc)if Alice, Msg RevealProof (taker is sender) if Bob, ADD PENDING Msg RevealProofMsg Reveal (taker is sender)if Bob, ask for fundingif Bob, ADD PENDING Msg Revealif Alice, Msg Reveal (taker is sender)Ctl WatchHeightif Bob, Watch Arbitrating Funding AddressIf Bob, Arbitrating Funding eventif Bob, Ctl Tx::FundingIf Bob, Ctl FundingUpdatedif Bob, SEND PENDING Msg RevealProof (taker is sender) if Bob, SEND PENDING Msg Reveal (taker is sender)Ctl RevealProof (maker is sender)Msg RevealProof (maker is sender)Msg Reveal (maker is sender)Msg RevealProof (maker is sender)if Alice, Msg RevealProof (maker is sender)if Bob, ADD PENDING Msg RevealProofMsg Reveal (maker is sender)if Bob, ask for fundingif Bob, ADD PENDING Msg Revealif Alice, Msg Reveal (maker is sender)If Bob, Arbitrating Funding eventif Bob, Ctl Tx::FundingIf Bob, Ctl FundingUpdatedif Bob, SEND PENDING Msg RevealProof (maker is sender)if Bob, SEND PENDING Msg Reveal (maker is sender)Commit-Reveal CompleteChanging semantics: On Commit-Reveal, Maker and Taker were the key roles. From now on Bob or Alice are the key roles. Now t_ is bob_ on the left and m_ is alice_ on the right.Swap setup: Bob is left, Alice rightCtl CheckpointWalletBobPrelockBobCtl CoreArbitratingSetupCtl CheckpointSwapBobPrelockBobWatch Arbitrating LockWatch CancelWatch RefundMsg CoreArbitratingSetupMsg CoreArbitratingSetupWatch Arbitrating LockWatch CancelWatch RefundMsg CoreArbitratingSetupCtl CheckpointWalletAlicePrelockBobCtl RefundProcedureSignaturesCtl CheckpointSwapAlicePrelockBobMsg RefundProcedureSignaturesMsg RefundProcedureSignaturesMsg RefundProcedureSignaturesCtl Datum::SignedArbitratingLockCtl CheckpointWalletBobPreBuySigCtl Tx::LockCtl Broadcast Arbitrating LockWatch Accordant LockCtl Tx::CancelCtl Tx::RefundCtl BuyProcedureSignatureCtl CheckpointSwapBobPreBuySigWatch BuyArbitrating Lock finalArbitrating Lock finalWatch Accordant LockAccordant Lock finalAccordant Lock finalCtl EstimateFee (btc)Msg BuyProcedureSignatureMsg BuyProcedureSignatureCtl CheckpointSwapAlicePreBuyWatch BuyMsg BuyProcedureSignatureCtl CheckpointWalletAlicePreBuySwap Setup CompleteBuy Procedure: Bob is left, Alice rightFully signed buyBroadcast buyEvent: buy seen on mempoolEvent: buy seen on mempoolCtl Buy signaturerecover accordant keysCancel Init t > t0: Bob is left, Alice right, either have a fully signed and valid cancel tx, and can publishCtl Cancel validCtl Cancel validBroadcast cancel (Alice inits)Broadcast cancel (Bob inits)Cancel detected t > t0: Bob is left, Alice rightEvent cancel finalBroadcast refundEvent: refund seenEvent: refund seenCtl Tx::Refund txrecover accordant keys Punish process t > t1 > t0 Ctl Event: punish validCtl Event: punish validfully sign punishCtl Tx::PunishCtl Broadcast punish tx \ No newline at end of file diff --git a/doc/sequencediagram.txt b/doc/sequencediagram.txt index 62bdfd77a..595afb1f6 100644 --- a/doc/sequencediagram.txt +++ b/doc/sequencediagram.txt @@ -51,6 +51,7 @@ m_swap -> m_wallet : Ctl Hello m_farcasterd -> m_farcasterd:launch syncer m_farcasterd -> m_swap : Ctl MakeSwap +m_swap->m_syncer:If Bob, Ctl EstimateFee (btc) m_swap -> peerd : Msg MakerCommit t_swap <- peerd : Msg MakerCommit // TODO: verify that swapd launches no matter what @@ -62,7 +63,6 @@ t_wallet -> t_swap : Ctl RevealProof (taker is sender) t_swap -> peerd : Msg RevealProof (taker is sender) t_swap -> peerd : Msg Reveal (taker is sender) peerd -> m_swap : Msg RevealProof (taker is sender) -m_swap->m_syncer:If Bob, Ctl EstimateFee (btc) m_swap -> m_wallet : if Alice, Msg RevealProof (taker is sender) m_swap -> m_swap : if Bob, ADD PENDING Msg RevealProof peerd -> m_swap : Msg Reveal (taker is sender)