Pass nHeight instead of pindex to AddToWalletIfInvolvingMe()
Co-authored by Jack Grigg (jack@electriccoin.co) and Sean Bowe (ewillbefull@gmail.com)
This commit is contained in:
parent
119bae082c
commit
1020254b6a
|
@ -122,7 +122,7 @@ void AMQPNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
|
|||
}
|
||||
}
|
||||
|
||||
void AMQPNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
|
||||
void AMQPNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight)
|
||||
{
|
||||
for (std::list<AMQPAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ) {
|
||||
AMQPAbstractNotifier *notifier = *i;
|
||||
|
|
|
@ -24,7 +24,7 @@ protected:
|
|||
void Shutdown();
|
||||
|
||||
// CValidationInterface
|
||||
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
|
||||
void SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight);
|
||||
void UpdatedBlockTip(const CBlockIndex *pindex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -25,7 +25,7 @@ CMainSignals& GetMainSignals()
|
|||
|
||||
void RegisterValidationInterface(CValidationInterface* pwalletIn) {
|
||||
g_signals.UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
|
||||
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
|
||||
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
|
||||
g_signals.EraseTransaction.connect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
|
||||
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
|
||||
g_signals.ChainTip.connect(boost::bind(&CValidationInterface::ChainTip, pwalletIn, _1, _2, _3));
|
||||
|
@ -47,7 +47,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
|
|||
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
|
||||
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
|
||||
g_signals.EraseTransaction.disconnect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
|
||||
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
|
||||
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
|
||||
g_signals.UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,8 @@ void UnregisterAllValidationInterfaces() {
|
|||
g_signals.UpdatedBlockTip.disconnect_all_slots();
|
||||
}
|
||||
|
||||
void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) {
|
||||
g_signals.SyncTransaction(tx, pblock);
|
||||
void SyncWithWallets(const CTransaction &tx, const CBlock *pblock, const int nHeight) {
|
||||
g_signals.SyncTransaction(tx, pblock, nHeight);
|
||||
}
|
||||
|
||||
struct CachedBlockData {
|
||||
|
@ -187,7 +187,7 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip)
|
|||
// Let wallets know transactions went from 1-confirmed to
|
||||
// 0-confirmed or conflicted:
|
||||
for (const CTransaction &tx : block.vtx) {
|
||||
SyncWithWallets(tx, NULL);
|
||||
SyncWithWallets(tx, NULL, pindexLastTip->nHeight);
|
||||
}
|
||||
// Update cached incremental witnesses
|
||||
GetMainSignals().ChainTip(pindexLastTip, &block, boost::none);
|
||||
|
@ -214,11 +214,11 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip)
|
|||
// Tell wallet about transactions that went from mempool
|
||||
// to conflicted:
|
||||
for (const CTransaction &tx : blockData.txConflicted) {
|
||||
SyncWithWallets(tx, NULL);
|
||||
SyncWithWallets(tx, NULL, blockData.pindex->nHeight + 1);
|
||||
}
|
||||
// ... and about transactions that got confirmed:
|
||||
for (const CTransaction &tx : block.vtx) {
|
||||
SyncWithWallets(tx, &block);
|
||||
SyncWithWallets(tx, &block, blockData.pindex->nHeight);
|
||||
}
|
||||
// Update cached incremental witnesses
|
||||
GetMainSignals().ChainTip(blockData.pindex, &block, blockData.oldTrees);
|
||||
|
@ -230,7 +230,7 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip)
|
|||
// Notify transactions in the mempool
|
||||
for (auto tx : recentlyAdded.first) {
|
||||
try {
|
||||
SyncWithWallets(tx, NULL);
|
||||
SyncWithWallets(tx, NULL, pindexLastTip->nHeight + 1);
|
||||
} catch (const boost::thread_interrupted&) {
|
||||
throw;
|
||||
} catch (const std::exception& e) {
|
||||
|
|
|
@ -33,7 +33,7 @@ void UnregisterAllValidationInterfaces();
|
|||
class CValidationInterface {
|
||||
protected:
|
||||
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
|
||||
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
|
||||
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight) {}
|
||||
virtual void EraseFromWallet(const uint256 &hash) {}
|
||||
virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>> added) {}
|
||||
virtual void SetBestChain(const CBlockLocator &locator) {}
|
||||
|
@ -52,7 +52,7 @@ struct CMainSignals {
|
|||
/** Notifies listeners of updated block chain tip */
|
||||
boost::signals2::signal<void (const CBlockIndex *)> UpdatedBlockTip;
|
||||
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
|
||||
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
|
||||
boost::signals2::signal<void (const CTransaction &, const CBlock *, const int nHeight)> SyncTransaction;
|
||||
/** Notifies listeners of an erased transaction (currently disabled, requires transaction replacement). */
|
||||
boost::signals2::signal<void (const uint256 &)> EraseTransaction;
|
||||
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
|
||||
|
|
|
@ -1711,22 +1711,14 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
|
|||
* updated; instead, the transaction being in the mempool or conflicted is determined on
|
||||
* the fly in CMerkleTx::GetDepthInMainChain().
|
||||
*/
|
||||
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, const CBlockIndex* pindex, bool fUpdate)
|
||||
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, const int nHeight, bool fUpdate)
|
||||
{
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
bool fExisted = mapWallet.count(tx.GetHash()) != 0;
|
||||
if (fExisted && !fUpdate) return false;
|
||||
auto sproutNoteData = FindMySproutNotes(tx);
|
||||
int height;
|
||||
if (pblock) {
|
||||
height = pindex->nHeight;
|
||||
} else {
|
||||
// assume tx is in mempool
|
||||
LOCK(cs_main);
|
||||
height = chainActive.Height();
|
||||
}
|
||||
auto saplingNoteDataAndAddressesToAdd = FindMySaplingNotes(tx, height);
|
||||
auto saplingNoteDataAndAddressesToAdd = FindMySaplingNotes(tx, nHeight);
|
||||
auto saplingNoteData = saplingNoteDataAndAddressesToAdd.first;
|
||||
auto addressesToAdd = saplingNoteDataAndAddressesToAdd.second;
|
||||
for (const auto &addressToAdd : addressesToAdd) {
|
||||
|
@ -1760,10 +1752,10 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
|
|||
return false;
|
||||
}
|
||||
|
||||
void CWallet::SyncTransaction(const CTransaction& tx, const CBlock* pblock, const CBlockIndex* pindex)
|
||||
void CWallet::SyncTransaction(const CTransaction& tx, const CBlock* pblock, const int nHeight)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
if (!AddToWalletIfInvolvingMe(tx, pblock, pindex, true))
|
||||
if (!AddToWalletIfInvolvingMe(tx, pblock, nHeight, true))
|
||||
return; // Not one of ours
|
||||
|
||||
MarkAffectedTransactionsDirty(tx);
|
||||
|
@ -2744,7 +2736,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
|
||||
BOOST_FOREACH(CTransaction& tx, block.vtx)
|
||||
{
|
||||
if (AddToWalletIfInvolvingMe(tx, &block, pindex, fUpdate)) {
|
||||
if (AddToWalletIfInvolvingMe(tx, &block, pindex->nHeight, fUpdate)) {
|
||||
myTxHashes.push_back(tx.GetHash());
|
||||
ret++;
|
||||
}
|
||||
|
|
|
@ -1162,8 +1162,8 @@ public:
|
|||
void UpdateSaplingNullifierNoteMapWithTx(CWalletTx& wtx);
|
||||
void UpdateSaplingNullifierNoteMapForBlock(const CBlock* pblock);
|
||||
bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb);
|
||||
void SyncTransaction(const CTransaction& tx, const CBlock* pblock, const CBlockIndex* pindex);
|
||||
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, const CBlockIndex* pindex, bool fUpdate);
|
||||
void SyncTransaction(const CTransaction& tx, const CBlock* pblock, const int nHeight);
|
||||
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, const int nHeight, bool fUpdate);
|
||||
void EraseFromWallet(const uint256 &hash);
|
||||
void WitnessNoteCommitment(
|
||||
std::vector<uint256> commitments,
|
||||
|
|
|
@ -163,7 +163,7 @@ void CZMQNotificationInterface::BlockChecked(const CBlock& block, const CValidat
|
|||
}
|
||||
}
|
||||
|
||||
void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
|
||||
void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight)
|
||||
{
|
||||
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ protected:
|
|||
void Shutdown();
|
||||
|
||||
// CValidationInterface
|
||||
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
|
||||
void SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight);
|
||||
void UpdatedBlockTip(const CBlockIndex *pindex);
|
||||
void BlockChecked(const CBlock& block, const CValidationState& state);
|
||||
|
||||
|
|
Loading…
Reference in New Issue