diff --git a/cmd/hack/hack.go b/cmd/hack/hack.go index 4f03dc380..ebdebd054 100644 --- a/cmd/hack/hack.go +++ b/cmd/hack/hack.go @@ -819,7 +819,7 @@ func trimTxs(chaindata string) error { txId := iter.Next() var key [8]byte binary.BigEndian.PutUint64(key[:], txId) - if err = txs.Delete(key[:], nil); err != nil { + if err = txs.Delete(key[:]); err != nil { return err } deleted++ diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index d3cb77845..e7055635d 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -1065,7 +1065,7 @@ func printAppliedMigrations(db kv.RwDB, ctx context.Context) error { func removeMigration(db kv.RwDB, ctx context.Context) error { return db.Update(ctx, func(tx kv.RwTx) error { - return tx.Delete(kv.Migrations, []byte(migration), nil) + return tx.Delete(kv.Migrations, []byte(migration)) }) } diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index b44037706..864a39f82 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -65,7 +65,7 @@ func TruncateCanonicalHash(tx kv.RwTx, blockFrom uint64, deleteHeaders bool) err if deleteHeaders { deleteHeader(tx, common.BytesToHash(v), blockFrom) } - return tx.Delete(kv.HeaderCanonical, k, nil) + return tx.Delete(kv.HeaderCanonical, k) }); err != nil { return fmt.Errorf("TruncateCanonicalHash: %w", err) } @@ -151,7 +151,7 @@ func WriteHeadBlockHash(db kv.Putter, hash common.Hash) { // DeleteHeaderNumber removes hash->number mapping. func DeleteHeaderNumber(db kv.Deleter, hash common.Hash) { - if err := db.Delete(kv.HeaderNumber, hash[:], nil); err != nil { + if err := db.Delete(kv.HeaderNumber, hash[:]); err != nil { log.Crit("Failed to delete hash mapping", "err", err) } } @@ -333,10 +333,10 @@ func WriteHeader(db kv.Putter, header *types.Header) { // deleteHeader - dangerous, use DeleteAncientBlocks/TruncateBlocks methods func deleteHeader(db kv.Deleter, hash common.Hash, number uint64) { - if err := db.Delete(kv.Headers, dbutils.HeaderKey(number, hash), nil); err != nil { + if err := db.Delete(kv.Headers, dbutils.HeaderKey(number, hash)); err != nil { log.Crit("Failed to delete header", "err", err) } - if err := db.Delete(kv.HeaderNumber, hash.Bytes(), nil); err != nil { + if err := db.Delete(kv.HeaderNumber, hash.Bytes()); err != nil { log.Crit("Failed to delete hash to number mapping", "err", err) } } @@ -710,7 +710,7 @@ func WriteSenders(db kv.Putter, hash common.Hash, number uint64, senders []commo // deleteBody removes all block body data associated with a hash. func deleteBody(db kv.Deleter, hash common.Hash, number uint64) { - if err := db.Delete(kv.BlockBody, dbutils.BlockBodyKey(number, hash), nil); err != nil { + if err := db.Delete(kv.BlockBody, dbutils.BlockBodyKey(number, hash)); err != nil { log.Crit("Failed to delete block body", "err", err) } } @@ -746,7 +746,7 @@ func MakeBodiesCanonical(tx kv.RwTx, from uint64, ctx context.Context, logPrefix if err := tx.Put(kv.EthTx, dbutils.EncodeBlockNumber(id), v); err != nil { return err } - if err := tx.Delete(kv.NonCanonicalTxs, k, nil); err != nil { + if err := tx.Delete(kv.NonCanonicalTxs, k); err != nil { return err } i++ @@ -814,7 +814,7 @@ func MakeBodiesNonCanonical(tx kv.RwTx, from uint64, deleteBodies bool, ctx cont return err } } - if err := tx.Delete(kv.EthTx, k, nil); err != nil { + if err := tx.Delete(kv.EthTx, k); err != nil { return err } i++ @@ -901,7 +901,7 @@ func WriteTd(db kv.Putter, hash common.Hash, number uint64, td *big.Int) error { // TruncateTd removes all block total difficulty from block number N func TruncateTd(tx kv.RwTx, blockFrom uint64) error { if err := tx.ForEach(kv.HeaderTD, dbutils.EncodeBlockNumber(blockFrom), func(k, _ []byte) error { - return tx.Delete(kv.HeaderTD, k, nil) + return tx.Delete(kv.HeaderTD, k) }); err != nil { return fmt.Errorf("TruncateTd: %w", err) } @@ -1068,7 +1068,7 @@ func AppendReceipts(tx kv.StatelessWriteTx, blockNumber uint64, receipts types.R // TruncateReceipts removes all receipt for given block number or newer func TruncateReceipts(db kv.RwTx, number uint64) error { if err := db.ForEach(kv.Receipts, dbutils.EncodeBlockNumber(number), func(k, _ []byte) error { - return db.Delete(kv.Receipts, k, nil) + return db.Delete(kv.Receipts, k) }); err != nil { return err } @@ -1076,7 +1076,7 @@ func TruncateReceipts(db kv.RwTx, number uint64) error { from := make([]byte, 8) binary.BigEndian.PutUint64(from, number) if err := db.ForEach(kv.Log, from, func(k, _ []byte) error { - return db.Delete(kv.Log, k, nil) + return db.Delete(kv.Log, k) }); err != nil { return err } @@ -1228,7 +1228,7 @@ func DeleteAncientBlocks(tx kv.RwTx, blockTo uint64, blocksDeleteLimit int) (del if !isCanonical { bucket = kv.NonCanonicalTxs } - if err = tx.Delete(bucket, txIDBytes, nil); err != nil { + if err = tx.Delete(bucket, txIDBytes); err != nil { return } } @@ -1236,10 +1236,10 @@ func DeleteAncientBlocks(tx kv.RwTx, blockTo uint64, blocksDeleteLimit int) (del // Copying k because otherwise the same memory will be reused // for the next key and Delete below will end up deleting 1 more record than required kCopy := common.CopyBytes(k) - if err = tx.Delete(kv.Headers, kCopy, nil); err != nil { + if err = tx.Delete(kv.Headers, kCopy); err != nil { return } - if err = tx.Delete(kv.BlockBody, kCopy, nil); err != nil { + if err = tx.Delete(kv.BlockBody, kCopy); err != nil { return } } @@ -1335,7 +1335,7 @@ func TruncateBlocks(ctx context.Context, tx kv.RwTx, blockFrom uint64) error { bucket = kv.NonCanonicalTxs } if err := tx.ForEach(bucket, dbutils.EncodeBlockNumber(b.BaseTxId), func(k, _ []byte) error { - if err := tx.Delete(bucket, k, nil); err != nil { + if err := tx.Delete(bucket, k); err != nil { return err } return nil @@ -1349,10 +1349,10 @@ func TruncateBlocks(ctx context.Context, tx kv.RwTx, blockFrom uint64) error { // Copying k because otherwise the same memory will be reused // for the next key and Delete below will end up deleting 1 more record than required kCopy := common.CopyBytes(k) - if err := tx.Delete(kv.Headers, kCopy, nil); err != nil { + if err := tx.Delete(kv.Headers, kCopy); err != nil { return err } - if err := tx.Delete(kv.BlockBody, kCopy, nil); err != nil { + if err := tx.Delete(kv.BlockBody, kCopy); err != nil { return err } @@ -1517,12 +1517,12 @@ func ReadAncestor(db kv.Getter, hash common.Hash, number, ancestor uint64, maxNo func DeleteNewerEpochs(tx kv.RwTx, number uint64) error { if err := tx.ForEach(kv.PendingEpoch, dbutils.EncodeBlockNumber(number), func(k, v []byte) error { - return tx.Delete(kv.Epoch, k, nil) + return tx.Delete(kv.Epoch, k) }); err != nil { return err } return tx.ForEach(kv.Epoch, dbutils.EncodeBlockNumber(number), func(k, v []byte) error { - return tx.Delete(kv.Epoch, k, nil) + return tx.Delete(kv.Epoch, k) }) } func ReadEpoch(tx kv.Tx, blockNum uint64, blockHash common.Hash) (transitionProof []byte, err error) { diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index 14e312e9a..00672d865 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -60,7 +60,7 @@ func WriteTxLookupEntries(db kv.Putter, block *types.Block) { // DeleteTxLookupEntry removes all transaction data associated with a hash. func DeleteTxLookupEntry(db kv.Deleter, hash common.Hash) error { - return db.Delete(kv.TxLookup, hash.Bytes(), nil) + return db.Delete(kv.TxLookup, hash.Bytes()) } // ReadTransactionByHash retrieves a specific transaction from the database, along with diff --git a/core/rawdb/accessors_metadata.go b/core/rawdb/accessors_metadata.go index b2d29ce7f..f4a3bdec3 100644 --- a/core/rawdb/accessors_metadata.go +++ b/core/rawdb/accessors_metadata.go @@ -59,5 +59,5 @@ func WriteChainConfig(db kv.Putter, hash common.Hash, cfg *params.ChainConfig) e // DeleteChainConfig retrieves the consensus settings based on the given genesis hash. func DeleteChainConfig(db kv.Deleter, hash common.Hash) error { - return db.Delete(kv.ConfigTable, hash[:], nil) + return db.Delete(kv.ConfigTable, hash[:]) } diff --git a/core/rawdb/bor_receipts.go b/core/rawdb/bor_receipts.go index 48a07967b..9df622909 100644 --- a/core/rawdb/bor_receipts.go +++ b/core/rawdb/bor_receipts.go @@ -113,7 +113,7 @@ func WriteBorReceipt(tx kv.RwTx, hash common.Hash, number uint64, borReceipt *ty func DeleteBorReceipt(tx kv.RwTx, hash common.Hash, number uint64) { key := borReceiptKey(number) - if err := tx.Delete(kv.BorReceipts, key, nil); err != nil { + if err := tx.Delete(kv.BorReceipts, key); err != nil { log.Crit("Failed to delete bor receipt", "err", err) } } @@ -211,7 +211,7 @@ func computeBorTransactionForBlock(db kv.Tx, block *types.Block) (types.Transact // TruncateBorReceipts removes all bor receipt for given block number or newer func TruncateBorReceipts(db kv.RwTx, number uint64) error { if err := db.ForEach(kv.BorReceipts, dbutils.EncodeBlockNumber(number), func(k, _ []byte) error { - return db.Delete(kv.BorReceipts, k, nil) + return db.Delete(kv.BorReceipts, k) }); err != nil { return err } diff --git a/core/rawdb/rawdbreset/reset_stages.go b/core/rawdb/rawdbreset/reset_stages.go index 2bf60380e..c2ccc90d7 100644 --- a/core/rawdb/rawdbreset/reset_stages.go +++ b/core/rawdb/rawdbreset/reset_stages.go @@ -70,7 +70,7 @@ func ResetBlocks(tx kv.RwTx) error { } // ensure no garbage records left (it may happen if db is inconsistent) - if err := tx.ForEach(kv.BlockBody, dbutils.EncodeBlockNumber(2), func(k, _ []byte) error { return tx.Delete(kv.BlockBody, k, nil) }); err != nil { + if err := tx.ForEach(kv.BlockBody, dbutils.EncodeBlockNumber(2), func(k, _ []byte) error { return tx.Delete(kv.BlockBody, k) }); err != nil { return err } if err := tx.ClearBucket(kv.NonCanonicalTxs); err != nil { diff --git a/core/state/database_test.go b/core/state/database_test.go index c7f69c880..47580c09b 100644 --- a/core/state/database_test.go +++ b/core/state/database_test.go @@ -1376,7 +1376,7 @@ func TestCacheCodeSizeInTrie(t *testing.T) { assert.NoError(t, err, "you can receive the code size ") assert.Equal(t, len(code), codeSize, "you can receive the code size") - assert.NoError(t, tx.Delete(kv.Code, codeHash[:], nil), nil) + assert.NoError(t, tx.Delete(kv.Code, codeHash[:]), nil) codeSize2, err := r.ReadAccountCodeSize(contract, 1, codeHash) assert.NoError(t, err, "you can still receive code size even with empty DB") diff --git a/core/state/db_state_writer.go b/core/state/db_state_writer.go index 5e5adcd9a..98929e398 100644 --- a/core/state/db_state_writer.go +++ b/core/state/db_state_writer.go @@ -84,7 +84,7 @@ func (dsw *DbStateWriter) DeleteAccount(address common.Address, original *accoun if err != nil { return err } - if err := dsw.db.Delete(kv.HashedAccounts, addrHash[:], nil); err != nil { + if err := dsw.db.Delete(kv.HashedAccounts, addrHash[:]); err != nil { return err } if original.Incarnation > 0 { @@ -136,7 +136,7 @@ func (dsw *DbStateWriter) WriteAccountStorage(address common.Address, incarnatio v := value.Bytes() if len(v) == 0 { - return dsw.db.Delete(kv.HashedStorage, compositeKey, nil) + return dsw.db.Delete(kv.HashedStorage, compositeKey) } return dsw.db.Put(kv.HashedStorage, compositeKey, v) } diff --git a/core/state/plain_state_writer.go b/core/state/plain_state_writer.go index bce28a27b..89a758fd1 100644 --- a/core/state/plain_state_writer.go +++ b/core/state/plain_state_writer.go @@ -82,7 +82,7 @@ func (w *PlainStateWriter) DeleteAccount(address common.Address, original *accou if w.accumulator != nil { w.accumulator.DeleteAccount(address) } - if err := w.db.Delete(kv.PlainState, address[:], nil); err != nil { + if err := w.db.Delete(kv.PlainState, address[:]); err != nil { return err } if original.Incarnation > 0 { @@ -112,7 +112,7 @@ func (w *PlainStateWriter) WriteAccountStorage(address common.Address, incarnati w.accumulator.ChangeStorage(address, incarnation, *key, v) } if len(v) == 0 { - return w.db.Delete(kv.PlainState, compositeKey, nil) + return w.db.Delete(kv.PlainState, compositeKey) } return w.db.Put(kv.PlainState, compositeKey, v) } diff --git a/core/state/recon_state_1.go b/core/state/recon_state_1.go index 7572a3a61..249e454c5 100644 --- a/core/state/recon_state_1.go +++ b/core/state/recon_state_1.go @@ -135,7 +135,7 @@ func (rs *ReconState1) Flush(rwTx kv.RwTx) error { var err error t.Ascend(func(item ReconStateItem1) bool { if len(item.val) == 0 { - if err = rwTx.Delete(table, item.key, nil); err != nil { + if err = rwTx.Delete(table, item.key); err != nil { return false } //fmt.Printf("Flush [%x]=>\n", ks) diff --git a/eth/stagedsync/stage_execute.go b/eth/stagedsync/stage_execute.go index 478568064..0566c40aa 100644 --- a/eth/stagedsync/stage_execute.go +++ b/eth/stagedsync/stage_execute.go @@ -489,7 +489,7 @@ func unwindExecutionStage(u *UnwindState, s *StageState, tx kv.RwTx, quit <-chan if original != nil { // clean up all the code incarnations original incarnation and the new one for incarnation := original.Incarnation; incarnation > acc.Incarnation && incarnation > 0; incarnation-- { - err = tx.Delete(kv.PlainContractCode, dbutils.PlainGenerateStoragePrefix(address[:], incarnation), nil) + err = tx.Delete(kv.PlainContractCode, dbutils.PlainGenerateStoragePrefix(address[:], incarnation)) if err != nil { return fmt.Errorf("writeAccountPlain for %x: %w", address, err) } diff --git a/eth/stagedsync/stage_interhashes.go b/eth/stagedsync/stage_interhashes.go index 5fcab1f24..7f830abf2 100644 --- a/eth/stagedsync/stage_interhashes.go +++ b/eth/stagedsync/stage_interhashes.go @@ -256,7 +256,7 @@ func (p *HashPromoter) Promote(logPrefix string, s *StageState, from, to uint64, slices.SortFunc(deletedAccounts, func(a, b []byte) bool { return bytes.Compare(a, b) < 0 }) for _, k := range deletedAccounts { if err := p.db.ForPrefix(kv.TrieOfStorage, k, func(k, v []byte) error { - if err := p.db.Delete(kv.TrieOfStorage, k, v); err != nil { + if err := p.db.Delete(kv.TrieOfStorage, k); err != nil { return err } return nil @@ -345,7 +345,7 @@ func (p *HashPromoter) Unwind(logPrefix string, s *StageState, u *UnwindState, s slices.SortFunc(deletedAccounts, func(a, b []byte) bool { return bytes.Compare(a, b) < 0 }) for _, k := range deletedAccounts { if err := p.db.ForPrefix(kv.TrieOfStorage, k, func(k, v []byte) error { - if err := p.db.Delete(kv.TrieOfStorage, k, v); err != nil { + if err := p.db.Delete(kv.TrieOfStorage, k); err != nil { return err } return nil diff --git a/eth/stagedsync/stage_interhashes_test.go b/eth/stagedsync/stage_interhashes_test.go index 91eea3bd9..6e3528c96 100644 --- a/eth/stagedsync/stage_interhashes_test.go +++ b/eth/stagedsync/stage_interhashes_test.go @@ -274,9 +274,9 @@ func TestStorageDeletion(t *testing.T) { // Delete storage and increment the trie // ---------------------------------------------------------------- - assert.Nil(t, tx.Delete(kv.HashedStorage, dbutils.GenerateCompositeStorageKey(hashedAddress, incarnation, hashedLocation1), value1)) - assert.Nil(t, tx.Delete(kv.HashedStorage, dbutils.GenerateCompositeStorageKey(hashedAddress, incarnation, hashedLocation2), value2)) - assert.Nil(t, tx.Delete(kv.HashedStorage, dbutils.GenerateCompositeStorageKey(hashedAddress, incarnation, hashedLocation3), value3)) + assert.Nil(t, tx.Delete(kv.HashedStorage, dbutils.GenerateCompositeStorageKey(hashedAddress, incarnation, hashedLocation1))) + assert.Nil(t, tx.Delete(kv.HashedStorage, dbutils.GenerateCompositeStorageKey(hashedAddress, incarnation, hashedLocation2))) + assert.Nil(t, tx.Delete(kv.HashedStorage, dbutils.GenerateCompositeStorageKey(hashedAddress, incarnation, hashedLocation3))) err = tx.Put(kv.StorageChangeSet, append(dbutils.EncodeBlockNumber(1), dbutils.PlainGenerateStoragePrefix(address[:], incarnation)...), plainLocation1[:]) assert.Nil(t, err) diff --git a/eth/stagedsync/stage_tevm.go b/eth/stagedsync/stage_tevm.go index 5e981366b..845eb6ccd 100644 --- a/eth/stagedsync/stage_tevm.go +++ b/eth/stagedsync/stage_tevm.go @@ -334,7 +334,7 @@ func UnwindTranspileStage(u *UnwindState, s *StageState, tx kv.RwTx, cfg Transpi continue } - err = tx.Delete(kv.ContractTEVMCode, codeHashBytes, nil) + err = tx.Delete(kv.ContractTEVMCode, codeHashBytes) if err != nil { return fmt.Errorf("can't delete TEVM code by hash %q: %w", codeHash, err) } diff --git a/ethdb/bitmapdb/dbutils.go b/ethdb/bitmapdb/dbutils.go index b8810d8eb..0631a4f57 100644 --- a/ethdb/bitmapdb/dbutils.go +++ b/ethdb/bitmapdb/dbutils.go @@ -99,7 +99,7 @@ func TruncateRange(db kv.RwTx, bucket string, key []byte, to uint32) error { if !bytes.HasPrefix(k, key) { return false, nil } - if err := db.Delete(bucket, k, nil); err != nil { + if err := db.Delete(bucket, k); err != nil { return false, err } return true, nil @@ -253,7 +253,7 @@ func TruncateRange64(db kv.RwTx, bucket string, key []byte, to uint64) error { if !bytes.HasPrefix(k, key) { return false, nil } - if err := cDel.Delete(k, nil); err != nil { + if err := cDel.Delete(k); err != nil { return false, err } return true, nil diff --git a/ethdb/db_interface.go b/ethdb/db_interface.go index 49ead52c2..d8a1cf590 100644 --- a/ethdb/db_interface.go +++ b/ethdb/db_interface.go @@ -61,8 +61,8 @@ type Database interface { // MinDatabase is a minimalistic version of the Database interface. type MinDatabase interface { Get(bucket string, key []byte) ([]byte, error) - Put(bucket string, key, value []byte) error - Delete(bucket string, k, v []byte) error + Put(table string, k, v []byte) error + Delete(table string, k []byte) error } // DbWithPendingMutations is an extended version of the Database, diff --git a/ethdb/olddb/database_test.go b/ethdb/olddb/database_test.go index ef34aa8ef..7767f3005 100644 --- a/ethdb/olddb/database_test.go +++ b/ethdb/olddb/database_test.go @@ -88,7 +88,7 @@ func TestPutGet(t *testing.T) { } for _, v := range testValues { - err := tx.Delete(testBucket, []byte(v), nil) + err := tx.Delete(testBucket, []byte(v)) require.NoError(t, err) } @@ -179,7 +179,7 @@ func TestParallelPutGet(t *testing.T) { go func(key string) { defer pending.Done() _ = db.Update(context.Background(), func(tx kv.RwTx) error { - err := tx.Delete(testBucket, []byte(key), nil) + err := tx.Delete(testBucket, []byte(key)) if err != nil { panic("delete failed: " + err.Error()) } diff --git a/ethdb/olddb/mapmutation.go b/ethdb/olddb/mapmutation.go index d14255220..8755385ab 100644 --- a/ethdb/olddb/mapmutation.go +++ b/ethdb/olddb/mapmutation.go @@ -161,23 +161,23 @@ func (m *mapmutation) Has(table string, key []byte) (bool, error) { } // puts a table key with a value and if the table is not found then it appends a table -func (m *mapmutation) Put(table string, key []byte, value []byte) error { +func (m *mapmutation) Put(table string, k, v []byte) error { m.mu.Lock() defer m.mu.Unlock() if _, ok := m.puts[table]; !ok { m.puts[table] = make(map[string][]byte) } - stringKey := *(*string)(unsafe.Pointer(&key)) + stringKey := *(*string)(unsafe.Pointer(&k)) var ok bool if _, ok = m.puts[table][stringKey]; !ok { - m.size += len(value) - len(m.puts[table][stringKey]) - m.puts[table][stringKey] = value + m.size += len(v) - len(m.puts[table][stringKey]) + m.puts[table][stringKey] = v return nil } - m.puts[table][stringKey] = value - m.size += len(key) + len(value) + m.puts[table][stringKey] = v + m.size += len(k) + len(v) m.count++ return nil } @@ -211,10 +211,7 @@ func (m *mapmutation) ForAmount(bucket string, prefix []byte, amount uint32, wal return m.db.ForAmount(bucket, prefix, amount, walker) } -func (m *mapmutation) Delete(table string, k, v []byte) error { - if v != nil { - return m.db.Delete(table, k, v) // TODO: mutation to support DupSort deletes - } +func (m *mapmutation) Delete(table string, k []byte) error { return m.Put(table, k, nil) } diff --git a/ethdb/olddb/mutation.go b/ethdb/olddb/mutation.go index 179e39216..4e1f7d61a 100644 --- a/ethdb/olddb/mutation.go +++ b/ethdb/olddb/mutation.go @@ -183,13 +183,13 @@ func (m *mutation) Has(table string, key []byte) (bool, error) { return false, nil } -func (m *mutation) Put(table string, key []byte, value []byte) error { +func (m *mutation) Put(table string, k, v []byte) error { m.mu.Lock() defer m.mu.Unlock() - newMi := &MutationItem{table: table, key: key, value: value} + newMi := &MutationItem{table: table, key: k, value: v} i := m.puts.ReplaceOrInsert(newMi) - m.size += int(unsafe.Sizeof(newMi)) + len(key) + len(value) + m.size += int(unsafe.Sizeof(newMi)) + len(k) + len(v) if i != nil { oldMi := i.(*MutationItem) m.size -= (int(unsafe.Sizeof(oldMi)) + len(oldMi.key) + len(oldMi.value)) @@ -226,10 +226,7 @@ func (m *mutation) ForAmount(bucket string, prefix []byte, amount uint32, walker return m.db.ForAmount(bucket, prefix, amount, walker) } -func (m *mutation) Delete(table string, k, v []byte) error { - if v != nil { - return m.db.Delete(table, k, v) // TODO: mutation to support DupSort deletes - } +func (m *mutation) Delete(table string, k []byte) error { //m.puts.Delete(table, k) return m.Put(table, k, nil) } @@ -272,7 +269,7 @@ func (m *mutation) doCommit(tx kv.RwTx) error { } } } else if len(mi.value) == 0 { - if err := c.Delete(mi.key, nil); err != nil { + if err := c.Delete(mi.key); err != nil { innerErr = err return false } diff --git a/ethdb/olddb/object_db.go b/ethdb/olddb/object_db.go index 63d84d11e..a8252f4ab 100644 --- a/ethdb/olddb/object_db.go +++ b/ethdb/olddb/object_db.go @@ -41,9 +41,9 @@ func NewObjectDatabase(kv kv.RwDB) *ObjectDatabase { } // Put inserts or updates a single entry. -func (db *ObjectDatabase) Put(bucket string, key []byte, value []byte) error { +func (db *ObjectDatabase) Put(table string, k, v []byte) error { err := db.kv.Update(context.Background(), func(tx kv.RwTx) error { - return tx.Put(bucket, key, value) + return tx.Put(table, k, v) }) return err } @@ -161,10 +161,10 @@ func (db *ObjectDatabase) ForPrefix(bucket string, prefix []byte, walker func(k, } // Delete deletes the key from the queue and database -func (db *ObjectDatabase) Delete(bucket string, k, v []byte) error { +func (db *ObjectDatabase) Delete(table string, k []byte) error { // Execute the actual operation err := db.kv.Update(context.Background(), func(tx kv.RwTx) error { - return tx.Delete(bucket, k, v) + return tx.Delete(table, k) }) return err } diff --git a/ethdb/olddb/tx_db.go b/ethdb/olddb/tx_db.go index 737e16686..5dd1ce38b 100644 --- a/ethdb/olddb/tx_db.go +++ b/ethdb/olddb/tx_db.go @@ -66,13 +66,13 @@ func (m *TxDb) ReadSequence(bucket string) (res uint64, err error) { return m.tx.ReadSequence(bucket) } -func (m *TxDb) Put(bucket string, key []byte, value []byte) error { - m.len += uint64(len(key) + len(value)) - c, err := m.cursor(bucket) +func (m *TxDb) Put(table string, k, v []byte) error { + m.len += uint64(len(k) + len(v)) + c, err := m.cursor(table) if err != nil { return err } - return c.(kv.RwCursor).Put(key, value) + return c.(kv.RwCursor).Put(k, v) } func (m *TxDb) Append(bucket string, key []byte, value []byte) error { @@ -93,13 +93,13 @@ func (m *TxDb) AppendDup(bucket string, key []byte, value []byte) error { return c.(kv.RwCursorDupSort).AppendDup(key, value) } -func (m *TxDb) Delete(bucket string, k, v []byte) error { +func (m *TxDb) Delete(table string, k []byte) error { m.len += uint64(len(k)) - c, err := m.cursor(bucket) + c, err := m.cursor(table) if err != nil { return err } - return c.(kv.RwCursor).Delete(k, v) + return c.(kv.RwCursor).Delete(k) } func (m *TxDb) begin(ctx context.Context, flags ethdb.TxFlags) error { diff --git a/go.mod b/go.mod index e4e4ff5a8..e852d2389 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon go 1.18 require ( - github.com/ledgerwatch/erigon-lib v0.0.0-20220726033341-68eb9dc34242 + github.com/ledgerwatch/erigon-lib v0.0.0-20220726054309-8e7222cd32be github.com/ledgerwatch/erigon-snapshot v1.0.0 github.com/ledgerwatch/log/v3 v3.4.1 github.com/ledgerwatch/secp256k1 v1.0.0 diff --git a/go.sum b/go.sum index c6b164d1c..05769b1ac 100644 --- a/go.sum +++ b/go.sum @@ -390,8 +390,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v0.0.0-20220726033341-68eb9dc34242 h1:lfe7qqh1abFhn+0pyEVLPc033u6toHhTXcr0EpPns0k= -github.com/ledgerwatch/erigon-lib v0.0.0-20220726033341-68eb9dc34242/go.mod h1:19wwSb5qbagorz9a4QN9FzNqSPjmOJkwa5TezGjloks= +github.com/ledgerwatch/erigon-lib v0.0.0-20220726054309-8e7222cd32be h1:DlrDNjVBEOpczYE7kUoaHnYGzKnOjqnBYlqmZkxv9fY= +github.com/ledgerwatch/erigon-lib v0.0.0-20220726054309-8e7222cd32be/go.mod h1:19wwSb5qbagorz9a4QN9FzNqSPjmOJkwa5TezGjloks= github.com/ledgerwatch/erigon-snapshot v1.0.0 h1:bp/7xoPdM5lK7LFdqEMH008RZmqxMZV0RUVEQiWs7v4= github.com/ledgerwatch/erigon-snapshot v1.0.0/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.4.1 h1:/xGwlVulXnsO9Uq+tzaExc8OWmXXHU0dnLalpbnY5Bc= diff --git a/migrations/migrations.go b/migrations/migrations.go index 2013a0fa8..1890bca35 100644 --- a/migrations/migrations.go +++ b/migrations/migrations.go @@ -222,7 +222,7 @@ func (m *Migrator) Apply(db kv.RwDB, dataDir string) error { return err } - err = tx.Delete(kv.Migrations, []byte("_progress_"+v.Name), nil) + err = tx.Delete(kv.Migrations, []byte("_progress_"+v.Name)) if err != nil { return err } diff --git a/migrations/txs_begin_end.go b/migrations/txs_begin_end.go index fbcc16c16..70af6c5b1 100644 --- a/migrations/txs_begin_end.go +++ b/migrations/txs_begin_end.go @@ -100,14 +100,14 @@ var txsBeginEnd = Migration{ } // del first tx in block - if err = tx.Delete(kv.EthTx, dbutils.EncodeBlockNumber(b.BaseTxId), nil); err != nil { + if err = tx.Delete(kv.EthTx, dbutils.EncodeBlockNumber(b.BaseTxId)); err != nil { return err } if err := writeTransactionsNewDeprecated(tx, txs, b.BaseTxId+1); err != nil { return fmt.Errorf("failed to write body txs: %w", err) } // del last tx in block - if err = tx.Delete(kv.EthTx, dbutils.EncodeBlockNumber(b.BaseTxId+uint64(b.TxAmount)-1), nil); err != nil { + if err = tx.Delete(kv.EthTx, dbutils.EncodeBlockNumber(b.BaseTxId+uint64(b.TxAmount)-1)); err != nil { return err } @@ -133,24 +133,24 @@ var txsBeginEnd = Migration{ for i := bodyForStorage.BaseTxId; i < bodyForStorage.BaseTxId+uint64(bodyForStorage.TxAmount); i++ { binary.BigEndian.PutUint64(numBuf, i) - if err = tx.Delete(kv.NonCanonicalTxs, numBuf, nil); err != nil { + if err = tx.Delete(kv.NonCanonicalTxs, numBuf); err != nil { return err } } - if err = tx.Delete(kv.BlockBody, k, nil); err != nil { + if err = tx.Delete(kv.BlockBody, k); err != nil { return err } - if err = tx.Delete(kv.Headers, k, nil); err != nil { + if err = tx.Delete(kv.Headers, k); err != nil { return err } - if err = tx.Delete(kv.HeaderTD, k, nil); err != nil { + if err = tx.Delete(kv.HeaderTD, k); err != nil { return err } - if err = tx.Delete(kv.HeaderNumber, k[8:], nil); err != nil { + if err = tx.Delete(kv.HeaderNumber, k[8:]); err != nil { return err } - if err = tx.Delete(kv.HeaderNumber, k[8:], nil); err != nil { + if err = tx.Delete(kv.HeaderNumber, k[8:]); err != nil { return err } @@ -314,7 +314,7 @@ func makeBodiesNonCanonicalDeprecated(tx kv.RwTx, from uint64, ctx context.Conte return err } id++ - return tx.Delete(kv.EthTx, k, nil) + return tx.Delete(kv.EthTx, k) }); err != nil { return err }