ethersphere / swarm

Swarm: Censorship resistant storage and communication infrastructure for a truly sovereign digital society
https://swarm.ethereum.org/
GNU Lesser General Public License v3.0
488 stars 110 forks source link

BMT panic #837

Closed nonsense closed 6 years ago

nonsense commented 6 years ago

Happens on v0.3.1

swarm_30403 panic: runtime error: index out of range
swarm_30403
swarm_30403 goroutine 32685 [running]:
swarm_30403 github.com/ethereum/go-ethereum/swarm/bmt.(*Hasher).writeSection(0xc44068ae30, 0x3ff, 0xc422f594c0, 0x40, 0x40, 0x440101)
swarm_30403     /go/src/github.com/ethereum/go-ethereum/swarm/bmt/bmt.go:539 +0x22b
swarm_30403 created by github.com/ethereum/go-ethereum/swarm/bmt.(*Hasher).Sum
swarm_30403     /go/src/github.com/ethereum/go-ethereum/swarm/bmt/bmt.go:302 +0x9a
nonsense commented 6 years ago
swarm_30403 panic: runtime error: index out of range
swarm_30403
swarm_30403 goroutine 6665 [running]:
swarm_30403 github.com/ethereum/go-ethereum/swarm/bmt.(*Hasher).writeSection(0xc4237d3430, 0xf7, 0xc427ea8380, 0x40, 0x40, 0xc4237d0001)
swarm_30403     /go/src/github.com/ethereum/go-ethereum/swarm/bmt/bmt.go:539 +0x22b
swarm_30403 created by github.com/ethereum/go-ethereum/swarm/bmt.(*Hasher).Write
swarm_30403     /go/src/github.com/ethereum/go-ethereum/swarm/bmt/bmt.go:350 +0x183

Note that in the stacktrace we see both Sum and Write. I don't know if this is of significance.

nonsense commented 6 years ago

@zelig I think we should have RefHasher implement SwarmHash so that we have at least one easy to understand implementation.

nonsense commented 6 years ago

Also tests on swarm/bmt take:

ok      github.com/ethereum/go-ethereum/swarm/bmt       49.107s

This seems wrong to me, considering that this is supposed to just build a binary merkle tree from a []byte.

gbalint commented 6 years ago

Note: this happens when (for some reason) there are chunks on the node with size different than 4K

gbalint commented 6 years ago

Can be closed with https://github.com/ethersphere/go-ethereum/issues/870 and https://github.com/ethersphere/go-ethereum/issues/869

nonsense commented 6 years ago

https://github.com/ethersphere/go-ethereum/pull/883 changed how we init the BMT hasher, so we should be able to run tests with different chunk sizes now within the same isolated cluster - obviously syncing them with nodes that run on a different size will not work.

            hasher := sha3.NewKeccak256
            hasherSize := hasher().Size()
            segmentCount := chunk.DefaultSize / hasherSize
            pool := bmt.NewTreePool(hasher, segmentCount, bmt.PoolSize)

I am closing this issue as the panic is addressed and we have both a CLI tool and validation in place.