Skip to content
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

endpoint: force wallet resync #1268

Merged
merged 9 commits into from
Jan 16, 2020
3 changes: 3 additions & 0 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,9 @@ instance ToSchema ApiUtxoStatistics where
instance ToSchema ApiNetworkInformation where
declareNamedSchema _ = declareSchemaForDefinition "ApiNetworkInformation"

instance ToSchema ApiNetworkTip where
declareNamedSchema _ = declareSchemaForDefinition "ApiNetworkTip"

-- | Utility function to provide an ad-hoc 'ToSchema' instance for a definition:
-- we simply look it up within the Swagger specification.
declareSchemaForDefinition :: T.Text -> Declare (Definitions Schema) NamedSchema
Expand Down
90 changes: 79 additions & 11 deletions specifications/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ x-blockReference: &blockReference
epoch_number: *epochNumber
height: *numberOfBlocks

x-genesisBlock: &genesisBlock
description: A reference to a particular block.
type: object
required:
- slot_number
- epoch_number
properties:
slot_number:
<<: *slotNumber
maximum: 0
example: 0
epoch_number:
<<: *epochNumber
maximum: 0
example: 0

x-percentage: &percentage
type: object
required:
Expand Down Expand Up @@ -492,16 +508,6 @@ x-networkInformationNodeTip: &networkInformationNodeTip
<<: *blockReference
description: Underlying node's tip

x-networkInformationNetworkTip: &networkInformationNetworkTip
description: Projected network's tip
type: object
required:
- slot_number
- epoch_number
properties:
slot_number: *slotNumber
epoch_number: *epochNumber

x-networkInformationProtocolUpdate: &networkInformationProtocolUpdate
type: string
description: |
Expand Down Expand Up @@ -536,6 +542,16 @@ definitions:
epoch_number: *epochNumber
epoch_start_time: *date

ApiNetworkTip: &ApiNetworkTip
description: A network tip
type: object
required:
- slot_number
- epoch_number
properties:
slot_number: *slotNumber
epoch_number: *epochNumber

ApiNetworkInformation: &ApiNetworkInformation
type: object
required:
Expand All @@ -546,7 +562,7 @@ definitions:
properties:
sync_progress: *networkInformationSyncProgress
node_tip: *networkInformationNodeTip
network_tip: *networkInformationNetworkTip
network_tip: *ApiNetworkTip
next_epoch: *ApiEpochInfo

ApiSelectCoinsData: &ApiSelectCoinsData
Expand Down Expand Up @@ -1057,6 +1073,16 @@ x-responsesDeleteWallet: &responsesDeleteWallet
204:
description: No Content

x-responsesForceResyncWallet: &responsesForceResyncWallet
<<: *responsesErr400
<<: *responsesErr403
<<: *responsesErr404
<<: *responsesErr405
<<: *responsesErr406
<<: *responsesErr415
204:
description: No Content

x-responsesPutWallet: &responsesPutWallet
<<: *responsesErr400
<<: *responsesErr404
Expand Down Expand Up @@ -1277,6 +1303,27 @@ paths:
schema: *ApiWalletPutData
responses: *responsesPutWallet

/wallets/{walletId}/tip:
put:
operationId: forceResync
tags: ["Wallets"]
summary: Force Resync
description: |
<p align="right">status: <strong>stable</strong></p>

Force the wallet to rewind back to the given block and sync again with the chain.
Any incoming transaction will be erased whereas outgoing transactions will be put back
as pending. This action should only be taken as an extreme measure to resolve potential
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this part. Is it for all the transactions, even if they are in ledger?

Why I'm asking: when you delete a wallet and create it again you have your transaction history available... My understanding and expectation of the forceResync would be to be an equivalent of delete and create (but without the need of deleting and creating a wallet again), am I wrong? (I bet I am...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotr-iohk force-resync is not equivalent to deleting and re-creating the wallet. It's actually equivalent to (and is a) rollback to the genesis block. So, after this, some transaction will be put back in pending such that, users can still track them.
The annoying part with deleting and re-creating your wallet is also that you completely loose track of your wallet history. If you attempted to made a payment, it won't show up unless visible in the ledger. But you may still have transaction floating around in mempools that don't show up in your wallet. Whereas, by using force resync here, you'll still see them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any incoming transaction will be erased whereas outgoing transactions will be put back as pending.

I think this statement may be somewhat misleading. After reading it I thought that after doing force resync all my incoming txs will be erased and not visible at all and outgoing will become pending. And it will be a finite state. But if they are in the ledger they will be discovered again and visible again. Hence the first comment, cause it was a bit surprising to me.

syncing issues. If its use is required, please submit a ticket to https://github.com/input-output-hk/cardano-wallet/issues.

> ⚠️ At this stage, the server only allows resyncing to genesis (i.e. `(0,0)`).
> Any other point will yield a `403 Forbidden` error.
parameters:
- *parametersWalletId
- <<: *parametersBody
schema: *genesisBlock
responses: *responsesForceResyncWallet

/wallets/{walletId}/statistics/utxos:
get:
operationId: getUTxOsStatistics
Expand Down Expand Up @@ -1571,6 +1618,27 @@ paths:
- *parametersWalletId
responses: *responsesDeleteWallet

/byron-wallets/{walletId}/tip:
put:
operationId: forceResyncByron
tags: ["Byron Wallets"]
summary: Force Resync
description: |
<p align="right">status: <strong>stable</strong></p>

Force the wallet to rewind back to the given block and sync again with the chain.
Any incoming transaction will be erased whereas outgoing transactions will be put back
as pending. This action should only be taken as an extreme measure to resolve potential
syncing issues. If its use is required, please submit a ticket to https://github.com/input-output-hk/cardano-wallet/issues.

> ⚠️ At this stage, the server only allows resyncing to genesis (i.e. `(0,0)`).
> Any other point will yield a `403 Forbidden` error.
parameters:
- *parametersWalletId
- <<: *parametersBody
schema: *genesisBlock
responses: *responsesForceResyncWallet

/byron-wallets/{walletId}/transactions:
get:
operationId: listByronTransactions
Expand Down