Skip to content

Commit

Permalink
Log the wallet tip on EndInitialize
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Nov 29, 2022
1 parent 1ea85ca commit 4a60dc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 9 additions & 6 deletions hydra-node/json-schemas/logs.yaml
Expand Up @@ -345,32 +345,34 @@ definitions:
oneOf:
- title: BeginInitialize
description: >-
The wallet (re-)initializes to given point on the chain.
The wallet is asked to (re-)initialize and fetch latest information
from the cardano-node.
type: object
additionalProperties: false
required:
- tag
- point
properties:
tag:
type: string
enum: ["BeginInitialize"]
point:
$ref: "api.yaml#/components/schemas/ChainPoint"
- title: EndInitialize
description: >-
The wallet has initialized with these UTxOs.
The wallet has been initialized with these UTxOs and will skip blocks
until reaching the tip.
type: object
additionalProperties: false
required:
- tag
- initialUTxO
- tip
properties:
tag:
type: string
enum: ["EndInitialize"]
initialUTxO:
$ref: "api.yaml#/components/schemas/UTxO"
tip:
$ref: "api.yaml#/components/schemas/ChainPoint"
- title: BeginUpdate
description: >-
The wallet has been given a new block to update it's state.
Expand All @@ -386,7 +388,8 @@ definitions:
$ref: "api.yaml#/components/schemas/ChainPoint"
- title: EndUpdate
description: >-
The wallet updated it's state by applying a block resulting in given UTxOs.
The wallet updated it's state by applying a block resulting in given
UTxOs.
additionalProperties: false
required:
- tag
Expand Down
9 changes: 5 additions & 4 deletions hydra-node/src/Hydra/Chain/Direct/Wallet.hs
@@ -1,3 +1,4 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TypeApplications #-}

-- | Companion tiny-wallet for the direct chain component. This module provide
Expand Down Expand Up @@ -148,7 +149,7 @@ newTinyWallet tracer networkId (vk, sk) queryWalletInfo queryEpochInfo = do
, reset = initialize >>= atomically . writeTVar walletInfoVar
, update = \block -> do
let point = fromConsensusPointHF $ blockPoint block
walletTip <- atomically $ readTVar walletInfoVar <&> tip
walletTip <- atomically $ readTVar walletInfoVar <&> \WalletInfoOnChain{tip} -> tip
if point < walletTip
then traceWith tracer $ SkipUpdate{point}
else do
Expand All @@ -163,8 +164,8 @@ newTinyWallet tracer networkId (vk, sk) queryWalletInfo queryEpochInfo = do
where
initialize = do
traceWith tracer BeginInitialize
walletInfo@WalletInfoOnChain{walletUTxO} <- queryWalletInfo QueryTip address
traceWith tracer $ EndInitialize{initialUTxO = walletUTxO}
walletInfo@WalletInfoOnChain{walletUTxO, tip} <- queryWalletInfo QueryTip address
traceWith tracer $ EndInitialize{initialUTxO = walletUTxO, tip}
pure walletInfo

address =
Expand Down Expand Up @@ -400,7 +401,7 @@ estimateScriptsCost pparams systemStart epochInfo utxo tx = do

data TinyWalletLog
= BeginInitialize
| EndInitialize {initialUTxO :: Map TxIn TxOut}
| EndInitialize {initialUTxO :: Map TxIn TxOut, tip :: ChainPoint}
| BeginUpdate {point :: ChainPoint}
| EndUpdate {newUTxO :: Map TxIn TxOut}
| SkipUpdate {point :: ChainPoint}
Expand Down

0 comments on commit 4a60dc2

Please sign in to comment.