Commit d0d84850 authored by David Vorick's avatar David Vorick

replace host.maxContractLen with modules.MaxfileContractSetLen

host.maxContractLen was a misleading constant, it was not the file
contract that was being checked for a size but the transaction set that
contains all of the unconfirmed dependencies of the file contract.

Because the constant was relevant to both the renter and the host, it
made sense to move the constant to the modules package.

The constant is currently based off of the TransactionSetSizeLimit. As
scalability improves on the network, it might make sense to reduce this
number substantially. While there is a weak connection between the two,
there is no inherent reason that the host should be limiting incoming
transactions based on the TransactionSetSizeLimit (other than having it
as an upper bound), and therefore a separate constant is used. An extra
buffer of 1kb is allowed because the transaction set is going to be
expanded during negotiation when details are added and the signatures
are added.

A sanity check has also been added, because it will never make sense for
the MaxFileContractSetLen to be larger than the transaction pool limit.
parent 29cee46e
......@@ -10,6 +10,14 @@ const (
// HostDir names the directory that contains the host persistence.
HostDir = "host"
// MaxfileContractSetLen determines the maximum allowed size of a
// transaction set that can be sent when trying to negotiate a file
// contract. The transaction set will contain all of the unconfirmed
// dependencies of the file contract, meaning that it can be quite large.
// The transaction pool's size limit for transaction sets has been chosen
// as a reasonable guideline for determining what is too large.
MaxFileContractSetLen = TransactionSetSizeLimit - 1e3
)
var (
......
......@@ -15,7 +15,6 @@ import (
)
const (
maxContractLen = 1 << 16 // The maximum allowed size of a file contract coming in over the wire. This does not include the file.
defaultTotalStorage = 10e9 // 10 GB.
defaultMaxDuration = 144 * 30 * 6 // 6 months.
)
......
......@@ -187,7 +187,7 @@ func (h *Host) managedNegotiateContract(conn net.Conn, filesize uint64, merkleRo
// Read the initial transaction set, which will contain a file contract and
// any required parent transactions.
var unsignedTxnSet []types.Transaction
if err := encoding.ReadObject(conn, &unsignedTxnSet, maxContractLen); err != nil {
if err := encoding.ReadObject(conn, &unsignedTxnSet, modules.MaxFileContractSetLen); err != nil {
return errors.New("couldn't read the initial transaction set: " + err.Error())
}
if len(unsignedTxnSet) == 0 {
......@@ -218,7 +218,7 @@ func (h *Host) managedNegotiateContract(conn net.Conn, filesize uint64, merkleRo
// The renter will sign the transaction set, agreeing to pay the host.
var signedTxnSet []types.Transaction
if err := encoding.ReadObject(conn, &signedTxnSet, maxContractLen); err != nil {
if err := encoding.ReadObject(conn, &signedTxnSet, modules.MaxFileContractSetLen); err != nil {
return errors.New("couldn't read signed transaction set:" + err.Error())
}
......
package modules
import (
"testing"
)
// TestMaxFileContractSetLenSanity checks that a sensible value for
// MaxFileContractSetLen has been chosen.
func TestMaxFileContractSetLenSanity(t *testing.T) {
// It does not make sense for the contract set limit to be higher than the
// IsStandard limit in the transaction pool. Such a transaction set would
// never be accepted by the transaction pool, and therefore is going to
// cause a failure later on in the host process. An extra 1kb is left
// because the file contract transaction is going to grow as the terms are
// negotiated and as signatures are added.
if MaxFileContractSetLen > TransactionSetSizeLimit - 1e3 {
t.Fatal("MaxfileContractSetLen does not have a sensible value - should be smaller than the TransactionSetSizeLimit")
}
}
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