les, params: use bloombitBlocksClient as a replacement

This commit is contained in:
rjl493456442 2018-07-18 12:30:02 +08:00
parent aef61b0c37
commit 98abaf09b7
6 changed files with 17 additions and 13 deletions

View file

@ -189,7 +189,7 @@ func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
return 0, 0
}
sections, _, _ := b.eth.bloomIndexer.Sections()
return params.BloomTrieFrequency, sections
return params.BloomBitsBlocksClient, sections
}
func (b *LesApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) {

View file

@ -106,9 +106,9 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
shutdownChan: make(chan bool),
networkId: config.NetworkId,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: eth.NewBloomIndexer(chainDb, params.BloomTrieFrequency, params.BloomConfirms),
bloomIndexer: eth.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
chtIndexer: light.NewChtIndexer(chainDb, params.CHTFrequencyClient, params.HelperTrieConfirmations),
bloomTrieIndexer: light.NewBloomTrieIndexer(chainDb, params.BloomTrieFrequency, params.BloomConfirms,
bloomTrieIndexer: light.NewBloomTrieIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations,
params.BloomTrieFrequency, params.HelperTrieConfirmations),
}
@ -223,7 +223,7 @@ func (s *LightEthereum) Protocols() []p2p.Protocol {
// Start implements node.Service, starting all internal goroutines needed by the
// Ethereum protocol implementation.
func (s *LightEthereum) Start(srvr *p2p.Server) error {
s.startBloomHandlers(params.BloomTrieFrequency, params.HelperTrieConfirmations)
s.startBloomHandlers(params.BloomBitsBlocksClient, params.HelperTrieConfirmations)
log.Warn("Light client mode is an experimental feature")
s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.networkId)
// clients are searching for the first advertised protocol in the list

View file

@ -450,13 +450,13 @@ func testGetCHTProofs(t *testing.T, protocol int) {
func TestGetBloombitsProofs(t *testing.T) {
// Assemble the test environment
db := ethdb.NewMemDatabase()
pm := newTestProtocolManagerMust(t, false, params.BloomTrieFrequency+256, testChainGen, nil, nil, db)
pm := newTestProtocolManagerMust(t, false, int(params.BloomBitsBlocksClient)+256, testChainGen, nil, nil, db)
bc := pm.blockchain.(*core.BlockChain)
peer, _ := newTestPeer(t, "peer", 2, pm, true)
defer peer.close()
// Wait a while for the bloombits indexer to process the new headers
time.Sleep(100 * time.Millisecond * time.Duration(params.BloomTrieFrequency/4096)) // Chain indexer throttling
time.Sleep(100 * time.Millisecond * time.Duration(params.BloomBitsBlocksClient/4096)) // Chain indexer throttling
time.Sleep(250 * time.Millisecond) // CI tester slack
// Request and verify each bit of the bloom bits proofs
@ -465,7 +465,7 @@ func TestGetBloombitsProofs(t *testing.T) {
key := make([]byte, 10)
binary.BigEndian.PutUint16(key[:2], uint16(bit))
binary.BigEndian.PutUint64(key[2:], uint64(params.BloomTrieFrequency))
binary.BigEndian.PutUint64(key[2:], params.BloomBitsBlocksClient)
requests := []HelperTrieReq{{
Type: htBloomBits,
@ -474,7 +474,7 @@ func TestGetBloombitsProofs(t *testing.T) {
}}
var proofs HelperTrieResps
root := light.GetBloomTrieRoot(db, 0, bc.GetHeaderByNumber(params.BloomTrieFrequency-1).Hash())
root := light.GetBloomTrieRoot(db, 0, bc.GetHeaderByNumber(params.BloomBitsBlocksClient-1).Hash())
trie, _ := trie.New(root, trie.NewDatabase(ethdb.NewTable(db, light.BloomTrieTablePrefix)))
trie.Prove(key, 0, &proofs.Proofs)

View file

@ -168,8 +168,8 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
db := ethdb.NewMemDatabase()
ldb := ethdb.NewMemDatabase()
odr := NewLesOdr(ldb, light.NewChtIndexer(db, params.CHTFrequencyClient, params.HelperTrieConfirmations),
light.NewBloomTrieIndexer(db, params.BloomTrieFrequency, params.BloomConfirms, params.BloomTrieFrequency, params.HelperTrieConfirmations),
eth.NewBloomIndexer(db, params.BloomTrieFrequency, params.BloomConfirms), rm)
light.NewBloomTrieIndexer(db, params.BloomBitsBlocksClient, params.HelperTrieConfirmations, params.BloomTrieFrequency, params.HelperTrieConfirmations),
eth.NewBloomIndexer(db, params.BloomBitsBlocksClient, params.HelperTrieConfirmations), rm)
pm := newTestProtocolManagerMust(t, false, 4, testChainGen, nil, nil, db)
lpm := newTestProtocolManagerMust(t, true, 0, nil, peers, odr, ldb)
_, err1, lpeer, err2 := newTestPeerPair("peer", protocol, pm, lpm)

View file

@ -91,8 +91,8 @@ func testAccess(t *testing.T, protocol int, fn accessTestFn) {
db := ethdb.NewMemDatabase()
ldb := ethdb.NewMemDatabase()
odr := NewLesOdr(ldb, light.NewChtIndexer(db, params.CHTFrequencyClient, params.HelperTrieConfirmations),
light.NewBloomTrieIndexer(db, params.BloomTrieFrequency, params.BloomConfirms, params.BloomTrieFrequency, params.HelperTrieConfirmations),
eth.NewBloomIndexer(db, params.BloomTrieFrequency, params.BloomConfirms), rm)
light.NewBloomTrieIndexer(db, params.BloomBitsBlocksClient, params.HelperTrieConfirmations, params.BloomTrieFrequency, params.HelperTrieConfirmations),
eth.NewBloomIndexer(db, params.BloomBitsBlocksClient, params.HelperTrieConfirmations), rm)
pm := newTestProtocolManagerMust(t, false, 4, testChainGen, nil, nil, db)
lpm := newTestProtocolManagerMust(t, true, 0, nil, peers, odr, ldb)

View file

@ -24,6 +24,10 @@ const (
// contains.
BloomBitsBlocks uint64 = 4096
// BloomBitsBlocksClient is the number of blocks a single bloom bit section vector
// contains on the light client side
BloomBitsBlocksClient uint64 = 32768
// BloomConfirms is the number of confirmation blocks before a bloom section is
// considered probably final and its rotated bits are calculated.
BloomConfirms = 256