-
Notifications
You must be signed in to change notification settings - Fork 71
/
dealfilter.go
99 lines (84 loc) · 3.46 KB
/
dealfilter.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
package modules
import (
"context"
"fmt"
"github.com/filecoin-project/boost/node/config"
"github.com/filecoin-project/boost/node/modules/dtypes"
"github.com/filecoin-project/boost/storagemarket/dealfilter"
lotus_repo "github.com/filecoin-project/lotus/node/repo"
)
func BasicDealFilter(cfg config.DealmakingConfig, userCmd dtypes.StorageDealFilter) func(onlineOk dtypes.ConsiderOnlineStorageDealsConfigFunc,
offlineOk dtypes.ConsiderOfflineStorageDealsConfigFunc,
verifiedOk dtypes.ConsiderVerifiedStorageDealsConfigFunc,
unverifiedOk dtypes.ConsiderUnverifiedStorageDealsConfigFunc,
blocklistFunc dtypes.StorageDealPieceCidBlocklistConfigFunc,
expectedSealTimeFunc dtypes.GetExpectedSealDurationFunc,
startDelay dtypes.GetMaxDealStartDelayFunc,
r lotus_repo.LockedRepo,
) dtypes.StorageDealFilter {
return func(onlineOk dtypes.ConsiderOnlineStorageDealsConfigFunc,
offlineOk dtypes.ConsiderOfflineStorageDealsConfigFunc,
verifiedOk dtypes.ConsiderVerifiedStorageDealsConfigFunc,
unverifiedOk dtypes.ConsiderUnverifiedStorageDealsConfigFunc,
blocklistFunc dtypes.StorageDealPieceCidBlocklistConfigFunc,
expectedSealTimeFunc dtypes.GetExpectedSealDurationFunc,
startDelay dtypes.GetMaxDealStartDelayFunc,
r lotus_repo.LockedRepo,
) dtypes.StorageDealFilter {
return func(ctx context.Context, params dealfilter.DealFilterParams) (bool, string, error) {
deal := params.DealParams
pr := deal.ClientDealProposal.Proposal
// TODO: maybe handle in userCmd?
b, err := onlineOk()
if err != nil {
return false, "miner error", err
}
if !deal.IsOffline && !b {
log.Warnf("online storage deal consideration disabled; rejecting storage deal proposal from client: %s", deal.ClientDealProposal.Proposal.Client.String())
return false, "miner is not considering online storage deals", nil
}
// TODO: maybe handle in userCmd?
b, err = offlineOk()
if err != nil {
return false, "miner error", err
}
if deal.IsOffline && !b {
log.Warnf("offline storage deal consideration disabled; rejecting storage deal proposal from client: %s", deal.ClientDealProposal.Proposal.Client.String())
return false, "miner is not accepting offline storage deals", nil
}
// TODO: maybe handle in userCmd?
b, err = verifiedOk()
if err != nil {
return false, "miner error", err
}
if pr.VerifiedDeal && !b {
log.Warnf("verified storage deal consideration disabled; rejecting storage deal proposal from client: %s", pr.Client.String())
return false, "miner is not accepting verified storage deals", nil
}
// TODO: maybe handle in userCmd?
b, err = unverifiedOk()
if err != nil {
return false, "miner error", err
}
if !pr.VerifiedDeal && !b {
log.Warnf("unverified storage deal consideration disabled; rejecting storage deal proposal from client: %s", pr.Client.String())
return false, "miner is not accepting unverified storage deals", nil
}
// TODO: maybe handle in userCmd?
blocklist, err := blocklistFunc()
if err != nil {
return false, "miner error", err
}
for idx := range blocklist {
if deal.ClientDealProposal.Proposal.PieceCID.Equals(blocklist[idx]) {
log.Warnf("piece CID in proposal %s is blocklisted; rejecting storage deal proposal from client: %s", pr.PieceCID, pr.Client.String())
return false, fmt.Sprintf("miner has blocklisted piece CID %s", pr.PieceCID), nil
}
}
if userCmd != nil {
return userCmd(ctx, params)
}
return true, "", nil
}
}
}