Skip to content

Commit

Permalink
Fix missing treasury balance in db-hash tool (#1907)
Browse files Browse the repository at this point in the history
* Fix missing treasury balance in db-hash tool

* Fix linter warnings

* Fix pebble L0StopWritesThreshold
  • Loading branch information
muXxer authored Aug 11, 2023
1 parent a22bed8 commit 1c371f3
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ linters:
#- containedctx
- contextcheck
- decorder
- depguard
#- depguard
- dogsled
#- dupl
- durationcheck
Expand Down
2 changes: 1 addition & 1 deletion components/inx/server_tips.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
iotago "github.com/iotaledger/iota.go/v3"
)

func (s *Server) RequestTips(ctx context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) {
func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) {
if deps.TipSelector == nil {
return nil, status.Error(codes.Unavailable, "no tipselector available")
}
Expand Down
6 changes: 1 addition & 5 deletions integration-tests/tester/framework/autopeered_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ func (n *AutopeeredNetwork) createEntryNode(privKey ed25519.PrivateKey) error {
return err
}

if err := n.entryNode.Start(); err != nil {
return err
}

return nil
return n.entryNode.Start()
}

// AwaitPeering waits until all peers have reached the minimum amount of peers.
Expand Down
6 changes: 1 addition & 5 deletions integration-tests/tester/framework/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ func (n *Network) CreateWhiteFlagMockServer(cfg *WhiteFlagMockServerConfig) erro
return err
}

if err := container.Start(); err != nil {
return err
}

return nil
return container.Start()
}

// generates a new private key or returns the one from the opt parameter.
Expand Down
6 changes: 1 addition & 5 deletions pkg/dag/concurrent_parents_traverser.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,7 @@ func (t *ConcurrentParentsTraverser) processStack(wg *sync.WaitGroup, doneChan c
}

// stop processing the stack if the caller returns an error
if err := t.onMissingParent(currentBlockID); err != nil {
return err
}

return nil
return t.onMissingParent(currentBlockID)
}
defer cachedBlockMeta.Release(true) // meta -1

Expand Down
2 changes: 1 addition & 1 deletion pkg/database/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func NewPebbleDB(directory string, reportCompactionRunning func(running bool), e
// sublevels. Writes are stopped when this threshold is reached.
//
// The default value is 12.
opts.L0StopWritesThreshold = 12
opts.L0StopWritesThreshold = 30

// The maximum number of bytes for LBase. The base level is the level which
// L0 is compacted into. The base level is determined dynamically based on
Expand Down
5 changes: 1 addition & 4 deletions pkg/model/migrator/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ func (rs *ReceiptService) Init() error {
if !rs.BackupEnabled {
return nil
}
if err := os.MkdirAll(rs.backupFolder, os.ModePerm); err != nil {
return err
}

return nil
return os.MkdirAll(rs.backupFolder, os.ModePerm)
}

// Backup backups the given receipt to disk.
Expand Down
12 changes: 2 additions & 10 deletions pkg/model/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,7 @@ func (s *Storage) configureStorages(tangleStore kvstore.KVStore, cachesProfile .
return err
}

if err := s.configureProtocolStore(tangleStore); err != nil {
return err
}

return nil
return s.configureProtocolStore(tangleStore)
}

func (s *Storage) FlushAndCloseStores() error {
Expand Down Expand Up @@ -475,9 +471,5 @@ func (s *Storage) CheckLedgerState() error {
return err
}

if err = s.UTXOManager().CheckLedgerState(protoParams.TokenSupply); err != nil {
return err
}

return nil
return s.UTXOManager().CheckLedgerState(protoParams.TokenSupply)
}
6 changes: 1 addition & 5 deletions pkg/model/utxo/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ func (u *Manager) ClearLedger(pruneReceipts bool) (err error) {
if err = u.utxoStorage.DeletePrefix([]byte{UTXOStoreKeyPrefixOutputUnspent}); err != nil {
return err
}

if err = u.utxoStorage.DeletePrefix([]byte{UTXOStoreKeyPrefixMilestoneDiffs}); err != nil {
return err
}
if err = u.utxoStorage.DeletePrefix([]byte{UTXOStoreKeyPrefixTreasuryOutput}); err != nil {
return err
}

return nil
return u.utxoStorage.DeletePrefix([]byte{UTXOStoreKeyPrefixTreasuryOutput})
}

func (u *Manager) ReadLockLedger() {
Expand Down
6 changes: 1 addition & 5 deletions pkg/snapshot/snapshot_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ func newFullHeaderConsumer(targetFullHeader *FullSnapshotHeader, utxoManager *ut

*targetFullHeader = *header

if err := utxoManager.StoreLedgerIndex(header.LedgerMilestoneIndex); err != nil {
return err
}

return nil
return utxoManager.StoreLedgerIndex(header.LedgerMilestoneIndex)
}
}

