Skip to content

Commit

Permalink
Merge pull request #657 from TRON-US/v1.3.6-release
Browse files Browse the repository at this point in the history
v1.3.6 release
  • Loading branch information
Eric Chen authored Aug 21, 2020
2 parents 20c165c + b1b5f14 commit b1722d1
Show file tree
Hide file tree
Showing 40 changed files with 638 additions and 184 deletions.
1 change: 1 addition & 0 deletions core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func TestCommands(t *testing.T) {
"/wallet/transactions",
"/wallet/transfer",
"/wallet/import",
"/wallet/discovery",
"/tron",
"/tron/prepare",
"/tron/send",
Expand Down
1 change: 1 addition & 0 deletions core/commands/rm/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func RmDag(ctx context.Context, hashes []string, n *core.IpfsNode, req *cmds.Req
if err != nil {
return nil, err
}

if pinned {
// Since we are removing a file, we need to set recursive flag to true
err = api.Pin().Rm(ctx, p, options.Pin.RmRecursive(true), options.Pin.RmForce(force))
Expand Down
97 changes: 83 additions & 14 deletions core/commands/storage/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ import (
)

const (
hostStoragePriceOptionName = "host-storage-price"
hostBandwidthPriceOptionName = "host-bandwidth-price"
hostCollateralPriceOptionName = "host-collateral-price"
hostBandwidthLimitOptionName = "host-bandwidth-limit"
hostStorageTimeMinOptionName = "host-storage-time-min"
hostStorageMaxOptionName = "host-storage-max"
hostStorageEnableOptionName = "enable-host-mode"
hostStoragePriceOptionName = "host-storage-price"
hostBandwidthPriceOptionName = "host-bandwidth-price"
hostCollateralPriceOptionName = "host-collateral-price"
hostBandwidthLimitOptionName = "host-bandwidth-limit"
hostStorageTimeMinOptionName = "host-storage-time-min"
hostStorageMaxOptionName = "host-storage-max"
hostStorageEnableOptionName = "enable-host-mode"
hostStorageCustomizedPricingOptionName = "host-storage-customized-pricing"

repairHostEnabledOptionName = "repair-host-enabled"
repairPriceDefaultOptionName = "repair-price-default"
repairPriceCustomizedOptionName = "repair-price-customized"
repairCustomizedPricingOptionName = "repair-customized-pricing"

challengeHostEnabledOptionName = "challenge-host-enabled"
challengePriceDefaultOptionName = "challenge-price-default"
challengePriceCustomizedOptionName = "challenge-price-customized"
challengeCustomizedPricingOptionName = "challenge-customized-pricing"

bttTotalSupply uint64 = 990_000_000_000
)
Expand All @@ -31,17 +42,26 @@ This command updates host information and broadcasts to the BTFS network.
Examples
To set the min price per GiB to 1000000 JUST (1 BTT):
To set the min price per GiB to 1000000 µBTT (1 BTT):
$ btfs storage announce --host-storage-price=1000000`,
},
Options: []cmds.Option{
cmds.Uint64Option(hostStoragePriceOptionName, "s", "Min price per GiB of storage per day in JUST."),
cmds.Uint64Option(hostBandwidthPriceOptionName, "b", "Min price per MiB of bandwidth in JUST."),
cmds.Uint64Option(hostCollateralPriceOptionName, "cl", "Max collateral stake per hour per GiB in JUST."),
cmds.Uint64Option(hostStoragePriceOptionName, "s", "Min price per GiB of storage per day in µBTT."),
cmds.Uint64Option(hostBandwidthPriceOptionName, "b", "Min price per MiB of bandwidth in µBTT."),
cmds.Uint64Option(hostCollateralPriceOptionName, "cl", "Max collateral stake per hour per GiB in µBTT."),
cmds.FloatOption(hostBandwidthLimitOptionName, "l", "Max bandwidth limit per MB/s."),
cmds.Uint64Option(hostStorageTimeMinOptionName, "d", "Min number of days for storage."),
cmds.Uint64Option(hostStorageMaxOptionName, "m", "Max number of GB this host provides for storage."),
cmds.BoolOption(hostStorageEnableOptionName, "hm", "Enable/disable host storage mode. By default no mode change is made. When specified, toggles between enable/disable host mode."),
cmds.BoolOption(hostStorageCustomizedPricingOptionName, "scp", fmt.Sprintf("Control customized pricing feature. Set false to disable and use network default price instead. Can only be enabled by explicitly setting %s.", hostStoragePriceOptionName)),
cmds.BoolOption(repairHostEnabledOptionName, "rm", "Enable/disable repair mode. By default no mode change is made. When specified, toggles between enable/disable repair mode."),
cmds.BoolOption(challengeHostEnabledOptionName, "cm", "Enable/disable challenge mode. By default no mode change is made. When specified, toggles between enable/disable challenge mode."),
cmds.BoolOption(repairCustomizedPricingOptionName, "rc", "Options of repair price, true for customized price and false means default price."),
cmds.BoolOption(challengeCustomizedPricingOptionName, "cc", "Options of challenge price, true for customized price and false means default price."),
cmds.Uint64Option(repairPriceDefaultOptionName, "rpd", "Host repair default price refer to market."),
cmds.Uint64Option(repairPriceCustomizedOptionName, "rpc", "Customized repair price provides by enabled Host."),
cmds.Uint64Option(challengePriceDefaultOptionName, "cpd", "Host challenge default price refer to market."),
cmds.Uint64Option(challengePriceCustomizedOptionName, "cpc", "Customized challenge price provides by enabled Host."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
cfg, err := cmdenv.GetConfig(env)
Expand All @@ -64,9 +84,27 @@ $ btfs storage announce --host-storage-price=1000000`,
return err
}
}
// turned off, do nothing
if !hm {
return nil
}

rm, rmFound := req.Options[repairHostEnabledOptionName].(bool)
if rmFound {
if rm != cfg.Experimental.HostRepairEnabled {
cfg.Experimental.HostRepairEnabled = rm
err = n.Repo.SetConfig(cfg)
if err != nil {
return err
}
}
}

cm, cmFound := req.Options[challengeHostEnabledOptionName].(bool)
if cmFound {
if cm != cfg.Experimental.HostChallengeEnabled {
cfg.Experimental.HostChallengeEnabled = cm
err = n.Repo.SetConfig(cfg)
if err != nil {
return err
}
}
}

Expand All @@ -76,6 +114,14 @@ $ btfs storage announce --host-storage-price=1000000`,
bl, blFound := req.Options[hostBandwidthLimitOptionName].(float64)
stm, stmFound := req.Options[hostStorageTimeMinOptionName].(uint64)
sm, smFound := req.Options[hostStorageMaxOptionName].(uint64)
scp, scpFound := req.Options[hostStorageCustomizedPricingOptionName].(bool)

rc, rcFound := req.Options[repairCustomizedPricingOptionName].(bool)
cc, ccFound := req.Options[challengeCustomizedPricingOptionName].(bool)
rpd, rpdFound := req.Options[repairPriceDefaultOptionName].(uint64)
rpc, rpcFound := req.Options[repairPriceCustomizedOptionName].(uint64)
cpd, cpdFound := req.Options[challengePriceDefaultOptionName].(uint64)
cpc, cpcFound := req.Options[challengePriceCustomizedOptionName].(uint64)

if sp > bttTotalSupply || cp > bttTotalSupply || bp > bttTotalSupply {
return fmt.Errorf("maximum price is %d", bttTotalSupply)
Expand All @@ -89,6 +135,11 @@ $ btfs storage announce --host-storage-price=1000000`,
// Update fields if set
if spFound {
ns.StoragePriceAsk = sp
ns.CustomizedPricing = true // turns on since we've set a price
} else if scpFound && !scp {
// Can only disable if no conflict with set price
ns.StoragePriceAsk = ns.StoragePriceDefault
ns.CustomizedPricing = false
}
if bpFound {
ns.BandwidthPriceAsk = bp
Expand All @@ -114,6 +165,24 @@ $ btfs storage announce --host-storage-price=1000000`,
return err
}
}
if rcFound {
ns.RepairCustomizedPricing = rc
}
if rpdFound {
ns.RepairPriceDefault = rpd
}
if rpcFound {
ns.RepairPriceCustomized = rpc
}
if ccFound {
ns.ChallengeCustomizedPricing = cc
}
if cpdFound {
ns.ChallengePriceDefault = cpd
}
if cpcFound {
ns.ChallengePriceCustomized = cpc
}

err = helper.PutHostStorageConfig(n, ns)
if err != nil {
Expand Down
21 changes: 19 additions & 2 deletions core/commands/storage/helper/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,39 @@ func GetHostStorageConfigForPeer(node *core.IpfsNode, peerID string) (*nodepb.No
// GetHostStorageConfig checks if locally is storing a config, if yes, returns it,
// otherwise, queries hub to retrieve the latest default config.
func GetHostStorageConfig(ctx context.Context, node *core.IpfsNode) (*nodepb.Node_Settings, error) {
return GetHostStorageConfigHelper(ctx, node, false)
}

// GetHostStorageConfigHelper checks if locally is storing a config, if yes, returns it,
// otherwise, queries hub to retrieve the latest default config.
// If syncHub is on, force a sync from Hub to retrieve latest information.
func GetHostStorageConfigHelper(ctx context.Context, node *core.IpfsNode,
syncHub bool) (*nodepb.Node_Settings, error) {
ns, err := GetHostStorageConfigForPeer(node, node.Identity.Pretty())
if err != nil && err != ds.ErrNotFound {
return nil, fmt.Errorf("cannot get current host storage settings: %s", err.Error())
}
// Exists
if err == nil {
if err == nil && !syncHub {
return ns, nil
}
cfg, err := node.Repo.Config()
if err != nil {
return nil, err
}
ns, err = hub.GetHostSettings(ctx, cfg.Services.HubDomain, node.Identity.Pretty())
hns, err := hub.GetHostSettings(ctx, cfg.Services.HubDomain, node.Identity.Pretty())
if err != nil {
return nil, err
}
// ns aleady exists, so replace with newer settings
if ns != nil {
ns.StoragePriceDefault = hns.StoragePriceDefault
if !ns.CustomizedPricing {
ns.StoragePriceAsk = hns.StoragePriceAsk
}
} else {
ns = hns
}
err = PutHostStorageConfig(node, ns)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/commands/storage/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This command displays host information synchronized from the BTFS network.
By default it shows local host node information.`,
},
Arguments: []cmds.Argument{
cmds.StringArg("peer-id", false, false, "Peer ID to show storage-related information. Default to self.").EnableStdin(),
cmds.StringArg("peer-id", false, false, "Peer ID to show storage-related information. Default to self."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
cfg, err := cmdenv.GetConfig(env)
Expand Down
8 changes: 8 additions & 0 deletions core/commands/storage/stats_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ func SyncStats(ctx context.Context, cfg *config.Config, node *core.IpfsNode, env
Online: cfg.Experimental.StorageHostEnabled,
Uptime: sr.Uptime,
Score: sr.Score,
UptimeScore: sr.UptimeScore,
AgeScore: sr.AgeScore,
VersionScore: sr.VersionScore,
SpeedScore: sr.SpeedScore,
UptimeWeight: sr.UptimeWeight,
AgeWeight: sr.AgeWeight,
VersionWeight: sr.VersionWeight,
SpeedWeight: sr.SpeedWeight,
StorageUsed: int64(stat.RepoSize),
StorageCap: int64(stat.StorageMax),
StorageDiskTotal: int64(du.Total),
Expand Down
26 changes: 24 additions & 2 deletions core/commands/storage/upload/sessions/renter_shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ func ListShardsContracts(d datastore.Datastore, peerId string, role string) ([]*
return contracts, nil
}

func DeleteShardsContracts(d datastore.Datastore, peerId string, role string) error {
var k string
if k = fmt.Sprintf(renterShardPrefix, peerId); role == nodepb.ContractStat_HOST.String() {
k = fmt.Sprintf(hostShardPrefix, peerId)
}
ks, err := ListKeys(d, k, "/contracts")
if err != nil {
return err
}
vs := make([]proto.Message, len(ks))
for range ks {
vs = append(vs, nil)
}
return Batch(d, ks, vs)
}

// SaveShardsContracts persists updated guard contracts from upstream, if an existing entry
// is not available, then an empty signed escrow contract is inserted along with the
// new guard contract.
Expand All @@ -193,10 +209,16 @@ func SaveShardsContracts(ds datastore.Datastore, scs []*shardpb.SignedContracts,
activeShards := map[string]bool{} // active shard hash -> has one file hash (bool)
activeFiles := map[string]bool{} // active file hash -> has one shard hash (bool)
invalidShards := map[string][]string{} // invalid shard hash -> (maybe) invalid file hash list
var key string
if role == nodepb.ContractStat_HOST.String() {
key = hostShardContractsKey
} else {
key = renterShardContractsKey
}
for _, c := range scs {
// only append the updated contracts
if gc, ok := gmap[c.SignedGuardContract.ContractId]; ok {
ks = append(ks, fmt.Sprintf(renterShardContractsKey, peerID, c.SignedGuardContract.ContractId))
ks = append(ks, fmt.Sprintf(key, peerID, c.SignedGuardContract.ContractId))
// update
c.SignedGuardContract = gc
vs = append(vs, c)
Expand All @@ -213,7 +235,7 @@ func SaveShardsContracts(ds datastore.Datastore, scs []*shardpb.SignedContracts,
}
// append what's left in guard map as new contracts
for contractID, gc := range gmap {
ks = append(ks, fmt.Sprintf(renterShardContractsKey, peerID, contractID))
ks = append(ks, fmt.Sprintf(key, peerID, contractID))
// add a new (guard contract only) signed contracts
c := &shardpb.SignedContracts{SignedGuardContract: gc}
scs = append(scs, c)
Expand Down
Loading

0 comments on commit b1722d1

Please sign in to comment.