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 10 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
43 changes: 24 additions & 19 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,8 +53,10 @@ type Config struct {
BaseKey []byte

// Swap configs
SwapBackendURL string
SwapEnabled bool
SwapBackendURL string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more explanation in comment needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please comment exported constants, explain what they are

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

SwapEnabled bool
SwapPaymentThreshold uint64
SwapDisconnectThreshold uint64

*network.HiveParams
Pss *pss.Params
Expand Down Expand Up @@ -81,26 +84,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(),
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: "",
SwapPaymentThreshold: swap.DefaultPaymentThreshold,
SwapDisconnectThreshold: swap.DefaultDisconnectThreshold,
Comment thread
mortelli marked this conversation as resolved.
Outdated
Comment thread
mortelli marked this conversation as resolved.
Outdated
}

return
Expand Down
73 changes: 42 additions & 31 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 != "" {
currentConfig.Contract = common.HexToAddress(chbookaddr)
}

if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" {
id, err := strconv.ParseUint(networkid, 10, 64)
if err != nil {
Expand Down Expand Up @@ -210,6 +210,18 @@ func flagsOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Confi
currentConfig.SwapEnabled = true
}

if swapBackendURL := ctx.GlobalString(SwarmSwapBackendURLFlag.Name); swapBackendURL != "" {
currentConfig.SwapBackendURL = swapBackendURL
}

Comment thread
mortelli marked this conversation as resolved.
Outdated
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
}
Expand All @@ -229,7 +241,6 @@ func flagsOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Confi
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)
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/swarm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ func TestConfigCmdLineOverrides(t *testing.T) {
fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
fmt.Sprintf("--%s", SwarmSwapPaymentThresholdFlag.Name), "10",
fmt.Sprintf("--%s", SwarmSwapDisconnectThresholdFlag.Name), "15",
}

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

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

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

node.Shutdown()
}

Expand Down
10 changes: 10 additions & 0 deletions cmd/swarm/flags.go
Original file line number Diff line number Diff line change
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 indebted to a peer at which you will initiate payment",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only from one peer's point of view. I would change this to "honey amount at which a payment is triggered"

@Eknir Eknir Sep 16, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in anything outside of the test directory, we should make the comments and variable names as if it is from the perspective of the node operator. Especially here, as this is a user-facing comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but even then, this node operator can cross the payment threshold in both ways. The threshold doesn't define if you are indebted or not, which is defined only in which direction you cross it.

I would like to insist on this being changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this threshold does define whether a node is indebted or not, because the threshold which is set here only applies to what this particular node does. Sure, there are other payment thresholds in the network, and the node can cross these from the other direction (and get paid). but this particular threshold is only about how much the node that the user is about to boot up must be indebted to other peers until payment will be initiated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we would add a log Warn on the creditor node that a peer crossed the threshold and is indebted with him?

Check this exact comment I made on another PR: #1754 (comment)

If we did this (and if we add some other metric or anything to help nodes track that peers got indebted to them), then your comment would not apply.

EnvVar: SwarmEnvSwapPaymentThreshold,
}
SwarmSwapDisconnectThresholdFlag = cli.Uint64Flag{
Name: "swap-disconnect-threshold",
Usage: "honey amount at debt of a peer at which you will disconnect",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here "honey amount at which a peers disconnect"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep this from the point of view of the node operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

EnvVar: SwarmEnvSwapDisconnectThreshold,
}
SwarmSyncDisabledFlag = cli.BoolTFlag{
Name: "nosync",
Usage: "Disable swarm syncing",
Expand Down
3 changes: 3 additions & 0 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ func init() {
CorsStringFlag,
EnsAPIFlag,
SwarmTomlConfigPathFlag,
//swap flags
Comment thread
mortelli marked this conversation as resolved.
SwarmSwapEnabledFlag,
SwarmSwapBackendURLFlag,
SwarmSwapDisconnectThresholdFlag,
SwarmSwapPaymentThresholdFlag,
SwarmSyncDisabledFlag,
SwarmSyncUpdateDelay,
SwarmMaxStreamPeerServersFlag,
Expand Down
4 changes: 2 additions & 2 deletions swap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ const (
// 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
AllowedNetworkID = 5
// While Swap is unstable, it is not allowed to run on mainnet
DisabledNetworkID = 1
Comment thread
mortelli marked this conversation as resolved.
Outdated
)
9 changes: 5 additions & 4 deletions swap/oracle.go → swap/honeyOracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

package swap

// PriceOracle is the interface through which Oracles will deliver prices
type PriceOracle interface {
// HoneyOracle is the interface through which Oracles will deliver prices
type HoneyOracle interface {
GetPrice(honey uint64) (uint64, error)
}

// NewPriceOracle returns the actual oracle to be used for discovering the price
// NewHoneyPriceOracle returns the actual oracle to be used for discovering the price
// It will return a default one
func NewPriceOracle() PriceOracle {
func NewHoneyPriceOracle() HoneyOracle {

return &fixedPriceOracle{
honeyPrice: defaultHoneyPrice,
}
Expand Down
4 changes: 2 additions & 2 deletions swap/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestTriggerPaymentThreshold(t *testing.T) {
defer cleanup()

// create a dummy pper
cPeer := newDummyPeerWithSpec(Spec)
cPeer := newDummyPeer(Spec)
creditor := NewPeer(cPeer.Peer, debitorSwap, common.Address{}, common.Address{})
// set the creditor as peer into the debitor's swap
debitorSwap.peers[creditor.ID()] = creditor
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestTriggerDisconnectThreshold(t *testing.T) {
defer clean()

// create a dummy pper
cPeer := newDummyPeerWithSpec(Spec)
cPeer := newDummyPeer(Spec)
debitor := NewPeer(cPeer.Peer, creditorSwap, common.Address{}, common.Address{})
// set the debitor as peer into the creditor's swap
creditorSwap.peers[debitor.ID()] = debitor
Expand Down
29 changes: 16 additions & 13 deletions swap/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ type Swap struct {
owner *Owner // contract access
params *Params // economic and operational parameters
contract swap.Contract // reference to the smart contract
oracle PriceOracle // the oracle providing the ether price for honey
paymentThreshold int64 // balance difference required for sending cheque
disconnectThreshold int64 // balance difference required for dropping peer
disconnectThreshold uint64 // amount at which the node will disconnect from the peer
thresholdOracle ThresholdOracle // oracle which resolves at which amount node will initiate payment
honeyPriceOracle HoneyOracle // oracle which resolves the price of honey (in Wei)
}

// Owner encapsulates information related to accessing the contract
Expand All @@ -86,7 +86,7 @@ func NewParams() *Params {
}

// New - swap constructor
func New(stateStore state.Store, prvkey *ecdsa.PrivateKey, contract common.Address, backend contract.Backend) *Swap {
func New(stateStore state.Store, prvkey *ecdsa.PrivateKey, contract common.Address, backend contract.Backend, disconnectThreshold uint64, paymentThreshold uint64) *Swap {
return &Swap{
store: stateStore,
balances: make(map[enode.ID]int64),
Expand All @@ -95,9 +95,9 @@ func New(stateStore state.Store, prvkey *ecdsa.PrivateKey, contract common.Addre
backend: backend,
owner: createOwner(prvkey, contract),
params: NewParams(),
paymentThreshold: DefaultPaymentThreshold,
disconnectThreshold: DefaultDisconnectThreshold,
oracle: NewPriceOracle(),
disconnectThreshold: disconnectThreshold,
thresholdOracle: NewThresholdOracle(paymentThreshold),
honeyPriceOracle: NewHoneyPriceOracle(),
}
}

Expand Down Expand Up @@ -158,8 +158,9 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) {
if !exists {
return fmt.Errorf("peer %v does not exist", peer.ID())
}
if balance >= s.disconnectThreshold {
return fmt.Errorf("balance for peer %s is over the disconnect threshold %d, disconnecting", peer.ID().String(), s.disconnectThreshold)
disconnectThreshold := s.disconnectThreshold
if balance >= int64(disconnectThreshold) {
return fmt.Errorf("balance for peer %s is over the disconnect threshold %d, disconnecting", peer.ID().String(), disconnectThreshold)
Comment thread
mortelli marked this conversation as resolved.
Outdated
}

var newBalance int64
Expand All @@ -171,8 +172,10 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) {
// Check if balance with peer crosses the payment threshold
// It is the peer with a negative balance who sends a cheque, thus we check
// that the balance is *below* the threshold
if newBalance <= -s.paymentThreshold {
log.Warn("balance for peer went over the payment threshold, sending cheque", "peer", peer.ID().String(), "payment threshold", s.paymentThreshold)
paymentThreshold, _ := s.thresholdOracle.GetPaymentThreshold()
Comment thread
mortelli marked this conversation as resolved.
Outdated

if newBalance <= -int64(paymentThreshold) {
Comment thread
mortelli marked this conversation as resolved.
Outdated
log.Warn("balance for peer went over the payment threshold, sending cheque", "peer", peer.ID().String(), "payment threshold", paymentThreshold)
swapPeer, ok := s.getPeer(peer.ID())
if !ok {
return fmt.Errorf("peer %s not found", peer)
Expand Down Expand Up @@ -289,7 +292,7 @@ func (s *Swap) processAndVerifyCheque(cheque *Cheque, p *Peer) (uint64, error) {
lastCheque := s.loadLastReceivedCheque(p)

// TODO: there should probably be a lock here?
expectedAmount, err := s.oracle.GetPrice(cheque.Honey)
expectedAmount, err := s.honeyPriceOracle.GetPrice(cheque.Honey)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -390,7 +393,7 @@ func (s *Swap) createCheque(swapPeer *Peer) (*Cheque, error) {
honey := uint64(-peerBalance)

var amount uint64
amount, err = s.oracle.GetPrice(honey)
amount, err = s.honeyPriceOracle.GetPrice(honey)
if err != nil {
return nil, fmt.Errorf("error getting price from oracle: %s", err.Error())
}
Expand Down
Loading