## 3 Methodology
### Enhanced LEACH Routing Protocol  
One of the major shortcomings of such a protocol is that no consideration is made of the residual energy of the node when selecting a new cluster head, and a new cluster head is only selected after a complete round. If a chosen cluster header dies midway through the round, all the aggregate data for that cluster header is lost, and no data can be received or transmitted with success until the next round when a new cluster head is chosen. Another drawback of LEACH is that a cluster head is chosen randomly or based on the cluster with the highest energy, but this selection process does not take into consideration the distance between the cluster and the sink or the package size, which determine the amount of energy required to transmit the message. A node with the highest energy may not be the most qualified node if it is the farthest away from the base station. In addition to this, as a summary, usually the parameters that define if the CH needs to be replaced are related to not reaching the minimum level of energy needed to gather all the packets sent from the leave nodes or light nodes or sensor nodes and prepare them to submit this data via regular links with the power consumption required. Another parameter that might trigger a replacement request is the detection of an Advanced Persistent Threat (APT) affecting the CH. This can be easily detected if we use DLTs, which refers to a distributed ledger technology that is a database administered by a group of users spread out across multiple nodes [34]. With smart contracts, which are simply programs stored on a blockchain that run when predetermined conditions are met [34]. Under these circumstances, the whole group of nodes is set into an alert mode in which an urgent rekeying operation will be triggered.  
To address these problems, we proposed two modifications to the original LEACH protocol as follows:  
Before transmitting a packet, the cluster header computes the energy required to transmit the packet, \(E_{tx}\). If the required energy to transmit a packet, \(E_{tx}\), is less than or equal to the residual energy (\(E_{residual}\)) of the node (i.e., \(E_{tx}\leq E_{residual}\)), then the cluster header will relinquish its status and a new cluster header will be chosen. The aggregated data stored in the old cluster header should be transferred to the new cluster header. For a packet of size \(PacketLength\), the required transmit energy can be computed using Equations (6) and (7).  
\[E_{tx}=S_{Etx}\times PacketLength+S_{Efs}\times d^{2} \tag{6}\]  
\[E_{tx}=S_{Etx}\times PacketLength+S_{Emp}\times d^{4} \tag{7}\]  
where \(S_{Etx}\) is base station transmitter energy parameter and \(S_{Emp}\) and \(S_{Efs}\) are the energy parameters for the radio transmitter type in the multipath and free space models, respectively. The parameter \(d\) is the distance between the node and the base station \(S\). Using Euclidean distance, the distance between node \(i\) and base station \(S\) can be calculated using Equation (8).  
\[d_{i}=\sqrt[2]{\left(x_{i}-x_{s}\right)^{2}+\left(y_{i}-y_{s}\right)^{2}} \tag{8}\]  
where \(x\) any \(x\) are the two-dimensional coordinates of the node or the base station. The cluster header is chosen based on the distance energy-factor \(F_{ed}\), defined using Equation (2). The node with the highest \(F_{ed}\) is always chosen as the cluster header. This ensures that the distance between the node and the base station is also considered in the selection process as against the random selection procedures or using nodes with the highest energy only in the LEACH protocol.  
\[E_{ed}=E_{residual}-E_{tx}\times\frac{1}{d^{2}} \tag{9}\]  
Moreover, during the cluster head selection process, only nodes that satisfy the requirement that their residual energy \(E_{residual}\) is greater than transit energy \(E_{tx}\) are considered as a potential cluster header candidate.