fix: comment on prove_block and only provide new blocks

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-08-05 11:58:16 +02:00
parent c3bcadf5d3
commit 77d9a6cc0e
2 changed files with 15 additions and 9 deletions

View File

@ -433,6 +433,9 @@ impl<Types: IpfsTypes> Behaviour<Types> {
) -> Result<SubscriptionFuture<(), String>, anyhow::Error> {
let key = cid.to_bytes();
match self.kademlia.start_providing(key.into()) {
// Kademlia queries are marked with QueryIds, which are most fitting to
// be used as kad Subscription keys - they are small and require no
// conversion for the applicable finish_subscription calls
Ok(id) => Ok(self.kad_subscriptions.create_subscription(id.into(), None)),
Err(e) => Err(anyhow!("kad: can't provide block {}: {:?}", cid, e)),
}

View File

@ -204,17 +204,20 @@ impl<TRepoTypes: RepoTypes> Repo<TRepoTypes> {
let (_cid, res) = self.block_store.put(block.clone()).await?;
self.subscriptions
.finish_subscription(cid.clone().into(), Ok(block));
// sending only fails if no one is listening anymore
// and that is okay with us.
let (tx, rx) = oneshot::channel();
self.events
.clone()
.send(RepoEvent::ProvideBlock(cid.clone(), tx))
.await
.ok();
if let BlockPut::NewBlock = res {
// sending only fails if no one is listening anymore
// and that is okay with us.
let (tx, rx) = oneshot::channel();
rx.await??.await?;
self.events
.clone()
.send(RepoEvent::ProvideBlock(cid.clone(), tx))
.await
.ok();
rx.await??.await?;
}
Ok((cid, res))
}