public static void processPendingTransactions() { // TODO TODO improve to include failed transactions ulong last_block_height = IxianHandler.getLastBlockHeight(); lock (PendingTransactions.pendingTransactions) { long cur_time = Clock.getTimestamp(); List <PendingTransaction> tmp_pending_transactions = new List <PendingTransaction>(PendingTransactions.pendingTransactions); int idx = 0; foreach (var entry in tmp_pending_transactions) { Transaction t = entry.transaction; long tx_time = entry.addedTimestamp; if (t.applied != 0) { PendingTransactions.pendingTransactions.RemoveAll(x => x.transaction.id.SequenceEqual(t.id)); continue; } // if transaction expired, remove it from pending transactions if (last_block_height > ConsensusConfig.getRedactedWindowSize() && t.blockHeight < last_block_height - ConsensusConfig.getRedactedWindowSize()) { ActivityStorage.updateStatus(t.id, ActivityStatus.Error, 0); PendingTransactions.pendingTransactions.RemoveAll(x => x.transaction.id.SequenceEqual(t.id)); continue; } if (cur_time - tx_time > 40) // if the transaction is pending for over 40 seconds, resend { CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'M', 'H' }, ProtocolMessageCode.transactionData, t.getBytes(), null); entry.addedTimestamp = cur_time; entry.confirmedNodeList.Clear(); } if (entry.confirmedNodeList.Count() >= 3) // if we get transaction from 3 nodes, we can consider it as confirmed { if (entry.messageId != null) { StreamProcessor.confirmMessage(entry.messageId); } continue; } if (cur_time - tx_time > 20) // if the transaction is pending for over 20 seconds, send inquiry { CoreProtocolMessage.broadcastGetTransaction(t.id, 0, null, false); } idx++; } } }
// Cleans the storage cache and logs public static bool cleanCacheAndLogs() { ActivityStorage.deleteCache(); PeerStorage.deletePeersFile(); Logging.clear(); Logging.info("Cleaned cache and logs."); return(true); }
public static void addTransactionToActivityStorage(Transaction transaction) { Activity activity = null; int type = -1; IxiNumber value = transaction.amount; List <byte[]> wallet_list = null; byte[] wallet = null; byte[] primary_address = (new Address(transaction.pubKey)).address; if (IxianHandler.getWalletStorage().isMyAddress(primary_address)) { wallet = primary_address; type = (int)ActivityType.TransactionSent; if (transaction.type == (int)Transaction.Type.PoWSolution) { type = (int)ActivityType.MiningReward; value = ConsensusConfig.calculateMiningRewardForBlock(BitConverter.ToUInt64(transaction.data, 0)); } } else { wallet_list = IxianHandler.getWalletStorage().extractMyAddressesFromAddressList(transaction.toList); if (wallet_list != null) { type = (int)ActivityType.TransactionReceived; if (transaction.type == (int)Transaction.Type.StakingReward) { type = (int)ActivityType.StakingReward; } } } if (type != -1) { int status = (int)ActivityStatus.Pending; if (transaction.applied > 0) { status = (int)ActivityStatus.Final; } if (wallet_list != null) { foreach (var entry in wallet_list) { activity = new Activity(IxianHandler.getWalletStorage().getSeedHash(), Base58Check.Base58CheckEncoding.EncodePlain(entry), Base58Check.Base58CheckEncoding.EncodePlain(primary_address), transaction.toList, type, transaction.id, transaction.toList[entry].ToString(), transaction.timeStamp, status, transaction.applied, Transaction.txIdV8ToLegacy(transaction.id)); ActivityStorage.insertActivity(activity); } } else if (wallet != null) { activity = new Activity(IxianHandler.getWalletStorage().getSeedHash(), Base58Check.Base58CheckEncoding.EncodePlain(wallet), Base58Check.Base58CheckEncoding.EncodePlain(primary_address), transaction.toList, type, transaction.id, value.ToString(), transaction.timeStamp, status, transaction.applied, Transaction.txIdV8ToLegacy(transaction.id)); ActivityStorage.insertActivity(activity); } } }
public override void receivedTransactionInclusionVerificationResponse(byte[] txid, bool verified) { // TODO implement error // TODO implement blocknum ActivityStatus status = ActivityStatus.Pending; if (verified) { status = ActivityStatus.Final; PendingTransactions.remove(txid); } ActivityStorage.updateStatus(txid, status, 0); }
public void start(bool verboseConsoleOutput) { // Generate presence list PresenceList.init(IxianHandler.publicIP, Config.serverPort, 'R'); // Start the network queue NetworkQueue.start(); ActivityStorage.prepareStorage(); if (Config.apiBinds.Count == 0) { Config.apiBinds.Add("http://localhost:" + Config.apiPort + "/"); } // Start the HTTP JSON API server apiServer = new APIServer(Config.apiBinds, Config.apiUsers, Config.apiAllowedIps); // Prepare stats screen ConsoleHelpers.verboseConsoleOutput = verboseConsoleOutput; Logging.consoleOutput = verboseConsoleOutput; Logging.flush(); if (ConsoleHelpers.verboseConsoleOutput == false) { statsConsoleScreen.clearScreen(); } // Check for test client mode if (Config.isTestClient) { TestClientNode.start(); return; } // Start the node stream server NetworkServer.beginNetworkOperations(); // Start the network client manager NetworkClientManager.start(); // Start the keepalive thread PresenceList.startKeepAlive(); // Start the maintenance thread maintenanceThread = new Thread(performMaintenance); maintenanceThread.Start(); }
static public void stop() { Program.noStart = true; IxianHandler.forceShutdown = true; // Stop TIV tiv.stop(); // Stop the keepalive thread PresenceList.stopKeepAlive(); // Stop the API server if (apiServer != null) { apiServer.stop(); apiServer = null; } if (maintenanceThread != null) { maintenanceThread.Abort(); maintenanceThread = null; } ActivityStorage.stopStorage(); // Stop the network queue NetworkQueue.stop(); // Check for test client mode if (Config.isTestClient) { TestClientNode.stop(); return; } // Stop all network clients NetworkClientManager.stop(); // Stop the network server NetworkServer.stopNetworkOperations(); // Stop the console stats screen // Console screen has a thread running even if we are in verbose mode statsConsoleScreen.stop(); }
public override void receivedTransactionInclusionVerificationResponse(byte[] txid, bool verified) { // TODO implement error // TODO implement blocknum ActivityStatus status = ActivityStatus.Pending; if (verified) { status = ActivityStatus.Final; PendingTransaction p_tx = PendingTransactions.getPendingTransaction(txid); if (p_tx != null) { if (p_tx.messageId != null) { StreamProcessor.confirmMessage(p_tx.messageId); } PendingTransactions.remove(txid); } } ActivityStorage.updateStatus(txid, status, 0); }
public void start(bool verboseConsoleOutput) { UpdateVerify.start(); // Generate presence list PresenceList.init(IxianHandler.publicIP, Config.serverPort, 'C'); // Start the network queue NetworkQueue.start(); ActivityStorage.prepareStorage(); if (Config.apiBinds.Count == 0) { Config.apiBinds.Add("http://localhost:" + Config.apiPort + "/"); } // Start the HTTP JSON API server apiServer = new APIServer(Config.apiBinds, Config.apiUsers, Config.apiAllowedIps); if (IXICore.Platform.onMono() == false && !Config.disableWebStart) { System.Diagnostics.Process.Start(Config.apiBinds[0]); } // Prepare stats screen ConsoleHelpers.verboseConsoleOutput = verboseConsoleOutput; Logging.consoleOutput = verboseConsoleOutput; Logging.flush(); if (ConsoleHelpers.verboseConsoleOutput == false) { statsConsoleScreen.clearScreen(); } // Start the node stream server NetworkServer.beginNetworkOperations(); // Start the network client manager NetworkClientManager.start(2); // Start the keepalive thread PresenceList.startKeepAlive(); // Start TIV string headers_path = ""; if (IxianHandler.isTestNet) { headers_path = Path.Combine(Config.dataDirectory, "testnet-headers"); } else { headers_path = Path.Combine(Config.dataDirectory, "headers"); } if (generatedNewWallet || !File.Exists(Path.Combine(Config.dataDirectory, Config.walletFile))) { generatedNewWallet = false; tiv.start(headers_path); } else { tiv.start(headers_path, 0, null); } // Start the maintenance thread maintenanceThread = new Thread(performMaintenance); maintenanceThread.Start(); pushNotifications = new PushNotifications(Config.pushServiceUrl); pushNotifications.start(); }
public JsonResponse onStatus(Dictionary <string, object> parameters) { JsonError error = null; Dictionary <string, object> networkArray = new Dictionary <string, object>(); networkArray.Add("Core Version", CoreConfig.version); networkArray.Add("Node Version", CoreConfig.productVersion); networkArray.Add("Network type", IxianHandler.networkType.ToString()); networkArray.Add("My time", Clock.getTimestamp()); networkArray.Add("Network time difference", Clock.networkTimeDifference); networkArray.Add("Real network time difference", Clock.realNetworkTimeDifference); networkArray.Add("My External IP", IxianHandler.publicIP); networkArray.Add("My Listening Port", IxianHandler.publicPort); //networkArray.Add("Listening interface", context.Request.RemoteEndPoint.Address.ToString()); networkArray.Add("Node Deprecation Block Limit", Config.nodeDeprecationBlock); string dltStatus = "Active"; if (Node.blockSync.synchronizing) { dltStatus = "Synchronizing"; } if (Node.blockChain.getTimeSinceLastBLock() > 1800) // if no block for over 1800 seconds { dltStatus = "ErrorLongTimeNoBlock"; } if (Node.blockProcessor.networkUpgraded) { dltStatus = "ErrorForkedViaUpgrade"; } networkArray.Add("Update", checkUpdate()); networkArray.Add("DLT Status", dltStatus); networkArray.Add("Core Status", IxianHandler.status); string bpStatus = "Stopped"; if (Node.blockProcessor.operating) { bpStatus = "Running"; } networkArray.Add("Block Processor Status", bpStatus); Block last_block = Node.blockChain.getLastBlock(); if (last_block != null) { networkArray.Add("Block Height", last_block.blockNum); networkArray.Add("Block Version", last_block.version); networkArray.Add("Block Signature Count", last_block.getFrozenSignatureCount()); } else { networkArray.Add("Block Height", 0); networkArray.Add("Block Version", 0); networkArray.Add("Block Signature Count", 1); } networkArray.Add("Network Block Height", IxianHandler.getHighestKnownNetworkBlockHeight()); networkArray.Add("Node Type", PresenceList.myPresenceType); networkArray.Add("Connectable", NetworkServer.isConnectable()); if (parameters.ContainsKey("vv") || parameters.ContainsKey("verbose")) { networkArray.Add("Required Consensus", Node.blockChain.getRequiredConsensus()); networkArray.Add("Wallets", Node.walletState.numWallets); networkArray.Add("Presences", PresenceList.getTotalPresences()); networkArray.Add("Supply", Node.walletState.calculateTotalSupply().ToString()); networkArray.Add("Applied TX Count", TransactionPool.getAppliedTransactionCount()); networkArray.Add("Unapplied TX Count", TransactionPool.getUnappliedTransactionCount()); networkArray.Add("Masters", PresenceList.countPresences('M')); networkArray.Add("Relays", PresenceList.countPresences('R')); networkArray.Add("Clients", PresenceList.countPresences('C')); } if (parameters.ContainsKey("vv")) { Dictionary <string, object> queues = new Dictionary <string, object>(); queues.Add("RcvLow", NetworkQueue.getLowPriorityMessageCount()); queues.Add("RcvMedium", NetworkQueue.getMediumPriorityMessageCount()); queues.Add("RcvHigh", NetworkQueue.getHighPriorityMessageCount()); queues.Add("SendClients", NetworkServer.getQueuedMessageCount()); queues.Add("SendServers", NetworkClientManager.getQueuedMessageCount()); queues.Add("Logging", Logging.getRemainingStatementsCount()); queues.Add("Pending Transactions", PendingTransactions.pendingTransactionCount()); queues.Add("Storage", Node.storage.getQueuedQueryCount()); queues.Add("Inventory", Node.inventoryCache.getItemCount()); queues.Add("Inventory Processed", Node.inventoryCache.getProcessedItemCount()); queues.Add("Activity", ActivityStorage.getQueuedQueryCount()); networkArray.Add("Queues", queues); networkArray.Add("WS Checksum", Crypto.hashToString(Node.walletState.calculateWalletStateChecksum())); } networkArray.Add("Network Clients", NetworkServer.getConnectedClients()); networkArray.Add("Network Servers", NetworkClientManager.getConnectedClients(true)); return(new JsonResponse { result = networkArray, error = error }); }
public void start(bool verboseConsoleOutput) { // Generate presence list PresenceList.init(IxianHandler.publicIP, Config.serverPort, 'R'); // Start the network queue NetworkQueue.start(); ActivityStorage.prepareStorage(); if (Config.apiBinds.Count == 0) { Config.apiBinds.Add("http://localhost:" + Config.apiPort + "/"); } // Start the HTTP JSON API server apiServer = new APIServer(Config.apiBinds, Config.apiUsers, Config.apiAllowedIps); if (IXICore.Platform.onMono() == false && !Config.disableWebStart) { System.Diagnostics.Process.Start(Config.apiBinds[0]); } // Prepare stats screen ConsoleHelpers.verboseConsoleOutput = verboseConsoleOutput; Logging.consoleOutput = verboseConsoleOutput; Logging.flush(); if (ConsoleHelpers.verboseConsoleOutput == false) { statsConsoleScreen.clearScreen(); } // Check for test client mode if (Config.isTestClient) { TestClientNode.start(); return; } // Start the node stream server NetworkServer.beginNetworkOperations(); // Start the network client manager NetworkClientManager.start(2); // Start the keepalive thread PresenceList.startKeepAlive(); // Start TIV if (generatedNewWallet || !walletStorage.walletExists()) { generatedNewWallet = false; tiv.start(""); } else { tiv.start("", 0, null); } // Start the maintenance thread maintenanceThread = new Thread(performMaintenance); maintenanceThread.Start(); }