Skip to content

Commit

Permalink
Merge pull request #1427 from dahlia/0.14-maintenance
Browse files Browse the repository at this point in the history
Release 0.14.0 (with 0.13.2 port)
  • Loading branch information
dahlia authored Aug 5, 2021
2 parents 8a01666 + e561214 commit 123101a
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 360 deletions.
27 changes: 15 additions & 12 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ Libplanet changelog
Version 0.14.0
--------------

To be released.

### Backward-incompatible API changes

### Backward-incompatible network protocol changes

### Backward-incompatible storage format changes
Released on Aug 5, 2021.

### Added APIs

- Added `NonblockRenderer<T>` class. [[#1402], [#1422]]
- Added `NonblockActionRenderer<T>` class. [[#1402], [#1422]]

### Behavioral changes
[#1402]: https://github.com/planetarium/libplanet/issues/1402
[#1422]: https://github.com/planetarium/libplanet/pull/1422

### Bug fixes

### CLI tools
Version 0.13.2
--------------

[#1402]: https://github.com/planetarium/libplanet/issues/1402
[#1422]: https://github.com/planetarium/libplanet/pull/1422
Released on Aug 5, 2021.

- When a reorg happens, `Swarm<T>` now broadcasts a reorged chain tip first
before rendering. [[#1385], [#1415]]
- Fixed a bug where `TurnClient` hadn't been recovered when TURN connection
had been disconnected. [[#1424]]

[#1385]: https://github.com/planetarium/libplanet/issues/1385
[#1415]: https://github.com/planetarium/libplanet/pull/1415
[#1424]: https://github.com/planetarium/libplanet/pull/1424


Version 0.13.1
Expand Down
42 changes: 24 additions & 18 deletions Libplanet.Stun/Stun/TurnClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public TurnClient(
public async Task InitializeTurnAsync(CancellationToken cancellationToken)
{
_control = new TcpClient();
#pragma warning disable PC001 // API not supported on all platforms
_control.Connect(_host, _port);
#pragma warning restore PC001 // API not supported on all platforms
await _control.ConnectAsync(_host, _port);
_processMessage = ProcessMessage(_turnTaskCts.Token);

BehindNAT = await IsBehindNAT(cancellationToken);
Expand Down Expand Up @@ -119,7 +117,19 @@ public async Task ReconnectTurn(int listenPort, CancellationToken cancellationTo
ClearSession();
_turnTaskCts = new CancellationTokenSource();

await InitializeTurnAsync(cancellationToken);
try
{
await InitializeTurnAsync(cancellationToken);
}
catch (Exception e)
{
_logger.Error(
e,
"Failed to initialize due to error ({Exception}); retry...",
e
);
await Task.Delay(1000, cancellationToken);
}
}
}
}
Expand Down Expand Up @@ -384,24 +394,14 @@ await stream.WriteAsync(

private async Task ProcessMessage(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested || _control.Connected)
while (!cancellationToken.IsCancellationRequested && _control.Connected)
{
NetworkStream stream = _control.GetStream();

try
{
NetworkStream stream = _control.GetStream();
StunMessage message;
try
{
message = await StunMessage.ParseAsync(stream, cancellationToken);
_logger.Debug("Stun Message is: {message}", message);
}
catch (TurnClientException e)
{
_logger.Error(e, "Failed to parse StunMessage. {e}", e);
ClearResponses();
break;
}
message = await StunMessage.ParseAsync(stream, cancellationToken);
_logger.Debug("Parsed " + nameof(StunMessage) + ": {Message}", message);

if (message is ConnectionAttempt attempt)
{
Expand All @@ -415,6 +415,12 @@ private async Task ProcessMessage(CancellationToken cancellationToken)
tcs.TrySetResult(message);
}
}
catch (TurnClientException e)
{
_logger.Error(e, "Failed to parse " + nameof(StunMessage) + ": {Exception}", e);
ClearResponses();
break;
}
catch (Exception e)
{
_logger.Error(
Expand Down
16 changes: 8 additions & 8 deletions Libplanet.Tests/Blockchain/BlockChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ IEnumerable<ExecuteRecord> NonRehearsalExecutions() =>
fx.GenesisBlock,
renderers: new[] { renderer }
);
chain.Swap(newChain, true);
chain.Swap(newChain, true)();
Assert.Empty(renderer.ActionRecords);
Assert.Empty(NonRehearsalExecutions());
}
Expand Down Expand Up @@ -760,7 +760,7 @@ public async void GetBlockLocator()
[InlineData(false)]
public void Swap(bool render)
{
Assert.Throws<ArgumentNullException>(() => _blockChain.Swap(null, render));
Assert.Throws<ArgumentNullException>(() => _blockChain.Swap(null, render)());

(var addresses, Transaction<DumbAction>[] txs1) =
MakeFixturesForAppendTests();
Expand Down Expand Up @@ -882,7 +882,7 @@ public void Swap(bool render)

Guid previousChainId = _blockChain.Id;
_renderer.ResetRecords();
_blockChain.Swap(fork, render);
_blockChain.Swap(fork, render)();

Assert.Empty(_blockChain.Store.IterateIndexes(previousChainId));
Assert.Empty(_blockChain.Store.ListTxNonces(previousChainId));
Expand Down Expand Up @@ -960,7 +960,7 @@ public void SwapForSameTip(bool render)
{
BlockChain<DumbAction> fork = _blockChain.Fork(_blockChain.Tip.Hash);
IReadOnlyList<RenderRecord<DumbAction>> prevRecords = _renderer.Records;
_blockChain.Swap(fork, render: render);
_blockChain.Swap(fork, render: render)();

// Render methods should be invoked if and only if the tip changes
Assert.Equal(prevRecords, _renderer.Records);
Expand All @@ -976,7 +976,7 @@ public async Task SwapWithoutReorg(bool render)
// The lower chain goes to the higher chain [#N -> #N+1]
await fork.MineBlock(default);
IReadOnlyList<RenderRecord<DumbAction>.Reorg> prevRecords = _renderer.ReorgRecords;
_blockChain.Swap(fork, render: render);
_blockChain.Swap(fork, render: render)();

// RenderReorg() should be invoked if and only if the actual reorg happens
Assert.Equal(prevRecords, _renderer.ReorgRecords);
Expand All @@ -990,7 +990,7 @@ public async Task TreatGoingBackwardAsReorg()
// The higher chain goes to the lower chain [#N -> #N-1]
await _blockChain.MineBlock(default);
IReadOnlyList<RenderRecord<DumbAction>.Reorg> prevRecords = _renderer.ReorgRecords;
_blockChain.Swap(fork, render: true);
_blockChain.Swap(fork, render: true)();

// RenderReorg() should be invoked if and only if the actual reorg happens
Assert.Equal(prevRecords.Count + 2, _renderer.ReorgRecords.Count);
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public async Task ReorgIsUnableToHeterogenousChain(bool render)
);

Assert.Throws<InvalidGenesisBlockException>(() =>
_blockChain.Swap(chain2, render)
_blockChain.Swap(chain2, render)()
);
}
}
Expand Down Expand Up @@ -1740,7 +1740,7 @@ private async void Reorged()

Assert.Empty(_renderer.ReorgRecords);

_blockChain.Swap(fork, true);
_blockChain.Swap(fork, true)();

IReadOnlyList<RenderRecord<DumbAction>.Reorg> reorgRecords = _renderer.ReorgRecords;
Assert.Equal(2, reorgRecords.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task Reorg()
BlockChain<Arithmetic> @base = _fx.Chain.Fork(_fx.Genesis.Hash);
await _fx.Mine();
_record.ResetRecords();
_fx.Chain.Swap(@base, true);
_fx.Chain.Swap(@base, true)();
IReadOnlyList<RenderRecord<Arithmetic>> records = _record.Records;
Assert.Equal(7, records.Count);
AssertTypeAnd<RenderRecord<Arithmetic>.Reorg>(records[0], r => Assert.True(r.Begin));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ Block<DumbAction> Branchpoint
Assert.Equal(17, delayedRenderer.GetBufferedActionRendererCount());
Assert.Equal(0, delayedRenderer.GetBufferedActionUnRendererCount());

chain.Swap(fork1, true);
chain.Swap(fork2, true);
chain.Swap(fork3, true);
chain.Swap(fork1, true)();
chain.Swap(fork2, true)();
chain.Swap(fork3, true)();
Assert.Equal(17, delayedRenderer.GetBufferedActionRendererCount());
Assert.Equal(15, delayedRenderer.GetBufferedActionUnRendererCount());

Expand Down Expand Up @@ -619,7 +619,7 @@ Block<DumbAction> Branchpoint
renderActions: false
);

chain.Swap(forked, true);
chain.Swap(forked, true)();

Assert.Equal(chain[2], delayedRenderer.Tip);
Assert.Empty(reorgLogs);
Expand Down Expand Up @@ -723,7 +723,7 @@ Block<DumbAction> Branchpoint
renderActions: false
);

chain.Swap(forked, true);
chain.Swap(forked, true)();

Assert.Equal(chain[1], delayedRenderer.Tip);
Assert.Empty(reorgLogs);
Expand Down
4 changes: 4 additions & 0 deletions Libplanet.Tests/Libplanet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\Libplanet.Stun\Libplanet.Stun.csproj" />
Expand Down
Loading

0 comments on commit 123101a

Please sign in to comment.