Class Juice

java.lang.Object
convex.core.lang.Juice

public class Juice extends Object
Static class defining juice costs for executable operations. "LISP programmers know the value of everything and the cost of nothing." - Alan Perlis
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Juice cost for accepting an offer of Convex coins.
    protected static final long
     
    static final long
    Juice for an apply operation Bit of cost to allow for parameter construction.
    protected static final long
     
    static final long
    Juice cost for an 'assoc'
    protected static final long
    Juice for balance core function.
    protected static final long
    Juice for creation of a blob.
    protected static final long
    Juice required to build a data structure.
    protected static final long
     
    protected static final long
    Juice required per element changed when building a data structure.
    static final long
    Juice required to call an Actor Slightly expensive for context switching?
    static final long
    Juice for a very cheap operation.
    static final long
    Juice cost to compile a Constant value
    static final long
    Juice cost to compile a Constant value
    static final long
    Juice cost to compile a general AST node
    static final long
    Juice required to execute a Cond expression Pretty cheap, nothing nasty here (though conditions / results themselves might get pricey).
    static final long
    Juice required to resolve a constant value Very cheap, no allocs / lookup.
    static final long
    Juice required to look up a core symbol.
    static final long
    Juice to create an account.
    static final long
    Juice required to define a value in the current environment.
    static final long
    Juice for a contract deployment Make this quite expensive, mainly to deter lots of willy-nilly deploying
    static final long
    Juice required to execute a Do block Very cheap, no allocs.
    static final long
    Juice for general object equality comparison Pretty cheap.
    protected static final long
    Probably should be expensive?
    static final long
    Juice cost to expand a constant
    static final long
    Juice cost to expand a sequence
    protected static final long
    Juice for data structure get.
    static final long
    Juice for a cryptographic hash Expensive.
    protected static final long
     
    static final long
    Juice required to create a lambda Sort of expensive - might allocate a bunch of stuff for the closure?
    static final long
    Juice required to execute a Let block Fairly cheap but some parameter munging required.
    static final long
     
    static final long
    Juice required to look up a value in the local environment.
    static final long
    Juice required to look up a value in the dynamic environment.
    static final long
    Juice required to look up a symbol with a regular Address
    protected static final long
     
    static final long
    Juice cost for extracting metadata from a Syntax object.
    static final long
    Juice for numeric comparison Pretty cheap.
    static final long
    Make this quite expensive.
    static final long
     
    static final long
    Juice for a recur form Fairly cheap, might have to construct some temp structures for recur arguments.
    protected static final long
     
    static final long
    Juice required to execute an exceptional return (return, halt, rollback etc.) Pretty cheap, one alloc and a bit of exceptional value handling.
    static final long
    Juice cost to schedule
    static final long
    Default future schedule juice (10 per hour) This makes scheduling a few hours / days ahead cheap but year is quite expensive (~87,600).
    static final long
     
    static final long
    Variable Juice cost for set comparison
    static final long
    Juice for a simple built-in core function.
    static final long
     
    static final long
     
    protected static final long
    Juice for constructing a String Fairly cheap, since mostly in fast code, but charge extra for additional chars.
    protected static final long
     
    static final long
    Juice cost for constructing a Syntax Object.
    static final long
    Base juice for any signed transaction
    static final long
    Juice per byte for any signed transaction
    static final long
    Juice for a transfer execution.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final long
    add(long a, long b)
    Saturating addition.
    static final long
    addMul(long a, long b, long c)
    Saturating multiply and add: result = a + (b * c) Returns Long.MAX_VALUE on overflow.
    static long
    buildBlobCost(long n)
    Gets the Juice cost for building a Blob
    static long
    buildDataCost(long n)
    Gets the Juice cost for building a data structure
    static long
    Gets the Juice cost for building a String
    static long
    costBuildStructure(ACountable<ACell> counted, long n)
    Computes the data build cost of a countable structure of given length
    static long
    limitString(Context<?> context)
    Gets the maximum number of string bytes that can be constructed
    static final long
    mul(long a, long b)
    Saturating multiply.
    static long
    Pre-costs a sequence of numeric arguments for addition / multiplication
    static long
    Pre-costs a sequence of numeric arguments for multiplication

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CONSTANT

      public static final long CONSTANT
      Juice required to resolve a constant value Very cheap, no allocs / lookup.
      See Also:
    • DEF

      public static final long DEF
      Juice required to define a value in the current environment. We make this somewhat expensive - we want to discourage over-use as a general rule since it writes to global chain state. However memory accounting helps discourage superfluous defs, so it only needs to reflect execution cost.
      See Also:
    • LOOKUP

      public static final long LOOKUP
      Juice required to look up a value in the local environment.
      See Also:
    • CORE

      public static final long CORE
      Juice required to look up a core symbol.
      See Also:
    • LOOKUP_DYNAMIC

      public static final long LOOKUP_DYNAMIC
      Juice required to look up a value in the dynamic environment. Potentially a bit pricey since read only, but might hit storage so.....
      See Also:
    • LOOKUP_SYM

      public static final long LOOKUP_SYM
      Juice required to look up a symbol with a regular Address
      See Also:
    • DO

      public static final long DO
      Juice required to execute a Do block Very cheap, no allocs.
      See Also:
    • LET

      public static final long LET
      Juice required to execute a Let block Fairly cheap but some parameter munging required. TODO: revisit binding costs?
      See Also:
    • COND_OP

      public static final long COND_OP
      Juice required to execute a Cond expression Pretty cheap, nothing nasty here (though conditions / results themselves might get pricey).
      See Also:
    • LAMBDA

      public static final long LAMBDA
      Juice required to create a lambda Sort of expensive - might allocate a bunch of stuff for the closure?
      See Also:
    • CALL_OP

      public static final long CALL_OP
      Juice required to call an Actor Slightly expensive for context switching?
      See Also:
    • BUILD_DATA

      protected static final long BUILD_DATA
      Juice required to build a data structure. Make a bit expensive?
      See Also:
    • BUILD_PER_ELEMENT

      protected static final long BUILD_PER_ELEMENT
      Juice required per element changed when building a data structure. Map entries count as two elements. We need to be a bit harsh on this! Risk of consuming too much heap space, might also result in multiple allocs for tree structures.
      See Also:
    • MAP

      protected static final long MAP
      See Also:
    • REDUCE

      protected static final long REDUCE
      See Also:
    • EQUALS

      public static final long EQUALS
      Juice for general object equality comparison Pretty cheap.
      See Also:
    • NUMERIC_COMPARE

      public static final long NUMERIC_COMPARE
      Juice for numeric comparison Pretty cheap. Bit of casting perhaps.
      See Also:
    • APPLY

      public static final long APPLY
      Juice for an apply operation Bit of cost to allow for parameter construction. Might need to revisit for bigger sequences?
      See Also:
    • HASH

      public static final long HASH
      Juice for a cryptographic hash Expensive.
      See Also:
    • CHEAP_OP

      public static final long CHEAP_OP
      Juice for a very cheap operation. O(1), no new cell allocations or non-trivial lookups.
      See Also:
    • SIMPLE_FN

      public static final long SIMPLE_FN
      Juice for a simple built-in core function. Simple operations are assumed to require no expensive resource access, and operate with O(1) allocations
      See Also:
    • STR

      protected static final long STR
      Juice for constructing a String Fairly cheap, since mostly in fast code, but charge extra for additional chars.
      See Also:
    • ARITHMETIC

      protected static final long ARITHMETIC
      See Also:
    • ADDRESS

      protected static final long ADDRESS
      See Also:
    • BALANCE

      protected static final long BALANCE
      Juice for balance core function. Some lookups required
      See Also:
    • BLOB

      protected static final long BLOB
      Juice for creation of a blob. Fairly cheap but needs per-byte cost
      See Also:
    • BUILD_PER_BYTE

      protected static final long BUILD_PER_BYTE
      See Also:
    • GET

      protected static final long GET
      Juice for data structure get. Hash lookup possibly required.
      See Also:
    • KEYWORD

      protected static final long KEYWORD
      See Also:
    • SYMBOL

      protected static final long SYMBOL
      See Also:
    • TRANSFER

      public static final long TRANSFER
      Juice for a transfer execution. Some account updates
      See Also:
    • TRANSACTION_BASE

      public static final long TRANSACTION_BASE
      Base juice for any signed transaction
      See Also:
    • TRANSACTION_PER_BYTE

      public static final long TRANSACTION_PER_BYTE
      Juice per byte for any signed transaction
      See Also:
    • SIMPLE_MACRO

      public static final long SIMPLE_MACRO
      See Also:
    • RECUR

      public static final long RECUR
      Juice for a recur form Fairly cheap, might have to construct some temp structures for recur arguments.
      See Also:
    • DEPLOY_CONTRACT

      public static final long DEPLOY_CONTRACT
      Juice for a contract deployment Make this quite expensive, mainly to deter lots of willy-nilly deploying
      See Also:
    • EVAL

      protected static final long EVAL
      Probably should be expensive?
      See Also:
    • COMPILE_CONSTANT

      public static final long COMPILE_CONSTANT
      Juice cost to compile a Constant value
      See Also:
    • COMPILE_LOOKUP

      public static final long COMPILE_LOOKUP
      Juice cost to compile a Constant value
      See Also:
    • COMPILE_NODE

      public static final long COMPILE_NODE
      Juice cost to compile a general AST node
      See Also:
    • EXPAND_CONSTANT

      public static final long EXPAND_CONSTANT
      Juice cost to expand a constant
      See Also:
    • EXPAND_SEQUENCE

      public static final long EXPAND_SEQUENCE
      Juice cost to expand a sequence
      See Also:
    • SCHEDULE

      public static final long SCHEDULE
      Juice cost to schedule
      See Also:
    • SCHEDULE_MILLIS_PER_JUICE_UNIT

      public static final long SCHEDULE_MILLIS_PER_JUICE_UNIT
      Default future schedule juice (10 per hour) This makes scheduling a few hours / days ahead cheap but year is quite expensive (~87,600). Also places an upper bound on advance schedules. TODO: review this. Maybe not needed given memory accounting?
      See Also:
    • RETURN

      public static final long RETURN
      Juice required to execute an exceptional return (return, halt, rollback etc.) Pretty cheap, one alloc and a bit of exceptional value handling.
      See Also:
    • ACCEPT

      public static final long ACCEPT
      Juice cost for accepting an offer of Convex coins. Define this to be equal to a transfer.
      See Also:
    • SYNTAX

      public static final long SYNTAX
      Juice cost for constructing a Syntax Object. Fairly lightweight.
      See Also:
    • META

      public static final long META
      Juice cost for extracting metadata from a Syntax object.
      See Also:
    • ASSOC

      public static final long ASSOC
      Juice cost for an 'assoc'
      See Also:
    • SET_COMPARE_PER_ELEMENT

      public static final long SET_COMPARE_PER_ELEMENT
      Variable Juice cost for set comparison
      See Also:
    • CREATE_ACCOUNT

      public static final long CREATE_ACCOUNT
      Juice to create an account. Some cost for new account data structure entry.
      See Also:
    • QUERY

      public static final long QUERY
      See Also:
    • LOG

      public static final long LOG
      See Also:
    • SPECIAL

      public static final long SPECIAL
      See Also:
    • SET_BANG

      public static final long SET_BANG
      See Also:
    • PEER_UPDATE

      public static final long PEER_UPDATE
      Make this quite expensive. Discourage spamming Peer updates
      See Also:
  • Constructor Details

    • Juice

      public Juice()
  • Method Details

    • addMul

      public static final long addMul(long a, long b, long c)
      Saturating multiply and add: result = a + (b * c) Returns Long.MAX_VALUE on overflow.
      Parameters:
      a - First number (to be added)
      b - Second number (to be multiplied)
      c - Thirst number (to be multiplied)
      Returns:
      long result, capped at Long.MAX_VALUE
    • mul

      public static final long mul(long a, long b)
      Saturating multiply. Returns Long.MAX_VALUE on overflow.
      Parameters:
      a - First number
      b - Second number
      Returns:
      long result, capped at Long.MAX_VALUE
    • add

      public static final long add(long a, long b)
      Saturating addition. Returns Long.MAX_VALUE on overflow.
      Parameters:
      a - First number
      b - Second number
      Returns:
      long result, capped at Long.MAX_VALUE
    • costBuildStructure

      public static long costBuildStructure(ACountable<ACell> counted, long n)
      Computes the data build cost of a countable structure of given length
      Parameters:
      counted - Counted data structure, used for type
      n - Element count of data structure constructed
      Returns:
      Calculated juice cost
    • buildStringCost

      public static long buildStringCost(long n)
      Gets the Juice cost for building a String
      Parameters:
      n - Length of String
      Returns:
      Juice cost
    • buildBlobCost

      public static long buildBlobCost(long n)
      Gets the Juice cost for building a Blob
      Parameters:
      n - Length of Blob
      Returns:
      Juice cost
    • limitString

      public static long limitString(Context<?> context)
      Gets the maximum number of string bytes that can be constructed
      Parameters:
      context - Context to check for Juice
      Returns:
      Limit in number of bytes
    • buildDataCost

      public static long buildDataCost(long n)
      Gets the Juice cost for building a data structure
      Parameters:
      n - Element count of data structure (number of CVM values)
      Returns:
      Juice cost
    • precostNumericLinear

      public static long precostNumericLinear(ACell[] args)
      Pre-costs a sequence of numeric arguments for addition / multiplication
      Parameters:
      args - Array of arguments, assumed to be numeric
      Returns:
      Juice cost, or negative if any argument is not numeric
    • precostNumericMultiply

      public static long precostNumericMultiply(ACell[] args)
      Pre-costs a sequence of numeric arguments for multiplication
      Parameters:
      args - Array of arguments, assumed to be numeric
      Returns:
      Juice cost, or negative if any argument is not numeric