Skip to content
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
8 changes: 8 additions & 0 deletions data/txHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,14 @@ func (handler *solicitedAsyncTxHandler) loop(ctx context.Context) {
handler.txHandler.net.RequestConnectOutgoing(false, make(chan struct{}))
transactionMessagesDroppedFromPool.Inc(nil)
} else if allTransactionsIncluded {
for _, txnGroup := range groups.txGroups {
// We reencode here instead of using rawmsg.Data to avoid broadcasting non-canonical encodings
err := handler.txHandler.net.Relay(ctx, protocol.TxnTag, reencode(txnGroup.Transactions), false, groups.networkPeer)
if err != nil {
logging.Base().Infof("solicitedAsyncTxHandler was unable to relay transaction message : %v")
break
}
}
select {
case groups.ackCh <- groups.messageSeq:
// all good, write was successful.
Expand Down
59 changes: 59 additions & 0 deletions test/e2e-go/features/transactions/sendReceive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,62 @@ func TestAccountsCanSendMoneyAcrossTxSync(t *testing.T) {
}
}
}

// this test checks that a relay would relay a transaction
// received via the txnsync onto a node that doesn't support
// transaction sync.
func TestTransactionSyncRelayBridge(t *testing.T) {

partitiontest.PartitionTest(t)
defer fixtures.ShutdownSynchronizedTest(t)

a := require.New(fixtures.SynchronizedTest(t))

var fixture fixtures.RestClientFixture
fixture.SetupNoStart(t, filepath.Join("nettemplates", "ThreeNodesOneOnline.json"))
defer fixture.Shutdown()

onlineNodeController, err := fixture.GetNodeController("OnlineNode")
a.NoError(err)

cfg, err := config.LoadConfigFromDisk(onlineNodeController.GetDataDir())
a.NoError(err)
cfg.NetworkProtocolVersion = "2.1"
cfg.SaveToDisk(onlineNodeController.GetDataDir())

offlineNodeController, err := fixture.GetNodeController("OfflineNode")
a.NoError(err)

cfg, err = config.LoadConfigFromDisk(offlineNodeController.GetDataDir())
a.NoError(err)
cfg.NetworkProtocolVersion = "3.0"
cfg.SaveToDisk(offlineNodeController.GetDataDir())

fixture.Start()

client := fixture.GetLibGoalClientFromNodeController(offlineNodeController)
accounts, err := fixture.GetNodeWalletsSortedByBalance(client.DataDir())
a.NoError(err)

a.Equal(1, len(accounts))

sendingAccount := accounts[0].Address

_, err = client.SendPaymentFromUnencryptedWallet(sendingAccount, sendingAccount, 1024*1024, 1024, nil)
a.NoError(err)

startRoundStatus, err := client.Status()
a.NoError(err)
for {
pendingTxns, err := client.GetPendingTransactions(2)
a.NoError(err)
if pendingTxns.TotalTxns == 0 {
break
}
status, err := client.Status()
a.NoError(err)
_, err = client.WaitForRound(status.LastRound)
a.NoError(err)
a.Less(uint64(status.LastRound), uint64(startRoundStatus.LastRound+5), "transaction is still pending after 5 rounds, whereas it should have been confirmed within 2 rounds.")
}
}
39 changes: 39 additions & 0 deletions test/testdata/nettemplates/ThreeNodesOneOnline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"Genesis": {
"NetworkName": "tbd",
"Wallets": [
{
"Name": "Wallet1",
"Stake": 50,
"Online": true
},
{
"Name": "Wallet2",
"Stake": 50,
"Online": false
}
]
},
"Nodes": [
{
"Name": "Primary",
"IsRelay": true,
"Wallets": [
]
},
{
"Name": "OnlineNode",
"Wallets": [
{ "Name": "Wallet1",
"ParticipationOnly": true }
]
},
{
"Name": "OfflineNode",
"Wallets": [
{ "Name": "Wallet2",
"ParticipationOnly": false }
]
}
]
}