-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement transaction negotiation message resending in the wallet
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 are tests so its not as big as it looks.
- Loading branch information
1 parent
463f0e3
commit 11fced4
Showing
37 changed files
with
3,045 additions
and
960 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
base_layer/core/src/transactions/transaction_protocol/proto/transaction_cancelled.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
syntax = "proto3"; | ||
|
||
package tari.transaction_protocol; | ||
|
||
message TransactionCancelledMessage { | ||
// The transaction id for the cancelled transaction | ||
uint64 tx_id = 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...tions/2020-08-17-141407_add_resend_count_and_timestamp_add_status_to_pending_txs/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
PRAGMA foreign_keys=off; | ||
ALTER TABLE completed_transactions RENAME TO completed_transactions_old; | ||
CREATE TABLE completed_transactions ( | ||
tx_id INTEGER PRIMARY KEY NOT NULL, | ||
source_public_key BLOB NOT NULL, | ||
destination_public_key BLOB NOT NULL, | ||
amount INTEGER NOT NULL, | ||
fee INTEGER NOT NULL, | ||
transaction_protocol TEXT NOT NULL, | ||
status INTEGER NOT NULL, | ||
message TEXT NOT NULL, | ||
timestamp DATETIME NOT NULL, | ||
cancelled INTEGER NOT NULL DEFAULT 0, | ||
direction INTEGER NULL DEFAULT NULL, | ||
coinbase_block_height INTEGER NULL DEFAULT NULL | ||
); | ||
INSERT INTO completed_transactions (tx_id, source_public_key, destination_public_key, amount, fee, transaction_protocol, status, message, timestamp, cancelled, direction, coinbase_block_height) | ||
SELECT tx_id, source_public_key, destination_public_key, amount, fee, transaction_protocol, status, message, timestamp, cancelled, direction, coinbase_block_height | ||
FROM completed_transactions_old; | ||
|
||
DROP TABLE completed_transactions_old; | ||
|
||
ALTER TABLE inbound_transactions RENAME TO inbound_transactions_old; | ||
CREATE TABLE inbound_transactions ( | ||
tx_id INTEGER PRIMARY KEY NOT NULL, | ||
source_public_key BLOB NOT NULL, | ||
amount INTEGER NOT NULL, | ||
receiver_protocol TEXT NOT NULL, | ||
message TEXT NOT NULL, | ||
timestamp DATETIME NOT NULL, | ||
cancelled INTEGER NOT NULL DEFAULT 0, | ||
direct_send_success INTEGER NOT NULL DEFAULT 0 | ||
); | ||
INSERT INTO inbound_transactions (tx_id, source_public_key, amount, receiver_protocol, message, timestamp, cancelled, direct_send_success) | ||
SELECT tx_id, source_public_key, amount, receiver_protocol, message, timestamp, cancelled, direct_send_success | ||
FROM inbound_transactions_old; | ||
|
||
DROP TABLE inbound_transactions_old; | ||
|
||
ALTER TABLE outbound_transactions RENAME TO outbound_transactions_old; | ||
CREATE TABLE outbound_transactions ( | ||
tx_id INTEGER PRIMARY KEY NOT NULL, | ||
destination_public_key BLOB NOT NULL, | ||
amount INTEGER NOT NULL, | ||
fee INTEGER NOT NULL, | ||
sender_protocol TEXT NOT NULL, | ||
message TEXT NOT NULL, | ||
timestamp DATETIME NOT NULL, | ||
cancelled INTEGER NOT NULL DEFAULT 0, | ||
direct_send_success INTEGER NOT NULL DEFAULT 0 | ||
); | ||
INSERT INTO outbound_transactions (tx_id, destination_public_key, amount, fee, sender_protocol, message, timestamp, cancelled, direct_send_success) | ||
SELECT tx_id, destination_public_key, amount, fee, sender_protocol, message, timestamp, cancelled, direct_send_success | ||
FROM outbound_transactions_old; | ||
|
||
DROP TABLE outbound_transactions_old; | ||
|
||
PRAGMA foreign_keys=on; |
14 changes: 14 additions & 0 deletions
14
...rations/2020-08-17-141407_add_resend_count_and_timestamp_add_status_to_pending_txs/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ALTER TABLE completed_transactions | ||
ADD COLUMN send_count INTEGER NOT NULL DEFAULT 0; | ||
ALTER TABLE completed_transactions | ||
ADD COLUMN last_send_timestamp DATETIME NULL DEFAULT NULL; | ||
|
||
ALTER TABLE inbound_transactions | ||
ADD COLUMN send_count INTEGER NOT NULL DEFAULT 0; | ||
ALTER TABLE inbound_transactions | ||
ADD COLUMN last_send_timestamp DATETIME NULL DEFAULT NULL; | ||
|
||
ALTER TABLE outbound_transactions | ||
ADD COLUMN send_count INTEGER NOT NULL DEFAULT 0; | ||
ALTER TABLE outbound_transactions | ||
ADD COLUMN last_send_timestamp DATETIME NULL DEFAULT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.