Skip to content

Commit

Permalink
"Rent" larger program size (#2157)
Browse files Browse the repository at this point in the history
Allow paying for more program space.
  • Loading branch information
shiqizng authored May 28, 2021
1 parent 0cbe9d4 commit 62b21a5
Show file tree
Hide file tree
Showing 28 changed files with 745 additions and 184 deletions.
6 changes: 5 additions & 1 deletion cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
approvalProgRawFile string
clearProgRawFile string

extraPages uint32

createOnCompletion string

localSchemaUints uint64
Expand Down Expand Up @@ -98,6 +100,7 @@ func init() {
createAppCmd.Flags().Uint64Var(&localSchemaByteSlices, "local-byteslices", 0, "Maximum number of byte slices that may be stored in local (per-account) key/value stores for this app. Immutable.")
createAppCmd.Flags().StringVar(&appCreator, "creator", "", "Account to create the application")
createAppCmd.Flags().StringVar(&createOnCompletion, "on-completion", "NoOp", "OnCompletion action for application transaction")
createAppCmd.Flags().Uint32Var(&extraPages, "extra-pages", 0, "Additional program space for supporting larger TEAL assembly program. A maximum of 3 extra pages is allowed. A page is 1024 bytes.")

callAppCmd.Flags().StringVarP(&account, "from", "f", "", "Account to call app from")
optInAppCmd.Flags().StringVarP(&account, "from", "f", "", "Account to opt in")
Expand Down Expand Up @@ -355,6 +358,7 @@ var createAppCmd = &cobra.Command{
Long: `Issue a transaction that creates an application`,
Args: validateNoPosArgsFn,
Run: func(cmd *cobra.Command, _ []string) {

dataDir := ensureSingleDataDir()
client := ensureFullClient(dataDir)

Expand All @@ -379,7 +383,7 @@ var createAppCmd = &cobra.Command{
reportWarnf("'--on-completion %s' may be ill-formed for 'goal app create'", createOnCompletion)
}

tx, err := client.MakeUnsignedAppCreateTx(onCompletion, approvalProg, clearProg, globalSchema, localSchema, appArgs, appAccounts, foreignApps, foreignAssets)
tx, err := client.MakeUnsignedAppCreateTx(onCompletion, approvalProg, clearProg, globalSchema, localSchema, appArgs, appAccounts, foreignApps, foreignAssets, extraPages)
if err != nil {
reportErrorf("Cannot create application txn: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ func assembleFile(fname string) (program []byte) {
}
_, params := getProto(protoVersion)
if ops.HasStatefulOps {
if len(ops.Program) > params.MaxAppProgramLen {
reportErrorf(tealAppSize, fname, len(ops.Program), params.MaxAppProgramLen)
if len(ops.Program) > config.MaxAvailableAppProgramLen {
reportErrorf(tealAppSize, fname, len(ops.Program), config.MaxAvailableAppProgramLen)
}
} else {
if uint64(len(ops.Program)) > params.LogicSigMaxSize {
Expand Down
2 changes: 1 addition & 1 deletion cmd/goal/interact.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ var appExecuteCmd = &cobra.Command{
localSchema = header.Query.Local.ToStateSchema()
globalSchema = header.Query.Global.ToStateSchema()
}
tx, err := client.MakeUnsignedApplicationCallTx(appIdx, appArgs, appAccounts, foreignApps, foreignAssets, onCompletion, approvalProg, clearProg, globalSchema, localSchema)
tx, err := client.MakeUnsignedApplicationCallTx(appIdx, appArgs, appAccounts, foreignApps, foreignAssets, onCompletion, approvalProg, clearProg, globalSchema, localSchema, 0)
if err != nil {
reportErrorf("Cannot create application txn: %v", err)
}
Expand Down
17 changes: 17 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ type ConsensusParams struct {
// program in bytes
MaxAppProgramLen int

// extra length for application program in pages. A page is MaxAppProgramLen bytes
MaxExtraAppProgramPages int

// maximum number of accounts in the ApplicationCall Accounts field.
// this determines, in part, the maximum number of balance records
// accessed by a single transaction
Expand Down Expand Up @@ -419,6 +422,14 @@ var MaxAppProgramLen int
// used for decoding purposes.
var MaxBytesKeyValueLen int

// MaxExtraAppProgramLen is the maximum extra app program length supported by any
// of the consensus protocols. used for decoding purposes.
var MaxExtraAppProgramLen int

// MaxAvailableAppProgramLen is the largest supported app program size include the extra pages
//supported supported by any of the consensus protocols. used for decoding purposes.
var MaxAvailableAppProgramLen int

func checkSetMax(value int, curMax *int) {
if value > *curMax {
*curMax = value
Expand Down Expand Up @@ -448,6 +459,9 @@ func checkSetAllocBounds(p ConsensusParams) {
// MaxBytesKeyValueLen is max of MaxAppKeyLen and MaxAppBytesValueLen
checkSetMax(p.MaxAppKeyLen, &MaxBytesKeyValueLen)
checkSetMax(p.MaxAppBytesValueLen, &MaxBytesKeyValueLen)
checkSetMax(p.MaxExtraAppProgramPages, &MaxExtraAppProgramLen)
// MaxAvailableAppProgramLen is the max of supported app program size
MaxAvailableAppProgramLen = MaxAppProgramLen * (1 + MaxExtraAppProgramLen)
}

// SaveConfigurableConsensus saves the configurable protocols file to the provided data directory.
Expand Down Expand Up @@ -916,6 +930,9 @@ func initConsensusProtocols() {

vFuture.EnableKeyregCoherencyCheck = true

// Enable support for larger app program size
vFuture.MaxExtraAppProgramPages = 3

// enable the InitialRewardsRateCalculation fix
vFuture.InitialRewardsRateCalculation = true
// Enable transaction Merkle tree.
Expand Down
Loading

0 comments on commit 62b21a5

Please sign in to comment.