Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2050903
swap: move oracle, paymentThreshold and disconnectThreshold to peer
Eknir Sep 3, 2019
83b9c3f
made thresholdOracle
Eknir Sep 3, 2019
82b100e
swap: using the paymentThresholdOracle, renaming priceOracle to honey…
Eknir Sep 3, 2019
6adc554
swap, api, cmd, swarm: made payment and disconnect threshold modifiable
Eknir Sep 3, 2019
578a2fc
swap: redo refactor => disconnectthreshold, thresholdOracle, honeyPri…
Eknir Sep 5, 2019
60d5a56
cmd/swarm/main: swapFlagsOverride
Eknir Sep 5, 2019
aa69db6
swap: AllowedNetworkID => DisabledNetworkID
Eknir Sep 5, 2019
4460d9a
swarm: updated TestNewSwarmFailure
Eknir Sep 5, 2019
db83c9e
cmd/swarm, swap: reverted unneeded changes
Eknir Sep 5, 2019
df154dc
cmd, swap, swarm: gofmt
Eknir Sep 5, 2019
bb85b52
swarm: goimports formatting
Eknir Sep 9, 2019
c49f905
Merge branch 'master' into incentives-thresholdConfig
Eknir Sep 9, 2019
ebd8314
api, cmd, swap: flag order and naming, removed paymentThresholdOracle
Eknir Sep 9, 2019
2cf5475
added tests
Eknir Sep 9, 2019
b6dea35
swap: made TestPaymentThreshold run
Eknir Sep 10, 2019
9bbbbbc
Merge branch 'master' into incentives-thresholdConfig
Eknir Sep 10, 2019
627fb77
swap: make complete incomplete merge in swap_test.go
Eknir Sep 10, 2019
a3b5137
swarm, swap: set config.NetworkID to config.DefaultNetworkID, removed…
Eknir Sep 10, 2019
70092e6
swap: removed redundant Prinln
Eknir Sep 10, 2019
33f0bc3
swarm: config.DefaultNetworkID => network.DefaultNetworkID
Eknir Sep 10, 2019
b0d1e54
Merge branch 'master' into incentives-thresholdConfig
Eknir Sep 10, 2019
db12380
swap: removed Spec from argument to newDummyPeer and newDummyProtocol…
Eknir Sep 10, 2019
5d7e68a
swap: fix misspelling
Eknir Sep 10, 2019
ff20676
api: commenting exported vars, swap: remove redundant vars
Eknir Sep 11, 2019
a1e0845
reverted allowedNetworkID/disabledNetworkID change
Eknir Sep 11, 2019
068e1dd
swarm, swap: SWAP integrity checks to NewSWAP, added check for discon…
Eknir Sep 11, 2019
f174f0d
cmd/swarm: get rid of magical numbers and use DefaultPaymentThreshold…
Eknir Sep 11, 2019
5227f7a
swap: updated comment of NewSWAP
Eknir Sep 11, 2019
9139dcc
Merge branch 'master' into incentives-thresholdConfig
Eknir Sep 11, 2019
faa6435
Merge branch 'master' into incentives-thresholdConfig
Eknir Sep 11, 2019
0368a99
swap: swap: call os.removeAll() in test, small refactor around paymen…
Eknir Sep 11, 2019
d652aa6
swap: rename TempDir
Eknir Sep 11, 2019
782b83d
create new dir for every swapStore
Eknir Sep 12, 2019
4d5a5ee
Merge branch 'master' into incentives-thresholdConfig
Eknir Sep 16, 2019
63b04ab
revert dummyPeer refactor
Eknir Sep 16, 2019
c0cc688
revert dummyPeer refactor
Eknir Sep 16, 2019
2765e9f
swap, swarm, cmd/swarm: rename swap constructor, remove redundant tes…
Eknir Sep 16, 2019
0f753f2
swarm: remove TODO comment
Eknir Sep 16, 2019
c5edfc2
swap: NewSWAP name update in test
Eknir Sep 16, 2019
acb3d89
swap: rename of variable in test and code comments
Eknir Sep 16, 2019
b8d9c0b
made thresholds an int64 on the swap object
Eknir Sep 17, 2019
e6de6c8
swap: grammatical correction TestNewSwapFailure comment
Eknir Sep 17, 2019
d0a7bc4
swap: removed int64 casting in tests
Eknir Sep 17, 2019
bf928a2
made comments w.r.t. flags from both peers point of view
Eknir Sep 17, 2019
49f0006
changed last comment w.r.t.s threshold comment from both peers point …
Eknir Sep 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/ethersphere/swarm/network"
"github.com/ethersphere/swarm/pss"
"github.com/ethersphere/swarm/storage"
"github.com/ethersphere/swarm/swap"
)

