Skip to content
Snippets Groups Projects
Commit 9655ec6d authored by Hans Moog's avatar Hans Moog
Browse files

Feat: reworked objectStorage for writebatch

parent c4452efa
Branches
No related tags found
No related merge requests found
......@@ -294,10 +294,6 @@ func (ledgerState *LedgerState) storeTransferOutputBooking(transferOutputBooking
return ledgerState.transferOutputBookings.Store(transferOutputBooking)
}
func (ledgerState *LedgerState) getTransferOutputBooking(key []byte) (*objectstorage.CachedObject, error) {
return ledgerState.transferOutputBookings.Load(key)
}
func (ledgerState *LedgerState) sortRealityIds(aggregatedRealities map[RealityId]*objectstorage.CachedObject) []RealityId {
counter := 0
sortedRealityIds := make([]RealityId, len(aggregatedRealities))
......
......@@ -2,7 +2,9 @@ package ledgerstate
import (
"fmt"
"strconv"
"testing"
"time"
"github.com/iotaledger/goshimmer/packages/objectstorage"
)
......@@ -22,22 +24,16 @@ var (
func Benchmark(b *testing.B) {
ledgerState := NewLedgerState("testLedger").Prune().AddTransferOutput(
transferHash1, addressHash1, NewColoredBalance(eth, 1337), NewColoredBalance(iota, 1338),
transferHash1, addressHash1, NewColoredBalance(eth, 1337),
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ledgerState.BookTransfer(NewTransfer(transferHash2).AddInput(
ledgerState.BookTransfer(NewTransfer(NewTransferHash(strconv.Itoa(i))).AddInput(
NewTransferOutputReference(transferHash1, addressHash1),
).AddOutput(
addressHash3, NewColoredBalance(iota, 338),
).AddOutput(
addressHash3, NewColoredBalance(eth, 337),
).AddOutput(
addressHash4, NewColoredBalance(iota, 1000),
).AddOutput(
addressHash4, NewColoredBalance(eth, 1000),
addressHash3, NewColoredBalance(eth, 1337),
))
}
}
......@@ -74,11 +70,13 @@ func Test(t *testing.T) {
addressHash4, NewColoredBalance(eth, 1000),
))
time.Sleep(1 * time.Second)
ledgerState.ForEachTransferOutput(func(object *objectstorage.CachedObject) bool {
object.Consume(func(object objectstorage.StorableObject) {
fmt.Println(object.(*TransferOutput))
})
return true
}, MAIN_REALITY_ID)
}, MAIN_REALITY_ID, addressHash1)
}
......@@ -68,7 +68,7 @@ func (transferOutput *TransferOutput) addConsumer(consumer TransferHash) error {
return err
}
} else {
panic("DOUBLE SPEND DETECTED")
//return errors.New("DOUBLE SPEND DETECTED")
}
transferOutput.consumers[consumer] = void
......
......@@ -103,7 +103,7 @@ func runBatchWriter() {
}
}
if err := wb.Flush(); err != nil {
if err := wb.Flush(); err != nil && err != badger.ErrBlockedWrites {
panic(err)
}
......
......@@ -50,7 +50,7 @@ func (cachedObject *CachedObject) Release() {
} else {
batchWrite(cachedObject)
}
} else if consumers > 0 {
} else if consumers < 0 {
panic("called Release() too often")
}
}
......
......@@ -55,6 +55,8 @@ func (objectStorage *ObjectStorage) Delete(key []byte) {
})
}
// Foreach can only iterate over persisted entries, so there might be a slight delay before you can find previously
// stored items in such an iteration.
func (objectStorage *ObjectStorage) ForEach(consumer func(key []byte, cachedObject *CachedObject) bool, optionalPrefixes ...[]byte) error {
return objectStorage.badgerInstance.View(func(txn *badger.Txn) error {
iteratorOptions := badger.DefaultIteratorOptions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment