Skip to content

Commit

Permalink
Merge pull request #1481 from limebell/bugfix/transfer-tx
Browse files Browse the repository at this point in the history
Prevent `KeyNotFoundException` during `TransferTxs()`
  • Loading branch information
limebell authored Sep 10, 2021
2 parents ffef70a + efc1f2d commit 8bda0a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ Libplanet changelog
Version 0.15.3
--------------

To be released.
Released on September 10, 2021.

- Fixed a bug where `Swarm<T>` fails to reply transaction when any of the
requested transactions id in `GetTxs` message does not exist in the storage.
[[#1481]]

[#1481]: https://github.com/planetarium/libplanet/pull/1481


Version 0.15.2
Expand Down
25 changes: 16 additions & 9 deletions Libplanet/Net/Swarm.MessageHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,25 @@ private void TransferTxs(GetTxs getTxs)
{
foreach (TxId txid in getTxs.TxIds)
{
Transaction<T> tx = BlockChain.GetTransaction(txid);

if (tx is null)
try
{
continue;
}
Transaction<T> tx = BlockChain.GetTransaction(txid);

if (tx is null)
{
continue;
}

Message response = new Messages.Tx(tx.Serialize(true))
Message response = new Messages.Tx(tx.Serialize(true))
{
Identity = getTxs.Identity,
};
Transport.ReplyMessage(response);
}
catch (KeyNotFoundException)
{
Identity = getTxs.Identity,
};
Transport.ReplyMessage(response);
_logger.Warning("Requested TxId {TxId} does not exist.", txid);
}
}
}

Expand Down

0 comments on commit 8bda0a1

Please sign in to comment.