Skip to content

Commit 2ec0435

Browse files
committed
remove Duration completely
1 parent b686203 commit 2ec0435

File tree

10 files changed

+74
-90
lines changed

10 files changed

+74
-90
lines changed

cmd/sptool/toolbox_deal_tools.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ var generateRandCar = &cli.Command{
257257
Usage: "creates a randomly generated dense car",
258258
ArgsUsage: "<outputPath>",
259259
Flags: []cli.Flag{
260-
&cli.IntFlag{
260+
&cli.Int64Flag{
261261
Name: "size",
262262
Aliases: []string{"s"},
263263
Usage: "The size of the data to turn into a car",
@@ -282,11 +282,11 @@ var generateRandCar = &cli.Command{
282282
}
283283

284284
outPath := cctx.Args().Get(0)
285-
size := cctx.Int("size")
285+
size := cctx.Int64("size")
286286
cs := cctx.Int64("chunksize")
287287
ml := cctx.Int("maxlinks")
288288

289-
rf, err := testutils.CreateRandomFile(outPath, int(time.Now().Unix()), size)
289+
rf, err := testutils.CreateRandomFile(outPath, time.Now().Unix(), size)
290290
if err != nil {
291291
return err
292292
}

deps/config/common.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package config
22

3+
import (
4+
"time"
5+
)
6+
37
type Common struct {
48
API API
59
Backup Backup
@@ -13,7 +17,7 @@ type API struct {
1317
// Binding address for the Binary's API
1418
ListenAddress string
1519
RemoteListenAddress string
16-
Timeout Duration
20+
Timeout time.Duration
1721
}
1822

1923
// // Common
@@ -63,7 +67,7 @@ type Libp2p struct {
6367
ConnMgrHigh uint
6468
// ConnMgrGrace is a time duration that new connections are immune from being
6569
// closed by the connection manager.
66-
ConnMgrGrace Duration
70+
ConnMgrGrace time.Duration
6771
}
6872

6973
type Pubsub struct {

deps/config/doc_gen.go

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/config/old_lotus_miner.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type DAGStoreConfig struct {
8585
// The time between calls to periodic dagstore GC, in time.Duration string
8686
// representation, e.g. 1m, 5m, 1h.
8787
// Default value: 1 minute.
88-
GCInterval Duration
88+
GCInterval time.Duration
8989
}
9090

9191
type MinerAddressConfig struct {
@@ -203,11 +203,11 @@ type SealingConfig struct {
203203
// CommittedCapacitySectorLifetime is the duration a Committed Capacity (CC) sector will
204204
// live before it must be extended or converted into sector containing deals before it is
205205
// terminated. Value must be between 180-1278 days (1278 in nv21, 540 before nv21).
206-
CommittedCapacitySectorLifetime Duration
206+
CommittedCapacitySectorLifetime time.Duration
207207

208208
// Period of time that a newly created sector will wait for more deals to be packed in to before it starts to seal.
209209
// Sectors which are fully filled will start sealing immediately
210-
WaitDealsDelay Duration
210+
WaitDealsDelay time.Duration
211211

212212
// Whether to keep unsealed copies of deal data regardless of whether the client requested that. This lets the miner
213213
// avoid the relatively high cost of unsealing the data later, at the cost of more storage space
@@ -234,9 +234,9 @@ type SealingConfig struct {
234234
// maximum precommit batch size - batches will be sent immediately above this size
235235
MaxPreCommitBatch int
236236
// how long to wait before submitting a batch after crossing the minimum batch size
237-
PreCommitBatchWait Duration
237+
PreCommitBatchWait time.Duration
238238
// time buffer for forceful batch submission before sectors/deal in batch would start expiring
239-
PreCommitBatchSlack Duration
239+
PreCommitBatchSlack time.Duration
240240

241241
// enable / disable commit aggregation (takes effect after nv13)
242242
AggregateCommits bool
@@ -245,9 +245,9 @@ type SealingConfig struct {
245245
// maximum batched commit size - batches will be sent immediately above this size
246246
MaxCommitBatch int
247247
// how long to wait before submitting a batch after crossing the minimum batch size
248-
CommitBatchWait Duration
248+
CommitBatchWait time.Duration
249249
// time buffer for forceful batch submission before sectors/deals in batch would start expiring
250-
CommitBatchSlack Duration
250+
CommitBatchSlack time.Duration
251251

252252
// network BaseFee below which to stop doing precommit batching, instead
253253
// sending precommit messages to the chain individually. When the basefee is
@@ -267,7 +267,7 @@ type SealingConfig struct {
267267

268268
TerminateBatchMax uint64
269269
TerminateBatchMin uint64
270-
TerminateBatchWait Duration
270+
TerminateBatchWait time.Duration
271271

272272
// Keep this many sectors in sealing pipeline, start CC if needed
273273
// todo TargetSealingSectors uint64
@@ -304,7 +304,7 @@ type ProvingConfig struct {
304304
// test challenge took longer than this timeout
305305
// WARNING: Setting this value too high risks missing PoSt deadline in case IO operations related to this sector are
306306
// blocked (e.g. in case of disconnected NFS mount)
307-
SingleCheckTimeout Duration
307+
SingleCheckTimeout time.Duration
308308

309309
// Maximum amount of time a proving pre-check can take for an entire partition. If the check times out, sectors in
310310
// the partition which didn't get checked on time will be skipped
@@ -313,7 +313,7 @@ type ProvingConfig struct {
313313
// test challenge took longer than this timeout
314314
// WARNING: Setting this value too high risks missing PoSt deadline in case IO operations related to this partition are
315315
// blocked or slow
316-
PartitionCheckTimeout Duration
316+
PartitionCheckTimeout time.Duration
317317

318318
// Disable Window PoSt computation on the lotus-miner process even if no window PoSt workers are present.
319319
//
@@ -434,12 +434,12 @@ type DealmakingConfig struct {
434434
// Maximum expected amount of time getting the deal into a sealed sector will take
435435
// This includes the time the deal will need to get transferred and published
436436
// before being assigned to a sector
437-
ExpectedSealDuration Duration
437+
ExpectedSealDuration time.Duration
438438
// Maximum amount of time proposed deal StartEpoch can be in future
439-
MaxDealStartDelay Duration
439+
MaxDealStartDelay time.Duration
440440
// When a deal is ready to publish, the amount of time to wait for more
441441
// deals to be ready to publish before publishing them all as a batch
442-
PublishMsgPeriod Duration
442+
PublishMsgPeriod time.Duration
443443
// The maximum number of deals to include in a single PublishStorageDeals
444444
// message
445445
MaxDealsPerPublishMsg uint64
@@ -537,7 +537,7 @@ func DefaultStorageMiner() *StorageMiner {
537537
MaxWaitDealsSectors: 2, // 64G with 32G sectors
538538
MaxSealingSectors: 0,
539539
MaxSealingSectorsForDeals: 0,
540-
WaitDealsDelay: Duration(time.Hour * 6),
540+
WaitDealsDelay: time.Hour * 6,
541541
AlwaysKeepUnsealedCopy: true,
542542
FinalizeEarly: false,
543543
MakeNewSectorForDeals: true,
@@ -547,32 +547,32 @@ func DefaultStorageMiner() *StorageMiner {
547547
DisableCollateralFallback: false,
548548

549549
MaxPreCommitBatch: miner5.PreCommitSectorBatchMaxSize, // up to 256 sectors
550-
PreCommitBatchWait: Duration(24 * time.Hour), // this should be less than 31.5 hours, which is the expiration of a precommit ticket
550+
PreCommitBatchWait: 24 * time.Hour, // this should be less than 31.5 hours, which is the expiration of a precommit ticket
551551
// XXX snap deals wait deals slack if first
552-
PreCommitBatchSlack: Duration(3 * time.Hour), // time buffer for forceful batch submission before sectors/deals in batch would start expiring, higher value will lower the chances for message fail due to expiration
552+
PreCommitBatchSlack: 3 * time.Hour, // time buffer for forceful batch submission before sectors/deals in batch would start expiring, higher value will lower the chances for message fail due to expiration
553553

554-
CommittedCapacitySectorLifetime: Duration(builtin.EpochDurationSeconds * uint64(maxSectorExtentsion) * uint64(time.Second)),
554+
CommittedCapacitySectorLifetime: time.Duration(builtin.EpochDurationSeconds * uint64(maxSectorExtentsion) * uint64(time.Second)),
555555

556556
AggregateCommits: true,
557557
MinCommitBatch: miner5.MinAggregatedSectors, // per FIP13, we must have at least four proofs to aggregate, where 4 is the cross over point where aggregation wins out on single provecommit gas costs
558558
MaxCommitBatch: miner5.MaxAggregatedSectors, // maximum 819 sectors, this is the maximum aggregation per FIP13
559-
CommitBatchWait: Duration(24 * time.Hour), // this can be up to 30 days
560-
CommitBatchSlack: Duration(1 * time.Hour), // time buffer for forceful batch submission before sectors/deals in batch would start expiring, higher value will lower the chances for message fail due to expiration
559+
CommitBatchWait: 24 * time.Hour, // this can be up to 30 days
560+
CommitBatchSlack: 1 * time.Hour, // time buffer for forceful batch submission before sectors/deals in batch would start expiring, higher value will lower the chances for message fail due to expiration
561561

562562
BatchPreCommitAboveBaseFee: types.FIL(types.BigMul(types.PicoFil, types.NewInt(320))), // 0.32 nFIL
563563
AggregateAboveBaseFee: types.FIL(types.BigMul(types.PicoFil, types.NewInt(320))), // 0.32 nFIL
564564

565565
TerminateBatchMin: 1,
566566
TerminateBatchMax: 100,
567-
TerminateBatchWait: Duration(5 * time.Minute),
567+
TerminateBatchWait: 5 * time.Minute,
568568
MaxSectorProveCommitsSubmittedPerEpoch: 20,
569569
UseSyntheticPoRep: false,
570570
},
571571

572572
Proving: ProvingConfig{
573573
ParallelCheckLimit: 32,
574-
PartitionCheckTimeout: Duration(20 * time.Minute),
575-
SingleCheckTimeout: Duration(10 * time.Minute),
574+
PartitionCheckTimeout: 20 * time.Minute,
575+
SingleCheckTimeout: 10 * time.Minute,
576576
},
577577

578578
Storage: SealerConfig{
@@ -605,9 +605,9 @@ func DefaultStorageMiner() *StorageMiner {
605605
ConsiderUnverifiedStorageDeals: true,
606606
PieceCidBlocklist: []cid.Cid{},
607607
// TODO: It'd be nice to set this based on sector size
608-
MaxDealStartDelay: Duration(time.Hour * 24 * 14),
609-
ExpectedSealDuration: Duration(time.Hour * 24),
610-
PublishMsgPeriod: Duration(time.Hour),
608+
MaxDealStartDelay: time.Hour * 24 * 14,
609+
ExpectedSealDuration: time.Hour * 24,
610+
PublishMsgPeriod: time.Hour,
611611
MaxDealsPerPublishMsg: 8,
612612
MaxProviderCollateralMultiplier: 2,
613613

@@ -678,7 +678,7 @@ func DefaultStorageMiner() *StorageMiner {
678678
MaxConcurrentIndex: 5,
679679
MaxConcurrencyStorageCalls: 100,
680680
MaxConcurrentUnseals: 5,
681-
GCInterval: Duration(1 * time.Minute),
681+
GCInterval: time.Minute,
682682
},
683683
HarmonyDB: HarmonyDB{
684684
Hosts: []string{"127.0.0.1"},
@@ -698,7 +698,7 @@ func defCommon() Common {
698698
return Common{
699699
API: API{
700700
ListenAddress: "/ip4/127.0.0.1/tcp/1234/http",
701-
Timeout: Duration(30 * time.Second),
701+
Timeout: 30 * time.Second,
702702
},
703703
Logging: Logging{
704704
SubsystemLevels: map[string]string{
@@ -722,7 +722,7 @@ func defCommon() Common {
722722

723723
ConnMgrLow: 150,
724724
ConnMgrHigh: 180,
725-
ConnMgrGrace: Duration(20 * time.Second),
725+
ConnMgrGrace: 20 * time.Second,
726726
},
727727
Pubsub: Pubsub{
728728
Bootstrapper: false,

deps/config/types.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -447,25 +447,6 @@ type CurioProvingConfig struct {
447447
PartitionCheckTimeout time.Duration
448448
}
449449

450-
// Duration is a wrapper type for time.Duration
451-
// for decoding and encoding from/to TOML
452-
type Duration time.Duration
453-
454-
func (dur Duration) MarshalText() ([]byte, error) {
455-
d := time.Duration(dur)
456-
return []byte(d.String()), nil
457-
}
458-
459-
// UnmarshalText implements interface for TOML decoding
460-
func (dur *Duration) UnmarshalText(text []byte) error {
461-
d, err := time.ParseDuration(string(text))
462-
if err != nil {
463-
return err
464-
}
465-
*dur = Duration(d)
466-
return err
467-
}
468-
469450
type CurioIngestConfig struct {
470451
// MaxMarketRunningPipelines is the maximum number of market pipelines that can be actively running tasks.
471452
// A "running" pipeline is one that has at least one task currently assigned to a machine (owner_id is not null).

lib/testutils/testutils.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,25 @@ import (
2727

2828
const defaultHashFunction = uint64(multihash.BLAKE2B_MIN + 31)
2929

30-
func CreateRandomFile(dir string, rseed, size int) (string, error) {
31-
source := io.LimitReader(rand.New(rand.NewSource(int64(rseed))), int64(size))
30+
func CreateRandomFile(dir string, rseed int64, size int64) (string, error) {
31+
source := io.LimitReader(rand.New(rand.NewSource(rseed)), size)
3232

3333
file, err := os.CreateTemp(dir, "sourcefile.dat")
3434
if err != nil {
3535
return "", err
3636
}
3737

38-
_, err = io.Copy(file, source)
38+
buff := make([]byte, 4<<20)
39+
40+
n, err := io.CopyBuffer(file, source, buff)
3941
if err != nil {
4042
return "", err
4143
}
4244

45+
if n != size {
46+
return "", fmt.Errorf("incorrect file size: written %d != expected %d", n, size)
47+
}
48+
4349
//
4450
_, err = file.Seek(0, io.SeekStart)
4551
if err != nil {

market/indexstore/indexstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestNewIndexStore(t *testing.T) {
4242
_ = os.RemoveAll(dir)
4343
}()
4444

45-
rf, err := testutils.CreateRandomFile(dir, int(time.Now().Unix()), 8000000)
45+
rf, err := testutils.CreateRandomFile(dir, time.Now().Unix(), 8000000)
4646
require.NoError(t, err)
4747

4848
caropts := []carv2.Option{

web/api/apihelper/apihelper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import (
77
logging "github.com/ipfs/go-log/v2"
88
)
99

10-
var log = logging.Logger("cu/web/apihelper")
10+
var log = logging.Logger("apihelper")
1111

1212
func OrHTTPFail(w http.ResponseWriter, err error) {
1313
if err != nil {
14-
w.WriteHeader(500)
15-
_, _ = w.Write([]byte(err.Error()))
14+
http.Error(w, err.Error(), 500)
1615
log.Errorw("http fail", "err", err, "stack", string(debug.Stack()))
1716
panic(err)
1817
}

web/api/config/config.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
"github.com/filecoin-project/curio/deps"
1717
"github.com/filecoin-project/curio/deps/config"
1818
"github.com/filecoin-project/curio/web/api/apihelper"
19+
20+
"github.com/filecoin-project/lotus/chain/types"
1921
)
2022

21-
var log = logging.Logger("curio/web/config")
23+
var log = logging.Logger("config-ui")
2224

2325
type cfg struct {
2426
*deps.Deps
@@ -59,10 +61,16 @@ func (c *cfg) addLayer(w http.ResponseWriter, r *http.Request) {
5961
func getSch(w http.ResponseWriter, r *http.Request) {
6062
ref := jsonschema.Reflector{
6163
Mapper: func(i reflect.Type) *jsonschema.Schema {
62-
if i == reflect.TypeOf(config.Duration(time.Second)) {
64+
if i == reflect.TypeOf(types.MustParseFIL("1 Fil")) { // Override the Pattern for types.FIL
65+
return &jsonschema.Schema{
66+
Type: "string",
67+
Pattern: "1 fil/0.03 fil/0.31/1 attofil",
68+
}
69+
}
70+
if i == reflect.TypeOf(time.Second) { // Override the Pattern for types.FIL
6371
return &jsonschema.Schema{
64-
Type: "string",
65-
Format: "duration",
72+
Type: "string",
73+
Pattern: "0h0m0s",
6674
}
6775
}
6876
return nil
@@ -147,14 +155,15 @@ func (c *cfg) setLayer(w http.ResponseWriter, r *http.Request) {
147155

148156
configStr := tomlData.String()
149157

158+
curioCfg := config.DefaultCurioConfig()
159+
_, err = deps.LoadConfigWithUpgrades(tomlData.String(), curioCfg)
160+
apihelper.OrHTTPFail(w, err)
161+
162+
cb, err := config.ConfigUpdate(curioCfg, config.DefaultCurioConfig(), config.Commented(true), config.DefaultKeepUncommented(), config.NoEnv())
163+
apihelper.OrHTTPFail(w, err)
164+
150165
// Generate a full commented string if this is base layer
151166
if layer == "base" {
152-
// Parse the into CurioConfig TOML
153-
curioCfg := config.DefaultCurioConfig()
154-
_, err = deps.LoadConfigWithUpgrades(tomlData.String(), curioCfg)
155-
apihelper.OrHTTPFail(w, err)
156-
cb, err := config.ConfigUpdate(curioCfg, config.DefaultCurioConfig(), config.Commented(true), config.DefaultKeepUncommented(), config.NoEnv())
157-
apihelper.OrHTTPFail(w, err)
158167
configStr = string(cb)
159168
}
160169

0 commit comments

Comments
 (0)