diff --git a/CHANGES.md b/CHANGES.md index 9de95b4d15..7543f1c1c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -249,6 +249,10 @@ To be released. was once called. [[#965]] - Fixed a bug that `TurnClient` had thrown `InvalidOperationException` when reconnecting. [[#957], [#972]] + - Fixed a bug that `Swarm` had not received block headers after failing + to receive previous blocks. [[#996]] + - Fixed a bug that `Swarm` had thrown `InvalidGenesisBlockException` + when reorg its chain repeatedly. [[#996]] ### CLI tools @@ -312,6 +316,7 @@ To be released. [#980]: https://github.com/planetarium/libplanet/pull/980 [#981]: https://github.com/planetarium/libplanet/pull/981 [#991]: https://github.com/planetarium/libplanet/pull/991 +[#996]: https://github.com/planetarium/libplanet/pull/996 [sleep mode]: https://en.wikipedia.org/wiki/Sleep_mode diff --git a/Libplanet/Net/Swarm.cs b/Libplanet/Net/Swarm.cs index 893ed75a5a..e65ba9efd3 100644 --- a/Libplanet/Net/Swarm.cs +++ b/Libplanet/Net/Swarm.cs @@ -1810,10 +1810,7 @@ out HashDigest branchPoint { _logger.Debug("It doesn't need to fork."); } - - // We can omit this clause if assume every chain shares - // same genesis block... - else if (!BlockChain.ContainsBlock(branchPoint)) + else if (!workspace.ContainsBlock(branchPoint)) { // FIXME: This behavior can unexpectedly terminate the swarm (and the game // app) if it encounters a peer having a different blockchain, and therefore @@ -1968,6 +1965,13 @@ await SyncPreviousBlocksAsync( $" {nameof(ProcessFillBlocks)}: {{e}}"; _logger.Error(e, msg, e); } + finally + { + using (await _blockSyncMutex.LockAsync(cancellationToken)) + { + _demandBlockHash = null; + } + } } }