cmd.Flags().String(optionWelcomeMessage,"","send a welcome message string during handshakes")
cmd.Flags().Bool(optionNameGlobalPinningEnabled,false,"enable global pinning")
cmd.Flags().String(optionNamePaymentThreshold,"10000000000000","threshold in BZZ where you expect to get paid from your peers")
cmd.Flags().String(optionNamePaymentTolerance,"50000000000000","excess debt above payment threshold in BZZ where you disconnect from your peer")
cmd.Flags().String(optionNamePaymentTolerance,"10000000000000","excess debt above payment threshold in BZZ where you disconnect from your peer")
cmd.Flags().String(optionNamePaymentEarly,"1000000000000","amount in BZZ below the peers payment threshold when we initiate settlement")
cmd.Flags().StringSlice(optionNameResolverEndpoints,[]string{},"ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url")
cmd.Flags().Bool(optionNameGatewayMode,false,"disable a set of sensitive features in the api")
// fraction of the refresh rate that is the minimum for monetary settlement
// this value is chosen so that tiny payments are prevented while still allowing small payments in environments with lower payment thresholds
minimumPaymentDivisor=int64(5)
)
// Interface is the Accounting interface.
...
...
@@ -40,8 +43,8 @@ type Interface interface {
Release(peerswarm.Address,priceuint64)
// Credit increases the balance the peer has with us (we "pay" the peer).
Credit(peerswarm.Address,priceuint64)error
// Debit increases the balance we have with the peer (we get "paid" back).
Debit(peerswarm.Address,priceuint64)error
// PrepareDebit returns an accounting Action for the later debit to be executed on and to implement shadowing a possibly credited part of reserve on the other side.
PrepareDebit(peerswarm.Address,priceuint64)Action
// Balance returns the current balance for the given peer.
Balance(peerswarm.Address)(*big.Int,error)
// SurplusBalance returns the current surplus balance for the given peer.
...
...
@@ -54,14 +57,37 @@ type Interface interface {
CompensatedBalances()(map[string]*big.Int,error)
}
// Action represents an accounting action that can be applied
typeActioninterface{
// Cleanup cleans up an action. Must be called wether it was applied or not.
Cleanup()
// Apply applies an action
Apply()error
}
// debitAction represents a future debit
typedebitActionstruct{
accounting*Accounting
price*big.Int
peerswarm.Address
accountingPeer*accountingPeer
appliedbool
}
// PayFunc is the function used for async monetary settlement
// shadowBalance returns the current debt reduced by any potentially debitable amount stored in shadowReservedBalance
// this represents how much less our debt could potentially be seen by the other party if it's ahead with processing credits corresponding to our shadow reserve
// We allow a refreshment to potentially put us into debt as it was previously negotiated and be limited to the peer's outstanding debt plus shadow reserve
a.logger.Tracef("crediting peer %v with amount %d due to payment, new balance is %d",peer,amount,nextBalance)
err=a.store.Put(peerBalanceKey(peer),nextBalance)
iferr!=nil{
returnfmt.Errorf("failed to persist balance: %w",err)