/// <inheritdoc /> public void Update(MultiHash deltaHash) { try { lock (_synchronisationLock) { var chainedDeltaHashes = _synchroniser .CacheDeltasBetween(LatestKnownDelta, deltaHash, CancellationToken.None) .Reverse() .ToList(); if (!Equals(chainedDeltaHashes.First(), LatestKnownDelta)) { _logger.Warning( "Failed to walk back the delta chain to {LatestKnownDelta}, giving up ledger update.", LatestKnownDelta); return; } foreach (var chainedDeltaHash in chainedDeltaHashes) { UpdateLedgerFromDelta(chainedDeltaHash); } } //https://github.com/catalyst-network/Catalyst.Node/issues/871 FlushTransactionsFromDelta(); } catch (Exception exception) { _logger.Error(exception, "Failed to update the ledger using the delta with hash {deltaHash}", deltaHash); } }
public void Should_Reconcile_On_New_Delta_Hash() { var hash1 = _hashProvider.ComputeUtf8MultiHash("update").CreateCid(); var hash2 = _hashProvider.ComputeUtf8MultiHash("update again").CreateCid(); var updates = new[] { hash1, hash2 }; _ledgerSynchroniser.CacheDeltasBetween(Arg.Is(_genesisHash), Arg.Is(hash1), default) .ReturnsForAnyArgs(new[] { hash2, hash1, _genesisHash }); _deltaHashProvider.DeltaHashUpdates.Returns(updates.ToObservable(_testScheduler)); _ledger = new LedgerService(_executor, _stateProvider, _storageProvider, new StateDb(), new StateDb(), _fakeRepository, _deltaHashProvider, _ledgerSynchroniser, _mempool, _mapperProvider, _logger); _testScheduler.Start(); _ledger.LatestKnownDelta.Should().Be(_genesisHash); }