Ignore redundant ZMQ block hash updates for the same block from multiple daemons
@@ -23,6 +23,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reactive.Linq;
+using System.Text;
using System.Threading.Tasks;
using Autofac;
using MiningCore.Blockchain.Bitcoin.Configuration;
@@ -115,7 +116,27 @@ namespace MiningCore.Blockchain.Bitcoin
logger.Info(() => $"[{LogCat}] Subscribing to ZMQ push-updates from {string.Join(", ", zmq.Values)}");
var newJobsPubSub = daemon.ZmqSubscribe(zmq, BitcoinConstants.ZmqPublisherTopicBlockHash, 2)
- .Do(x=> x.Dispose()) // we don't care about the contents
+ .Select(frames =>
+ {
+ try
+ {
+ // second frame contains the block hash as binary data
+ if (frames.Length > 1)
+ {
+ var hash = frames[1].ToHexString();
+ return hash;
+ }
+ }
+
+ finally
+ {
+ frames.Dispose();
+ }
+
+ return null;
+ })
+ .Where(x=> x != null)
+ .DistinctUntilChanged()
.Select(_ => Observable.FromAsync(() => UpdateJob(false, "ZMQ pub/sub")))
.Concat()
.Publish()
