4 of 9
added history of code segment in question
user avatar
user avatar

Pertaining to the required sequence, how can the requested transaction hash be the same as the received transaction hash?

In the IRI Node class, this code segment checks to see if the requested transaction hash is the same as the received transaction hash:

https://github.com/iotaledger/iri/blob/dev/src/main/java/com/iota/iri/network/Node.java#L284

//Request bytes    
//add request to reply queue (requestedHash, neighbor)
Hash requestedHash = new Hash(receivedData, TransactionViewModel.SIZE, reqHashSize);
if (requestedHash.equals(receivedTransactionHash)) {
     //requesting a random tip
     requestedHash = Hash.NULL_HASH;
}

How is it possible for the request hash to be part of the received transaction hash since the received transaction hash is not known until the transaction is made?

Perhaps I am missing some detail - can someone please explain the purpose of this.

History

I did some digging. According to the earliest available commits for the Node class, when the transaction hash and the requested hash were the same, the request was to be the Milestone that is requested. Perhaps someone can shed some light on why this existed like this and why it was changed.

See https://github.com/iotaledger/iri/blob/5db789222fabd11a9880b457b2b9f24cd783789f/src/iri/Node.java#L90

if (Arrays.equals(requestedTransaction, receivedTransaction.hash)) {
    transactionPointer = Storage.transactionPointer(Milestone.latestMilestone.bytes);
} else {
    transactionPointer = Storage.transactionPointer(requestedTransaction);
}
user1543