Skip to content

Commit

Permalink
Fix accounts count issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Rozinko committed Jun 3, 2021
1 parent 3986b4b commit 44ea0b4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion collector/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Collector) syncStatusPump() error {
}

status := res.GetStatus()
// log.Info("Node sync status: %v", status)
log.Info("Node sync status: %v", status)

c.listener.OnNodeStatus(
status.GetConnectedPeers(),
Expand Down
5 changes: 0 additions & 5 deletions model/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import (
type Account struct {
Address string // account public address
Balance uint64 // known account balance
Sent uint64
Received uint64
Awards uint64
Fees uint64
Timestamp uint32
Counter uint64
}

Expand Down
5 changes: 4 additions & 1 deletion storage/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (

func (s *Storage) InitAccountsStorage(ctx context.Context) error {
_, err := s.db.Collection("accounts").Indexes().CreateOne(ctx, mongo.IndexModel{Keys: bson.D{{"address", 1}}, Options: options.Index().SetName("addressIndex").SetUnique(true)});
_, err = s.db.Collection("accounts").Indexes().CreateOne(ctx, mongo.IndexModel{Keys: bson.D{{"layer", -1}}, Options: options.Index().SetName("layerIndex").SetUnique(false)});
_, err = s.db.Collection("accounts").Indexes().CreateOne(ctx, mongo.IndexModel{Keys: bson.D{{"created", 1}}, Options: options.Index().SetName("createIndex").SetUnique(false)});
_, err = s.db.Collection("accounts").Indexes().CreateOne(ctx, mongo.IndexModel{Keys: bson.D{{"layer", -1}}, Options: options.Index().SetName("modifiedIndex").SetUnique(false)});
_, err = s.db.Collection("ledger").Indexes().CreateOne(ctx, mongo.IndexModel{Keys: bson.D{{"address", 1}}, Options: options.Index().SetName("addressIndex").SetUnique(false)});
_, err = s.db.Collection("ledger").Indexes().CreateOne(ctx, mongo.IndexModel{Keys: bson.D{{"layer", 1}}, Options: options.Index().SetName("layerIndex").SetUnique(false)});
return err
Expand Down Expand Up @@ -81,6 +82,7 @@ func (s *Storage) AddAccount(parent context.Context, layer uint32, address strin
defer cancel()
_, err := s.db.Collection("accounts").InsertOne(ctx, bson.D{
{"address", address},
{"created", layer},
{"layer", layer},
{"balance", balance},
{"counter", uint64(0)},
Expand All @@ -96,6 +98,7 @@ func (s *Storage) SaveAccount(parent context.Context, layer uint32, in *model.Ac
defer cancel()
_, err := s.db.Collection("accounts").InsertOne(ctx, bson.D{
{"address", in.Address},
{"created", layer},
{"layer", layer},
{"balance", in.Balance},
{"counter", in.Counter},
Expand Down
2 changes: 1 addition & 1 deletion storage/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (s *Storage) computeStatistics(epoch *model.Epoch) {
a := math.Min(float64(epoch.Stats.Current.Smeshers), 1e4)
epoch.Stats.Current.Decentral = int64(100.0 * (0.5 * (a * a) /1e8 + 0.5 * (1.0 - utils.Gini(smeshers))))
}
epoch.Stats.Current.Accounts = s.GetAccountsCount(context.Background(), &bson.D{{"layer", bson.D{{"$lte", layerEnd}}}})
epoch.Stats.Current.Accounts = s.GetAccountsCount(context.Background(), &bson.D{{"created", bson.D{{"$lte", layerEnd}}}})
epoch.Stats.Cumulative.Circulation, _ = s.GetLayersRewards(context.Background(), 0, layerEnd)
epoch.Stats.Current.Rewards, epoch.Stats.Current.RewardsNumber = s.GetLayersRewards(context.Background(), layerStart, layerEnd)
}
3 changes: 2 additions & 1 deletion storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ func (s *Storage) updateEpoch(epochNumber int32, prev *model.Epoch) *model.Epoch
if prev != nil {
epoch.Stats.Cumulative.Capacity = epoch.Stats.Current.Capacity
epoch.Stats.Cumulative.Decentral = prev.Stats.Current.Decentral
epoch.Stats.Cumulative.Smeshers = prev.Stats.Current.Smeshers
// epoch.Stats.Cumulative.Smeshers = prev.Stats.Current.Smeshers
epoch.Stats.Cumulative.Smeshers = epoch.Stats.Current.Smeshers
epoch.Stats.Cumulative.Transactions = prev.Stats.Cumulative.Transactions + epoch.Stats.Current.Transactions
epoch.Stats.Cumulative.Accounts = epoch.Stats.Current.Accounts
epoch.Stats.Cumulative.Rewards = prev.Stats.Cumulative.Rewards + epoch.Stats.Current.Rewards
Expand Down

0 comments on commit 44ea0b4

Please sign in to comment.