Skip to content

Commit

Permalink
progress #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 committed Jun 14, 2022
1 parent cad32ee commit 519fd20
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ethdb/olddb/memorymutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type memorymutation struct {
memDb kv.RwDB
deletedEntries map[string]map[string]struct{}
clearedTables map[string]struct{}
dupsortTables map[string]struct{}
db kv.Tx
}

Expand All @@ -54,11 +53,6 @@ func NewMemoryBatch(tx kv.Tx) *memorymutation {
memTx: memTx,
deletedEntries: make(map[string]map[string]struct{}),
clearedTables: make(map[string]struct{}),
dupsortTables: map[string]struct{}{
kv.AccountChangeSet: {},
kv.StorageChangeSet: {},
kv.HashedStorage: {},
},
}
}

Expand Down Expand Up @@ -305,7 +299,7 @@ func (m *memorymutation) Flush(tx kv.RwTx) error {
}
// Iterate over each bucket and apply changes accordingly.
for _, bucket := range buckets {
if _, ok := m.dupsortTables[bucket]; ok && bucket != kv.HashedStorage {
if isTablePurelyDupsort(bucket) {
cbucket, err := m.memTx.CursorDupSort(bucket)
if err != nil {
return err
Expand Down Expand Up @@ -343,6 +337,16 @@ func (m *memorymutation) Flush(tx kv.RwTx) error {
return nil
}

// Check if a bucket is dupsorted and has dupsort conversion off
func isTablePurelyDupsort(bucket string) bool {
config, ok := kv.ChaindataTablesCfg[bucket]
// If we do not have the configuration we assume it is not dupsorted
if !ok {
return false
}
return !config.AutoDupSortKeysConversion && config.Flags == kv.DupSort
}

// Cursor creates a new cursor (the real fun begins here)
func (m *memorymutation) makeCursor(bucket string) (kv.RwCursorDupSort, error) {
c := &memorymutationcursor{}
Expand All @@ -361,8 +365,7 @@ func (m *memorymutation) makeCursor(bucket string) (kv.RwCursorDupSort, error) {
if err != nil {
return nil, err
}
_, isDupsort := m.dupsortTables[bucket]
c.isDupsort = isDupsort
c.isDupsort = isTablePurelyDupsort(bucket)
c.memCursor = c.memDupCursor
c.mutation = m
return c, err
Expand Down

0 comments on commit 519fd20

Please sign in to comment.