Skip to content

Commit

Permalink
feat: increase default Reprovider.Interval (#9326)
Browse files Browse the repository at this point in the history
* increase republish interval based on RFM17
* refactor(config): switch to implicit default

Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
cortze and lidel committed Dec 8, 2022
1 parent bf61e63 commit 72bad5c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
4 changes: 2 additions & 2 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func InitWithIdentity(identity Identity) (*Config, error) {
APICommands: []string{},
},
Reprovider: Reprovider{
Interval: "12h",
Strategy: "all",
Interval: nil,
Strategy: nil,
},
Pinning: Pinning{
RemoteServices: map[string]RemotePinningService{},
Expand Down
2 changes: 1 addition & 1 deletion config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fetching may be degraded.
Transform: func(c *Config) error {
c.Routing.Type = "dhtclient"
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
c.Reprovider.Interval = "0"
c.Reprovider.Interval = NewOptionalDuration(0)

lowWater := int64(20)
highWater := int64(40)
Expand Down
4 changes: 2 additions & 2 deletions config/reprovider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

type Reprovider struct {
Interval string // Time period to reprovide locally stored objects to the network
Strategy string // Which keys to announce
Interval *OptionalDuration `json:",omitempty"` // Time period to reprovide locally stored objects to the network
Strategy *OptionalString `json:",omitempty"` // Which keys to announce
}
5 changes: 5 additions & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ type OptionalDuration struct {
value *time.Duration
}

// NewOptionalDuration returns an OptionalDuration from a string
func NewOptionalDuration(d time.Duration) *OptionalDuration {
return &OptionalDuration{value: &d}
}

func (d *OptionalDuration) UnmarshalJSON(input []byte) error {
switch string(input) {
case "null", "undefined", "\"null\"", "", "default", "\"\"", "\"default\"":
Expand Down
14 changes: 12 additions & 2 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option {
fx.Provide(p2p.New),

LibP2P(bcfg, cfg),
OnlineProviders(cfg.Experimental.StrategicProviding, cfg.Experimental.AcceleratedDHTClient, cfg.Reprovider.Strategy, cfg.Reprovider.Interval),
OnlineProviders(
cfg.Experimental.StrategicProviding,
cfg.Experimental.AcceleratedDHTClient,
cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy),
cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval),
),
)
}

Expand All @@ -304,7 +309,12 @@ func Offline(cfg *config.Config) fx.Option {
fx.Provide(libp2p.Routing),
fx.Provide(libp2p.ContentRouting),
fx.Provide(libp2p.OfflineRouting),
OfflineProviders(cfg.Experimental.StrategicProviding, cfg.Experimental.AcceleratedDHTClient, cfg.Reprovider.Strategy, cfg.Reprovider.Interval),
OfflineProviders(
cfg.Experimental.StrategicProviding,
cfg.Experimental.AcceleratedDHTClient,
cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy),
cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval),
),
)
}

Expand Down
33 changes: 7 additions & 26 deletions core/node/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
irouting "github.com/ipfs/kubo/routing"
)

const kReprovideFrequency = time.Hour * 12
const DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326
const DefaultReproviderStrategy = "all"

// SIMPLE

Expand Down Expand Up @@ -61,20 +62,10 @@ func SimpleProviderSys(isOnline bool) interface{} {
}

// BatchedProviderSys creates new provider system
func BatchedProviderSys(isOnline bool, reprovideInterval string) interface{} {
func BatchedProviderSys(isOnline bool, reprovideInterval time.Duration) interface{} {
return func(lc fx.Lifecycle, cr irouting.ProvideManyRouter, q *q.Queue, keyProvider simple.KeyChanFunc, repo repo.Repo) (provider.System, error) {
reprovideIntervalDuration := kReprovideFrequency
if reprovideInterval != "" {
dur, err := time.ParseDuration(reprovideInterval)
if err != nil {
return nil, err
}

reprovideIntervalDuration = dur
}

sys, err := batched.New(cr, q,
batched.ReproviderInterval(reprovideIntervalDuration),
batched.ReproviderInterval(reprovideInterval),
batched.Datastore(repo.Datastore()),
batched.KeyProvider(keyProvider))
if err != nil {
Expand All @@ -100,7 +91,7 @@ func BatchedProviderSys(isOnline bool, reprovideInterval string) interface{} {
// ONLINE/OFFLINE

// OnlineProviders groups units managing provider routing records online
func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval string) fx.Option {
func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval time.Duration) fx.Option {
if useStrategicProviding {
return fx.Provide(provider.NewOfflineProvider)
}
Expand All @@ -113,7 +104,7 @@ func OnlineProviders(useStrategicProviding bool, useBatchedProviding bool, repro
}

// OfflineProviders groups units managing provider routing records offline
func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval string) fx.Option {
func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, reprovideStrategy string, reprovideInterval time.Duration) fx.Option {
if useStrategicProviding {
return fx.Provide(provider.NewOfflineProvider)
}
Expand All @@ -126,17 +117,7 @@ func OfflineProviders(useStrategicProviding bool, useBatchedProviding bool, repr
}

// SimpleProviders creates the simple provider/reprovider dependencies
func SimpleProviders(reprovideStrategy string, reprovideInterval string) fx.Option {
reproviderInterval := kReprovideFrequency
if reprovideInterval != "" {
dur, err := time.ParseDuration(reprovideInterval)
if err != nil {
return fx.Error(err)
}

reproviderInterval = dur
}

func SimpleProviders(reprovideStrategy string, reproviderInterval time.Duration) fx.Option {
var keyProvider fx.Option
switch reprovideStrategy {
case "all":
Expand Down
11 changes: 11 additions & 0 deletions docs/changelogs/v0.18.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Below is an outline of all that is in this release, so you get a sense of all th
- [Overview](#overview)
- [🔦 Highlights](#-highlights)
- [(DAG-)JSON and (DAG-)CBOR Response Formats on Gateways](#dag-json-and-dag-cbor-response-formats-on-gateways)
- [Increased `Reprovider.Interval`](#increased-reproviderinterval)
- [Changelog](#changelog)
- [Contributors](#contributors)

Expand Down Expand Up @@ -68,6 +69,16 @@ $ curl "http://127.0.0.1:8080/ipfs/$DIR_CID?format=dag-json" | jq
}
```

#### Increased `Reprovider.Interval`

Default changed from 12h to 22h.
We also stopped `ipfs init` from hardcoding the default value in user config, allowing Kubo to adjust implicit default in future releases.

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)
and [kubo#9326](https://github.com/ipfs/kubo/pull/9326).

Learn more: [`Reprovider` config](https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#reprovider)

### Changelog

### Contributors

0 comments on commit 72bad5c

Please sign in to comment.