Skip to content

Commit 3f33e68

Browse files
committed
minor fixes
1 parent 51bc1b0 commit 3f33e68

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

lib/filecoinpayment/utils.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ func SettleLockupPeriod(ctx context.Context, db *harmonydb.DB, ethClient *ethcli
6161
railIds = append(railIds, r.RailId)
6262
}
6363

64-
// If rail terminated in the last 15 days, we should try to settle it
65-
// TODO: Rethink this to be more generic
66-
if uint64(r.EndEpoch.Int64()) > current-(builtin.EpochsInDay*15) {
64+
// If rail terminated in the last 30 days, we should consider it for settlement
65+
if uint64(r.EndEpoch.Int64()) > current-(builtin.EpochsInDay*30) {
6766
railIds = append(railIds, r.RailId)
6867
}
6968
}

tasks/pay/settle_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (s *SettleTask) TypeDetails() harmonytask.TaskTypeDetails {
9292
Ram: 64 << 20,
9393
},
9494
MaxFailures: 3,
95-
IAmBored: harmonytask.SingletonTaskAdder(time.Hour*24, s),
95+
IAmBored: harmonytask.SingletonTaskAdder(time.Hour*48, s),
9696
}
9797
}
9898

tasks/pdp/task_terminate_data_set.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (t *DeleteDataSetTask) TypeDetails() harmonytask.TaskTypeDetails {
132132
Ram: 64 << 20,
133133
},
134134
MaxFailures: 3,
135-
IAmBored: passcall.Every(time.Minute, func(taskFunc harmonytask.AddTaskFunc) error {
135+
IAmBored: passcall.Every(time.Hour, func(taskFunc harmonytask.AddTaskFunc) error {
136136
return t.schedule(context.Background(), taskFunc)
137137
}),
138138
}
@@ -174,7 +174,12 @@ func (t *DeleteDataSetTask) schedule(ctx context.Context, addTaskFunc harmonytas
174174

175175
pending := pendings[0]
176176

177-
n, err := tx.Exec(`UPDATE pdp_delete_data_set SET terminate_service_task_id = $1 WHERE id = $2 AND terminate_service_task_id IS NULL AND after_terminate_service = FALSE`, taskID, pending)
177+
n, err := tx.Exec(`UPDATE pdp_delete_data_set
178+
SET terminate_service_task_id = $1
179+
WHERE id = $2
180+
AND delete_data_set_task_id IS NULL
181+
AND after_delete_data_set = FALSE
182+
AND after_terminate_service = TRUE`, taskID, pending)
178183

179184
if err != nil {
180185
return false, xerrors.Errorf("failed to update pdp_delete_data_set: %w", err)

tasks/pdp/task_terminate_service.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"math/big"
77
"time"
88

9+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
910
"github.com/ethereum/go-ethereum/common"
1011
"github.com/ethereum/go-ethereum/core/types"
1112
"github.com/ethereum/go-ethereum/ethclient"
@@ -46,6 +47,32 @@ func (t *TerminateServiceTask) Do(taskID harmonytask.TaskID, stillOwned func() b
4647
return false, xerrors.Errorf("failed to select data set: %w", err)
4748
}
4849

50+
sAddr := contract.ContractAddresses().AllowedPublicRecordKeepers.FWSService
51+
fwssv, err := FWSS.NewFilecoinWarmStorageServiceStateView(sAddr, t.ethClient)
52+
if err != nil {
53+
return false, xerrors.Errorf("failed to instantiate FWSS service state view: %w", err)
54+
}
55+
56+
ds, err := fwssv.GetDataSet(&bind.CallOpts{Context: ctx}, big.NewInt(dataSetId))
57+
if err != nil {
58+
return false, xerrors.Errorf("failed to get data set %d: %w", dataSetId, err)
59+
}
60+
61+
if ds.PdpEndEpoch.Int64() != 0 {
62+
n, err := t.db.Exec(ctx, `UPDATE pdp_delete_data_set
63+
SET after_terminate_service = TRUE,
64+
terminate_service_task_id = NULL,
65+
termination_epoch = $2
66+
WHERE terminate_service_task_id = $1`, taskID, ds.PdpEndEpoch.Int64())
67+
if err != nil {
68+
return false, xerrors.Errorf("failed to update pdp_delete_data_set: %w", err)
69+
}
70+
71+
if n != 1 {
72+
return false, xerrors.Errorf("expected to update 1 row but got %d", n)
73+
}
74+
}
75+
4976
sender, err := getPDPOwner(ctx, t.db)
5077
if err != nil {
5178
return false, xerrors.Errorf("failed to get pdp owner: %w", err)

tasks/pdp/watch_data_set_delete.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ func NewDataSetDeleteWatcher(db *harmonydb.DB, ethClient *ethclient.Client, pcs
3535
func processPendingDeletes(ctx context.Context, db *harmonydb.DB, ethClient *ethclient.Client) error {
3636
var deletes []dataSetDelete
3737

38-
err := db.Select(ctx, &deletes, `SELECT id, delete_tx_hash FROM pdp_delete_data_set WHERE termination_epoch IS NOT NULL AND terminated = FALSE`)
38+
err := db.Select(ctx, &deletes, `SELECT id, delete_tx_hash
39+
FROM pdp_delete_data_set
40+
WHERE termination_epoch IS NOT NULL
41+
AND terminated = FALSE
42+
AND after_delete_data_set = TRUE
43+
AND delete_tx_hash IS NOT NULL`)
3944
if err != nil {
4045
return xerrors.Errorf("failed to select pending data sets: %w", err)
4146
}

tasks/pdp/watch_fwss_terminate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func processPendingTermination(ctx context.Context, db *harmonydb.DB, client *et
8282
return xerrors.Errorf("failed to get data set %d: %w", term.DataSetId, err)
8383
}
8484

85+
if ds.PdpEndEpoch.Int64() == 0 {
86+
// Huston! we have a serious problem
87+
return xerrors.Errorf("data set %d has no termination epoch", term.DataSetId)
88+
}
89+
8590
n, err := db.Exec(ctx, `UPDATE pdp_delete_data_set SET termination_epoch = $1 WHERE id = $2`, ds.PdpEndEpoch.Int64(), term.DataSetId)
8691
if err != nil {
8792
return xerrors.Errorf("failed to update pdp_delete_data_set: %w", err)

0 commit comments

Comments
 (0)