Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

bzzeth: Phase 1 #1685

Merged
merged 8 commits into from
Sep 25, 2019
Merged

bzzeth: Phase 1 #1685

merged 8 commits into from
Sep 25, 2019

Conversation

jmozah
Copy link
Collaborator

@jmozah jmozah commented Aug 22, 2019

Phase 1 does the following things

  1. Handles NewBlockHeaders from trinity
  2. Sends GetBlockHeaders and Handles BlockHeaders (which means it stores it too)
  3. Unit test cases

And test this with Trinity client.

@jmozah
Copy link
Collaborator Author

jmozah commented Sep 16, 2019

@zelig @janos
Even though the testcase passes... there is an issue with decoding "Headers" in BlockHeaders message.
This is because of the rlp.RawValue which is not getting decoded properly.

This is the error i get

ERROR[09-16|17:57:55.915|github.com/ethersphere/swarm/p2p/protocols/protocol.go:238] peer.handleIncoming                      err="Invalid message (RLP error): <= msg #3 (16 bytes): rlp: element is larger than containing list"

But this is not causing a issue in when we test with the Trinity client.
We can either spend time fixing this... OR in phase 2 we are any way going to replace this with proper BlockHeader struct...we can tackle it there...

So i am submitting this for review.

Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor

bzzeth/bzzeth.go Outdated
default:
p.logger.Error("Invalid msg")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need for default case, p2p protocols knows about possible message types

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

vhash := addresses[i]
if wantHeaderFunc(vhash, b.kad) {
hashes = append(hashes, vhash)
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super nit picking but call wantedHeader but if not wanted we report not in proximity. so you display more specific property than granted by wantedHeaders which can also be overwritten.
Generally code is simpler to interpret if it avoids these latent logical leaps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure i understand this comment. Are you saying not to log.Trace if header is not in proximity?

bzzeth/bzzeth.go Outdated
hdr := make([]byte, len(h))
copy(hdr, h)
wg.Add(1)
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we rewrite this using errgroup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in addition, you could probably avoid the copy operation with changing
go func() { to go func(h []byte) { then calling the closure with (h[:])

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errGroups Go routine can onlu accept func().. so cant pass it like that..
func (g *Group) Go(f func() error)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then shadow it?

bzzeth/bzzeth.go Outdated
req.lock.RLock()
defer req.lock.RUnlock()
rcvdFlag, ok = req.hashes[addr]
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return explicit values as per our guidelines :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

})
}

func blockHeaderExchange(tester *p2ptest.ProtocolTester, peerID enode.ID, requestID uint32, wantedData []rlp.RawValue) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not seem to test much

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blockHeaderExchange does not test anything from the protocol response perspective, but TestNewBlockHeaders testcase checks the effect of receiving this message. Especially see the functions checkStorage and checkDelivery.

bzzeth/bzzeth.go Show resolved Hide resolved
bzzeth/bzzeth.go Outdated Show resolved Hide resolved
bzzeth/bzzeth.go Outdated Show resolved Hide resolved
bzzeth/bzzeth.go Outdated Show resolved Hide resolved
bzzeth/bzzeth.go Outdated Show resolved Hide resolved
bzzeth/bzzeth_test.go Show resolved Hide resolved
bzzeth/bzzeth_test.go Show resolved Hide resolved
bzzeth/wire.go Outdated Show resolved Hide resolved
bzzeth/wire.go Outdated Show resolved Hide resolved
bzzeth/wire.go Outdated Show resolved Hide resolved
yes, err := b.netStore.Store.HasMulti(ctx, addresses...)
if err != nil {
log.Error("Error checking hashesh in store", "Reason", err)
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider dropping the peer here before returning

addresses := make([]chunk.Address, len(*msg))
for i, h := range *msg {
addresses[i] = h.Hash.Bytes()
log.Trace("Received hashes ", "Header", hex.EncodeToString(h.Hash.Bytes()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use p.logger instead, also in 135, remove the extra space after "hashes " and don't capitalize the words in the logger, we usually log lowercase

deliveries := make(chan []byte)
req, err := p.getBlockHeaders(ctx, hashes, deliveries)
if err != nil {
p.logger.Error("Error sending GetBlockHeader message", "Reason", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant instead of Reason write err

return
}

// convert rlp.RawValue to bytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment

bzzeth/bzzeth.go Outdated
}

// convert rlp.RawValue to bytes
var headers [][]byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant it might need shadowing inside the loop. for now just make the above change with:

headers := make([][]byte, len(msg.Headers)) 
for i, h ... {
   headers[i]=h
}

bzzeth/bzzeth.go Outdated
hdr := make([]byte, len(h))
copy(hdr, h)
wg.Add(1)
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then shadow it?

Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is great now

close(errC)

// Store all the valid header chunks in one shot
results, err := b.netStore.Put(ctx, chunk.ModePutUpload, chunks...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need

@acud acud merged commit d0bf0b6 into master Sep 25, 2019
@skylenet skylenet added this to the 0.5.0 milestone Sep 25, 2019
@skylenet
Copy link
Contributor

This is failing on Appveyor with:

--- FAIL: TestNewBlockHeaders (0.03s)
    bzzeth_test.go:89: Could not remove localstore dir

It's now also happening on master after being merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants