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

wallet2: do not commit transactions more than once #8796

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6745,6 +6745,24 @@ void wallet2::commit_tx(pending_tx& ptx)
crypto::hash txid;

txid = get_transaction_hash(ptx.tx);

// if it's already processed, bail
if (std::find_if(m_transfers.begin(), m_transfers.end(), [&txid](const transfer_details &td) { return td.m_txid == txid; }) != m_transfers.end())
{
MDEBUG("Transaction " << txid << " already processed");
return;
}
if (m_unconfirmed_txs.find(txid) != m_unconfirmed_txs.end())
{
MDEBUG("Transaction " << txid << " already processed");
return;
}
if (m_confirmed_txs.find(txid) != m_confirmed_txs.end())
{
MDEBUG("Transaction " << txid << " already processed");
return;
}

crypto::hash payment_id = crypto::null_hash;
std::vector<cryptonote::tx_destination_entry> dests;
uint64_t amount_in = 0;
Expand Down
34 changes: 34 additions & 0 deletions tests/functional_tests/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def run_test(self):
self.check_tx_notes()
self.check_rescan()
self.check_is_key_image_spent()
self.check_multiple_submissions()

def reset(self):
print('Resetting blockchain')
Expand Down Expand Up @@ -829,6 +830,39 @@ def check_is_key_image_spent(self):
res = daemon.is_key_image_spent(ki)
assert res.spent_status == expected

def check_multiple_submissions(self):
daemon = Daemon()

print('Testing multiple submissions')

dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}

self.wallet[0].refresh()
res = self.wallet[0].get_balance()
balance = res.balance

res = self.wallet[0].transfer([dst], ring_size = 16, get_tx_key = False, get_tx_hex = False, get_tx_metadata = True)
tx_hex = res.tx_metadata
tx_fee = res.fee
res = self.wallet[0].relay_tx(tx_hex)

# submit again before mined
res = self.wallet[0].relay_tx(tx_hex)
daemon.generateblocks('44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', 1)

self.wallet[0].refresh()
res = self.wallet[0].get_balance()
assert res.balance == balance - tx_fee

balance = res.balance

# submit again after mined
res = self.wallet[0].relay_tx(tx_hex)
daemon.generateblocks('44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', 1)

self.wallet[0].refresh()
res = self.wallet[0].get_balance()
assert res.balance == balance

if __name__ == '__main__':
TransferTest().run_test()