feat: increase default Reprovider.Interval (#9326)
* increase republish interval based on RFM17 * refactor(config): switch to implicit default Co-authored-by: Marcin Rataj <lidel@lidel.org>
Mikel Cortes committed
Dec 8, 2022 at 21:28 UTC
72bad5c060376b2c2c4d6ff682ef9a3c9db4baad
7 files changed
+40
-33
config/init.go
+2
-2
@@ -76,8 +76,8 @@ func InitWithIdentity(identity Identity) (*Config, error) {
76
APICommands: []string{},
77
},
78
Reprovider: Reprovider{
79
- Interval: "12h",
80
- Strategy: "all",
79
+ Interval: nil,
80
+ Strategy: nil,
81
},
82
Pinning: Pinning{
83
RemoteServices: map[string]RemotePinningService{},
config/profile.go
+1
-1
@@ -176,7 +176,7 @@ fetching may be degraded.
176
Transform: func(c *Config) error {
177
c.Routing.Type = "dhtclient"
178
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
179
- c.Reprovider.Interval = "0"
179
+ c.Reprovider.Interval = NewOptionalDuration(0)
180
181
lowWater := int64(20)
182
highWater := int64(40)
config/reprovider.go
+2
-2
@@ -1,6 +1,6 @@
1
package config
2
3
type Reprovider struct {
4
- Interval string // Time period to reprovide locally stored objects to the network
5
- Strategy string // Which keys to announce
4
+ Interval *OptionalDuration `json:",omitempty"` // Time period to reprovide locally stored objects to the network
5
+ Strategy *OptionalString `json:",omitempty"` // Which keys to announce
6
}
config/types.go
+5
@@ -218,6 +218,11 @@ type OptionalDuration struct {
218
value *time.Duration
219
}
220
221
+// NewOptionalDuration returns an OptionalDuration from a string
222
+func NewOptionalDuration(d time.Duration) *OptionalDuration {
223
+ return &OptionalDuration{value: &d}
224
+}
225
+
226
func (d *OptionalDuration) UnmarshalJSON(input []byte) error {
227
switch string(input) {
228
case "null", "undefined", "\"null\"", "", "default", "\"\"", "\"default\"":
core/node/groups.go
+12
-2
@@ -291,7 +291,12 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option {
291
fx.Provide(p2p.New),
292
293
LibP2P(bcfg, cfg),
294
- OnlineProviders(cfg.Experimental.StrategicProviding, cfg.Experimental.AcceleratedDHTClient, cfg.Reprovider.Strategy, cfg.Reprovider.Interval),
294
+ OnlineProviders(
295
+ cfg.Experimental.StrategicProviding,
296
+ cfg.Experimental.AcceleratedDHTClient,
297
+ cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy),
298
+ cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval),
299
+ ),
300
)
301
}
302
@@ -304,7 +309,12 @@ func Offline(cfg *config.Config) fx.Option {
309
fx.Provide(libp2p.Routing),
310
fx.Provide(libp2p.ContentRouting),
311
fx.Provide(libp2p.OfflineRouting),
307
- OfflineProviders(cfg.Experimental.StrategicProviding, cfg.Experimental.AcceleratedDHTClient, cfg.Reprovider.Strategy, cfg.Reprovider.Interval),
312
+ OfflineProviders(
313
+ cfg.Experimental.StrategicProviding,
314
+ cfg.Experimental.AcceleratedDHTClient,
315
+ cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy),
316
+ cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval),
317
+ ),
318
)
319
}
320
core/node/provider.go
+7
-26
@@ -18,7 +18,8 @@ import (
18
irouting "github.com/ipfs/kubo/routing"
19
)
20
21
-const kReprovideFrequency = time.Hour * 12
21
+const DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326
22
+const DefaultReproviderStrategy = "all"
23
24
// SIMPLE
25
@@ -61,20 +62,10 @@ func SimpleProviderSys(isOnline bool) interface{} {
62
}
63
64
// BatchedProviderSys creates new provider system
64
-func BatchedProviderSys(isOnline bool, reprovideInterval string) interface{} {
65
+func BatchedProviderSys(isOnline bool, reprovideInterval time.Duration) interface{} {
66
return func(lc fx.Lifecycle, cr irouting.ProvideManyRouter, q *q.Queue, keyProvider simple.KeyChanFunc, repo repo.Repo) (provider.System, error) {
66
- reprovideIntervalDuration := kReprovideFrequency
67
- if reprovideInterval != "" {
68
- dur, err := time.ParseDuration(reprovideInterval)
69
- if err != nil {
70
- return nil, err
71
- }
72
-
73
- reprovideIntervalDuration = dur
74
- }
75
-
67
sys, err := batched.New(cr, q,
77
- batched.ReproviderInterval(reprovideIntervalDuration),
68
+ batched.ReproviderInterval(reprovideInterval),
69
batched.Datastore(repo.Datastore()),
70
batched.KeyProvider(keyProvider))
71
if err != nil {
@@ -100,7 +91,7 @@ func BatchedProviderSys(isOnline bool, reprovideInterval string) interface{} {
91
// ONLINE/OFFLINE
92
93
// OnlineProviders groups units managing provider routing records online
103
-func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval string) fx.Option {
94
+func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval time.Duration) fx.Option {
95
if useStrategicProviding {
96
return fx.Provide(provider.NewOfflineProvider)
97
}
@@ -113,7 +104,7 @@ func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, repro
104
}
105
106
// OfflineProviders groups units managing provider routing records offline
116
-func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval string) fx.Option {
107
+func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval time.Duration) fx.Option {
108
if useStrategicProviding {
109
return fx.Provide(provider.NewOfflineProvider)
110
}
@@ -126,17 +117,7 @@ func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, repr
117
}
118
119
// SimpleProviders creates the simple provider/reprovider dependencies
129
-func SimpleProviders(reprovideStrategy string, reprovideInterval string) fx.Option {
130
- reproviderInterval := kReprovideFrequency
131
- if reprovideInterval != "" {
132
- dur, err := time.ParseDuration(reprovideInterval)
133
- if err != nil {
134
- return fx.Error(err)
135
- }
136
-
137
- reproviderInterval = dur
138
- }
139
-
120
+func SimpleProviders(reprovideStrategy string, reproviderInterval time.Duration) fx.Option {
121
var keyProvider fx.Option
122
switch reprovideStrategy {
123
case "all":
docs/changelogs/v0.18.md
+11
@@ -11,6 +11,7 @@ Below is an outline of all that is in this release, so you get a sense of all th
11
- [Overview](#overview)
12
- [🔦 Highlights](#-highlights)
13
- [(DAG-)JSON and (DAG-)CBOR Response Formats on Gateways](#dag-json-and-dag-cbor-response-formats-on-gateways)
14
+ - [Increased `Reprovider.Interval`](#increased-reproviderinterval)
15
- [Changelog](#changelog)
16
- [Contributors](#contributors)
17
@@ -68,6 +69,16 @@ $ curl "http://127.0.0.1:8080/ipfs/$DIR_CID?format=dag-json" | jq
69
}
70
```
71
72
+#### Increased `Reprovider.Interval`
73
+
74
+Default changed from 12h to 22h.
75
+We also stopped `ipfs init` from hardcoding the default value in user config, allowing Kubo to adjust implicit default in future releases.
76
+
77
+Rationale for increasing this can be found in [RFM 17: Provider Record Livenes Report](https://github.com/protocol/network-measurements/blob/master/results/rfm17-provider-record-liveness.md)
78
+and [kubo#9326](https://github.com/ipfs/kubo/pull/9326).
79
+
80
+Learn more: [`Reprovider` config](https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#reprovider)
81
+
82
### Changelog
83
84
### Contributors