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

Implement transaction negotiation message resending in the wallet #2161

Merged

Conversation

philipr-za
Copy link
Contributor

@philipr-za philipr-za commented Aug 25, 2020

Description

Currently the logic for sending transactions and negotiating them between parties is not very robust. Each stage in the negotiation is sent only once. When sending we first try to send the message directly and if that fails, or discovery needs to occur, the message is sent indirectly via Store and Forward (SAF). We hoped to get SAF 100% reliable but due to reasons laid out in #2137 it is not tenable.

This PR adds in the logic to periodically resends the initial Transaction Sender Message and the Transaction Reply in order to illicit the next step in the negotiation protocol from the counterparty. The PR also adds the logic to respond to repeated messages but with a cool down period in which repeats will be ignored to protect against DoS attacks.

The PR also adds in a new comms level message to inform the counterparty if a transaction protocol has been cancelled. Initially this is sent if the Sender cancels an in progress transaction so that the receiver knows to stop expecting it. This message is also sent if a Transaction Reply is received for a cancelled message to let the Received know about the cancellation.

In order to stop a wallet resending these message indefinitely a transaction will be cancelled if it hasn’t resolved after a long timeout period (Default is being set to 3 days).

A large portion of the PR is tests and some code reorganization so its not as big as it looks.

Motivation and Context

Closes #2137
Closes #1804

How Has This Been Tested?

Tests are provided that test:

  1. A sender repeats sending the initial message if no response is received from the receiver
  2. A receiver repeats sending the Reply in no response is received from the receiver
  3. For both parties that the repeated message is sent on startup if the period has elapsed.
  4. For both parties that they can handle receiving the repeated messages and respond appropriately
  5. Check that both parties ignore repeated messages sent before the cool down has elapsed
  6. Check the cancellation messages are sent by the Sender when a transaction is cancelled
  7. Check that receiver acts correctly on receiving a cancellation message
  8. Check that the transaction is cancelled by both parties after the timeout is reached during operation or on startup.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Feature refactor (No new feature or functional changes, but performance or technical debt improvements)
  • New Tests
  • Documentation

Checklist:

  • I'm merging against the development branch.
  • I ran cargo-fmt --all before pushing.
  • I have squashed my commits into a single commit.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@philipr-za philipr-za force-pushed the philip-tx-resending branch from 5d2bfc5 to 00ce339 Compare August 26, 2020 07:27
sdbondi
sdbondi previously approved these changes Aug 27, 2020
Copy link
Member

@sdbondi sdbondi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - will run a few tests on the branch before approving

sdbondi
sdbondi previously approved these changes Sep 14, 2020
Copy link
Member

@sdbondi sdbondi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my stuck transactions on the base node went through after one retry 🎉

Currently the logic for sending transactions and negotiating them between parties is not very robust. Each stage in the negotiation is sent only once. When sending we first try to send the message directly and if that fails, or discovery needs to occur, the message is sent indirectly via Store and Forward (SAF). We hoped to get SAF 100% reliable but due to reasons laid out in tari-project#2137 it is not tenable. 

This PR adds in the logic to periodically resends the initial Transaction Sender Message and the Transaction Reply in order to illicit the next step in the negotiation protocol from the counterparty. The PR also adds the logic to respond to repeated messages but with a cool down period in which repeats will be ignored to protect against DoS attacks. 

The PR also adds in a new comms level message to inform the counterparty if a transaction protocol has been cancelled. Initially this is sent if the Sender cancels an in progress transaction so that the receiver knows to stop expecting it. This message is also sent if a Transaction Reply is received for a cancelled message to let the Received know about the cancellation.

In order to stop a wallet resending these message indefinitely a transaction will be cancelled if it hasn’t resolved after a long timeout period (Default is being set to 3 days).

A large portion of the PR are tests so its not as big as it looks.
@stringhandler stringhandler merged commit e6ef75a into tari-project:development Sep 15, 2020
stringhandler added a commit that referenced this pull request Sep 18, 2020
Major Fixes since v0.5.4
* Many fixes and updates to tari_merge_mining_proxy
* Implement transaction negotiation message resending in the wallet (#2161)

Minor Fixes
* Added basic RPC interface for DHT (#2188)
* Refactor Tokio runtime out of wallet container (#2213)
* Add period stats UI call (#2189)
* Protect against possible panics in header/horizon sync (#2219)
* Fix coinbase vulnerability (#2143)
* Added a user configurable chain monitoring timeout (#2202)
* Implement LMDB automatic resizing
* Add `is_synced` flag to BaseNodeServiceResponse & update UTXO validator
@philipr-za philipr-za deleted the philip-tx-resending branch June 8, 2021 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants