Merge #16911: wallet: Only check the hash of transactions loaded from disk

cd68594dcdadc195bd2ea9394fa04edfdbdf1149 Only check the hash of transactions loaded from disk (Andrew Chow)

Pull request description:

  It feels unnecessary to do a full `CheckTransaction` for every transaction saved in the wallet. It should not be possible for an invalid transaction to get into the wallet in the first place, and if there is any disk corruption, the hash check will catch it.

ACKs for top commit:
  MarcoFalke:
    ACK cd68594dcdadc195bd2ea9394fa04edfdbdf1149
  laanwj:
    ACK cd68594dcdadc195bd2ea9394fa04edfdbdf1149
  promag:
    ACK cd68594dcdadc195bd2ea9394fa04edfdbdf1149, AFAICT the check is not needed, hash comparison gives data integrity.

Tree-SHA512: 5b2e719f76097cfbf125392db6cc6c764355c81f0b7a5b60aee4b06af1afcca80cfd38a3cf5307fd9e2c1afc405f8321929a4552943099a8161e6762965451fb
This commit is contained in:
Wladimir J. van der Laan 2019-10-23 12:03:57 +02:00 committed by PastaPastaPasta
parent 4052f1e548
commit 97b1f6875e

View File

@ -6,8 +6,6 @@
#include <wallet/walletdb.h> #include <wallet/walletdb.h>
#include <consensus/tx_check.h>
#include <consensus/validation.h>
#include <key_io.h> #include <key_io.h>
#include <fs.h> #include <fs.h>
#include <governance/object.h> #include <governance/object.h>
@ -255,8 +253,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
ssKey >> hash; ssKey >> hash;
CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef()); CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef());
ssValue >> wtx; ssValue >> wtx;
CValidationState state; if (wtx.GetHash() != hash)
if (!(CheckTransaction(*wtx.tx, state) && (wtx.GetHash() == hash) && state.IsValid()))
return false; return false;
// Undo serialize changes in 31600 // Undo serialize changes in 31600