mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-08 07:06:43 +00:00
Delete existing UTXOSet when commiting VirtualUTXOSet. (#1403)
This commit is contained in:
parent
8ad5725421
commit
ce348373c6
@ -9,6 +9,22 @@ type dbTransaction struct {
|
|||||||
transaction database.Transaction
|
transaction database.Transaction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *dbTransaction) Get(key model.DBKey) ([]byte, error) {
|
||||||
|
return d.transaction.Get(dbKeyToDatabaseKey(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbTransaction) Has(key model.DBKey) (bool, error) {
|
||||||
|
return d.transaction.Has(dbKeyToDatabaseKey(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dbTransaction) Cursor(bucket model.DBBucket) (model.DBCursor, error) {
|
||||||
|
cursor, err := d.transaction.Cursor(dbBucketToDatabaseBucket(bucket))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newDBCursor(cursor), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *dbTransaction) Put(key model.DBKey, value []byte) error {
|
func (d *dbTransaction) Put(key model.DBKey, value []byte) error {
|
||||||
return d.transaction.Put(dbKeyToDatabaseKey(key), value)
|
return d.transaction.Put(dbKeyToDatabaseKey(key), value)
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,23 @@ func (css *consensusStateStore) commitVirtualUTXOSet(dbTx model.DBTransaction) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the existing virtual utxo set in database before adding the new one
|
||||||
|
cursor, err := dbTx.Cursor(utxoSetBucket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for cursor.Next() {
|
||||||
|
key, err := cursor.Key()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = dbTx.Delete(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now put the new virtualUTXOSet into the database
|
||||||
css.virtualUTXOSetCache.Clear()
|
css.virtualUTXOSetCache.Clear()
|
||||||
iterator := css.virtualUTXOSetStaging.Iterator()
|
iterator := css.virtualUTXOSetStaging.Iterator()
|
||||||
for iterator.Next() {
|
for iterator.Next() {
|
||||||
|
@ -58,6 +58,7 @@ type DBWriter interface {
|
|||||||
// access that requires an open database transaction
|
// access that requires an open database transaction
|
||||||
type DBTransaction interface {
|
type DBTransaction interface {
|
||||||
DBWriter
|
DBWriter
|
||||||
|
DBReader
|
||||||
|
|
||||||
// Rollback rolls back whatever changes were made to the
|
// Rollback rolls back whatever changes were made to the
|
||||||
// database within this transaction.
|
// database within this transaction.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user