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 long
    Juice cost for accepting an offer of Convex coins.
    protected static long
     
    static long
    Juice for an apply operation Bit of cost to allow for parameter construction.
    protected static long
     
    static long
    Juice cost for an 'assoc'
    protected static long
     
    protected static long
    Juice for creation of a blob
    protected static long
     
    protected static long
    Juice required to build a data structure.
    protected static long
    Juice required per element changed when building a data structure.
    static long
    Juice required to call an Actor Slightly expensive for context switching?
    static long
    Juice for a very cheap operation.
    static long
    Juice cost to compile a Constant value
    static long
    Juice cost to compile a Constant value
    static long
    Juice cost to compile a general AST node
    static long
    Juice required to execute a Cond expression Pretty cheap, nothing nasty here (though conditions / results themselves might get pricey).
    static long
    Juice required to resolve a constant value Very cheap, no allocs / lookup.
    static long
     
    static long
    Juice required to define a value in the current environment.
    static long
    Juice for a contract deployment Make this quite expensive, mainly to deter lots of willy-nilly deploying
    static long
    Juice required to execute a Do block Very cheap, no allocs.
    static long
    Juice for general object equality comparison Pretty cheap.
    protected static long
    Probably should be expensive?
    static long
    Juice cost to expand a constant
    static long
    Juice cost to expand a sequence
    protected static long
     
    protected static long
     
    static long
    Juice for a cryptographic hash Expensive.
    protected static long
     
    static long
    Juice required to create a lambda Sort of expensive - might allocate a bunch of stuff for the closure?
    static long
    Juice required to execute a Let block Fairly cheap but some parameter munging required.
    static long
     
    static long
    Juice required to look up a value in the local environment.
    static long
    Juice required to look up a value in the dynamic environment.
    static long
    Juice required to look up a symbol with a regular Address
    protected static long
     
    static long
    Juice cost for extracting metadata from a Syntax object.
    static long
    Juice for numeric comparison Pretty cheap.
    static long
    Make this quite expensive.
    static long
     
    static long
    Juice for a recur form Fairly cheap, might have to construct some temp structures for recur arguments.
    protected static long
     
    static long
    Juice required to execute an exceptional return (return, halt, rollback etc.) Pretty cheap, one alloc and a bit of exceptional value handling.
    static long
    Juice cost to schedule
    static 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 long
     
    static long
    Variable Juice cost for set comparison
    static long
    Juice for a simple built-in core function.
    static long
     
    static long
     
    protected static long
    Juice for storing a new constant value permanently in on-chain state Charged per node stored
    protected static long
    Juice for constructing a String Fairly cheap, since mostly in fast code, but charge extra for additional chars.
    protected static long
     
    protected static long
     
    static long
    Juice cost for constructing a Syntax Object.
    static long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    add​(long a, long b)
    Saturating addition.
    static long
    addMul​(long a, long b, long c)
    Saturating multiply and add: result = a + (b * c) Returns Long.MAX_VALUE on overflow.
    static long
    mul​(long a, long b)
    Saturating multiply.

    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:
      Constant Field Values
    • 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:
      Constant Field Values
    • LOOKUP

      public static final long LOOKUP
      Juice required to look up a value in the local environment.
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • LOOKUP_SYM

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

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

      public static final long LET
      Juice required to execute a Let block Fairly cheap but some parameter munging required. Might revisit binding costs?
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • 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:
      Constant Field Values
    • CALL_OP

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

      protected static final long BUILD_DATA
      Juice required to build a data structure. Make a bit expensive?
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • MAP

      protected static final long MAP
      See Also:
      Constant Field Values
    • REDUCE

      protected static final long REDUCE
      See Also:
      Constant Field Values
    • EQUALS

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

      public static final long NUMERIC_COMPARE
      Juice for numeric comparison Pretty cheap. Bit of casting perhaps.
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • HASH

      public static final long HASH
      Juice for a cryptographic hash Expensive.
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • 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:
      Constant Field Values
    • 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:
      Constant Field Values
    • STR_PER_CHAR

      protected static final long STR_PER_CHAR
      See Also:
      Constant Field Values
    • STORE

      protected static final long STORE
      Juice for storing a new constant value permanently in on-chain state Charged per node stored
      See Also:
      Constant Field Values
    • FETCH

      protected static final long FETCH
      See Also:
      Constant Field Values
    • ARITHMETIC

      protected static final long ARITHMETIC
      See Also:
      Constant Field Values
    • ADDRESS

      protected static final long ADDRESS
      See Also:
      Constant Field Values
    • BALANCE

      protected static final long BALANCE
      See Also:
      Constant Field Values
    • BLOB

      protected static final long BLOB
      Juice for creation of a blob
      See Also:
      Constant Field Values
    • BLOB_PER_BYTE

      protected static final long BLOB_PER_BYTE
      See Also:
      Constant Field Values
    • GET

      protected static final long GET
      See Also:
      Constant Field Values
    • KEYWORD

      protected static final long KEYWORD
      See Also:
      Constant Field Values
    • SYMBOL

      protected static final long SYMBOL
      See Also:
      Constant Field Values
    • TRANSFER

      public static final long TRANSFER
      See Also:
      Constant Field Values
    • SIMPLE_MACRO

      public static final long SIMPLE_MACRO
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • 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:
      Constant Field Values
    • EVAL

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

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

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

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

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

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

      public static final long SCHEDULE
      Juice cost to schedule
      See Also:
      Constant Field Values
    • 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
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • ACCEPT

      public static final long ACCEPT
      Juice cost for accepting an offer of Convex coins. We make this a little expensive because it involves updating two separate accounts.
      See Also:
      Constant Field Values
    • SYNTAX

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

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

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

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

      public static final long CREATE_ACCOUNT
      See Also:
      Constant Field Values
    • QUERY

      public static final long QUERY
      See Also:
      Constant Field Values
    • LOG

      public static final long LOG
      See Also:
      Constant Field Values
    • SPECIAL

      public static final long SPECIAL
      See Also:
      Constant Field Values
    • SET_BANG

      public static final long SET_BANG
      See Also:
      Constant Field Values
    • PEER_UPDATE

      public static final long PEER_UPDATE
      Make this quite expensive. Discourage spamming Peer updates
      See Also:
      Constant Field Values
  • 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