From 7221cb1434eebce879a0bd1bf3867cd8a24bcc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 15 Apr 2019 12:36:27 +0300 Subject: core, eth, les, light: scope receipt functionality a bit cleaner --- les/handler.go | 2 +- les/odr_test.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'les') diff --git a/les/handler.go b/les/handler.go index 9c72c6b13..732cb6042 100644 --- a/les/handler.go +++ b/les/handler.go @@ -733,7 +733,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { // Retrieve the requested block's receipts, skipping if unknown to us var results types.Receipts if number := rawdb.ReadHeaderNumber(pm.chainDb, hash); number != nil { - results = rawdb.ReadReceipts(pm.chainDb, hash, *number) + results = rawdb.ReadRawReceipts(pm.chainDb, hash, *number) } if results == nil { if header := pm.blockchain.GetHeaderByHash(hash); header == nil || header.ReceiptHash != types.EmptyRootHash { diff --git a/les/odr_test.go b/les/odr_test.go index bc587a183..2cc28e384 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -60,7 +60,7 @@ func odrGetReceipts(ctx context.Context, db ethdb.Database, config *params.Chain var receipts types.Receipts if bc != nil { if number := rawdb.ReadHeaderNumber(db, bhash); number != nil { - receipts = rawdb.ReadReceipts(db, bhash, *number) + receipts = rawdb.ReadReceipts(db, bhash, *number, config) } } else { if number := rawdb.ReadHeaderNumber(db, bhash); number != nil { @@ -159,6 +159,9 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { client.pm.synchronise(client.rPeer) test := func(expFail uint64) { + // Mark this as a helper to put the failures at the correct lines + t.Helper() + for i := uint64(0); i <= server.pm.blockchain.CurrentHeader().Number.Uint64(); i++ { bhash := rawdb.ReadCanonicalHash(server.db, i) b1 := fn(light.NoOdr, server.db, server.pm.chainConfig, server.pm.blockchain.(*core.BlockChain), nil, bhash) @@ -170,10 +173,10 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { eq := bytes.Equal(b1, b2) exp := i < expFail if exp && !eq { - t.Errorf("odr mismatch") + t.Fatalf("odr mismatch: have %x, want %x", b2, b1) } if !exp && eq { - t.Errorf("unexpected odr match") + t.Fatalf("unexpected odr match") } } } @@ -182,6 +185,7 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { client.peers.Unregister(client.rPeer.id) time.Sleep(time.Millisecond * 10) // ensure that all peerSetNotify callbacks are executed test(expFail) + // expect all retrievals to pass client.peers.Register(client.rPeer) time.Sleep(time.Millisecond * 10) // ensure that all peerSetNotify callbacks are executed @@ -189,6 +193,7 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { client.rPeer.hasBlock = func(common.Hash, uint64, bool) bool { return true } client.peers.lock.Unlock() test(5) + // still expect all retrievals to pass, now data should be cached locally client.peers.Unregister(client.rPeer.id) time.Sleep(time.Millisecond * 10) // ensure that all peerSetNotify callbacks are executed -- cgit v1.2.3