Skip to content

BlockService: AddBlock & AddBlocks write twice to datastore when used with Bitswap #7956

@hannahhoward

Description

@hannahhoward

Version information:

current

Description:

Calling AddBlock or AddBlocks on the block service appears to write to the data store twice. The reason is that the blockservice calls Put here:
https://github.com/ipfs/go-blockservice/blob/master/blockservice.go#L146
And then calls exchange.HasBlock here:
https://github.com/ipfs/go-blockservice/blob/master/blockservice.go#L153
HasBlock eventually calls PutMany here:
https://github.com/ipfs/go-bitswap/blob/master/bitswap.go#L372

I produces a test to repro the issue (it's pretty ugly but should demonstrate that I'm not just reading it wrong): https://github.com/ipfs/go-blockservice/blob/test/prove_double_write/test/blocks_test.go#L108

I believe you could fix it by changing https://github.com/ipfs/go-bitswap/blob/master/bitswap.go#L371 from:

if len(wanted) > 0 {

to

if len(wanted) > 0 && from != "" {

but I dunno what side effects that might cause.

I just was reading through the code trying to figure some stuff out about designing new ipld-prime interfaces and I saw that. I dunno what the penalty is for double writing but when adding a big DAG I can imagine it might be large.

Metadata

Metadata

Assignees

Labels

P2Medium: Good to have, but can wait until someone steps upeffort/daysEstimated to take multiple days, but less than a weekexp/wizardExtensive knowledge (implications, ramifications) requiredkind/bugA bug in existing code (including security flaws)status/readyReady to be worked

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions