Commit 4574eb23 authored by Chris Schinnerl's avatar Chris Schinnerl

fix underflow

parent 866463c7
Pipeline #152492258 failed with stages
in 28 minutes and 51 seconds
......@@ -49,7 +49,7 @@ func (h *Host) staticPayByEphemeralAccount(stream siamux.Stream) (modules.Paymen
}
// Payment done through EAs don't move collateral
return newPaymentDetails(req.Message.Account, req.Message.Amount, types.ZeroCurrency), nil
return newPaymentDetails(req.Message.Account, req.Message.Amount), nil
}
// managedPayByContract processes a PayByContractRequest coming in over the
......@@ -92,7 +92,7 @@ func (h *Host) managedPayByContract(stream siamux.Stream) (modules.PaymentDetail
paymentRevision := revisionFromRequest(currentRevision, pbcr)
// verify the payment revision
amount, collateral, err := verifyPayByContractRevision(currentRevision, paymentRevision, bh)
amount, err := verifyPayByContractRevision(currentRevision, paymentRevision, bh)
if err != nil {
return nil, errors.AddContext(err, "Invalid payment revision")
}
......@@ -127,7 +127,7 @@ func (h *Host) managedPayByContract(stream siamux.Stream) (modules.PaymentDetail
return nil, errors.AddContext(err, "Could not send PayByContractResponse")
}
return newPaymentDetails(accountID, amount, collateral), nil
return newPaymentDetails(accountID, amount), nil
}
// managedFundAccount processes a PayByContractRequest coming in over the given
......@@ -169,13 +169,10 @@ func (h *Host) managedFundAccount(stream siamux.Stream, request modules.FundAcco
paymentRevision := revisionFromRequest(currentRevision, pbcr)
// verify the payment revision
amount, collateral, err := verifyPayByContractRevision(currentRevision, paymentRevision, bh)
amount, err := verifyPayByContractRevision(currentRevision, paymentRevision, bh)
if err != nil {
return types.ZeroCurrency, errors.AddContext(err, "Invalid payment revision")
}
if !collateral.IsZero() {
return types.ZeroCurrency, errors.AddContext(err, "Invalid payment revision, collateral was not zero")
}
// sign the revision
renterSignature := signatureFromRequest(currentRevision, pbcr)
......@@ -274,31 +271,28 @@ func signatureFromRequest(recent types.FileContractRevision, pbcr modules.PayByC
// verifyPayByContractRevision verifies the given payment revision and returns
// the amount that was transferred, the collateral that was moved and a
// potential error.
func verifyPayByContractRevision(current, payment types.FileContractRevision, blockHeight types.BlockHeight) (amount, collateral types.Currency, err error) {
func verifyPayByContractRevision(current, payment types.FileContractRevision, blockHeight types.BlockHeight) (amount types.Currency, err error) {
if err = verifyPaymentRevision(current, payment, blockHeight, types.ZeroCurrency); err != nil {
return
}
// Note that we can safely subtract the values of the outputs seeing as verifyPaymentRevision will have checked for potential underflows
amount = payment.ValidHostPayout().Sub(current.ValidHostPayout())
collateral = current.MissedHostOutput().Value.Sub(payment.MissedHostOutput().Value)
return
}
// payment details is a helper struct that implements the PaymentDetails
// interface.
type paymentDetails struct {
account modules.AccountID
amount types.Currency
addedCollateral types.Currency
account modules.AccountID
amount types.Currency
}
// newPaymentDetails returns a new paymentDetails object using the given values
func newPaymentDetails(account modules.AccountID, amountPaid, addedCollateral types.Currency) *paymentDetails {
func newPaymentDetails(account modules.AccountID, amountPaid types.Currency) *paymentDetails {
return &paymentDetails{
account: account,
amount: amountPaid,
addedCollateral: addedCollateral,
account: account,
amount: amountPaid,
}
}
......@@ -308,7 +302,3 @@ func (pd *paymentDetails) AccountID() modules.AccountID { return pd.account }
// Amount returns how much money the host received.
func (pd *paymentDetails) Amount() types.Currency { return pd.amount }
// AddedCollatoral returns the amount of collateral that moved from the host to
// the void output.
func (pd *paymentDetails) AddedCollateral() types.Currency { return pd.addedCollateral }
......@@ -352,9 +352,6 @@ func testPayByContract(t *testing.T, pair *renterHostPair) {
if !payment.Amount().Equals(amount) {
t.Fatalf("Unexpected amount paid, expected %v actual %v", amountStr, payment.Amount().HumanString())
}
if !payment.AddedCollateral().IsZero() {
t.Fatalf("Unexpected collateral added, expected 0H actual %v", payment.AddedCollateral())
}
// prepare a set of payouts that do not deduct payment from the renter
validPayouts, missedPayouts := updated.payouts()
......
......@@ -55,10 +55,6 @@ func (h *Host) managedRPCExecuteProgram(stream siamux.Stream) error {
}
}()
}()
// Don't expect any added collateral.
if !pd.AddedCollateral().IsZero() {
return fmt.Errorf("no collateral should be moved but got %v", pd.AddedCollateral().HumanString())
}
// Read request
var epr modules.RPCExecuteProgramRequest
......
......@@ -2,7 +2,6 @@ package host
import (
"encoding/json"
"fmt"
"time"
"gitlab.com/NebulousLabs/Sia/modules"
......@@ -62,10 +61,6 @@ func (h *Host) managedRPCUpdatePriceTable(stream siamux.Stream) error {
if payment.Amount().Cmp(pt.UpdatePriceTableCost) < 0 {
return modules.ErrInsufficientPaymentForRPC
}
// Don't expect any added collateral.
if !payment.AddedCollateral().IsZero() {
return fmt.Errorf("no collateral should be moved but got %v", payment.AddedCollateral().HumanString())
}
// after payment has been received, track the price table in the host's list
// of price tables and signal the renter we consider the price table valid
......
......@@ -73,7 +73,6 @@ type PaymentProvider interface {
type PaymentDetails interface {
AccountID() AccountID
Amount() types.Currency
AddedCollateral() types.Currency
}
// Payment identifiers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment