Skip to content

Commit d8b3680

Browse files
committed
Remove LES v5 protocol
1 parent 42c2236 commit d8b3680

7 files changed

+10
-281
lines changed

les/fetcher_test.go

-23
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ func TestSequentialAnnouncementsLes3(t *testing.T) {
7575
func TestSequentialAnnouncementsUltraLes3(t *testing.T) {
7676
testSequentialAnnouncements(t, downloader.LightestSync, lpv3)
7777
}
78-
func TestSequentialAnnouncementsLes5(t *testing.T) {
79-
testSequentialAnnouncements(t, downloader.LightSync, lpv5)
80-
}
81-
func TestSequentialAnnouncementsUltraLes5(t *testing.T) {
82-
testSequentialAnnouncements(t, downloader.LightestSync, lpv5)
83-
}
8478

8579
func testSequentialAnnouncements(t *testing.T, syncMode downloader.SyncMode, protocol int) {
8680
netconfig := testnetConfig{
@@ -132,13 +126,6 @@ func TestGappedAnnouncementsUltraLes3(t *testing.T) {
132126
t.Skip("added in the les refactor, check if necessary for LightestSync")
133127
testGappedAnnouncements(t, downloader.LightestSync, lpv3)
134128
}
135-
func TestGappedAnnouncementsLes5(t *testing.T) {
136-
testGappedAnnouncements(t, downloader.LightSync, lpv5)
137-
}
138-
func TestGappedAnnouncementsUltraLes5(t *testing.T) {
139-
t.Skip("added in the les refactor, check if necessary for LightestSync")
140-
testGappedAnnouncements(t, downloader.LightestSync, lpv5)
141-
}
142129

143130
func testGappedAnnouncements(t *testing.T, syncMode downloader.SyncMode, protocol int) {
144131
// log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
@@ -203,15 +190,6 @@ func TestTrustedAnnouncementsUltraLes3(t *testing.T) {
203190
testTrustedAnnouncement(t, downloader.LightestSync, lpv3)
204191
}
205192

206-
func TestTrustedAnnouncementsLes5(t *testing.T) {
207-
testTrustedAnnouncement(t, downloader.LightSync, lpv5)
208-
}
209-
210-
func TestTrustedAnnouncementsUltraLes5(t *testing.T) {
211-
t.Skip("added in the les refactor, check if necessary for LightestSync")
212-
testTrustedAnnouncement(t, downloader.LightestSync, lpv5)
213-
}
214-
215193
func testTrustedAnnouncement(t *testing.T, syncMode downloader.SyncMode, protocol int) {
216194
var (
217195
servers []*testServer
@@ -287,7 +265,6 @@ func testTrustedAnnouncement(t *testing.T, syncMode downloader.SyncMode, protoco
287265

288266
func TestInvalidAnnouncesLES2(t *testing.T) { testInvalidAnnounces(t, downloader.LightSync, lpv2) }
289267
func TestInvalidAnnouncesLES3(t *testing.T) { testInvalidAnnounces(t, downloader.LightSync, lpv3) }
290-
func TestInvalidAnnouncesLES5(t *testing.T) { testInvalidAnnounces(t, downloader.LightSync, lpv5) }
291268

292269
func testInvalidAnnounces(t *testing.T, syncMode downloader.SyncMode, protocol int) {
293270
t.Skip("Validates through a smaller td for the same header number. We verify this using the header number")

les/handler_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ func testGetBloombitsProofs(t *testing.T, protocol int) {
590590

591591
func TestTransactionStatusLes2(t *testing.T) { testTransactionStatus(t, lpv2) }
592592
func TestTransactionStatusLes3(t *testing.T) { testTransactionStatus(t, lpv3) }
593-
func TestTransactionStatusLes5(t *testing.T) { testTransactionStatus(t, lpv5) }
594593

595594
func testTransactionStatus(t *testing.T, protocol int) {
596595
netconfig := testnetConfig{
@@ -692,7 +691,6 @@ func testTransactionStatus(t *testing.T, protocol int) {
692691
}
693692

694693
func TestStopResumeLES3(t *testing.T) { testStopResume(t, lpv3) }
695-
func TestStopResumeLES5(t *testing.T) { testStopResume(t, lpv5) }
696694

697695
func testStopResume(t *testing.T, protocol int) {
698696
netconfig := testnetConfig{
@@ -755,9 +753,6 @@ func TestTransactionGatewayFeeRequirementLes2(t *testing.T) {
755753
func TestTransactionGatewayFeeRequirementLes3(t *testing.T) {
756754
testTransactionGatewayFeeRequirement(t, lpv3)
757755
}
758-
func TestTransactionGatewayFeeRequirementLes5(t *testing.T) {
759-
testTransactionGatewayFeeRequirement(t, lpv5)
760-
}
761756

762757
func testTransactionGatewayFeeRequirement(t *testing.T, protocol int) {
763758
netconfig := testnetConfig{

les/odr_test.go

-201
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ package les
1919
import (
2020
"bytes"
2121
"context"
22-
"crypto/rand"
23-
"fmt"
2422
"math/big"
25-
"reflect"
2623
"testing"
2724
"time"
2825

@@ -32,7 +29,6 @@ import (
3229
"github.com/celo-org/celo-blockchain/core"
3330
"github.com/celo-org/celo-blockchain/core/rawdb"
3431
"github.com/celo-org/celo-blockchain/core/state"
35-
"github.com/celo-org/celo-blockchain/p2p"
3632

3733
"github.com/celo-org/celo-blockchain/core/types"
3834
"github.com/celo-org/celo-blockchain/core/vm"
@@ -260,200 +256,3 @@ func testOdr(t *testing.T, protocol int, expFail uint64, checkCached bool, fn od
260256
test(5)
261257
}
262258
}
263-
264-
func TestGetTxStatusFromUnindexedPeersLES5(t *testing.T) { testGetTxStatusFromUnindexedPeers(t, lpv5) }
265-
266-
func testGetTxStatusFromUnindexedPeers(t *testing.T, protocol int) {
267-
var (
268-
blocks = 8
269-
netconfig = testnetConfig{
270-
blocks: blocks,
271-
syncMode: downloader.LightSync,
272-
protocol: protocol,
273-
nopruning: true,
274-
}
275-
)
276-
server, client, tearDown := newClientServerEnv(t, netconfig)
277-
defer tearDown()
278-
279-
// Iterate the chain, create the tx indexes locally
280-
var (
281-
testHash common.Hash
282-
testStatus light.TxStatus
283-
284-
txs = make(map[common.Hash]*types.Transaction) // Transaction objects set
285-
blockNumbers = make(map[common.Hash]uint64) // Transaction hash to block number mappings
286-
blockHashes = make(map[common.Hash]common.Hash) // Transaction hash to block hash mappings
287-
intraIndex = make(map[common.Hash]uint64) // Transaction intra-index in block
288-
)
289-
for number := uint64(1); number < server.backend.Blockchain().CurrentBlock().NumberU64(); number++ {
290-
block := server.backend.Blockchain().GetBlockByNumber(number)
291-
if block == nil {
292-
t.Fatalf("Failed to retrieve block %d", number)
293-
}
294-
for index, tx := range block.Transactions() {
295-
txs[tx.Hash()] = tx
296-
blockNumbers[tx.Hash()] = number
297-
blockHashes[tx.Hash()] = block.Hash()
298-
intraIndex[tx.Hash()] = uint64(index)
299-
300-
if testHash == (common.Hash{}) {
301-
testHash = tx.Hash()
302-
testStatus = light.TxStatus{
303-
Status: core.TxStatusIncluded,
304-
Lookup: &rawdb.LegacyTxLookupEntry{
305-
BlockHash: block.Hash(),
306-
BlockIndex: block.NumberU64(),
307-
Index: uint64(index),
308-
},
309-
}
310-
}
311-
}
312-
}
313-
// serveMsg processes incoming GetTxStatusMsg and sends the response back.
314-
serveMsg := func(peer *testPeer, txLookup uint64) error {
315-
var (
316-
msg p2p.Msg
317-
err error
318-
)
319-
loop:
320-
for {
321-
msg, err = peer.app.ReadMsg()
322-
if err != nil {
323-
return err
324-
}
325-
switch msg.Code {
326-
case GetEtherbaseMsg:
327-
continue
328-
default:
329-
break loop
330-
}
331-
}
332-
if msg.Code != GetTxStatusMsg {
333-
return fmt.Errorf("message code mismatch: got %d, expected %d", msg.Code, GetTxStatusMsg)
334-
}
335-
var r GetTxStatusPacket
336-
if err := msg.Decode(&r); err != nil {
337-
return err
338-
}
339-
stats := make([]light.TxStatus, len(r.Hashes))
340-
for i, hash := range r.Hashes {
341-
number, exist := blockNumbers[hash]
342-
if !exist {
343-
continue // Filter out unknown transactions
344-
}
345-
min := uint64(blocks) - txLookup
346-
if txLookup != txIndexUnlimited && (txLookup == txIndexDisabled || number < min) {
347-
continue // Filter out unindexed transactions
348-
}
349-
stats[i].Status = core.TxStatusIncluded
350-
stats[i].Lookup = &rawdb.LegacyTxLookupEntry{
351-
BlockHash: blockHashes[hash],
352-
BlockIndex: number,
353-
Index: intraIndex[hash],
354-
}
355-
}
356-
data, _ := rlp.EncodeToBytes(stats)
357-
reply := &reply{peer.app, TxStatusMsg, r.ReqID, data}
358-
if err = reply.send(testBufLimit); err != nil {
359-
return err
360-
}
361-
return nil
362-
}
363-
364-
var testspecs = []struct {
365-
peers int
366-
txLookups []uint64
367-
txs []common.Hash
368-
results []light.TxStatus
369-
}{
370-
// Retrieve mined transaction from the empty peerset
371-
{
372-
peers: 0,
373-
txLookups: []uint64{},
374-
txs: []common.Hash{testHash},
375-
results: []light.TxStatus{{}},
376-
},
377-
// Retrieve unknown transaction from the full peers
378-
{
379-
peers: 3,
380-
txLookups: []uint64{txIndexUnlimited, txIndexUnlimited, txIndexUnlimited},
381-
txs: []common.Hash{randomHash()},
382-
results: []light.TxStatus{{}},
383-
},
384-
// Retrieve mined transaction from the full peers
385-
{
386-
peers: 3,
387-
txLookups: []uint64{txIndexUnlimited, txIndexUnlimited, txIndexUnlimited},
388-
txs: []common.Hash{testHash},
389-
results: []light.TxStatus{testStatus},
390-
},
391-
// Retrieve mixed transactions from the full peers
392-
{
393-
peers: 3,
394-
txLookups: []uint64{txIndexUnlimited, txIndexUnlimited, txIndexUnlimited},
395-
txs: []common.Hash{randomHash(), testHash},
396-
results: []light.TxStatus{{}, testStatus},
397-
},
398-
// Retrieve mixed transactions from unindexed peer(but the target is still available)
399-
{
400-
peers: 3,
401-
txLookups: []uint64{uint64(blocks) - testStatus.Lookup.BlockIndex, uint64(blocks) - testStatus.Lookup.BlockIndex - 1, uint64(blocks) - testStatus.Lookup.BlockIndex - 2},
402-
txs: []common.Hash{randomHash(), testHash},
403-
results: []light.TxStatus{{}, testStatus},
404-
},
405-
// Retrieve mixed transactions from unindexed peer(but the target is not available)
406-
{
407-
peers: 3,
408-
txLookups: []uint64{uint64(blocks) - testStatus.Lookup.BlockIndex - 1, uint64(blocks) - testStatus.Lookup.BlockIndex - 1, uint64(blocks) - testStatus.Lookup.BlockIndex - 2},
409-
txs: []common.Hash{randomHash(), testHash},
410-
results: []light.TxStatus{{}, {}},
411-
},
412-
}
413-
for _, testspec := range testspecs {
414-
// Create a bunch of server peers with different tx history
415-
var (
416-
serverPeers []*testPeer
417-
closeFns []func()
418-
)
419-
for i := 0; i < testspec.peers; i++ {
420-
peer, closePeer, _ := client.newRawPeer(t, fmt.Sprintf("server-%d", i), protocol, testspec.txLookups[i])
421-
serverPeers = append(serverPeers, peer)
422-
closeFns = append(closeFns, closePeer)
423-
424-
// Create a one-time routine for serving message
425-
go func(i int, peer *testPeer, lookup uint64) {
426-
serveMsg(peer, lookup)
427-
}(i, peer, testspec.txLookups[i])
428-
}
429-
430-
// Send out the GetTxStatus requests, compare the result with
431-
// expected value.
432-
r := &light.TxStatusRequest{Hashes: testspec.txs}
433-
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
434-
defer cancel()
435-
436-
err := client.handler.backend.odr.RetrieveTxStatus(ctx, r)
437-
if err != nil {
438-
t.Errorf("Failed to retrieve tx status %v", err)
439-
} else {
440-
if !reflect.DeepEqual(testspec.results, r.Status) {
441-
t.Errorf("Result mismatch, diff")
442-
}
443-
}
444-
445-
// Close all connected peers and start the next round
446-
for _, closeFn := range closeFns {
447-
closeFn()
448-
}
449-
}
450-
}
451-
452-
// randomHash generates a random blob of data and returns it as a hash.
453-
func randomHash() common.Hash {
454-
var hash common.Hash
455-
if n, err := rand.Read(hash[:]); n != common.HashLength || err != nil {
456-
panic(err)
457-
}
458-
return hash
459-
}

les/peer.go

+7-32
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,6 @@ func (p *peerCommons) handshake(td *big.Int, head common.Hash, headNum uint64, g
272272
send = send.add("headNum", headNum)
273273
send = send.add("genesisHash", genesis)
274274

275-
// If the protocol version is beyond les4, then pass the forkID
276-
// as well. Check http://eips.ethereum.org/EIPS/eip-2124 for more
277-
// spec detail.
278-
if p.version >= lpv5 {
279-
send = send.add("forkID", forkID)
280-
}
281275
// Add client-specified or server-specified fields
282276
if sendCallback != nil {
283277
sendCallback(&send)
@@ -311,16 +305,6 @@ func (p *peerCommons) handshake(td *big.Int, head common.Hash, headNum uint64, g
311305
if int(rVersion) != p.version {
312306
return errResp(ErrProtocolVersionMismatch, "%d (!= %d)", rVersion, p.version)
313307
}
314-
// Check forkID if the protocol version is beyond the les4
315-
if p.version >= lpv5 {
316-
var forkID forkid.ID
317-
if err := recv.get("forkID", &forkID); err != nil {
318-
return err
319-
}
320-
if err := forkFilter(forkID); err != nil {
321-
return errResp(ErrForkIDRejected, "%v", err)
322-
}
323-
}
324308
if recvCallback != nil {
325309
return recvCallback(recv)
326310
}
@@ -715,18 +699,12 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter
715699
if recv.get("txRelay", nil) != nil {
716700
p.onlyAnnounce = true
717701
}
718-
if p.version >= lpv5 {
719-
var recentTx uint
720-
if err := recv.get("recentTxLookup", &recentTx); err != nil {
721-
return err
722-
}
723-
p.txHistory = uint64(recentTx)
724-
} else {
725-
// The weak assumption is held here that legacy les server(les2,3)
726-
// has unlimited transaction history. The les serving in these legacy
727-
// versions is disabled if the transaction is unindexed.
728-
p.txHistory = txIndexUnlimited
729-
}
702+
703+
// The weak assumption is held here that legacy les server(les2,3)
704+
// has unlimited transaction history. The les serving in these legacy
705+
// versions is disabled if the transaction is unindexed.
706+
p.txHistory = txIndexUnlimited
707+
730708
if p.onlyAnnounce && !p.trusted {
731709
return errResp(ErrUselessPeer, "peer cannot serve requests")
732710
}
@@ -1139,7 +1117,7 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge
11391117
if server.config.UltraLightOnlyAnnounce {
11401118
recentTx = txIndexDisabled
11411119
}
1142-
if recentTx != txIndexUnlimited && p.version < lpv5 {
1120+
if recentTx != txIndexUnlimited {
11431121
return errors.New("Cannot serve old clients without a complete tx index")
11441122
}
11451123
// Note: clientPeer.headInfo should contain the last head announced to the client by us.
@@ -1161,9 +1139,6 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge
11611139
*lists = (*lists).add("serveRecentState", stateRecent)
11621140
*lists = (*lists).add("txRelay", nil)
11631141
}
1164-
if p.version >= lpv5 {
1165-
*lists = (*lists).add("recentTxLookup", recentTx)
1166-
}
11671142
*lists = (*lists).add("flowControl/BL", server.defParams.BufLimit)
11681143
*lists = (*lists).add("flowControl/MRR", server.defParams.MinRecharge)
11691144

les/protocol.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ import (
3535
const (
3636
lpv2 = 2
3737
lpv3 = 3
38-
lpv5 = 5 // eth lpv4
3938
)
4039

4140
// Supported versions of the les protocol (first is primary)
4241
var (
43-
ClientProtocolVersions = []uint{lpv2, lpv3, lpv5}
44-
ServerProtocolVersions = []uint{lpv2, lpv3, lpv5}
42+
ClientProtocolVersions = []uint{lpv2, lpv3}
43+
ServerProtocolVersions = []uint{lpv2, lpv3}
4544
AdvertiseProtocolVersions = []uint{lpv2} // clients are searching for the first advertised protocol in the list
4645
)
4746

4847
// Number of implemented message corresponding to different protocol versions.
49-
var ProtocolLengths = map[uint]uint64{lpv2: 24, lpv3: 26, lpv5: 28}
48+
var ProtocolLengths = map[uint]uint64{lpv2: 24, lpv3: 26}
5049

5150
const (
5251
NetworkId = 1

0 commit comments

Comments
 (0)