0
votes

While reading the doc on attachments I see that "(Attachments) These files are automatically requested from the node sending the transaction when needed and cached locally so they are not re-requested if encountered again."

Can anyone help me by explaining how it is done ?

If a node knows the hash of an attachment it can just request it from the original node who uploaded it ?

how does it actually " request it from the sender who sends it to them ". Does any node who knows the hash can request the attachment ?

Question from Corda-ledger Slack: http://slack.corda.net/

1

1 Answers

2
votes

Transaction contains the hash of the attachment. A receiving node checks their vault for the hash. If it does not exist, it requests it from the sender who sends it to them. They store it in their db. If the hash is included in a transaction again it will be loaded from their own vault

See the code for FetchAttachmentsFlow

/**
 * Given a set of hashes either loads from local storage or requests them from the other peer. Downloaded
 * attachments are saved to local storage automatically.
 */
class FetchAttachmentsFlow(requests: Set<SecureHash>,
                           otherSide: FlowSession) : FetchDataFlow<Attachment, ByteArray>(requests, otherSide, DataType.ATTACHMENT)

Here is the link: https://github.com/corda/corda/blob/release/4.1/core/src/main/kotlin/net/corda/core/internal/FetchDataFlow.kt#L148