When reading code for "ipfs add ", it seems same data block put twice in local datastore. In AddBlock() of blockservice.go, first put block into datastore, and then in exchange.HasBlock(), this block is put again. Is same block put into datastore twice? If so, why need put twice?
The block will only be stored once. The problem here is that, in the current architecture, the exchange doesn’t actually know that the block has been put in its blockstore. It has just been told “make this block available to the network” so it stores the block so it can continue to do so.
But yes, this is definitely sub-optimal and should be improved (really, all the blockservice/blockstore/exchange interfaces need a facelift).