Skip to content

Commit

Permalink
commitment domain: make .kvi default index (#13276)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Dec 30, 2024
1 parent 0e548a4 commit dd3663a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
12 changes: 11 additions & 1 deletion erigon-lib/state/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func domainIntegrityCheck(name kv.Domain, dirs datadir.Dirs, fromStep, toStep ui
}
}

var dbgCommBtIndex = dbg.EnvBool("AGG_COMMITMENT_BT", false)

func init() {
if dbgCommBtIndex {
cfg := Schema[kv.CommitmentDomain]
cfg.indexList = withBTree | withExistence
Schema[kv.CommitmentDomain] = cfg
}
}

var Schema = map[kv.Domain]domainCfg{
kv.AccountsDomain: {
name: kv.AccountsDomain, valuesTable: kv.TblAccountVals,
Expand Down Expand Up @@ -195,7 +205,7 @@ var Schema = map[kv.Domain]domainCfg{
kv.CommitmentDomain: {
name: kv.CommitmentDomain, valuesTable: kv.TblCommitmentVals,

indexList: withBTree | withExistence,
indexList: withHashMap,
compression: seg.CompressKeys,
compressCfg: DomainCompressCfg,

Expand Down
21 changes: 18 additions & 3 deletions erigon-lib/state/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,24 @@ func TestAggregator_RebuildCommitmentBasedOnFiles(t *testing.T) {
compression := ac.d[kv.CommitmentDomain].d.compression
fnames := []string{}
for _, f := range ac.d[kv.CommitmentDomain].files {
k, stateVal, _, found, err := f.src.bindex.Get(keyCommitmentState, seg.NewReader(f.src.decompressor.MakeGetter(), compression))
require.NoError(t, err)
require.True(t, found)
var k, stateVal []byte
if ac.d[kv.CommitmentDomain].d.indexList&withHashMap != 0 {
idx := f.src.index.GetReaderFromPool()
r := seg.NewReader(f.src.decompressor.MakeGetter(), compression)

offset, ok := idx.TwoLayerLookup(keyCommitmentState)
require.True(t, ok)
r.Reset(offset)
k, _ = r.Next(nil)
stateVal, _ = r.Next(nil)
} else {
var found bool
var err error
k, stateVal, _, found, err = f.src.bindex.Get(keyCommitmentState, seg.NewReader(f.src.decompressor.MakeGetter(), compression))
require.NoError(t, err)
require.True(t, found)
require.EqualValues(t, keyCommitmentState, k)
}
require.EqualValues(t, keyCommitmentState, k)
rh, err := commitment.HexTrieExtractStateRoot(stateVal)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/state/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ func (d *Domain) buildFileRange(ctx context.Context, stepFrom, stepTo uint64, co
if err = d.buildAccessor(ctx, stepFrom, stepTo, valuesDecomp, ps); err != nil {
return StaticFiles{}, fmt.Errorf("build %s values idx: %w", d.filenameBase, err)
}
valuesIdx, err = recsplit.OpenIndex(d.efAccessorFilePath(stepFrom, stepTo))
valuesIdx, err = recsplit.OpenIndex(d.kvAccessorFilePath(stepFrom, stepTo))
if err != nil {
return StaticFiles{}, err
}
Expand Down Expand Up @@ -1158,7 +1158,7 @@ func (d *Domain) buildFiles(ctx context.Context, step uint64, collation Collatio
if err = d.buildAccessor(ctx, step, step+1, valuesDecomp, ps); err != nil {
return StaticFiles{}, fmt.Errorf("build %s values idx: %w", d.filenameBase, err)
}
valuesIdx, err = recsplit.OpenIndex(d.efAccessorFilePath(step, step+1))
valuesIdx, err = recsplit.OpenIndex(d.kvAccessorFilePath(step, step+1))
if err != nil {
return StaticFiles{}, err
}
Expand Down

0 comments on commit dd3663a

Please sign in to comment.