const (
Expand All @@ -52,12 +53,15 @@ type Config struct {
BaseKey []byte

// Swap configs
SwapBackendURL string
SwapEnabled bool
SwapBackendURL string // Ethereum API endpoint
SwapEnabled bool // whether SWAP incentives are enabled
SwapPaymentThreshold uint64 // honey amount at which a payment is triggered
SwapDisconnectThreshold uint64 // honey amount at which a peer disconnects
Contract common.Address // address of the chequebook contract
// end of Swap configs

*network.HiveParams
Pss *pss.Params
Contract common.Address
EnsRoot common.Address
EnsAPIs []string
Path string
Expand All @@ -81,26 +85,28 @@ type Config struct {
privateKey *ecdsa.PrivateKey
}

//create a default config with all parameters to set to defaults
//NewConfig creates a default config with all parameters to set to defaults
func NewConfig() (c *Config) {

c = &Config{
FileStoreParams: storage.NewFileStoreParams(),
HiveParams: network.NewHiveParams(),
Pss: pss.NewParams(),
ListenAddr: DefaultHTTPListenAddr,
Port: DefaultHTTPPort,
Path: node.DefaultDataDir(),
EnsAPIs: nil,
EnsRoot: ens.TestNetAddress,
NetworkID: network.DefaultNetworkID,
SyncEnabled: true,
SyncingSkipCheck: false,
MaxStreamPeerServers: 10000,
DeliverySkipCheck: true,
SyncUpdateDelay: 15 * time.Second,
SwapEnabled: false,
SwapBackendURL: "",
FileStoreParams: storage.NewFileStoreParams(),
SwapBackendURL: "",
SwapEnabled: false,
SwapPaymentThreshold: swap.DefaultPaymentThreshold,
SwapDisconnectThreshold: swap.DefaultDisconnectThreshold,
HiveParams: network.NewHiveParams(),
Pss: pss.NewParams(),
EnsRoot: ens.TestNetAddress,
EnsAPIs: nil,
Path: node.DefaultDataDir(),
ListenAddr: DefaultHTTPListenAddr,
Port: DefaultHTTPPort,
NetworkID: network.DefaultNetworkID,
SyncEnabled: true,
SyncingSkipCheck: false,
DeliverySkipCheck: true,
MaxStreamPeerServers: 10000,
SyncUpdateDelay: 15 * time.Second,
}

return
Expand Down
96 changes: 40 additions & 56 deletions cmd/swarm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"strings"
"unicode"

"github.com/ethereum/go-ethereum/common"
cli "gopkg.in/urfave/cli.v1"

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/naoina/toml"
Expand Down Expand Up @@ -59,33 +59,35 @@ var (

//constants for environment variables
const (
SwarmEnvChequebookAddr = "SWARM_CHEQUEBOOK_ADDR"
SwarmEnvAccount = "SWARM_ACCOUNT"
SwarmEnvBzzKeyHex = "SWARM_BZZ_KEY_HEX"
SwarmEnvListenAddr = "SWARM_LISTEN_ADDR"
SwarmEnvPort = "SWARM_PORT"
SwarmEnvNetworkID = "SWARM_NETWORK_ID"
SwarmEnvSwapEnable = "SWARM_SWAP_ENABLE"
SwarmEnvSwapBackendURL = "SWARM_SWAP_BACKEND_URL"
SwarmEnvSyncDisable = "SWARM_SYNC_DISABLE"
SwarmEnvSyncUpdateDelay = "SWARM_ENV_SYNC_UPDATE_DELAY"
SwarmEnvMaxStreamPeerServers = "SWARM_ENV_MAX_STREAM_PEER_SERVERS"
SwarmEnvLightNodeEnable = "SWARM_LIGHT_NODE_ENABLE"
SwarmEnvDeliverySkipCheck = "SWARM_DELIVERY_SKIP_CHECK"
SwarmEnvENSAPI = "SWARM_ENS_API"
SwarmEnvENSAddr = "SWARM_ENS_ADDR"
SwarmEnvCORS = "SWARM_CORS"
SwarmEnvBootnodes = "SWARM_BOOTNODES"
SwarmEnvPSSEnable = "SWARM_PSS_ENABLE"
SwarmEnvStorePath = "SWARM_STORE_PATH"
SwarmEnvStoreCapacity = "SWARM_STORE_CAPACITY"
SwarmEnvStoreCacheCapacity = "SWARM_STORE_CACHE_CAPACITY"
SwarmEnvBootnodeMode = "SWARM_BOOTNODE_MODE"
SwarmEnvNATInterface = "SWARM_NAT_INTERFACE"
SwarmAccessPassword = "SWARM_ACCESS_PASSWORD"
SwarmAutoDefaultPath = "SWARM_AUTO_DEFAULTPATH"
SwarmGlobalstoreAPI = "SWARM_GLOBALSTORE_API"
GethEnvDataDir = "GETH_DATADIR"
SwarmEnvChequebookAddr = "SWARM_CHEQUEBOOK_ADDR"
SwarmEnvAccount = "SWARM_ACCOUNT"
SwarmEnvBzzKeyHex = "SWARM_BZZ_KEY_HEX"
SwarmEnvListenAddr = "SWARM_LISTEN_ADDR"
SwarmEnvPort = "SWARM_PORT"
SwarmEnvNetworkID = "SWARM_NETWORK_ID"
SwarmEnvSwapEnable = "SWARM_SWAP_ENABLE"
SwarmEnvSwapBackendURL = "SWARM_SWAP_BACKEND_URL"
SwarmEnvSwapPaymentThreshold = "SWARM_SWAP_PAYMENT_THRESHOLD"
SwarmEnvSwapDisconnectThreshold = "SWARM_SWAP_DISCONNECT_THRESHOLD"
SwarmEnvSyncDisable = "SWARM_SYNC_DISABLE"
SwarmEnvSyncUpdateDelay = "SWARM_ENV_SYNC_UPDATE_DELAY"
SwarmEnvMaxStreamPeerServers = "SWARM_ENV_MAX_STREAM_PEER_SERVERS"
SwarmEnvLightNodeEnable = "SWARM_LIGHT_NODE_ENABLE"
SwarmEnvDeliverySkipCheck = "SWARM_DELIVERY_SKIP_CHECK"
SwarmEnvENSAPI = "SWARM_ENS_API"
SwarmEnvENSAddr = "SWARM_ENS_ADDR"
SwarmEnvCORS = "SWARM_CORS"
SwarmEnvBootnodes = "SWARM_BOOTNODES"
SwarmEnvPSSEnable = "SWARM_PSS_ENABLE"
SwarmEnvStorePath = "SWARM_STORE_PATH"
SwarmEnvStoreCapacity = "SWARM_STORE_CAPACITY"
SwarmEnvStoreCacheCapacity = "SWARM_STORE_CACHE_CAPACITY"
SwarmEnvBootnodeMode = "SWARM_BOOTNODE_MODE"
SwarmEnvNATInterface = "SWARM_NAT_INTERFACE"
SwarmAccessPassword = "SWARM_ACCESS_PASSWORD"
SwarmAutoDefaultPath = "SWARM_AUTO_DEFAULTPATH"
SwarmGlobalstoreAPI = "SWARM_GLOBALSTORE_API"
GethEnvDataDir = "GETH_DATADIR"
)

// These settings ensure that TOML keys use the same names as Go struct fields.
Expand Down Expand Up @@ -176,11 +178,9 @@ func flagsOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Confi
if keyid := ctx.GlobalString(SwarmAccountFlag.Name); keyid != "" {
currentConfig.BzzAccount = keyid
}

if chbookaddr := ctx.GlobalString(ChequebookAddrFlag.Name); chbookaddr != "" {
if chbookaddr := ctx.GlobalString(SwarmSwapChequebookAddrFlag.Name); chbookaddr != "" {
currentConfig.Contract = common.HexToAddress(chbookaddr)
}

if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" {
id, err := strconv.ParseUint(networkid, 10, 64)
if err != nil {
Expand All @@ -190,50 +190,44 @@ func flagsOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Confi
currentConfig.NetworkID = id
}
}

if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
if datadir := ctx.GlobalString(utils.DataDirFlag.Name); datadir != "" {
currentConfig.Path = expandPath(datadir)
}
}

bzzport := ctx.GlobalString(SwarmPortFlag.Name)
if len(bzzport) > 0 {
currentConfig.Port = bzzport
}

if bzzaddr := ctx.GlobalString(SwarmListenAddrFlag.Name); bzzaddr != "" {
currentConfig.ListenAddr = bzzaddr
}

if ctx.GlobalIsSet(SwarmSwapEnabledFlag.Name) {
currentConfig.SwapEnabled = true
}

if swapBackendURL := ctx.GlobalString(SwarmSwapBackendURLFlag.Name); swapBackendURL != "" {
currentConfig.SwapBackendURL = swapBackendURL
}
if paymentThreshold := ctx.GlobalUint64(SwarmSwapPaymentThresholdFlag.Name); paymentThreshold != 0 {
currentConfig.SwapPaymentThreshold = paymentThreshold
}
if disconnectThreshold := ctx.GlobalUint64(SwarmSwapDisconnectThresholdFlag.Name); disconnectThreshold != 0 {
Comment thread
mortelli marked this conversation as resolved.
currentConfig.SwapDisconnectThreshold = disconnectThreshold
}
if ctx.GlobalIsSet(SwarmSyncDisabledFlag.Name) {
currentConfig.SyncEnabled = false
}

if d := ctx.GlobalDuration(SwarmSyncUpdateDelay.Name); d > 0 {
currentConfig.SyncUpdateDelay = d
}

// any value including 0 is acceptable
currentConfig.MaxStreamPeerServers = ctx.GlobalInt(SwarmMaxStreamPeerServersFlag.Name)

if ctx.GlobalIsSet(SwarmLightNodeEnabled.Name) {
currentConfig.LightNodeEnabled = true
}

if ctx.GlobalIsSet(SwarmDeliverySkipCheckFlag.Name) {
currentConfig.DeliverySkipCheck = true
}

currentConfig.SwapBackendURL = ctx.GlobalString(SwarmSwapBackendURLFlag.Name)
if currentConfig.SwapEnabled && currentConfig.SwapBackendURL == "" {
Comment thread
Eknir marked this conversation as resolved.
utils.Fatalf(SwarmErrSwapSetNoBackendURL)
}

if ctx.GlobalIsSet(EnsAPIFlag.Name) {
ensAPIs := ctx.GlobalStringSlice(EnsAPIFlag.Name)
// preserve backward compatibility to disable ENS with --ens-api=""
Expand All @@ -243,40 +237,30 @@ func flagsOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Confi
for i := range ensAPIs {
ensAPIs[i] = expandPath(ensAPIs[i])
}

currentConfig.EnsAPIs = ensAPIs
}

if cors := ctx.GlobalString(CorsStringFlag.Name); cors != "" {
currentConfig.Cors = cors
}

if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" {
currentConfig.ChunkDbPath = storePath
}

if storeCapacity := ctx.GlobalUint64(SwarmStoreCapacity.Name); storeCapacity != 0 {
currentConfig.DbCapacity = storeCapacity
}

if ctx.GlobalIsSet(SwarmStoreCacheCapacity.Name) {
currentConfig.CacheCapacity = ctx.GlobalUint(SwarmStoreCacheCapacity.Name)
}

if ctx.GlobalIsSet(SwarmBootnodeModeFlag.Name) {
currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name)
}

if ctx.GlobalIsSet(SwarmDisableAutoConnectFlag.Name) {
currentConfig.DisableAutoConnect = ctx.GlobalBool(SwarmDisableAutoConnectFlag.Name)
}

if ctx.GlobalIsSet(SwarmGlobalStoreAPIFlag.Name) {
currentConfig.GlobalStoreAPI = ctx.GlobalString(SwarmGlobalStoreAPIFlag.Name)
}

return currentConfig

}

