Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bs statistic #1388

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ replace (
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.6.0
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/forbole/juno/v4 => github.com/bnb-chain/juno/v4 v4.0.0-20240415080646-269767e40736
github.com/forbole/juno/v4 => github.com/bnb-chain/juno/v4 v4.0.0-20240422102216-0039530fcfb2
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20231206043955-0855e0965b
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20231206043955-0855e0965bc8/go.mod h1:An0MllWJY6PxibUpnwGk8jOm+a/qIxlKmL5Zyp9NnaM=
github.com/bnb-chain/greenfield-iavl v0.20.1 h1:y3L64GU99otNp27/xLVBTDbv4eroR6CzoYz0rbaVotM=
github.com/bnb-chain/greenfield-iavl v0.20.1/go.mod h1:oLksTs8dfh7DYIKBro7hbRQ+ewls7ghJ27pIXlbEXyI=
github.com/bnb-chain/juno/v4 v4.0.0-20240415080646-269767e40736 h1:B464Z533SEPBfv3mjocuuajFa/Fb3S80ZucUTrTDZd0=
github.com/bnb-chain/juno/v4 v4.0.0-20240415080646-269767e40736/go.mod h1:p+KkPIHURpqUJOdXanhhYgZpTLQxGZWkrAwtUaOuPlM=
github.com/bnb-chain/juno/v4 v4.0.0-20240422102216-0039530fcfb2 h1:Zpq40LEvqzaqtT7QqISASBg6E51SZPAWLQ5gdbAtsfk=
github.com/bnb-chain/juno/v4 v4.0.0-20240422102216-0039530fcfb2/go.mod h1:p+KkPIHURpqUJOdXanhhYgZpTLQxGZWkrAwtUaOuPlM=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
Expand Down
33 changes: 24 additions & 9 deletions modular/blocksyncer/blocksyncer_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,34 @@ func (b *BlockSyncerModular) prepareMasterFlagTable() error {
func (b *BlockSyncerModular) dbStatistics(ctx context.Context) {
duration := b.DataStatisticsDuration
if duration == 0 {
duration = 3600
duration = 2000
}
ticker := time.NewTicker(time.Duration(duration) * time.Second)
ticker := time.NewTicker(30 * time.Minute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will 30 min be quite frequent ?

defer ticker.Stop()
var totalCount, sealCount, delCount []int64
var err error
var (
totalCount, sealCount, delCount []int64
preHeight int64
)
lastDbBlockHeight := int64(0)
preHeight = 0
for range ticker.C {
latestBlockHeightAny := Cast(b.parserCtx.Indexer).GetLatestBlockHeight().Load()
latestBlockHeight := latestBlockHeightAny.(int64)
if latestBlockHeight < 10 {
epoch, err := b.parserCtx.Database.GetEpoch(context.TODO())
if err != nil {
log.Errorw("failed to get last block height from database", "error", err)
continue
}
lastDbBlockHeight = epoch.BlockHeight
if lastDbBlockHeight < duration {
continue
}
if lastDbBlockHeight/duration == preHeight/duration {
log.Infow("The current height has been counted. Skip", "lastDbBlockHeight", lastDbBlockHeight, "preHeight", preHeight)
continue
}
if b.BlockResultStorage && latestBlockHeight-b.MaxBlockNum > 0 {
if delErr := db.Cast(b.parserCtx.Database).DeleteBlockResult(ctx, latestBlockHeight-b.MaxBlockNum); delErr != nil {
//if duration = 2000 then 20001 -> 20000, 4050300 -> 4050000
latestBlockHeight := lastDbBlockHeight / duration * duration
if b.BlockResultStorage && lastDbBlockHeight-b.MaxBlockNum > 0 {
if delErr := db.Cast(b.parserCtx.Database).DeleteBlockResult(ctx, lastDbBlockHeight-b.MaxBlockNum); delErr != nil {
log.Errorw("failed to delete the expired block result", "error", delErr)
metrics.DataStatisticsErr.Inc()
}
Expand Down Expand Up @@ -447,6 +461,7 @@ func (b *BlockSyncerModular) dbStatistics(ctx context.Context) {
log.CtxErrorw(ctx, "failed to save statistic data", "error", err)
metrics.DataStatisticsErr.Inc()
}
preHeight = latestBlockHeight
}
}

Expand Down
Loading