-
Notifications
You must be signed in to change notification settings - Fork 462
/
config.go
604 lines (528 loc) · 20.1 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
package config
import (
"encoding/json"
"fmt"
"io"
"os"
"reflect"
"regexp"
"strings"
"time"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/pkg/errors"
"github.com/filecoin-project/venus/pkg/constants"
"github.com/filecoin-project/venus/venus-shared/types"
)
const (
scryptN = 1 << 21
scryptP = 1
)
var DefaultDefaultMaxFee = types.MustParseFIL("10")
// Config is an in memory representation of the filecoin configuration file
type Config struct {
API *APIConfig `json:"api"`
Bootstrap *BootstrapConfig `json:"bootstrap"`
Datastore *DatastoreConfig `json:"datastore"`
Mpool *MessagePoolConfig `json:"mpool"`
NetworkParams *NetworkParamsConfig `json:"parameters"`
Observability *ObservabilityConfig `json:"observability"`
Swarm *SwarmConfig `json:"swarm"`
Wallet *WalletConfig `json:"walletModule"`
SlashFilterDs *SlashFilterDsConfig `json:"slashFilter"`
RateLimitCfg *RateLimitCfg `json:"rateLimit"`
FevmConfig *FevmConfig `json:"fevm"`
}
// APIConfig holds all configuration options related to the api.
// nolint
type APIConfig struct {
VenusAuthURL string `json:"venusAuthURL"`
APIAddress string `json:"apiAddress"`
AccessControlAllowOrigin []string `json:"accessControlAllowOrigin"`
AccessControlAllowCredentials bool `json:"accessControlAllowCredentials"`
AccessControlAllowMethods []string `json:"accessControlAllowMethods"`
}
type RateLimitCfg struct {
Endpoint string `json:"RedisEndpoint"`
User string `json:"user"`
Pwd string `json:"pwd"`
Enable bool `json:"enable"`
}
func newDefaultAPIConfig() *APIConfig {
return &APIConfig{
APIAddress: "/ip4/127.0.0.1/tcp/3453",
AccessControlAllowOrigin: []string{
"http://localhost:8080",
"https://localhost:8080",
"http://127.0.0.1:8080",
"https://127.0.0.1:8080",
},
AccessControlAllowMethods: []string{"GET", "POST", "PUT"},
}
}
// DatastoreConfig holds all the configuration options for the datastore.
// TODO: use the advanced datastore configuration from ipfs
type DatastoreConfig struct {
Type string `json:"type"`
Path string `json:"path"`
}
// Validators hold the list of validation functions for each configuration
// property. Validators must take a key and json string respectively as
// arguments, and must return either an error or nil depending on whether or not
// the given key and value are valid. Validators will only be run if a property
// being set matches the name given in this map.
var Validators = map[string]func(string, string) error{
"heartbeat.nickname": validateLettersOnly,
}
func newDefaultDatastoreConfig() *DatastoreConfig {
return &DatastoreConfig{
Type: "badgerds",
Path: "badger",
}
}
// SwarmConfig holds all configuration options related to the swarm.
type SwarmConfig struct {
Address string `json:"address"`
PublicRelayAddress string `json:"public_relay_address,omitempty"`
}
func newDefaultSwarmConfig() *SwarmConfig {
return &SwarmConfig{
Address: "/ip4/0.0.0.0/tcp/0",
}
}
// BootstrapConfig holds all configuration options related to bootstrap nodes
type BootstrapConfig struct {
Addresses []string `json:"addresses"`
MinPeerThreshold int `json:"minPeerThreshold"`
Period string `json:"period,omitempty"`
}
// TODO: provide bootstrap node addresses
func newDefaultBootstrapConfig() *BootstrapConfig {
return &BootstrapConfig{
Addresses: []string{},
MinPeerThreshold: 3, // TODO: we don't actually have an bootstrap peers yet.
Period: "1m",
}
}
// WalletConfig holds all configuration options related to the wallet.
type WalletConfig struct {
DefaultAddress address.Address `json:"defaultAddress,omitempty"`
PassphraseConfig PassphraseConfig `json:"passphraseConfig,omitempty"`
RemoteEnable bool `json:"remoteEnable"`
RemoteBackend string `json:"remoteBackend"`
}
type PassphraseConfig struct {
ScryptN int `json:"scryptN"`
ScryptP int `json:"scryptP"`
}
func newDefaultWalletConfig() *WalletConfig {
return &WalletConfig{
DefaultAddress: address.Undef,
PassphraseConfig: DefaultPassphraseConfig(),
}
}
func DefaultPassphraseConfig() PassphraseConfig {
return PassphraseConfig{
ScryptN: scryptN,
ScryptP: scryptP,
}
}
func TestPassphraseConfig() PassphraseConfig {
return PassphraseConfig{
ScryptN: 1 << 15,
ScryptP: scryptP,
}
}
// DrandConfig holds all configuration options related to pulling randomness from Drand servers
type DrandConfig struct {
StartTimeUnix int64 `json:"startTimeUnix"`
RoundSeconds int `json:"roundSeconds"`
}
// HeartbeatConfig holds all configuration options related to node heartbeat.
type HeartbeatConfig struct {
// BeatTarget represents the address the filecoin node will send heartbeats to.
BeatTarget string `json:"beatTarget"`
// BeatPeriod represents how frequently heartbeats are sent.
// Golang duration units are accepted.
BeatPeriod string `json:"beatPeriod"`
// ReconnectPeriod represents how long the node waits before attempting to reconnect.
// Golang duration units are accepted.
ReconnectPeriod string `json:"reconnectPeriod"`
// Nickname represents the nickname of the filecoin node,
Nickname string `json:"nickname"`
}
// ObservabilityConfig is a container for configuration related to observables.
type ObservabilityConfig struct {
Metrics *MetricsConfig `json:"metrics"`
Tracing *TraceConfig `json:"tracing"`
}
func newDefaultObservabilityConfig() *ObservabilityConfig {
return &ObservabilityConfig{
Metrics: newDefaultMetricsConfig(),
Tracing: newDefaultTraceConfig(),
}
}
// MetricsConfig holds all configuration options related to node metrics.
type MetricsConfig struct {
// Enabled will enable prometheus metrics when true.
PrometheusEnabled bool `json:"prometheusEnabled"`
// ReportInterval represents how frequently filecoin will update its prometheus metrics.
ReportInterval string `json:"reportInterval"`
// PrometheusEndpoint represents the address filecoin will expose prometheus metrics at.
PrometheusEndpoint string `json:"prometheusEndpoint"`
}
func newDefaultMetricsConfig() *MetricsConfig {
return &MetricsConfig{
PrometheusEnabled: false,
ReportInterval: "5s",
PrometheusEndpoint: "/ip4/0.0.0.0/tcp/9400",
}
}
// TraceConfig holds all configuration options related to enabling and exporting
// filecoin node traces.
type TraceConfig struct {
// JaegerTracingEnabled will enable exporting traces to jaeger when true.
JaegerTracingEnabled bool `json:"jaegerTracingEnabled"`
// ProbabilitySampler will sample fraction of traces, 1.0 will sample all traces.
ProbabilitySampler float64 `json:"probabilitySampler"`
// JaegerEndpoint is the URL traces are collected on.
JaegerEndpoint string `json:"jaegerEndpoint"`
ServerName string `json:"servername"`
}
func newDefaultTraceConfig() *TraceConfig {
return &TraceConfig{
JaegerEndpoint: "localhost:6831",
JaegerTracingEnabled: false,
ProbabilitySampler: 1.0,
ServerName: "venus-node",
}
}
// MessagePoolConfig holds all configuration options related to nodes message pool (mpool).
type MessagePoolConfig struct {
// MaxNonceGap is the maximum nonce of a message past the last received on chain
MaxNonceGap uint64 `json:"maxNonceGap"`
// MaxFee
MaxFee types.FIL `json:"maxFee"`
}
var DefaultMessagePoolParam = &MessagePoolConfig{
MaxNonceGap: 100,
MaxFee: DefaultDefaultMaxFee,
}
func newDefaultMessagePoolConfig() *MessagePoolConfig {
return &MessagePoolConfig{
MaxNonceGap: 100,
MaxFee: DefaultDefaultMaxFee,
}
}
// NetworkParamsConfig record netork parameters
type NetworkParamsConfig struct {
DevNet bool `json:"-"`
NetworkType types.NetworkType `json:"networkType"`
AddressNetwork address.Network `json:"-"`
GenesisNetworkVersion network.Version `json:"-"`
ConsensusMinerMinPower uint64 `json:"-"` // uint64 goes up to 18 EiB
MinVerifiedDealSize int64 `json:"-"`
ReplaceProofTypes []abi.RegisteredSealProof `json:"-"`
BlockDelay uint64 `json:"-"`
DrandSchedule map[abi.ChainEpoch]DrandEnum `json:"-"`
ForkUpgradeParam *ForkUpgradeConfig `json:"-"`
PreCommitChallengeDelay abi.ChainEpoch `json:"-"`
PropagationDelaySecs uint64 `json:"-"`
AllowableClockDriftSecs uint64 `json:"allowableClockDriftSecs"`
// ChainId defines the chain ID used in the Ethereum JSON-RPC endpoint.
// As per https://github.com/ethereum-lists/chains
Eip155ChainID int `json:"-"`
// NOTE: DO NOT change this unless you REALLY know what you're doing. This is consensus critical.
ActorDebugging bool `json:"-"`
}
// ForkUpgradeConfig record upgrade parameters
type ForkUpgradeConfig struct {
UpgradeSmokeHeight abi.ChainEpoch `json:"upgradeSmokeHeight"`
UpgradeBreezeHeight abi.ChainEpoch `json:"upgradeBreezeHeight"`
UpgradeIgnitionHeight abi.ChainEpoch `json:"upgradeIgnitionHeight"`
UpgradeLiftoffHeight abi.ChainEpoch `json:"upgradeLiftoffHeight"`
UpgradeAssemblyHeight abi.ChainEpoch `json:"upgradeActorsV2Height"`
UpgradeRefuelHeight abi.ChainEpoch `json:"upgradeRefuelHeight"`
UpgradeTapeHeight abi.ChainEpoch `json:"upgradeTapeHeight"`
UpgradeKumquatHeight abi.ChainEpoch `json:"upgradeKumquatHeight"`
UpgradePriceListOopsHeight abi.ChainEpoch `json:"upgradePriceListOopsHeight"`
BreezeGasTampingDuration abi.ChainEpoch `json:"breezeGasTampingDuration"`
UpgradeCalicoHeight abi.ChainEpoch `json:"upgradeCalicoHeight"`
UpgradePersianHeight abi.ChainEpoch `json:"upgradePersianHeight"`
UpgradeOrangeHeight abi.ChainEpoch `json:"upgradeOrangeHeight"`
UpgradeClausHeight abi.ChainEpoch `json:"upgradeClausHeight"`
UpgradeTrustHeight abi.ChainEpoch `json:"upgradeActorsV3Height"`
UpgradeNorwegianHeight abi.ChainEpoch `json:"upgradeNorwegianHeight"`
UpgradeTurboHeight abi.ChainEpoch `json:"upgradeActorsV4Height"`
UpgradeHyperdriveHeight abi.ChainEpoch `json:"upgradeHyperdriveHeight"`
UpgradeChocolateHeight abi.ChainEpoch `json:"upgradeChocolateHeight"`
UpgradeOhSnapHeight abi.ChainEpoch `json:"upgradeOhSnapHeight"`
UpgradeSkyrHeight abi.ChainEpoch `json:"upgradeSkyrHeight"`
UpgradeSharkHeight abi.ChainEpoch `json:"upgradeSharkHeight"`
UpgradeHyggeHeight abi.ChainEpoch `json:"upgradeHyggeHeight"`
}
func IsNearUpgrade(epoch, upgradeEpoch abi.ChainEpoch) bool {
return epoch > upgradeEpoch-constants.Finality && epoch < upgradeEpoch+constants.Finality
}
var DefaultForkUpgradeParam = &ForkUpgradeConfig{
UpgradeBreezeHeight: 41280,
BreezeGasTampingDuration: 120,
UpgradeSmokeHeight: 51000,
UpgradeIgnitionHeight: 94000,
UpgradeRefuelHeight: 130800,
UpgradeTapeHeight: 140760,
UpgradeLiftoffHeight: 148888,
UpgradeKumquatHeight: 170000,
UpgradeCalicoHeight: 265200,
UpgradePersianHeight: 265200 + 120*60,
UpgradeAssemblyHeight: 138720,
UpgradeOrangeHeight: 336458,
UpgradeClausHeight: 343200,
UpgradeTrustHeight: 550321,
UpgradeNorwegianHeight: 665280,
UpgradeTurboHeight: 712320,
UpgradeHyperdriveHeight: 892800,
UpgradeChocolateHeight: 1231620,
UpgradeOhSnapHeight: 1594680,
UpgradeSkyrHeight: 1960320,
UpgradeSharkHeight: 2383680,
UpgradeHyggeHeight: 99999999999999,
}
func newDefaultNetworkParamsConfig() *NetworkParamsConfig {
defaultParams := *DefaultForkUpgradeParam
return &NetworkParamsConfig{
DevNet: true,
ConsensusMinerMinPower: 0, // 0 means don't override the value
ReplaceProofTypes: []abi.RegisteredSealProof{
abi.RegisteredSealProof_StackedDrg2KiBV1,
abi.RegisteredSealProof_StackedDrg512MiBV1,
abi.RegisteredSealProof_StackedDrg32GiBV1,
abi.RegisteredSealProof_StackedDrg64GiBV1,
},
DrandSchedule: map[abi.ChainEpoch]DrandEnum{0: 5, -1: 1},
ForkUpgradeParam: &defaultParams,
PropagationDelaySecs: 10,
AllowableClockDriftSecs: 1,
Eip155ChainID: 314,
}
}
type MySQLConfig struct {
ConnectionString string `json:"connectionString"`
MaxOpenConn int `json:"maxOpenConn"` // 100
MaxIdleConn int `json:"maxIdleConn"` // 10
ConnMaxLifeTime time.Duration `json:"connMaxLifeTime"` // minuter: 60
Debug bool `json:"debug"`
}
type SlashFilterDsConfig struct {
Type string `json:"type"`
MySQL MySQLConfig `json:"mysql"`
}
func newDefaultSlashFilterDsConfig() *SlashFilterDsConfig {
return &SlashFilterDsConfig{
Type: "local",
MySQL: MySQLConfig{},
}
}
func newRateLimitConfig() *RateLimitCfg {
return &RateLimitCfg{
Enable: false,
}
}
type EventConfig struct {
// EnableRealTimeFilterAPI enables APIs that can create and query filters for actor events as they are emitted.
EnableRealTimeFilterAPI bool `json:"enableRealTimeFilterAPI"`
// EnableHistoricFilterAPI enables APIs that can create and query filters for actor events that occurred in the past.
// A queryable index of events will be maintained.
EnableHistoricFilterAPI bool `json:"enableHistoricFilterAPI"`
// FilterTTL specifies the time to live for actor event filters. Filters that haven't been accessed longer than
// this time become eligible for automatic deletion.
FilterTTL Duration `json:"filterTTL"`
// MaxFilters specifies the maximum number of filters that may exist at any one time.
MaxFilters int `json:"maxFilters"`
// MaxFilterResults specifies the maximum number of results that can be accumulated by an actor event filter.
MaxFilterResults int `json:"maxFilterResults"`
// MaxFilterHeightRange specifies the maximum range of heights that can be used in a filter (to avoid querying
// the entire chain)
MaxFilterHeightRange uint64 `json:"maxFilterHeightRange"`
// DatabasePath is the full path to a sqlite database that will be used to index actor events to
// support the historic filter APIs. If the database does not exist it will be created. The directory containing
// the database must already exist and be writeable. If a relative path is provided here, sqlite treats it as
// relative to the CWD (current working directory).
DatabasePath string `json:"databasePath"`
// Others, not implemented yet:
// Set a limit on the number of active websocket subscriptions (may be zero)
// Set a timeout for subscription clients
// Set upper bound on index size
}
type FevmConfig struct {
//EnableEthRPC enables eth_rpc, and enables storing a mapping of eth transaction hashes to filecoin message Cids.
EnableEthRPC bool `json:"enableEthRPC"`
// EthTxHashMappingLifetimeDays the transaction hash lookup database will delete mappings that have been stored for more than x days
// Set to 0 to keep all mappings
EthTxHashMappingLifetimeDays int `json:"ethTxHashMappingLifetimeDays"`
Event EventConfig `json:"event"`
}
func newFevmConfig() *FevmConfig {
return &FevmConfig{
EnableEthRPC: false,
EthTxHashMappingLifetimeDays: 0,
Event: EventConfig{
EnableRealTimeFilterAPI: false,
EnableHistoricFilterAPI: false,
FilterTTL: Duration(time.Hour * 24),
MaxFilters: 100,
MaxFilterResults: 10000,
MaxFilterHeightRange: 2880, // conservative limit of one day
},
}
}
// NewDefaultConfig returns a config object with all the fields filled out to
// their default values
func NewDefaultConfig() *Config {
return &Config{
API: newDefaultAPIConfig(),
Bootstrap: newDefaultBootstrapConfig(),
Datastore: newDefaultDatastoreConfig(),
Mpool: newDefaultMessagePoolConfig(),
NetworkParams: newDefaultNetworkParamsConfig(),
Observability: newDefaultObservabilityConfig(),
Swarm: newDefaultSwarmConfig(),
Wallet: newDefaultWalletConfig(),
SlashFilterDs: newDefaultSlashFilterDsConfig(),
RateLimitCfg: newRateLimitConfig(),
FevmConfig: newFevmConfig(),
}
}
// WriteFile writes the config to the given filepath.
func (cfg *Config) WriteFile(file string) error {
f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
return err
}
defer f.Close() // nolint: errcheck
configString, err := json.MarshalIndent(*cfg, "", "\t")
if err != nil {
return err
}
_, err = fmt.Fprint(f, string(configString))
return err
}
// ReadFile reads a config file from disk.
func ReadFile(file string) (*Config, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
cfg := NewDefaultConfig()
rawConfig, err := io.ReadAll(f)
if err != nil {
return nil, err
}
if len(rawConfig) == 0 {
return cfg, nil
}
err = json.Unmarshal(rawConfig, &cfg)
if err != nil {
return nil, err
}
return cfg, nil
}
// Set sets the config sub-struct referenced by `key`, e.g. 'api.address'
// or 'datastore' to the json key value pair encoded in jsonVal.
func (cfg *Config) Set(dottedKey string, jsonString string) error {
if !json.Valid([]byte(jsonString)) {
jsonBytes, _ := json.Marshal(jsonString)
jsonString = string(jsonBytes)
}
if err := validate(dottedKey, jsonString); err != nil {
return err
}
keys := strings.Split(dottedKey, ".")
for i := len(keys) - 1; i >= 0; i-- {
jsonString = fmt.Sprintf(`{ "%s": %s }`, keys[i], jsonString)
}
decoder := json.NewDecoder(strings.NewReader(jsonString))
decoder.DisallowUnknownFields()
return decoder.Decode(&cfg)
}
// Get gets the config sub-struct referenced by `key`, e.g. 'api.address'
func (cfg *Config) Get(key string) (interface{}, error) {
v := reflect.Indirect(reflect.ValueOf(cfg))
keyTags := strings.Split(key, ".")
OUTER:
for j, keyTag := range keyTags {
if v.Type().Kind() == reflect.Struct {
for i := 0; i < v.NumField(); i++ {
jsonTag := strings.Split(
v.Type().Field(i).Tag.Get("json"),
",")[0]
if jsonTag == keyTag {
v = v.Field(i)
if j == len(keyTags)-1 {
return v.Interface(), nil
}
v = reflect.Indirect(v) // only attempt one dereference
continue OUTER
}
}
}
return nil, fmt.Errorf("key: %s invalid for config", key)
}
// Cannot get here as len(strings.Split(s, sep)) >= 1 with non-empty sep
return nil, fmt.Errorf("empty key is invalid")
}
// validate runs validations on a given key and json string. validate uses the
// validators map defined at the top of this file to determine which validations
// to use for each key.
func validate(dottedKey string, jsonString string) error {
var obj interface{}
if err := json.Unmarshal([]byte(jsonString), &obj); err != nil {
return err
}
// recursively validate sub-keys by partially unmarshalling
if reflect.ValueOf(obj).Kind() == reflect.Map {
var obj map[string]json.RawMessage
if err := json.Unmarshal([]byte(jsonString), &obj); err != nil {
return err
}
for key := range obj {
if err := validate(dottedKey+"."+key, string(obj[key])); err != nil {
return err
}
}
return nil
}
if validationFunc, present := Validators[dottedKey]; present {
return validationFunc(dottedKey, jsonString)
}
return nil
}
// validateLettersOnly validates that a given value contains only letters. If it
// does not, an error is returned using the given key for the message.
func validateLettersOnly(key string, value string) error {
if match, _ := regexp.MatchString("^\"[a-zA-Z]+\"$", value); !match {
return errors.Errorf(`"%s" must only contain letters`, key)
}
return nil
}
var (
_ json.Marshaler = (*Duration)(nil)
_ json.Unmarshaler = (*Duration)(nil)
)
// Duration is a wrapper type for time.Duration
// for decoding and encoding from/to JSON
type Duration time.Duration
// UnmarshalJSON implements interface for json decoding
func (dur *Duration) UnmarshalJSON(data []byte) error {
d, err := time.ParseDuration(strings.Trim(string(data), "\""))
if err != nil {
return err
}
*dur = Duration(d)
return err
}
func (dur Duration) MarshalJSON() ([]byte, error) {
d := time.Duration(dur)
return []byte(fmt.Sprintf("\"%s\"", d.String())), nil
}