private bool CreateNextLedger() { var evt = new AutoResetEvent(false); var ledger = GetLedger(); if (ledger == null) { return(false); } ledgerService.SetNextLedger(ledger, () => evt.Set()); if (!evt.WaitOne(3000)) { return(false); } return(true); }
private void DispatchResponse(IConnectionSession session, Response response, ResultCode resultCode) { if (response is GetTransactionsResponse) { if (resultCode != ResultCode.Success) { logger.Log($"GetTransactionsResponse: ResultCode {resultCode}"); return; } var message = (GetTransactionsResponse)response; if (ResponseHelper.TryReadSignedTransactions(message, out var transactions)) { foreach (var signed in transactions) { LiveService.AddCommand(new SendTransactionCommand(signed)); } } else { logger.Log("GetTransactionsResponse: Cannot read SignedTransactions"); } } if (response is GetSignedLedgerResponse) { if (resultCode != ResultCode.Success) { logger.Log($"GetSignedLedgerResponse: ResultCode {resultCode}"); return; } var message = (GetSignedLedgerResponse)response; if (!ResponseHelper.TryReadSignedLedger(message, out var signed)) { logger.Log("GetSignedLedgerResponse: Cannot read SignedLedger"); return; } var nextHeight = LedgerService.LedgerManager.GetNextHeight(); if (signed.Ledger.LedgerLight.Height != nextHeight) { logger.Log($"GetSignedLedgerResponse : Received height is not Next. Next height {nextHeight}, Received {signed.Ledger.LedgerLight.Height}"); return; } var ledger = LedgerService.LedgerManager.GetSignedLedger(); if (!signed.Ledger.LedgerLight.Lastledger.Equals(ledger.Hash)) { logger.Log($"GetSignedLedgerResponse : PreviousLedger hash does not match. Current {ledger.Hash.ToBase64()}, Received prev {signed.Ledger.LedgerLight.Lastledger.ToBase64()}"); return; } if (!LedgerService.LedgerManager.ValidateSignatures(signed)) { logger.Log("GetSignedLedgerResponse: Ledger signatures are not valid"); return; } LedgerService.SetNextLedger(signed, () => { LiveService.CatchupManager.TryProcessHeight(session); }); } }