Expand Down
7 changes: 2 additions & 5 deletions pkg/snapshot/snapshot_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,6 @@ func (s *Manager) createDeltaSnapshotWithoutLocking(ctx context.Context, targetI
return err
}

timeSetSnapshotInfo := timeStreamSnapshotData
timeSnapshotMilestoneIndexChanged := timeStreamSnapshotData

// since we write to the database, the targetIndex should exist
targetMsTimestamp, err := s.storage.MilestoneTimestampByIndex(targetIndex)
if err != nil {
Expand All @@ -636,9 +633,9 @@ func (s *Manager) createDeltaSnapshotWithoutLocking(ctx context.Context, targetI
s.LogPanic(err)
}

timeSetSnapshotInfo = time.Now()
timeSetSnapshotInfo := time.Now()
s.Events.SnapshotMilestoneIndexChanged.Trigger(targetIndex)
timeSnapshotMilestoneIndexChanged = time.Now()
timeSnapshotMilestoneIndexChanged := time.Now()

snapshotMetrics.DurationInit = timeInit.Sub(timeStart)
snapshotMetrics.DurationSetSnapshotInfo = timeSetSnapshotInfo.Sub(timeStreamSnapshotData)
Expand Down
4 changes: 3 additions & 1 deletion pkg/toolset/database_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func calculateDatabaseLedgerHash(dbStorage *storage.Storage, outputJSON bool) er
return fmt.Errorf("unable to serialize ledger index: %w", err)
}

var ledgerTokenSupply uint64

// read out treasury tx
treasuryOutput, err := dbStorage.UTXOManager().UnspentTreasuryOutputWithoutLocking()
if err != nil {
Expand All @@ -79,6 +81,7 @@ func calculateDatabaseLedgerHash(dbStorage *storage.Storage, outputJSON bool) er
if err := binary.Write(lsHash, binary.LittleEndian, treasuryOutput.Amount); err != nil {
return fmt.Errorf("unable to serialize treasury output amount: %w", err)
}
ledgerTokenSupply += treasuryOutput.Amount
}

// get all UTXOs
Expand All @@ -87,7 +90,6 @@ func calculateDatabaseLedgerHash(dbStorage *storage.Storage, outputJSON bool) er
return err
}

var ledgerTokenSupply uint64
// write all unspent outputs in lexicographical order
for _, outputID := range outputIDs.RemoveDupsAndSort() {
output, err := dbStorage.UTXOManager().ReadOutputByOutputID(outputID)
Expand Down
6 changes: 1 addition & 5 deletions pkg/toolset/database_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,5 @@ func databaseHealth(args []string) error {
dbPath := *databasePathFlag
dbName := path.Base(dbPath)

if err := checkDatabaseHealth(dbPath, dbName, *outputJSONFlag); err != nil {
return err
}

return nil
return checkDatabaseHealth(dbPath, dbName, *outputJSONFlag)
}
17 changes: 3 additions & 14 deletions pkg/toolset/database_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,7 @@ func verifyDatabase(
}

// cleanup the state changes from the temporary UTXOManager to save memory
if err := cleanupMilestoneFromUTXOManager(utxoManagerTemp, milestonePayload, msIndex); err != nil {
return err
}

return nil
return cleanupMilestoneFromUTXOManager(utxoManagerTemp, milestonePayload, msIndex)
}

// we start to verify the cone with the first index after the solid entry point index of the genesis snapshot
Expand Down Expand Up @@ -343,11 +339,8 @@ func verifyDatabase(
}

println("verifying final ledger state ...")
if err := compareLedgerState(tangleStoreSource.UTXOManager(), tangleStoreTemp.UTXOManager()); err != nil {
return err
}

return nil
return compareLedgerState(tangleStoreSource.UTXOManager(), tangleStoreTemp.UTXOManager())
}

func getSolidEntryPointsSHA256Sum(dbStorage *storage.Storage) ([]byte, error) {
Expand Down Expand Up @@ -431,9 +424,5 @@ func cleanupMilestoneFromUTXOManager(utxoManager *utxo.Manager, milestonePayload
}
}

if err := utxoManager.PruneMilestoneIndexWithoutLocking(msIndex, true, receiptMigratedAtIndex...); err != nil {
return err
}

return nil
return utxoManager.PruneMilestoneIndexWithoutLocking(msIndex, true, receiptMigratedAtIndex...)
}

0 comments on commit 1c371f3

Please sign in to comment.