Skip to content

Commit 64f9c1e

Browse files
committed
les, light: remove support for les/1 4096 block CHT sections
1 parent 5515f36 commit 64f9c1e

8 files changed

Lines changed: 26 additions & 68 deletions

File tree

‎les/backend.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
119119
leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool)
120120

121121
leth.odr = NewLesOdr(chainDb, light.DefaultClientIndexerConfig, leth.retriever)
122-
leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequencyClient, params.HelperTrieConfirmations)
122+
leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequency, params.HelperTrieConfirmations)
123123
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency)
124124
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
125125

‎les/benchmark.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ func (b *benchmarkHelperTrie) init(pm *ProtocolManager, count int) error {
135135
b.sectionCount, b.headNum, _ = pm.server.bloomTrieIndexer.Sections()
136136
} else {
137137
b.sectionCount, _, _ = pm.server.chtIndexer.Sections()
138-
b.sectionCount /= (params.CHTFrequencyClient / params.CHTFrequencyServer)
139-
b.headNum = b.sectionCount*params.CHTFrequencyClient - 1
138+
b.headNum = b.sectionCount*params.CHTFrequency - 1
140139
}
141140
if b.sectionCount == 0 {
142141
return fmt.Errorf("no processed sections available")

‎les/commons.go‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,16 @@ func (c *lesCommons) nodeInfo() interface{} {
8080
sections, _, _ := c.chtIndexer.Sections()
8181
sections2, _, _ := c.bloomTrieIndexer.Sections()
8282

83-
if !c.protocolManager.lightSync {
84-
// convert to client section size if running in server mode
85-
sections /= c.iConfig.PairChtSize / c.iConfig.ChtSize
86-
}
87-
8883
if sections2 < sections {
8984
sections = sections2
9085
}
9186
if sections > 0 {
9287
sectionIndex := sections - 1
9388
sectionHead := c.bloomTrieIndexer.SectionHead(sectionIndex)
94-
var chtRoot common.Hash
95-
if c.protocolManager.lightSync {
96-
chtRoot = light.GetChtRoot(c.chainDb, sectionIndex, sectionHead)
97-
} else {
98-
idxV2 := (sectionIndex+1)*c.iConfig.PairChtSize/c.iConfig.ChtSize - 1
99-
chtRoot = light.GetChtRoot(c.chainDb, idxV2, sectionHead)
100-
}
10189
cht = params.TrustedCheckpoint{
10290
SectionIndex: sectionIndex,
10391
SectionHead: sectionHead,
104-
CHTRoot: chtRoot,
92+
CHTRoot: light.GetChtRoot(c.chainDb, sectionIndex, sectionHead),
10593
BloomRoot: light.GetBloomTrieRoot(c.chainDb, sectionIndex, sectionHead),
10694
}
10795
}

‎les/handler.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,8 @@ func (pm *ProtocolManager) getAccount(triedb *trie.Database, root, hash common.H
10751075
func (pm *ProtocolManager) getHelperTrie(id uint, idx uint64) (common.Hash, string) {
10761076
switch id {
10771077
case htCanonical:
1078-
idxV1 := (idx+1)*(pm.iConfig.PairChtSize/pm.iConfig.ChtSize) - 1
1079-
sectionHead := rawdb.ReadCanonicalHash(pm.chainDb, (idxV1+1)*pm.iConfig.ChtSize-1)
1080-
return light.GetChtRoot(pm.chainDb, idxV1, sectionHead), light.ChtTablePrefix
1078+
sectionHead := rawdb.ReadCanonicalHash(pm.chainDb, (idx+1)*pm.iConfig.ChtSize-1)
1079+
return light.GetChtRoot(pm.chainDb, idx, sectionHead), light.ChtTablePrefix
10811080
case htBloomBits:
10821081
sectionHead := rawdb.ReadCanonicalHash(pm.chainDb, (idx+1)*pm.iConfig.BloomTrieSize-1)
10831082
return light.GetBloomTrieRoot(pm.chainDb, idx, sectionHead), light.BloomTrieTablePrefix

‎les/handler_test.go‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,43 +342,37 @@ func TestGetCHTProofsLes2(t *testing.T) { testGetCHTProofs(t, 2) }
342342

343343
func testGetCHTProofs(t *testing.T, protocol int) {
344344
config := light.TestServerIndexerConfig
345-
frequency := config.ChtSize
346-
if protocol == 2 { //qqq
347-
frequency = config.PairChtSize
348-
}
349345

350346
waitIndexers := func(cIndexer, bIndexer, btIndexer *core.ChainIndexer) {
351-
expectSections := frequency / config.ChtSize
352347
for {
353348
cs, _, _ := cIndexer.Sections()
354-
bs, _, _ := bIndexer.Sections()
355-
if cs >= expectSections && bs >= expectSections {
349+
if cs >= 1 {
356350
break
357351
}
358352
time.Sleep(10 * time.Millisecond)
359353
}
360354
}
361-
server, tearDown := newServerEnv(t, int(frequency+config.ChtConfirms), protocol, waitIndexers)
355+
server, tearDown := newServerEnv(t, int(config.ChtSize+config.ChtConfirms), protocol, waitIndexers)
362356
defer tearDown()
363357
bc := server.pm.blockchain.(*core.BlockChain)
364358

365359
// Assemble the proofs from the different protocols
366-
header := bc.GetHeaderByNumber(frequency - 1)
360+
header := bc.GetHeaderByNumber(config.ChtSize - 1)
367361
rlp, _ := rlp.EncodeToBytes(header)
368362

369363
key := make([]byte, 8)
370-
binary.BigEndian.PutUint64(key, frequency-1)
364+
binary.BigEndian.PutUint64(key, config.ChtSize-1)
371365

372366
proofsV2 := HelperTrieResps{
373367
AuxData: [][]byte{rlp},
374368
}
375-
root := light.GetChtRoot(server.db, (frequency/config.ChtSize)-1, bc.GetHeaderByNumber(frequency-1).Hash())
369+
root := light.GetChtRoot(server.db, 0, bc.GetHeaderByNumber(config.ChtSize-1).Hash())
376370
trie, _ := trie.New(root, trie.NewDatabase(rawdb.NewTable(server.db, light.ChtTablePrefix)))
377371
trie.Prove(key, 0, &proofsV2.Proofs)
378372
// Assemble the requests for the different protocols
379373
requestsV2 := []HelperTrieReq{{
380374
Type: htCanonical,
381-
TrieIdx: frequency/config.PairChtSize - 1,
375+
TrieIdx: 0,
382376
Key: key,
383377
AuxReq: auxHeader,
384378
}}
@@ -396,10 +390,8 @@ func TestGetBloombitsProofs(t *testing.T) {
396390

397391
waitIndexers := func(cIndexer, bIndexer, btIndexer *core.ChainIndexer) {
398392
for {
399-
cs, _, _ := cIndexer.Sections()
400-
bs, _, _ := bIndexer.Sections()
401393
bts, _, _ := btIndexer.Sections()
402-
if cs >= 8 && bs >= 8 && bts >= 1 {
394+
if bts >= 1 {
403395
break
404396
}
405397
time.Sleep(10 * time.Millisecond)

‎les/server.go‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
8989
config: config,
9090
chainDb: eth.ChainDb(),
9191
iConfig: light.DefaultServerIndexerConfig,
92-
chtIndexer: light.NewChtIndexer(eth.ChainDb(), nil, params.CHTFrequencyServer, params.HelperTrieProcessConfirmations),
92+
chtIndexer: light.NewChtIndexer(eth.ChainDb(), nil, params.CHTFrequency, params.HelperTrieProcessConfirmations),
9393
bloomTrieIndexer: light.NewBloomTrieIndexer(eth.ChainDb(), nil, params.BloomBitsBlocks, params.BloomTrieFrequency),
9494
protocolManager: pm,
9595
},
@@ -108,15 +108,11 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
108108
srv.thcBlockProcessing = config.LightServ/100 + 1
109109
srv.fcManager = flowcontrol.NewClientManager(nil, &mclock.System{})
110110

111-
chtV1SectionCount, _, _ := srv.chtIndexer.Sections() // indexer still uses LES/1 4k section size for backwards server compatibility
112-
chtV2SectionCount := chtV1SectionCount / (params.CHTFrequencyClient / params.CHTFrequencyServer)
113-
if chtV2SectionCount != 0 {
114-
// convert to LES/2 section
115-
chtLastSection := chtV2SectionCount - 1
116-
// convert last LES/2 section index back to LES/1 index for chtIndexer.SectionHead
117-
chtLastSectionV1 := (chtLastSection+1)*(params.CHTFrequencyClient/params.CHTFrequencyServer) - 1
118-
chtSectionHead := srv.chtIndexer.SectionHead(chtLastSectionV1)
119-
chtRoot := light.GetChtRoot(pm.chainDb, chtLastSectionV1, chtSectionHead)
111+
chtSectionCount, _, _ := srv.chtIndexer.Sections()
112+
if chtSectionCount != 0 {
113+
chtLastSection := chtSectionCount - 1
114+
chtSectionHead := srv.chtIndexer.SectionHead(chtLastSection)
115+
chtRoot := light.GetChtRoot(pm.chainDb, chtLastSection, chtSectionHead)
120116
logger.Info("Loaded CHT", "section", chtLastSection, "head", chtSectionHead, "root", chtRoot)
121117
}
122118
bloomTrieSectionCount, _, _ := srv.bloomTrieIndexer.Sections()

‎light/postprocess.go‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ type IndexerConfig struct {
4141
// The block frequency for creating CHTs.
4242
ChtSize uint64
4343

44-
// A special auxiliary field represents client's chtsize for server config, otherwise represents server's chtsize.
45-
PairChtSize uint64
46-
4744
// The number of confirmations needed to generate/accept a canonical hash help trie.
4845
ChtConfirms uint64
4946

@@ -64,8 +61,7 @@ type IndexerConfig struct {
6461
var (
6562
// DefaultServerIndexerConfig wraps a set of configs as a default indexer config for server side.
6663
DefaultServerIndexerConfig = &IndexerConfig{
67-
ChtSize: params.CHTFrequencyServer,
68-
PairChtSize: params.CHTFrequencyClient,
64+
ChtSize: params.CHTFrequency,
6965
ChtConfirms: params.HelperTrieProcessConfirmations,
7066
BloomSize: params.BloomBitsBlocks,
7167
BloomConfirms: params.BloomConfirms,
@@ -74,8 +70,7 @@ var (
7470
}
7571
// DefaultClientIndexerConfig wraps a set of configs as a default indexer config for client side.
7672
DefaultClientIndexerConfig = &IndexerConfig{
77-
ChtSize: params.CHTFrequencyClient,
78-
PairChtSize: params.CHTFrequencyServer,
73+
ChtSize: params.CHTFrequency,
7974
ChtConfirms: params.HelperTrieConfirmations,
8075
BloomSize: params.BloomBitsBlocksClient,
8176
BloomConfirms: params.HelperTrieConfirmations,
@@ -84,8 +79,7 @@ var (
8479
}
8580
// TestServerIndexerConfig wraps a set of configs as a test indexer config for server side.
8681
TestServerIndexerConfig = &IndexerConfig{
87-
ChtSize: 64,
88-
PairChtSize: 512,
82+
ChtSize: 512,
8983
ChtConfirms: 4,
9084
BloomSize: 64,
9185
BloomConfirms: 4,
@@ -95,7 +89,6 @@ var (
9589
// TestClientIndexerConfig wraps a set of configs as a test indexer config for client side.
9690
TestClientIndexerConfig = &IndexerConfig{
9791
ChtSize: 512,
98-
PairChtSize: 64,
9992
ChtConfirms: 32,
10093
BloomSize: 512,
10194
BloomConfirms: 32,
@@ -116,7 +109,7 @@ var (
116109
ErrNoTrustedCht = errors.New("no trusted canonical hash trie")
117110
ErrNoTrustedBloomTrie = errors.New("no trusted bloom trie")
118111
ErrNoHeader = errors.New("header not found")
119-
chtPrefix = []byte("chtRoot-") // chtPrefix + chtNum (uint64 big endian) -> trie root hash
112+
chtPrefix = []byte("chtRootV2-") // chtPrefix + chtNum (uint64 big endian) -> trie root hash
120113
ChtTablePrefix = "cht-"
121114
)
122115

@@ -127,7 +120,6 @@ type ChtNode struct {
127120
}
128121

129122
// GetChtRoot reads the CHT root associated to the given section from the database
130-
// Note that sectionIdx is specified according to LES/1 CHT section size.
131123
func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) common.Hash {
132124
var encNumber [8]byte
133125
binary.BigEndian.PutUint64(encNumber[:], sectionIdx)
@@ -136,7 +128,6 @@ func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) c
136128
}
137129

138130
// StoreChtRoot writes the CHT root associated to the given section into the database
139-
// Note that sectionIdx is specified according to LES/1 CHT section size.
140131
func StoreChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead, root common.Hash) {
141132
var encNumber [8]byte
142133
binary.BigEndian.PutUint64(encNumber[:], sectionIdx)
@@ -163,7 +154,7 @@ func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64) *co
163154
triedb: trie.NewDatabaseWithCache(trieTable, 1), // Use a tiny cache only to keep memory down
164155
sectionSize: size,
165156
}
166-
return core.NewChainIndexer(db, rawdb.NewTable(db, "chtIndex-"), backend, size, confirms, time.Millisecond*100, "cht")
157+
return core.NewChainIndexer(db, rawdb.NewTable(db, "chtIndexV2-"), backend, size, confirms, time.Millisecond*100, "cht")
167158
}
168159

169160
// fetchMissingNodes tries to retrieve the last entry of the latest trusted CHT from the
@@ -235,9 +226,7 @@ func (c *ChtIndexerBackend) Commit() error {
235226
}
236227
c.triedb.Commit(root, false)
237228

238-
if ((c.section+1)*c.sectionSize)%params.CHTFrequencyClient == 0 {
239-
log.Info("Storing CHT", "section", c.section*c.sectionSize/params.CHTFrequencyClient, "head", fmt.Sprintf("%064x", c.lastHash), "root", fmt.Sprintf("%064x", root))
240-
}
229+
log.Info("Storing CHT", "section", c.section, "head", fmt.Sprintf("%064x", c.lastHash), "root", fmt.Sprintf("%064x", root))
241230
StoreChtRoot(c.diskdb, c.section, c.lastHash, root)
242231
return nil
243232
}

‎params/network_params.go‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@ const (
3232
// considered probably final and its rotated bits are calculated.
3333
BloomConfirms = 256
3434

35-
// CHTFrequencyClient is the block frequency for creating CHTs on the client side.
36-
CHTFrequencyClient = 32768
37-
38-
// CHTFrequencyServer is the block frequency for creating CHTs on the server side.
39-
// Eventually this can be merged back with the client version, but that requires a
40-
// full database upgrade, so that should be left for a suitable moment.
41-
CHTFrequencyServer = 4096
35+
// CHTFrequency is the block frequency for creating CHTs
36+
CHTFrequency = 32768
4237

4338
// BloomTrieFrequency is the block frequency for creating BloomTrie on both
4439
// server/client sides.

0 commit comments

Comments
 (0)