public ResponseCode OnTransactionReceived(ProtocolMessage protocolMessage) { var transactionBroadcast = protocolMessage.FromProtocolMessage <TransactionBroadcast>(); var transactionValid = _validator.ValidateTransaction(transactionBroadcast.PublicEntry); if (!transactionValid) { return(ResponseCode.Error); } var transactionDao = transactionBroadcast.PublicEntry.ToDao <PublicEntry, PublicEntryDao>(_mapperProvider); _logger.Verbose("Adding transaction {id} to mempool", transactionDao.Id); if (_mempool.Service.TryReadItem(transactionDao.Id)) { _logger.Information("Transaction {id} already exists in mempool", transactionDao.Id); return(ResponseCode.Exists); } _mempool.Service.CreateItem(transactionDao); _logger.Information("Broadcasting {signature} transaction", protocolMessage); _broadcastManager.BroadcastAsync(protocolMessage).ConfigureAwait(false); return(ResponseCode.Successful); }
public ResponseCode OnTransactionReceived(ProtocolMessage protocolMessage) { var transaction = protocolMessage.FromProtocolMessage <TransactionBroadcast>(); var transactionValid = _validator.ValidateTransaction(transaction, _peerSettings.NetworkType); if (!transactionValid) { return(ResponseCode.Error); } var transactionSignature = transaction.Signature; _logger.Verbose("Adding transaction {signature} to mempool", transactionSignature); // https://github.com/catalyst-network/Catalyst.Node/issues/910 - should we fail or succeed if we already have the transaction in the ledger? if (_mempool.Repository.TryReadItem(transactionSignature.RawBytes)) { _logger.Information("Transaction {signature} already exists in mempool", transactionSignature); return(ResponseCode.Error); } _mempool.Repository.CreateItem(transaction); _logger.Information("Broadcasting {signature} transaction", protocolMessage); _broadcastManager.BroadcastAsync(protocolMessage); return(ResponseCode.Successful); }
/// <inheritdoc /> public void BroadcastCandidate(CandidateDeltaBroadcast candidate) { Guard.Argument(candidate, nameof(candidate)).NotNull().Require(c => c.IsValid()); _logger.Information("Broadcasting candidate delta {0}", candidate); if (!candidate.ProducerId.Equals(_peerId)) { _logger.Warning($"{nameof(BroadcastCandidate)} " + "should only be called by the producer of a candidate."); return; } var protocolMessage = candidate.ToProtocolMessage(_peerId, CorrelationId.GenerateCorrelationId()); _broadcastManager.BroadcastAsync(protocolMessage).ConfigureAwait(false); _logger.Debug("Broadcast candidate {0} done.", candidate); }
public ResponseCode OnTransactionReceived(ProtocolMessage protocolMessage) { var transactionBroadcast = protocolMessage.FromProtocolMessage <TransactionBroadcast>(); PublicEntry publicEntry = transactionBroadcast.PublicEntry; if (publicEntry.SenderAddress.Length == 32) { var transactionValid = _validator.ValidateTransaction(publicEntry); if (!transactionValid) { return(ResponseCode.Error); } byte[] kvmAddressBytes = Keccak.Compute(publicEntry.SenderAddress.ToByteArray()).Bytes.AsSpan(12).ToArray(); string hex = kvmAddressBytes.ToHexString() ?? throw new ArgumentNullException("kvmAddressBytes.ToHexString()"); publicEntry.SenderAddress = kvmAddressBytes.ToByteString(); if (publicEntry.ReceiverAddress.Length == 1) { publicEntry.ReceiverAddress = ByteString.Empty; } } var transactionDao = transactionBroadcast.PublicEntry.ToDao <PublicEntry, PublicEntryDao>(_mapperProvider); _logger.Verbose("Adding transaction {id} to mempool", transactionDao.Id); if (_mempool.Service.TryReadItem(transactionDao.Id)) { _logger.Information("Transaction {id} already exists in mempool", transactionDao.Id); return(ResponseCode.Exists); } _mempool.Service.CreateItem(transactionDao); _logger.Information("Broadcasting {signature} transaction", protocolMessage); _broadcastManager.BroadcastAsync(protocolMessage).ConfigureAwait(false); return(ResponseCode.Successful); }