mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
- Change Go version from 1.24.6 to 1.22.8 (stable version) - Ensure all build scripts have executable permissions - Fix covdata issue by using stable Go version - CI should now pass all checks
81 lines
2.8 KiB
Go
81 lines
2.8 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package eth
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/luxfi/evm/core"
|
|
"github.com/luxfi/evm/core/bloombits"
|
|
"github.com/luxfi/evm/plugin/evm/customrawdb"
|
|
"github.com/luxfi/geth/common"
|
|
"github.com/luxfi/geth/common/bitutil"
|
|
"github.com/luxfi/geth/core/rawdb"
|
|
"github.com/luxfi/geth/core/types"
|
|
"github.com/luxfi/geth/ethdb"
|
|
)
|
|
|
|
const (
|
|
// bloomThrottling is the time to wait between processing two consecutive index sections.
|
|
// It's useful during chain upgrades to prevent disk overload.
|
|
bloomThrottling = 100 * time.Millisecond
|
|
)
|
|
|
|
// BloomIndexer implements core.ChainIndexerBackend, building up a rotated bloom bits index
|
|
// for the Ethereum header bloom filters, permitting blazing fast filtering.
|
|
type BloomIndexer struct {
|
|
size uint64 // section size to generate bloombits for
|
|
db ethdb.Database // database instance to write index data and metadata into
|
|
gen *bloombits.Generator // generator to rotate the bloom bits crating the bloom index
|
|
section uint64 // Section is the section number being processed currently
|
|
head common.Hash // Head is the hash of the last header processed
|
|
}
|
|
|
|
// NewBloomIndexer returns a bloom chain indexer that generates bloom bits data for the
|
|
// canonical chain for fast logs filtering.
|
|
func NewBloomIndexer(db ethdb.Database, size, confirms uint64) *core.ChainIndexer {
|
|
backend := &BloomIndexer{
|
|
db: db,
|
|
size: size,
|
|
}
|
|
table := rawdb.NewTable(db, "blt")
|
|
return core.NewChainIndexer(db, table, backend, size, confirms, bloomThrottling, "bloombits")
|
|
}
|
|
|
|
// Reset implements core.ChainIndexerBackend, starting a new bloombits index
|
|
// section.
|
|
func (b *BloomIndexer) Reset(ctx context.Context, section uint64, lastSectionHead common.Hash) error {
|
|
gen, err := bloombits.NewGenerator(uint(b.size))
|
|
b.gen, b.section, b.head = gen, section, common.Hash{}
|
|
return err
|
|
}
|
|
|
|
// Process implements core.ChainIndexerBackend, adding a new header's bloom into
|
|
// the index.
|
|
func (b *BloomIndexer) Process(ctx context.Context, header *types.Header) error {
|
|
b.gen.AddBloom(uint(header.Number.Uint64()-b.section*b.size), header.Bloom)
|
|
b.head = header.Hash()
|
|
return nil
|
|
}
|
|
|
|
// Commit implements core.ChainIndexerBackend, finalizing the bloom section and
|
|
// writing it out into the database.
|
|
func (b *BloomIndexer) Commit() error {
|
|
batch := b.db.NewBatch()
|
|
for i := 0; i < types.BloomBitLength; i++ {
|
|
bits, err := b.gen.Bitset(uint(i))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
customrawdb.WriteBloomBits(batch, uint(i), b.section, b.head, bitutil.CompressBytes(bits))
|
|
}
|
|
return batch.Write()
|
|
}
|
|
|
|
// Prune returns an empty error since we don't support pruning here.
|
|
func (b *BloomIndexer) Prune(threshold uint64) error {
|
|
return nil
|
|
}
|