Skip to content

Commit

Permalink
Better document usage of SyncTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
morcos authored and furszy committed Jan 28, 2021
1 parent 21be4e2 commit 4cb5820
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ struct MainSignalsInstance {
boost::signals2::signal<void (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)> UpdatedBlockTip;
/** A posInBlock value for SyncTransaction which indicates the transaction was conflicted, disconnected, or not in a block */
static const int SYNC_TRANSACTION_NOT_IN_BLOCK = -1;
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
/** Notifies listeners of updated transaction data (transaction, and
* optionally the block it is found in). Called with block data when
* transaction is included in a connected block, and without block data when
* transaction was accepted to mempool, removed from mempool (only when
* removal was due to conflict from connected block), or appeared in a
* disconnected block.*/
boost::signals2::signal<void (const CTransaction &, const CBlockIndex *pindex, int posInBlock)> SyncTransaction;
/** Notifies listeners of an updated transaction lock without new data. */
boost::signals2::signal<void (const CTransaction &)> NotifyTransactionLock;
Expand Down
4 changes: 3 additions & 1 deletion src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class CMainSignals {
public:
CMainSignals();

/** A posInBlock value for SyncTransaction which indicates the transaction was conflicted, disconnected, or not in a block */
/** A posInBlock value for SyncTransaction calls for transactions not
* included in connected blocks such as transactions removed from mempool,
* accepted to mempool or appearing in disconnected blocks.*/
static const int SYNC_TRANSACTION_NOT_IN_BLOCK = -1;

void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
Expand Down
12 changes: 10 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,9 +1048,17 @@ void CWallet::AddExternalNotesDataToTx(CWalletTx& wtx) const
}

/**
* Add a transaction to the wallet, or update it.
* pblock is optional, but should be provided if the transaction is known to be in a block.
* Add a transaction to the wallet, or update it. pIndex and posInBlock should
* be set when the transaction was known to be included in a block. When
* posInBlock = SYNC_TRANSACTION_NOT_IN_BLOCK (-1) , then wallet state is not
* updated in AddToWallet, but notifications happen and cached balances are
* marked dirty.
* If fUpdate is true, existing transactions will be updated.
* TODO: One exception to this is that the abandoned state is cleared under the
* assumption that any further notification of a transaction that was considered
* abandoned is an indication that it is not safe to be considered abandoned.
* Abandoned state should probably be more carefully tracked via different
* posInBlock signals or by checking mempool presence when necessary.
*/
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const uint256& blockHash, int posInBlock, bool fUpdate)
{
Expand Down

0 comments on commit 4cb5820

Please sign in to comment.