Skip to content

Commit 52340c3

Browse files
GO-15: mempool outdated
1 parent 0409720 commit 52340c3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

node/chain_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type MempoolResponse struct {
4343
Refused []Failed `json:"refused"`
4444
BranchRefused []Failed `json:"branch_refused"`
4545
BranchDelayed []Failed `json:"branch_delayed"`
46+
Outdated []Failed `json:"outdated"`
4647
}
4748

4849
// Applied -

node/monitor.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
filterRefused = "refused"
1919
filterBranchRefused = "branch_refused"
2020
filterBranchDelayed = "branch_delayed"
21+
filterOutdated = "outdated"
2122
)
2223

2324
// Monitor -
@@ -29,11 +30,13 @@ type Monitor struct {
2930
refused chan []*FailedMonitor
3031
branchDelayed chan []*FailedMonitor
3132
branchRefused chan []*FailedMonitor
33+
outdated chan []*FailedMonitor
3234

3335
subscribedOnApplied bool
3436
subscribedOnRefused bool
3537
subscribedOnBranchDelayed bool
3638
subscribedOnBranchRefused bool
39+
subscribedOnOutdated bool
3740

3841
wg sync.WaitGroup
3942
}
@@ -51,6 +54,7 @@ func NewMonitor(url string) *Monitor {
5154
refused: make(chan []*FailedMonitor, 4096),
5255
branchDelayed: make(chan []*FailedMonitor, 4096),
5356
branchRefused: make(chan []*FailedMonitor, 4096),
57+
outdated: make(chan []*FailedMonitor, 4096),
5458
client: &http.Client{
5559
Transport: t,
5660
Timeout: time.Minute,
@@ -102,13 +106,25 @@ func (monitor *Monitor) SubscribeOnMempoolBranchDelayed(ctx context.Context) {
102106
go monitor.pollingMempool(ctx, filterBranchDelayed)
103107
}
104108

109+
// SubscribeOnMempoolOutdated -
110+
func (monitor *Monitor) SubscribeOnMempoolOutdated(ctx context.Context) {
111+
if monitor.subscribedOnOutdated {
112+
return
113+
}
114+
monitor.subscribedOnOutdated = true
115+
116+
monitor.wg.Add(1)
117+
go monitor.pollingMempool(ctx, filterOutdated)
118+
}
119+
105120
func (monitor *Monitor) Close() error {
106121
monitor.wg.Wait()
107122

108123
close(monitor.applied)
109124
close(monitor.refused)
110125
close(monitor.branchDelayed)
111126
close(monitor.branchRefused)
127+
close(monitor.outdated)
112128
return nil
113129
}
114130

@@ -132,6 +148,11 @@ func (monitor *Monitor) Refused() <-chan []*FailedMonitor {
132148
return monitor.refused
133149
}
134150

151+
// Outdated -
152+
func (monitor *Monitor) Outdated() <-chan []*FailedMonitor {
153+
return monitor.outdated
154+
}
155+
135156
func (monitor *Monitor) pollingMempool(ctx context.Context, filter string) {
136157
defer monitor.wg.Done()
137158

@@ -168,6 +189,8 @@ func (monitor *Monitor) process(ctx context.Context, filter, url string) error {
168189
return monitor.longPollingFailed(ctx, url, monitor.branchRefused)
169190
case filterRefused:
170191
return monitor.longPollingFailed(ctx, url, monitor.refused)
192+
case filterOutdated:
193+
return monitor.longPollingFailed(ctx, url, monitor.outdated)
171194
default:
172195
return errors.Errorf("unknown filter: %s", filter)
173196
}

0 commit comments

Comments
 (0)