Put back p2p and async interface
MODIFY
WalletWasabi/BitcoinCore/CoreNode.cs
WalletWasabi/BitcoinCore/CoreNode.cs
@@ -191,8 +191,7 @@ namespace WalletWasabi.BitcoinCore
coreNode.P2pNode = new P2pNode(coreNode.Network, coreNode.P2pEndPoint, coreNode.MempoolService, coreNodeParams.UserAgent);
await coreNode.P2pNode.ConnectAsync(cancel).ConfigureAwait(false);
- coreNode.BlockNotifier = new BlockNotifier(TimeSpan.FromSeconds(7), new RpcWrappedClient(coreNode.RpcClient));
- coreNode.P2pNode.BlockInv += coreNode.OnP2pBlockInv;
+ coreNode.BlockNotifier = new BlockNotifier(TimeSpan.FromSeconds(7), new RpcWrappedClient(coreNode.RpcClient), coreNode.P2pNode);
coreNode.BlockNotifier.Start();
@@ -200,11 +199,6 @@ namespace WalletWasabi.BitcoinCore
}
}
- private void OnP2pBlockInv(object sender, uint256 e)
- {
- BlockNotifier.TriggerRound();
- }
-
public static async Task<Version> GetVersionAsync(CancellationToken cancel)
{
var arguments = "-version";
@@ -249,7 +243,6 @@ namespace WalletWasabi.BitcoinCore
var p2pNode = P2pNode;
if (p2pNode is { })
{
- p2pNode.BlockInv -= OnP2pBlockInv;
p2pNode.Dispose();
}
_disposedValue = true;

MODIFY
WalletWasabi/BitcoinCore/RpcWrappedClient.cs
WalletWasabi/BitcoinCore/RpcWrappedClient.cs
@@ -15,19 +15,19 @@ namespace WalletWasabi.BitcoinCore
public Network Network => Rpc.Network;
- public Task<uint256> GetBestBlockHashAsync()
+ public async Task<uint256> GetBestBlockHashAsync()
{
- return Rpc.GetBestBlockHashAsync();
+ return await Rpc.GetBestBlockHashAsync().ConfigureAwait(false);
}
- public Task<Block> GetBlockAsync(uint256 blockId)
+ public async Task<Block> GetBlockAsync(uint256 blockId)
{
- return Rpc.GetBlockAsync(blockId);
+ return await Rpc.GetBlockAsync(blockId).ConfigureAwait(false);
}
- public Task<BlockHeader> GetBlockHeaderAsync(uint256 blockHash)
+ public async Task<BlockHeader> GetBlockHeaderAsync(uint256 blockHash)
{
- return Rpc.GetBlockHeaderAsync(blockHash);
+ return await Rpc.GetBlockHeaderAsync(blockHash).ConfigureAwait(false);
}
}
}

MODIFY
WalletWasabi/Blockchain/Blocks/BlockNotifier.cs
WalletWasabi/Blockchain/Blocks/BlockNotifier.cs
@@ -25,11 +25,22 @@ namespace WalletWasabi.Blockchain.Blocks
public IRPCClient RpcClient { get; set; }
public Network Network => RpcClient.Network;
private List<BlockHeader> ProcessedBlocks { get; }
+ public P2pNode P2pNode { get; }
- public BlockNotifier(TimeSpan period, IRPCClient rpcClient) : base(period, null)
+ public BlockNotifier(TimeSpan period, IRPCClient rpcClient, P2pNode p2pNode = null) : base(period, null)
{
RpcClient = Guard.NotNull(nameof(rpcClient), rpcClient);
+ P2pNode = p2pNode;
ProcessedBlocks = new List<BlockHeader>();
+ if (p2pNode is { })
+ {
+ p2pNode.BlockInv += P2pNode_BlockInv;
+ }
+ }
+
+ private void P2pNode_BlockInv(object sender, uint256 blockHash)
+ {
+ TriggerRound();
}
protected override async Task<uint256> ActionAsync(CancellationToken cancel)
@@ -183,6 +194,11 @@ namespace WalletWasabi.Blockchain.Blocks
public new async Task StopAsync()
{
+ if (P2pNode is { })
+ {
+ P2pNode.BlockInv -= P2pNode_BlockInv;
+ }
+
await base.StopAsync().ConfigureAwait(false);
}
}

Put back p2p and async interface