Skip to content

Commit

Permalink
Address some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
karimodm committed Sep 19, 2023
1 parent ca2f8f4 commit 3a3b48e
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 106 deletions.
9 changes: 4 additions & 5 deletions pkg/protocol/enginemanager/enginemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type engineInfo struct {
Name string `json:"name"`
}

// region EngineManager ////////////////////////////////////////////////////////////////////////////////////////////////

type EngineManager struct {
directory *utils.Directory
dbVersion byte
Expand Down Expand Up @@ -261,12 +259,11 @@ func (e *EngineManager) loadEngineInstanceWithStorage(engineAlias string, storag
}

func (e *EngineManager) ForkEngineAtSlot(index iotago.SlotIndex) (*engine.Engine, error) {
engineAlias := lo.PanicOnErr(uuid.NewUUID()).String()
engineAlias := newEngineAlias()
errorHandler := func(err error) {
e.errorHandler(ierrors.Wrapf(err, "engine (%s)", engineAlias[0:8]))
}

// TODO: lock active instance so it doesn't use storage when we clone it
// Copy raw data on disk.
newStorage, err := storage.CloneStorage(e.activeInstance.Storage, e.directory.Path(engineAlias), e.dbVersion, errorHandler, e.storageOptions...)
if err != nil {
Expand Down Expand Up @@ -324,4 +321,6 @@ func (e *EngineManager) OnEngineCreated(handler func(*engine.Engine)) (unsubscri
return e.engineCreated.Hook(handler).Unhook
}

// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
func newEngineAlias() string {
return lo.PanicOnErr(uuid.NewUUID()).String()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package performance

import (
"fmt"

"github.com/iotaledger/hive.go/ds"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/kvstore"
Expand Down Expand Up @@ -94,7 +92,6 @@ func (t *Tracker) ApplyEpoch(epoch iotago.EpochIndex, committee *account.Account
timeProvider := t.apiProvider.APIForEpoch(epoch).TimeProvider()
epochStartSlot := timeProvider.EpochStart(epoch)
epochEndSlot := timeProvider.EpochEnd(epoch)
fmt.Println("apply epoch", epoch, committee.TotalStake(), committee.TotalValidatorStake())
profitMargin := calculateProfitMargin(committee.TotalValidatorStake(), committee.TotalStake())
poolsStats := &model.PoolsStats{
TotalStake: committee.TotalStake(),
Expand All @@ -105,7 +102,7 @@ func (t *Tracker) ApplyEpoch(epoch iotago.EpochIndex, committee *account.Account
if err := t.poolStatsStore.Store(epoch, poolsStats); err != nil {
panic(ierrors.Wrapf(err, "failed to store pool stats for epoch %d", epoch))
}
fmt.Println("commit epoch", epoch)

rewardsMap, err := t.rewardsMap(epoch)
if err != nil {
panic(ierrors.Wrapf(err, "failed to create rewards tree for epoch %d", epoch))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"github.com/iotaledger/hive.go/ds/types"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/kvstore"
"github.com/iotaledger/hive.go/runtime/syncutils"
"github.com/iotaledger/hive.go/serializer/v2/byteutils"
Expand Down Expand Up @@ -117,6 +118,10 @@ func (s *lockedKVStore) Close() error {
s.instanceMutex.RLock()
defer s.instanceMutex.RUnlock()

if err := s.FlushWithoutLocking(); err != nil {
return ierrors.Wrap(err, "failed to flush database")
}

return s.CloseWithoutLocking()
}
func (s *lockedKVStore) CloseWithoutLocking() error {
Expand Down
1 change: 0 additions & 1 deletion pkg/storage/prunable/prunable.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (p *Prunable) Rollback(targetSlotIndex iotago.SlotIndex) error {

// Removed entries that belong to the old fork and cannot be re-used.
for epochIdx := lastCommittedEpoch + 1; ; epochIdx++ {
fmt.Println("rollback before if", epochIdx, targetSlotEpoch)
if epochIdx > targetSlotEpoch {
shouldRollback, err := p.shouldRollbackCommittee(epochIdx, targetSlotIndex)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,4 @@ func (s *Storage) Shutdown() {
func (s *Storage) Flush() {
s.permanent.Flush()
s.prunable.Flush()
}

func (s *Storage) RollbackPrunable(targetIndex iotago.SlotIndex) error {
return s.prunable.Rollback(targetIndex)
}
}

Check failure on line 145 in pkg/storage/storage.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/storage/storage.go#L145

File is not `gofmt`-ed with `-s` (gofmt)
Raw output
pkg/storage/storage.go:145: File is not `gofmt`-ed with `-s` (gofmt)
}
4 changes: 4 additions & 0 deletions pkg/storage/storage_prunable.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ func (s *Storage) RestoreFromDisk() {

s.lastPrunedEpoch.MarkEvicted(lastPrunedEpoch)
}

func (s *Storage) RollbackPrunable(targetIndex iotago.SlotIndex) error {
return s.prunable.Rollback(targetIndex)
}
183 changes: 92 additions & 91 deletions pkg/testsuite/mock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/iotaledger/hive.go/runtime/syncutils"
"github.com/iotaledger/hive.go/runtime/workerpool"
"github.com/iotaledger/iota-core/pkg/blockfactory"
"github.com/iotaledger/iota-core/pkg/core/account"
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol"
"github.com/iotaledger/iota-core/pkg/protocol/chainmanager"
Expand Down Expand Up @@ -222,11 +223,11 @@ func (n *Node) attachEngineLogs(failOnBlockFiltered bool, instance *engine.Engin
defer n.mutex.Unlock()
n.attachedBlocks = append(n.attachedBlocks, block)
})
//
//events.BlockDAG.BlockSolid.Hook(func(block *blocks.Block) {
// fmt.Printf("%s > [%s] BlockDAG.BlockSolid: %s\n", n.Name, engineName, block.ID())
//})
//

events.BlockDAG.BlockSolid.Hook(func(block *blocks.Block) {
fmt.Printf("%s > [%s] BlockDAG.BlockSolid: %s\n", n.Name, engineName, block.ID())
})

events.BlockDAG.BlockInvalid.Hook(func(block *blocks.Block, err error) {
fmt.Printf("%s > [%s] BlockDAG.BlockInvalid: %s - %s\n", n.Name, engineName, block.ID(), err)
})
Expand Down Expand Up @@ -340,92 +341,92 @@ func (n *Node) attachEngineLogs(failOnBlockFiltered bool, instance *engine.Engin
fmt.Printf("%s > [%s] NotarizationManager.LatestCommitmentUpdated: %s\n", n.Name, engineName, commitment.ID())
})

//events.BlockGadget.BlockPreAccepted.Hook(func(block *blocks.Block) {
// fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockPreAccepted: %s %s\n", n.Name, engineName, block.ID(), block.ProtocolBlock().SlotCommitmentID)
//})
//
//events.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) {
// fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockAccepted: %s @ slot %s committing to %s\n", n.Name, engineName, block.ID(), block.ID().Index(), block.ProtocolBlock().SlotCommitmentID)
//})
//
//events.BlockGadget.BlockPreConfirmed.Hook(func(block *blocks.Block) {
// fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockPreConfirmed: %s %s\n", n.Name, engineName, block.ID(), block.ProtocolBlock().SlotCommitmentID)
//})
//
//events.BlockGadget.BlockConfirmed.Hook(func(block *blocks.Block) {
// fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockConfirmed: %s %s\n", n.Name, engineName, block.ID(), block.ProtocolBlock().SlotCommitmentID)
//})
//
//events.SlotGadget.SlotFinalized.Hook(func(slotIndex iotago.SlotIndex) {
// fmt.Printf("%s > [%s] Consensus.SlotGadget.SlotFinalized: %s\n", n.Name, engineName, slotIndex)
//})
//
//events.SeatManager.OnlineCommitteeSeatAdded.Hook(func(seat account.SeatIndex, accountID iotago.AccountID) {
// fmt.Printf("%s > [%s] SybilProtection.OnlineCommitteeSeatAdded: %d - %s\n", n.Name, engineName, seat, accountID)
//})
//
//events.SeatManager.OnlineCommitteeSeatRemoved.Hook(func(seat account.SeatIndex) {
// fmt.Printf("%s > [%s] SybilProtection.OnlineCommitteeSeatRemoved: %d\n", n.Name, engineName, seat)
//})
//
//events.ConflictDAG.ConflictCreated.Hook(func(conflictID iotago.TransactionID) {
// fmt.Printf("%s > [%s] ConflictDAG.ConflictCreated: %s\n", n.Name, engineName, conflictID)
//})
//
//events.ConflictDAG.ConflictEvicted.Hook(func(conflictID iotago.TransactionID) {
// fmt.Printf("%s > [%s] ConflictDAG.ConflictEvicted: %s\n", n.Name, engineName, conflictID)
//})
//events.ConflictDAG.ConflictRejected.Hook(func(conflictID iotago.TransactionID) {
// fmt.Printf("%s > [%s] ConflictDAG.ConflictRejected: %s\n", n.Name, engineName, conflictID)
//})
//
//events.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) {
// fmt.Printf("%s > [%s] ConflictDAG.ConflictAccepted: %s\n", n.Name, engineName, conflictID)
//})
//
//instance.Ledger.OnTransactionAttached(func(transactionMetadata mempool.TransactionMetadata) {
// fmt.Printf("%s > [%s] Ledger.TransactionAttached: %s\n", n.Name, engineName, transactionMetadata.ID())
//
// transactionMetadata.OnSolid(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionSolid: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnExecuted(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionExecuted: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnBooked(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionBooked: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnConflicting(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionConflicting: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnAccepted(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionAccepted: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnRejected(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionRejected: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnInvalid(func(err error) {
// fmt.Printf("%s > [%s] MemPool.TransactionInvalid(%s): %s\n", n.Name, engineName, err, transactionMetadata.ID())
// })
//
// transactionMetadata.OnOrphaned(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionOrphaned: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnCommitted(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionCommitted: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//
// transactionMetadata.OnPending(func() {
// fmt.Printf("%s > [%s] MemPool.TransactionPending: %s\n", n.Name, engineName, transactionMetadata.ID())
// })
//})
events.BlockGadget.BlockPreAccepted.Hook(func(block *blocks.Block) {
fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockPreAccepted: %s %s\n", n.Name, engineName, block.ID(), block.ProtocolBlock().SlotCommitmentID)
})

Check failure on line 347 in pkg/testsuite/mock/node.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/testsuite/mock/node.go#L347

File is not `gofmt`-ed with `-s` (gofmt)
Raw output
pkg/testsuite/mock/node.go:347: File is not `gofmt`-ed with `-s` (gofmt)
	
events.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) {
fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockAccepted: %s @ slot %s committing to %s\n", n.Name, engineName, block.ID(), block.ID().Index(), block.ProtocolBlock().SlotCommitmentID)
})

events.BlockGadget.BlockPreConfirmed.Hook(func(block *blocks.Block) {
fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockPreConfirmed: %s %s\n", n.Name, engineName, block.ID(), block.ProtocolBlock().SlotCommitmentID)
})

events.BlockGadget.BlockConfirmed.Hook(func(block *blocks.Block) {
fmt.Printf("%s > [%s] Consensus.BlockGadget.BlockConfirmed: %s %s\n", n.Name, engineName, block.ID(), block.ProtocolBlock().SlotCommitmentID)
})

events.SlotGadget.SlotFinalized.Hook(func(slotIndex iotago.SlotIndex) {
fmt.Printf("%s > [%s] Consensus.SlotGadget.SlotFinalized: %s\n", n.Name, engineName, slotIndex)
})

events.SeatManager.OnlineCommitteeSeatAdded.Hook(func(seat account.SeatIndex, accountID iotago.AccountID) {
fmt.Printf("%s > [%s] SybilProtection.OnlineCommitteeSeatAdded: %d - %s\n", n.Name, engineName, seat, accountID)
})

events.SeatManager.OnlineCommitteeSeatRemoved.Hook(func(seat account.SeatIndex) {
fmt.Printf("%s > [%s] SybilProtection.OnlineCommitteeSeatRemoved: %d\n", n.Name, engineName, seat)
})

events.ConflictDAG.ConflictCreated.Hook(func(conflictID iotago.TransactionID) {
fmt.Printf("%s > [%s] ConflictDAG.ConflictCreated: %s\n", n.Name, engineName, conflictID)
})

events.ConflictDAG.ConflictEvicted.Hook(func(conflictID iotago.TransactionID) {
fmt.Printf("%s > [%s] ConflictDAG.ConflictEvicted: %s\n", n.Name, engineName, conflictID)
})
events.ConflictDAG.ConflictRejected.Hook(func(conflictID iotago.TransactionID) {
fmt.Printf("%s > [%s] ConflictDAG.ConflictRejected: %s\n", n.Name, engineName, conflictID)
})

events.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) {
fmt.Printf("%s > [%s] ConflictDAG.ConflictAccepted: %s\n", n.Name, engineName, conflictID)
})

instance.Ledger.OnTransactionAttached(func(transactionMetadata mempool.TransactionMetadata) {
fmt.Printf("%s > [%s] Ledger.TransactionAttached: %s\n", n.Name, engineName, transactionMetadata.ID())

transactionMetadata.OnSolid(func() {
fmt.Printf("%s > [%s] MemPool.TransactionSolid: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnExecuted(func() {
fmt.Printf("%s > [%s] MemPool.TransactionExecuted: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnBooked(func() {
fmt.Printf("%s > [%s] MemPool.TransactionBooked: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnConflicting(func() {
fmt.Printf("%s > [%s] MemPool.TransactionConflicting: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnAccepted(func() {
fmt.Printf("%s > [%s] MemPool.TransactionAccepted: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnRejected(func() {
fmt.Printf("%s > [%s] MemPool.TransactionRejected: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnInvalid(func(err error) {
fmt.Printf("%s > [%s] MemPool.TransactionInvalid(%s): %s\n", n.Name, engineName, err, transactionMetadata.ID())
})

transactionMetadata.OnOrphaned(func() {
fmt.Printf("%s > [%s] MemPool.TransactionOrphaned: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnCommitted(func() {
fmt.Printf("%s > [%s] MemPool.TransactionCommitted: %s\n", n.Name, engineName, transactionMetadata.ID())
})

transactionMetadata.OnPending(func() {
fmt.Printf("%s > [%s] MemPool.TransactionPending: %s\n", n.Name, engineName, transactionMetadata.ID())
})
})
}

func (n *Node) Wait() {
Expand Down

0 comments on commit 3a3b48e

Please sign in to comment.