Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Added BorFinality to kv table definitions to support polygon milestones #1116

Merged
merged 3 commits into from
Sep 10, 2023
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
46 changes: 42 additions & 4 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion kv/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -531,6 +532,7 @@ var ChaindataTables = []string{
StateCode,
StateCommitment,
BorReceipts,
BorFinality,
BorTxLookup,
BorSeparate,
BorEvents,
Expand Down Expand Up @@ -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() {
Expand Down
Loading