// dumpConfig is the dumpconfig command.
Expand Down
27 changes: 13 additions & 14 deletions cmd/swarm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net"
"os"
"os/exec"
"strconv"
"testing"
"time"

Expand All @@ -34,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethersphere/swarm"
"github.com/ethersphere/swarm/api"
"github.com/ethersphere/swarm/swap"
"github.com/ethersphere/swarm/testutil"
)

Expand All @@ -48,20 +50,6 @@ func TestConfigDump(t *testing.T) {
swarm.ExpectExit()
}

func TestConfigFailsSwapEnabledNoBackendURL(t *testing.T) {
Comment thread
Eknir marked this conversation as resolved.
flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "42",
fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545",
fmt.Sprintf("--%s", utils.ListenPortFlag.Name), "0",
fmt.Sprintf("--%s", SwarmSwapEnabledFlag.Name),
"--verbosity", fmt.Sprintf("%d", *testutil.Loglevel),
}

swarm := runSwarm(t, flags...)
swarm.Expect("Fatal: " + SwarmErrSwapSetNoBackendURL + "\n")
swarm.ExpectExit()
}

func TestBzzKeyFlag(t *testing.T) {
key, err := crypto.GenerateKey()
if err != nil {
Expand Down Expand Up @@ -251,7 +239,10 @@ func TestConfigCmdLineOverrides(t *testing.T) {
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
"--verbosity", fmt.Sprintf("%d", *testutil.Loglevel),
fmt.Sprintf("--%s", SwarmSwapPaymentThresholdFlag.Name), strconv.Itoa(swap.DefaultPaymentThreshold + 1),
fmt.Sprintf("--%s", SwarmSwapDisconnectThresholdFlag.Name), strconv.Itoa(swap.DefaultDisconnectThreshold + 1),
}

node.Cmd = runSwarm(t, flags...)
node.Cmd.InputLine(testPassphrase)
defer func() {
Expand Down Expand Up @@ -296,6 +287,14 @@ func TestConfigCmdLineOverrides(t *testing.T) {
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors)
}

if info.SwapPaymentThreshold != (swap.DefaultPaymentThreshold + 1) {
t.Fatalf("Expected SwapPaymentThreshold to be %d, but got %d", swap.DefaultPaymentThreshold+1, info.SwapPaymentThreshold)
}

if info.SwapDisconnectThreshold != (swap.DefaultDisconnectThreshold + 1) {
t.Fatalf("Expected SwapDisconnectThreshold to be %d, but got %d", swap.DefaultDisconnectThreshold+1, info.SwapDisconnectThreshold)
}

node.Shutdown()
}

Expand Down
12 changes: 11 additions & 1 deletion cmd/swarm/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package main
import cli "gopkg.in/urfave/cli.v1"

var (
ChequebookAddrFlag = cli.StringFlag{
SwarmSwapChequebookAddrFlag = cli.StringFlag{
Name: "chequebook",
Usage: "chequebook contract address",
EnvVar: SwarmEnvChequebookAddr,
Expand Down Expand Up @@ -65,6 +65,16 @@ var (
Usage: "URL of the Ethereum API provider to use to settle SWAP payments",
EnvVar: SwarmEnvSwapBackendURL,
}
SwarmSwapPaymentThresholdFlag = cli.Uint64Flag{
Name: "swap-payment-threshold",
Usage: "honey amount at which payment is triggered",
EnvVar: SwarmEnvSwapPaymentThreshold,
}
SwarmSwapDisconnectThresholdFlag = cli.Uint64Flag{
Name: "swap-disconnect-threshold",
Usage: "honey amount at which a peer disconnects",
EnvVar: SwarmEnvSwapDisconnectThreshold,
}
SwarmSyncDisabledFlag = cli.BoolTFlag{
Name: "nosync",
Usage: "Disable swarm syncing",
Expand Down
9 changes: 6 additions & 3 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ var gitCommit string

//declare a few constant error messages, useful for later error check comparisons in test
var (
SwarmErrNoBZZAccount = "bzzaccount option is required but not set; check your config file, command line or environment variables"
SwarmErrSwapSetNoBackendURL = "SWAP is enabled but --swap-backend-url is not set"
SwarmErrNoBZZAccount = "bzzaccount option is required but not set; check your config file, command line or environment variables"
)

// this help command gets added to any subcommand that does not define it explicitly
Expand Down Expand Up @@ -177,8 +176,13 @@ func init() {
CorsStringFlag,
EnsAPIFlag,
SwarmTomlConfigPathFlag,
//swap flags
Comment thread
mortelli marked this conversation as resolved.
SwarmSwapEnabledFlag,
SwarmSwapBackendURLFlag,
SwarmSwapDisconnectThresholdFlag,
SwarmSwapPaymentThresholdFlag,
SwarmSwapChequebookAddrFlag,
// end of swap flags
SwarmSyncDisabledFlag,
SwarmSyncUpdateDelay,
SwarmMaxStreamPeerServersFlag,
Expand All @@ -189,7 +193,6 @@ func init() {
SwarmAccountFlag,
SwarmBzzKeyHexFlag,
SwarmNetworkIdFlag,
ChequebookAddrFlag,
// upload flags
SwarmApiFlag,
SwarmRecursiveFlag,
Expand Down
3 changes: 1 addition & 2 deletions swap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
// This is the amount of time in seconds which an issuer has to wait to decrease the harddeposit of a beneficiary.
// The smart-contract allows for setting this variable differently per beneficiary
defaultHarddepositTimeoutDuration = 24 * time.Hour

// While Swap is unstable, it's only allowed to be run under a specific network ID
// Until we deploy swap officially, it's only allowed to be enabled under a specific network ID (use the --bzznetworkid flag to set it)
AllowedNetworkID = 5
)
Loading