## 6 Conclusions  
In the paper, we attempted to improve cooperation between IoT and blockchain technologies. We observed that data collected from IoT sensors are, at most, as secure as we can trust administrators. One of the ways to improve the security of data is using solutions that ensure immutability. Currently, blockchain networks offer needed functionality but do not offer the efficiency needed to support analytics tools, especially when we have to validate the provenance of a bigger dataset containing historical records. In this paper, we proposed an improved method of storing data from IoT sensors in blockchain networks. The original data were extended with metadata that offered additional information about indexes.  
We implemented this mechanism for two different blockchains, proving its versatility. For Hyperledger Fabric, we achieved up to 2609 times shorter query time compared to the unaggregated query counterpart, and in Stellar, the improvement was at a level of 3.75. For Hyperledger and any other smart contract platform, the implementation is straightforward, because aggregation can be performed within the smart contract execution. Stellar and other non-smart contract platforms require introducing an external component responsible for performing aggregation updates. For blockchains intended for open networks, the security of the data at rest is assured by storing logs in an encrypted format; therefore, data theft does not reveal any useful information. The proposed optimization technique successfully reduced the time needed to execute aggregation queries on both Stellar and Hyperledger Fabric. The source code used to conduct the experiments is available at [[https://github.com/stanbar/Blockchain-and-IoT-infrastructure-monitoring](https://github.com/stanbar/Blockchain-and-IoT-infrastructure-monitoring)]([https://github.com/stanbar/Blockchain-and-IoT-infrastructure-monitoring](https://github.com/stanbar/Blockchain-and-IoT-infrastructure-monitoring)) (accessed on 7 July 2022).  
Further optimization could be achieved by introducing not only time-based indexes but also value-based indexes, allowing optimization of value-based queries, as we have seen in query no. 2. In general, each query can be optimized by introducing indexes. Such an index could be constructed by creating buckets consisting of logs that match a range predicate, e.g., \"log's value in range \(value_{1}\)-\(value_{2}\)\", as we showed in this paper with time frames, i.e., \"log's time in the range \(time_{1}\)-\(time_{2}\)\".  
As we have demonstrated, it is possible to construct such indexes on both transaction-based (Stellar) and smart contract-based (Hyperledger Fabric) blockchain platforms. The proposed model is universal and can be deployed in each blockchain network that exists in industrial infrastructures.  
\begin{table}
\begin{tabular}{c c c c} \hline
**Query** & **w/o Aggregation (s)** & **w/ Aggregation (s)** & **Improvement** \\ \hline
1 & 77.859 & 23.084 & 3.37\(\times\) \\
2 & 18.552 & N/A & 1\(\times\) \\
3 & 270.076 & 72.114 & 3.75\(\times\) \\
4 & 126.828 & 75.084 & 1.69\(\times\) \\ \hline \end{tabular}
\end{table}
Table 2: Query times with and without aggregation using Stellar.  
**Author Contributions:** Conceptualization, J.S.; methodology, A.S.; software, S.B.; validation, A.S.; formal analysis, S.B.; investigation, A.S.; resources, S.B.; writing--original draft preparation, A.S., J.S. and S.B.; writing--review and editing, A.S., J.S. and S.B.; supervision, J.S.; project administration, A.S.; funding acquisition, J.S.; All authors have read and agreed to the published version of the manuscript.  
**Funding:** This work has been supported partially by funds of the faculty of Electronic Telecommunications and Informatics, Gdarsk University of Technology.  
**Conflicts of Interest:** The authors declare no conflict of interest.