mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 13:40:05 +00:00
b747ab5324
* Initial commit for CallTraces index * Fix compilation * fix lint, add comment * Fix integration * Add Close function to ethdb.Cursor, fix some compile errors * Try to stop cursor leak in Get * Fix compile errors in RPC daemon * Fix compile errors * fixing another way * Some fixes * More fixes * More fixes * More fixes * Fixes to core/state * Fix lint * Fix lint * Fixes * Stage caching for call trace stage * Add mem stats * Try to stop the leak * Turn off debug * Chunks for 10k blocks * Print * Revert "Print" This reverts commit 5ffada4828d61e00e5dad1ca12c98258dfbbad00. * Revert "Chunks for 10k blocks" This reverts commit cfb9d498e782e5583d41c30abf0e2137da27383e. * Trying to fix the leak * Don't compute receipts in re-tracing * Not compose block * Print speed, fix receipts, bigger caches * Fix lint * Utilise changeset info * Counters * Use NoReceipts and ReadOnly * ReadOnly is incompatible with caching * Skip test leaking transactions * Fix block test * Change disable message for call-traces stage * Use block option for call traces integration * Fix retracing due to incarnation
121 lines
4.4 KiB
Go
121 lines
4.4 KiB
Go
// Copyright 2017 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package eth
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/common/bitutil"
|
|
"github.com/ledgerwatch/turbo-geth/core"
|
|
"github.com/ledgerwatch/turbo-geth/core/bloombits"
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
)
|
|
|
|
const (
|
|
// bloomServiceThreads is the number of goroutines used globally by an Ethereum
|
|
// instance to service bloombits lookups for all running filters.
|
|
bloomServiceThreads = 16
|
|
|
|
// bloomFilterThreads is the number of goroutines used locally per filter to
|
|
// multiplex requests onto the global servicing goroutines.
|
|
bloomFilterThreads = 3
|
|
|
|
// bloomRetrievalBatch is the maximum number of bloom bit retrievals to service
|
|
// in a single batch.
|
|
bloomRetrievalBatch = 16
|
|
|
|
// bloomRetrievalWait is the maximum time to wait for enough bloom bit requests
|
|
// to accumulate request an entire batch (avoiding hysteresis).
|
|
bloomRetrievalWait = time.Duration(0)
|
|
)
|
|
|
|
// startBloomHandlers starts a batch of goroutines to accept bloom bit database
|
|
// retrievals from possibly a range of filters and serving the data to satisfy.
|
|
func (eth *Ethereum) startBloomHandlers(sectionSize uint64) {
|
|
}
|
|
|
|
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 a core.ChainIndexer, 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 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,
|
|
}
|
|
|
|
return core.NewChainIndexer(db, dbutils.BloomBitsIndexPrefix, 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(blockNr uint64) error {
|
|
batch := b.db.NewBatch()
|
|
for i := 0; i < types.BloomBitLength; i++ {
|
|
bits, err := b.gen.Bitset(uint(i))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if bits != nil {
|
|
rawdb.WriteBloomBits(batch, uint(i), b.section, b.head, bitutil.CompressBytes(bits))
|
|
}
|
|
}
|
|
_, err := batch.Commit()
|
|
return err
|
|
}
|
|
|
|
// Prune returns an empty error since we don't support pruning here.
|
|
func (b *BloomIndexer) Prune(threshold uint64) error {
|
|
return nil
|
|
}
|