/ upgrades / 01_noupgrade.md
01_noupgrade.md
  1  # Non-upgradable Programs
  2  In many cases, developers will want to deploy a program that is not upgradable.
  3  This is the default mode supported by Leo.
  4  Let's take a look at a simple example.
  5  
  6  ## Initializing the Project
  7  You may either use the existing `noupgrade` project 
  8  ```
  9  > cd noupgrade 
 10  ```
 11  or create a new Leo project with the following command:
 12  ```
 13  > leo new noupgrade
 14  ```
 15  
 16  ## The Program
 17  ```leo
 18  program noupgrade_example.alpha {
 19      @noupgrade
 20      async constructor() {}
 21      
 22      transition main(public a: u32, b: u32) -> u32 {
 23          let c: u32 = a + b;
 24          return c;
 25      }
 26  }
 27  ```
 28  Upgrades are defined by the logic of the `constructor`.
 29  The constructor is an **immutable** asynchronous function that is strictly on-chain.
 30  This means that once the program is deployed, the constructor cannot be changed.
 31  It is executed every time the program is deployed or upgraded.
 32  
 33  
 34  The `@noupgrade` annotation indicates that this program is not upgradable.
 35  If the `@noupgrade` annotation is specified, the body of the constructor must be left blank.
 36  The Leo compiler will automatically generate the appropriate code.
 37  The constructor checks that the program's edition (version) is `0`.
 38  
 39  Each program is automatically assigned a version when the network processes the deployment.
 40  If the program is already deployed on the network, the assigned version will be non-zero, the constructor will fail to execute, and the deployment will be rejected.
 41  
 42  ## Deploying the Program
 43  ```
 44  > leo deploy --broadcast
 45         Leo     3 statements before dead code elimination.
 46         Leo     3 statements after dead code elimination.
 47         Leo     The program checksum is: '[12u8, 65u8, 184u8, 236u8, 12u8, 123u8, 129u8, 53u8, 156u8, 105u8, 181u8, 154u8, 185u8, 201u8, 147u8, 232u8, 5u8, 12u8, 127u8, 88u8, 130u8, 105u8, 56u8, 198u8, 194u8, 9u8, 51u8, 107u8, 11u8, 148u8, 96u8, 114u8]'.
 48         Leo โœ… Compiled 'noupgrade_example.alpha' into Aleo instructions.
 49  Attempting to determine the consensus version from the latest block height at http://localhost:3030...
 50  
 51  ๐Ÿ› ๏ธ  Deployment Plan Summary
 52  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 53  ๐Ÿ”ง Configuration:
 54    Private Key:        APrivateKey1zkp8CZNn3yeC...
 55    Address:            aleo1rhgdu77hgyqd3xjj8uc...
 56    Endpoint:           http://localhost:3030
 57    Network:            testnet
 58    Consensus Version:  9
 59  
 60  ๐Ÿ“ฆ Deployment Tasks:
 61    โ€ข noupgrade_example.alpha  โ”‚ priority fee: 0  โ”‚ fee record: no (public fee)
 62  
 63  โš™๏ธ Actions:
 64    โ€ข Transaction(s) will NOT be printed to the console.
 65    โ€ข Transaction(s) will NOT be saved to a file.
 66    โ€ข Transaction(s) will be broadcast to http://localhost:3030
 67  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 68  
 69  โœ” Do you want to proceed with deployment? ยท yes
 70  
 71  
 72  ๐Ÿ”ง You program 'noupgrade_example.alpha' has the following constructor.
 73  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 74  constructor:
 75  assert.eq edition 0u16;
 76  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 77  Once it is deployed, it CANNOT be changed.
 78  
 79  โœ” Would you like to proceed? ยท yes
 80  
 81  ๐Ÿ“ฆ Creating deployment transaction for 'noupgrade_example.alpha'...
 82  
 83  
 84  ๐Ÿ“Š Deployment Summary for noupgrade_example.alpha
 85  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 86    Total Variables:      17,276
 87    Total Constraints:    12,927
 88    Max Variables:        2,097,152
 89    Max Constraints:      2,097,152
 90  
 91  ๐Ÿ’ฐ Cost Breakdown (credits)
 92    Transaction Storage:  0.886000
 93    Program Synthesis:    0.755075
 94    Namespace:            1.000000
 95    Constructor:          0.050000
 96    Priority Fee:         0.000000
 97    Total Fee:            2.691075
 98  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 99  
100  ๐Ÿ“ก Broadcasting deployment for noupgrade_example.alpha...
101  ๐Ÿ’ฐYour current public balance is 93749987.434492 credits.
102  
103  โœ” This transaction will cost you 2.691075 credits. Do you want to proceed? ยท yes
104  
105  โœ‰๏ธ Broadcasted transaction with:
106    - transaction ID: 'at1gk55y5asypvckqnszf83de8ktkte4f0k5m7cqe4pplccrvnhnszs53mnmu'
107    - fee ID: 'au1s7xwundv875gtj599l9v7wk8xdr6tncq8w8l4h65hqvj55k4svfqe0tc9k'
108  ๐Ÿ”„ Searching up to 12 blocks to confirm transaction (this may take several seconds)...
109  Explored 1 blocks.
110  Transaction accepted.
111  โœ… Deployment confirmed!
112  ```
113  
114  We can query the network to see that the deployment transaction has been accepted:
115  ```
116  leo query transaction at1gk55y5asypvckqnszf83de8ktkte4f0k5m7cqe4pplccrvnhnszs53mnmu
117  ```
118  
119  ## Attempting to Upgrade
120  To test the upgrade functionality, we can try to deploy the same program again.
121  You may also try to modify the program to add a new function.
122  Please refer to the [documentation](https://docs.leo-lang.org/guides/upgradability) for more details on what constitutes a valid upgrade.
123  
124  Now we will run
125  ```
126  > leo upgrade --broadcast
127         Leo     3 statements after dead code elimination.
128         Leo     The program checksum is: '[12u8, 65u8, 184u8, 236u8, 12u8, 123u8, 129u8, 53u8, 156u8, 105u8, 181u8, 154u8, 185u8, 201u8, 147u8, 232u8, 5u8, 12u8, 127u8, 88u8, 130u8, 105u8, 56u8, 198u8, 194u8, 9u8, 51u8, 107u8, 11u8, 148u8, 96u8, 114u8]'.
129         Leo โœ… Compiled 'noupgrade_example.alpha' into Aleo instructions.
130  Attempting to determine the consensus version from the latest block height at http://localhost:3030...
131  
132  ๐Ÿ› ๏ธ  Deployment Plan Summary
133  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
134  ๐Ÿ”ง Configuration:
135    Private Key:        APrivateKey1zkp8CZNn3yeC...
136    Address:            aleo1rhgdu77hgyqd3xjj8uc...
137    Endpoint:           http://localhost:3030
138    Network:            testnet
139    Consensus Version:  9
140  
141  ๐Ÿ“ฆ Deployment Tasks:
142    โ€ข noupgrade_example.alpha  โ”‚ priority fee: 0  โ”‚ fee record: no (public fee)
143  
144  โš™๏ธ Actions:
145    โ€ข Transaction(s) will NOT be printed to the console.
146    โ€ข Transaction(s) will NOT be saved to a file.
147    โ€ข Transaction(s) will be broadcast to http://localhost:3030
148  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
149  
150  โœ” Do you want to proceed with upgrade? ยท yes
151  
152  ๐Ÿ“ฆ Creating deployment transaction for 'noupgrade_example.alpha'...
153  
154  
155  ๐Ÿ“Š Deployment Summary for noupgrade_example.alpha
156  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
157    Total Variables:      17,276
158    Total Constraints:    12,927
159    Max Variables:        2,097,152
160    Max Constraints:      2,097,152
161  
162  ๐Ÿ’ฐ Cost Breakdown (credits)
163    Transaction Storage:  0.886000
164    Program Synthesis:    0.755075
165    Namespace:            1.000000
166    Constructor:          0.050000
167    Priority Fee:         0.000000
168    Total Fee:            2.691075
169  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
170  ๐Ÿ“ก Broadcasting upgrade for noupgrade_example.alpha...
171  ๐Ÿ’ฐYour current public balance is 93749961.436972 credits.
172  
173  โœ” This transaction will cost you 2.691075 credits. Do you want to proceed? ยท yes
174  
175  โœ‰๏ธ Broadcasted transaction with:
176    - transaction ID: 'at1geum6h7f7ym97d8z6k4zgnj7ycl0kegqygenquxmd999rys0wvgsxms7jg'
177    - fee ID: 'au1wgjj8e2pa4swpt4myr99znypuag2w7c35ds3druuze5fm5tga5xspvjjq8'
178  ๐Ÿ”„ Searching up to 12 blocks to confirm transaction (this may take several seconds)...
179  Explored 2 blocks.
180  Transaction rejected.
181  โŒ Failed to upgrade program noupgrade_example.alpha: Transaction apparently not accepted.
182  ```