mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
core/filtermaps: embedded f.Params function calls
This commit is contained in:
parent
4b2ff2fe24
commit
6124e29fe9
3 changed files with 24 additions and 24 deletions
|
|
@ -403,7 +403,7 @@ func (f *FilterMaps) init() error {
|
||||||
batch := f.db.NewBatch()
|
batch := f.db.NewBatch()
|
||||||
for epoch := range bestLen {
|
for epoch := range bestLen {
|
||||||
cp := checkpoints[bestIdx][epoch]
|
cp := checkpoints[bestIdx][epoch]
|
||||||
f.storeLastBlockOfMap(batch, f.Params.lastEpochMap(uint32(epoch)), cp.BlockNumber, cp.BlockId)
|
f.storeLastBlockOfMap(batch, f.lastEpochMap(uint32(epoch)), cp.BlockNumber, cp.BlockId)
|
||||||
f.storeBlockLvPointer(batch, cp.BlockNumber, cp.FirstIndex)
|
f.storeBlockLvPointer(batch, cp.BlockNumber, cp.FirstIndex)
|
||||||
}
|
}
|
||||||
fmr := filterMapsRange{
|
fmr := filterMapsRange{
|
||||||
|
|
@ -412,7 +412,7 @@ func (f *FilterMaps) init() error {
|
||||||
if bestLen > 0 {
|
if bestLen > 0 {
|
||||||
cp := checkpoints[bestIdx][bestLen-1]
|
cp := checkpoints[bestIdx][bestLen-1]
|
||||||
fmr.blocks = common.NewRange(cp.BlockNumber+1, 0)
|
fmr.blocks = common.NewRange(cp.BlockNumber+1, 0)
|
||||||
fmr.maps = common.NewRange(f.Params.firstEpochMap(uint32(bestLen)), 0)
|
fmr.maps = common.NewRange(f.firstEpochMap(uint32(bestLen)), 0)
|
||||||
}
|
}
|
||||||
f.setRange(batch, f.targetView, fmr, false)
|
f.setRange(batch, f.targetView, fmr, false)
|
||||||
return batch.Write()
|
return batch.Write()
|
||||||
|
|
@ -583,10 +583,10 @@ func (f *FilterMaps) getFilterMapRows(mapIndices []uint32, rowIndex uint32, base
|
||||||
var ptr int
|
var ptr int
|
||||||
for len(mapIndices) > ptr {
|
for len(mapIndices) > ptr {
|
||||||
var (
|
var (
|
||||||
groupIndex = f.Params.mapGroupIndex(mapIndices[ptr])
|
groupIndex = f.mapGroupIndex(mapIndices[ptr])
|
||||||
groupLength = 1
|
groupLength = 1
|
||||||
)
|
)
|
||||||
for ptr+groupLength < len(mapIndices) && f.Params.mapGroupIndex(mapIndices[ptr+groupLength]) == groupIndex {
|
for ptr+groupLength < len(mapIndices) && f.mapGroupIndex(mapIndices[ptr+groupLength]) == groupIndex {
|
||||||
groupLength++
|
groupLength++
|
||||||
}
|
}
|
||||||
if err := f.getFilterMapRowsOfGroup(rows[ptr:ptr+groupLength], mapIndices[ptr:ptr+groupLength], rowIndex, baseLayerOnly); err != nil {
|
if err := f.getFilterMapRowsOfGroup(rows[ptr:ptr+groupLength], mapIndices[ptr:ptr+groupLength], rowIndex, baseLayerOnly); err != nil {
|
||||||
|
|
@ -601,7 +601,7 @@ func (f *FilterMaps) getFilterMapRows(mapIndices []uint32, rowIndex uint32, base
|
||||||
// belonging to the same base row group.
|
// belonging to the same base row group.
|
||||||
func (f *FilterMaps) getFilterMapRowsOfGroup(target []FilterRow, mapIndices []uint32, rowIndex uint32, baseLayerOnly bool) error {
|
func (f *FilterMaps) getFilterMapRowsOfGroup(target []FilterRow, mapIndices []uint32, rowIndex uint32, baseLayerOnly bool) error {
|
||||||
var (
|
var (
|
||||||
groupIndex = f.Params.mapGroupIndex(mapIndices[0])
|
groupIndex = f.mapGroupIndex(mapIndices[0])
|
||||||
mapRowIndex = f.mapRowIndex(groupIndex, rowIndex)
|
mapRowIndex = f.mapRowIndex(groupIndex, rowIndex)
|
||||||
)
|
)
|
||||||
baseRows, err := rawdb.ReadFilterMapBaseRows(f.db, mapRowIndex, f.baseRowGroupSize, f.logMapWidth)
|
baseRows, err := rawdb.ReadFilterMapBaseRows(f.db, mapRowIndex, f.baseRowGroupSize, f.logMapWidth)
|
||||||
|
|
@ -609,10 +609,10 @@ func (f *FilterMaps) getFilterMapRowsOfGroup(target []FilterRow, mapIndices []ui
|
||||||
return fmt.Errorf("failed to retrieve base row group %d of row %d: %v", groupIndex, rowIndex, err)
|
return fmt.Errorf("failed to retrieve base row group %d of row %d: %v", groupIndex, rowIndex, err)
|
||||||
}
|
}
|
||||||
for i, mapIndex := range mapIndices {
|
for i, mapIndex := range mapIndices {
|
||||||
if f.Params.mapGroupIndex(mapIndex) != groupIndex {
|
if f.mapGroupIndex(mapIndex) != groupIndex {
|
||||||
return fmt.Errorf("maps are not in the same base row group, index: %d, group: %d", mapIndex, groupIndex)
|
return fmt.Errorf("maps are not in the same base row group, index: %d, group: %d", mapIndex, groupIndex)
|
||||||
}
|
}
|
||||||
row := baseRows[f.Params.mapGroupOffset(mapIndex)]
|
row := baseRows[f.mapGroupOffset(mapIndex)]
|
||||||
if !baseLayerOnly {
|
if !baseLayerOnly {
|
||||||
extRow, err := rawdb.ReadFilterMapExtRow(f.db, f.mapRowIndex(mapIndex, rowIndex), f.logMapWidth)
|
extRow, err := rawdb.ReadFilterMapExtRow(f.db, f.mapRowIndex(mapIndex, rowIndex), f.logMapWidth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -631,9 +631,9 @@ func (f *FilterMaps) storeFilterMapRows(batch ethdb.Batch, mapIndices []uint32,
|
||||||
for len(mapIndices) > 0 {
|
for len(mapIndices) > 0 {
|
||||||
var (
|
var (
|
||||||
pos = 1
|
pos = 1
|
||||||
groupIndex = f.Params.mapGroupIndex(mapIndices[0])
|
groupIndex = f.mapGroupIndex(mapIndices[0])
|
||||||
)
|
)
|
||||||
for pos < len(mapIndices) && f.Params.mapGroupIndex(mapIndices[pos]) == groupIndex {
|
for pos < len(mapIndices) && f.mapGroupIndex(mapIndices[pos]) == groupIndex {
|
||||||
pos++
|
pos++
|
||||||
}
|
}
|
||||||
if err := f.storeFilterMapRowsOfGroup(batch, mapIndices[:pos], rowIndex, rows[:pos]); err != nil {
|
if err := f.storeFilterMapRowsOfGroup(batch, mapIndices[:pos], rowIndex, rows[:pos]); err != nil {
|
||||||
|
|
@ -649,7 +649,7 @@ func (f *FilterMaps) storeFilterMapRows(batch ethdb.Batch, mapIndices []uint32,
|
||||||
func (f *FilterMaps) storeFilterMapRowsOfGroup(batch ethdb.Batch, mapIndices []uint32, rowIndex uint32, rows []FilterRow) error {
|
func (f *FilterMaps) storeFilterMapRowsOfGroup(batch ethdb.Batch, mapIndices []uint32, rowIndex uint32, rows []FilterRow) error {
|
||||||
var (
|
var (
|
||||||
baseRows [][]uint32
|
baseRows [][]uint32
|
||||||
groupIndex = f.Params.mapGroupIndex(mapIndices[0])
|
groupIndex = f.mapGroupIndex(mapIndices[0])
|
||||||
mapRowIndex = f.mapRowIndex(groupIndex, rowIndex)
|
mapRowIndex = f.mapRowIndex(groupIndex, rowIndex)
|
||||||
)
|
)
|
||||||
if uint32(len(mapIndices)) != f.baseRowGroupSize { // skip base rows read if all rows are replaced
|
if uint32(len(mapIndices)) != f.baseRowGroupSize { // skip base rows read if all rows are replaced
|
||||||
|
|
@ -662,7 +662,7 @@ func (f *FilterMaps) storeFilterMapRowsOfGroup(batch ethdb.Batch, mapIndices []u
|
||||||
baseRows = make([][]uint32, f.baseRowGroupSize)
|
baseRows = make([][]uint32, f.baseRowGroupSize)
|
||||||
}
|
}
|
||||||
for i, mapIndex := range mapIndices {
|
for i, mapIndex := range mapIndices {
|
||||||
if f.Params.mapGroupIndex(mapIndex) != groupIndex {
|
if f.mapGroupIndex(mapIndex) != groupIndex {
|
||||||
return fmt.Errorf("maps are not in the same base row group, index: %d, group: %d", mapIndex, groupIndex)
|
return fmt.Errorf("maps are not in the same base row group, index: %d, group: %d", mapIndex, groupIndex)
|
||||||
}
|
}
|
||||||
baseRow := []uint32(rows[i])
|
baseRow := []uint32(rows[i])
|
||||||
|
|
@ -759,12 +759,12 @@ func (f *FilterMaps) deleteTailEpoch(epoch uint32) (bool, error) {
|
||||||
defer f.indexLock.Unlock()
|
defer f.indexLock.Unlock()
|
||||||
|
|
||||||
// determine epoch boundaries
|
// determine epoch boundaries
|
||||||
lastBlock, _, err := f.getLastBlockOfMap(f.Params.lastEpochMap(epoch))
|
lastBlock, _, err := f.getLastBlockOfMap(f.lastEpochMap(epoch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("failed to retrieve last block of deleted epoch %d: %v", epoch, err)
|
return false, fmt.Errorf("failed to retrieve last block of deleted epoch %d: %v", epoch, err)
|
||||||
}
|
}
|
||||||
var firstBlock uint64
|
var firstBlock uint64
|
||||||
firstMap := f.Params.firstEpochMap(epoch)
|
firstMap := f.firstEpochMap(epoch)
|
||||||
if epoch > 0 {
|
if epoch > 0 {
|
||||||
firstBlock, _, err = f.getLastBlockOfMap(firstMap - 1)
|
firstBlock, _, err = f.getLastBlockOfMap(firstMap - 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -775,8 +775,8 @@ func (f *FilterMaps) deleteTailEpoch(epoch uint32) (bool, error) {
|
||||||
// update rendered range if necessary
|
// update rendered range if necessary
|
||||||
var (
|
var (
|
||||||
fmr = f.indexedRange
|
fmr = f.indexedRange
|
||||||
firstEpoch = f.Params.mapEpoch(f.indexedRange.maps.First())
|
firstEpoch = f.mapEpoch(f.indexedRange.maps.First())
|
||||||
afterLastEpoch = f.Params.mapEpoch(f.indexedRange.maps.AfterLast() + f.mapsPerEpoch - 1)
|
afterLastEpoch = f.mapEpoch(f.indexedRange.maps.AfterLast() + f.mapsPerEpoch - 1)
|
||||||
)
|
)
|
||||||
if f.indexedRange.tailPartialEpoch != 0 && firstEpoch > 0 {
|
if f.indexedRange.tailPartialEpoch != 0 && firstEpoch > 0 {
|
||||||
firstEpoch--
|
firstEpoch--
|
||||||
|
|
@ -788,7 +788,7 @@ func (f *FilterMaps) deleteTailEpoch(epoch uint32) (bool, error) {
|
||||||
// first fully or partially rendered epoch and there is at least one
|
// first fully or partially rendered epoch and there is at least one
|
||||||
// rendered map in the next epoch; remove from indexed range
|
// rendered map in the next epoch; remove from indexed range
|
||||||
fmr.tailPartialEpoch = 0
|
fmr.tailPartialEpoch = 0
|
||||||
fmr.maps.SetFirst(f.Params.firstEpochMap(epoch + 1))
|
fmr.maps.SetFirst(f.firstEpochMap(epoch + 1))
|
||||||
fmr.blocks.SetFirst(lastBlock + 1)
|
fmr.blocks.SetFirst(lastBlock + 1)
|
||||||
f.setRange(f.db, f.indexedView, fmr, false)
|
f.setRange(f.db, f.indexedView, fmr, false)
|
||||||
default:
|
default:
|
||||||
|
|
@ -869,7 +869,7 @@ func (f *FilterMaps) exportCheckpoints() {
|
||||||
w.WriteString("[\n")
|
w.WriteString("[\n")
|
||||||
comma := ","
|
comma := ","
|
||||||
for epoch := uint32(0); epoch < epochCount; epoch++ {
|
for epoch := uint32(0); epoch < epochCount; epoch++ {
|
||||||
lastBlock, lastBlockId, err := f.getLastBlockOfMap(f.Params.lastEpochMap(epoch))
|
lastBlock, lastBlockId, err := f.getLastBlockOfMap(f.lastEpochMap(epoch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error fetching last block of epoch", "epoch", epoch, "error", err)
|
log.Error("Error fetching last block of epoch", "epoch", epoch, "error", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ func (f *FilterMaps) tryIndexHead() error {
|
||||||
// is changed.
|
// is changed.
|
||||||
func (f *FilterMaps) tryIndexTail() (bool, error) {
|
func (f *FilterMaps) tryIndexTail() (bool, error) {
|
||||||
for {
|
for {
|
||||||
firstEpoch := f.Params.mapEpoch(f.indexedRange.maps.First())
|
firstEpoch := f.mapEpoch(f.indexedRange.maps.First())
|
||||||
if firstEpoch == 0 || !f.needTailEpoch(firstEpoch-1) {
|
if firstEpoch == 0 || !f.needTailEpoch(firstEpoch-1) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -359,7 +359,7 @@ func (f *FilterMaps) tryIndexTail() (bool, error) {
|
||||||
// Note that unindexing is very quick as it only removes continuous ranges of
|
// Note that unindexing is very quick as it only removes continuous ranges of
|
||||||
// data from the database and is also called while running head indexing.
|
// data from the database and is also called while running head indexing.
|
||||||
func (f *FilterMaps) tryUnindexTail() (bool, error) {
|
func (f *FilterMaps) tryUnindexTail() (bool, error) {
|
||||||
firstEpoch := f.Params.mapEpoch(f.indexedRange.maps.First())
|
firstEpoch := f.mapEpoch(f.indexedRange.maps.First())
|
||||||
if f.indexedRange.tailPartialEpoch > 0 && firstEpoch > 0 {
|
if f.indexedRange.tailPartialEpoch > 0 && firstEpoch > 0 {
|
||||||
firstEpoch--
|
firstEpoch--
|
||||||
}
|
}
|
||||||
|
|
@ -392,11 +392,11 @@ func (f *FilterMaps) tryUnindexTail() (bool, error) {
|
||||||
// needTailEpoch returns true if the given tail epoch needs to be kept
|
// needTailEpoch returns true if the given tail epoch needs to be kept
|
||||||
// according to the current tail target, false if it can be removed.
|
// according to the current tail target, false if it can be removed.
|
||||||
func (f *FilterMaps) needTailEpoch(epoch uint32) bool {
|
func (f *FilterMaps) needTailEpoch(epoch uint32) bool {
|
||||||
firstEpoch := f.Params.mapEpoch(f.indexedRange.maps.First())
|
firstEpoch := f.mapEpoch(f.indexedRange.maps.First())
|
||||||
if epoch > firstEpoch {
|
if epoch > firstEpoch {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if f.Params.firstEpochMap(epoch+1) >= f.indexedRange.maps.AfterLast() {
|
if f.firstEpochMap(epoch+1) >= f.indexedRange.maps.AfterLast() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if epoch+1 < firstEpoch {
|
if epoch+1 < firstEpoch {
|
||||||
|
|
@ -405,7 +405,7 @@ func (f *FilterMaps) needTailEpoch(epoch uint32) bool {
|
||||||
var lastBlockOfPrevEpoch uint64
|
var lastBlockOfPrevEpoch uint64
|
||||||
if epoch > 0 {
|
if epoch > 0 {
|
||||||
var err error
|
var err error
|
||||||
lastBlockOfPrevEpoch, _, err = f.getLastBlockOfMap(f.Params.lastEpochMap(epoch - 1))
|
lastBlockOfPrevEpoch, _, err = f.getLastBlockOfMap(f.lastEpochMap(epoch - 1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not get last block of previous epoch", "epoch", epoch-1, "error", err)
|
log.Error("Could not get last block of previous epoch", "epoch", epoch-1, "error", err)
|
||||||
return epoch >= firstEpoch
|
return epoch >= firstEpoch
|
||||||
|
|
@ -414,7 +414,7 @@ func (f *FilterMaps) needTailEpoch(epoch uint32) bool {
|
||||||
if f.historyCutoff > lastBlockOfPrevEpoch {
|
if f.historyCutoff > lastBlockOfPrevEpoch {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
lastBlockOfEpoch, _, err := f.getLastBlockOfMap(f.Params.lastEpochMap(epoch))
|
lastBlockOfEpoch, _, err := f.getLastBlockOfMap(f.lastEpochMap(epoch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not get last block of epoch", "epoch", epoch, "error", err)
|
log.Error("Could not get last block of epoch", "epoch", epoch, "error", err)
|
||||||
return epoch >= firstEpoch
|
return epoch >= firstEpoch
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ func (r *mapRenderer) run(stopCb func() bool, writeCb func()) (bool, error) {
|
||||||
// map finished
|
// map finished
|
||||||
r.finishedMaps[r.currentMap.mapIndex] = r.currentMap
|
r.finishedMaps[r.currentMap.mapIndex] = r.currentMap
|
||||||
r.finished.SetLast(r.finished.AfterLast())
|
r.finished.SetLast(r.finished.AfterLast())
|
||||||
if len(r.finishedMaps) >= maxMapsPerBatch || r.f.Params.mapGroupOffset(r.finished.AfterLast()) == 0 {
|
if len(r.finishedMaps) >= maxMapsPerBatch || r.f.mapGroupOffset(r.finished.AfterLast()) == 0 {
|
||||||
if err := r.writeFinishedMaps(stopCb); err != nil {
|
if err := r.writeFinishedMaps(stopCb); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue