diff --git a/downloader/downloader.go b/downloader/downloader.go index cf1296a45..cb86a9a44 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -74,6 +74,44 @@ type AggStats struct { UploadRate, DownloadRate uint64 } +func (s *AggStats) clone() *AggStats { + sc := &AggStats{ + MetadataReady: s.MetadataReady, + FilesTotal: s.FilesTotal, + PeersUnique: s.PeersUnique, + ConnectionsTotal: s.ConnectionsTotal, + Completed: s.Completed, + Progress: s.Progress, + BytesCompleted: s.BytesCompleted, + BytesTotal: s.BytesTotal, + BytesDownload: s.BytesDownload, + BytesUpload: s.BytesUpload, + UploadRate: s.UploadRate, + DownloadRate: s.DownloadRate, + } + sc.DroppedCompleted.Store(s.DroppedCompleted.Load()) + sc.DroppedTotal.Store(s.DroppedTotal.Load()) + return sc +} + +func (s *AggStats) copy(o *AggStats) *AggStats { + s.MetadataReady = o.MetadataReady + s.FilesTotal = o.FilesTotal + s.PeersUnique = o.PeersUnique + s.ConnectionsTotal = o.ConnectionsTotal + s.Completed = o.Completed + s.Progress = o.Progress + s.BytesCompleted = o.BytesCompleted + s.BytesTotal = o.BytesTotal + s.BytesDownload = o.BytesDownload + s.BytesUpload = o.BytesUpload + s.UploadRate = o.UploadRate + s.DownloadRate = o.DownloadRate + s.DroppedCompleted.Store(o.DroppedCompleted.Load()) + s.DroppedTotal.Store(o.DroppedTotal.Load()) + return s +} + func New(ctx context.Context, cfg *downloadercfg.Cfg) (*Downloader, error) { if err := portMustBeTCPAndUDPOpen(cfg.ListenPort); err != nil { return nil, err @@ -303,7 +341,7 @@ func (d *Downloader) ReCalcStats(interval time.Duration) { d.statsLock.Lock() defer d.statsLock.Unlock() - prevStats, stats := d.stats, d.stats + prevStats, stats := d.stats.clone(), d.stats.clone() stats.Completed = true stats.BytesDownload = uint64(connStats.BytesReadUsefulIntendedData.Int64()) @@ -345,7 +383,7 @@ func (d *Downloader) ReCalcStats(interval time.Duration) { stats.PeersUnique = int32(len(peers)) stats.FilesTotal = int32(len(torrents)) - d.stats = stats + d.stats.copy(stats) } func moveFromTmp(snapDir string) error { @@ -543,10 +581,10 @@ func (d *Downloader) addSegments(ctx context.Context) error { return nil } -func (d *Downloader) Stats() AggStats { +func (d *Downloader) Stats() *AggStats { d.statsLock.RLock() defer d.statsLock.RUnlock() - return d.stats + return d.stats.clone() } func (d *Downloader) Close() { diff --git a/kv/tables.go b/kv/tables.go index 19d8e1f4a..d700ce173 100644 --- a/kv/tables.go +++ b/kv/tables.go @@ -358,6 +358,7 @@ const ( // BOR BorReceipts = "BorReceipt" + BorFinality = "BorFinality" BorTxLookup = "BlockBorTransactionLookup" // transaction_hash -> block_num_u64 BorSeparate = "BorSeparate" // persisted snapshots of the Validator Sets, with their proposer priorities BorEvents = "BorEvents" // event_id -> event_payload @@ -531,6 +532,7 @@ var ChaindataTables = []string{ StateCode, StateCommitment, BorReceipts, + BorFinality, BorTxLookup, BorSeparate, BorEvents, @@ -724,7 +726,7 @@ func TablesCfgByLabel(label Label) TableCfg { case DownloaderDB: return DownloaderTablesCfg default: - panic(fmt.Sprintf("unexpected label")) + panic(fmt.Sprintf("unexpected label: %s", label)) } } func sortBuckets() {