Skip to content

Commit

Permalink
Tutorial additions and typo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Sep 17, 2024
1 parent bd7260b commit 959c261
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/overview/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Convex is governed by the non-profit Convex Foundation. The Foundation performs

- Ensures good governance of the Convex Network
- Operates key resources on behalf of the community, including the https://convex.world website and developer resources such as GitHub repositories
- Acts as this initial issuer of Convex Coins to individuals and organisations, inlciding management of the release curve
- Acts as this initial issuer of Convex Coins to individuals and organisations, including management of the release curve
- Provides awards for contributors to Convex (e.g. open source developers)
- Supports the development of the Convex ecosystem via partnerships, marketing, education and other initiatives
4 changes: 2 additions & 2 deletions docs/overview/convex-whitepaper.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ In this simple case, the new Consensus is confirmed within just three rounds of

In more complex cases:

* Multiple Peers may propose Blocks at the same time. In this case, stake-weighted voting would be used to resolve conflicts and determine which Blocks are included first. It may take an additional round or two to resolve such conflicts into a stable Ordering. Overall, this is more efficient since multiple Blocks are being brought into Consensus in a similar toatl number of rounds.
* Multiple Peers may propose Blocks at the same time. In this case, stake-weighted voting would be used to resolve conflicts and determine which Blocks are included first. It may take an additional round or two to resolve such conflicts into a stable Ordering. Overall, this is more efficient since multiple Blocks are being brought into Consensus in a similar total number of rounds.
* The network might not reach a quiescent state before further new Blocks are added. This is not an issue: consensus will be confirmed for the initial Block(s) while the new Blocks are still being propagated at earlier stages.
* Some Peers might misbehave or be temporarily unavailable. Again, this is not a problem as long as a sufficient number of Good Peers are still operating and connected, since the consensus thresholds can still be met. Temporarily disconnected or offline Peers can "catch up" later.
* The Peer Network may not be fully connected, potentially adding `O(log(number of peers))` additional rounds of propagation assuming that each Peer propagates to a small constant number of other Peers in each time period. In practice, not all these additional rounds may be needed because a smaller number of highly staked and well-connected Peers will be able to confirm consensus without waiting for the rest of the Network.
Expand Down Expand Up @@ -1007,7 +1007,7 @@ To solve the state growth problem, Convex implements **Memory Accounting** with

**Note 1**: that in practice, the actual storage size of the CVM state will be significantly smaller than the tracked state size, because the use of immutable persistent data structures allows many equal tree branches to be shared. The effectiveness of this structural sharing needs to be observed over time, but we anticipate perhaps a 2-3x reduction in state size may be possible in the long term.

**Note 2**: Observant system hackers may notice that the memory accounting mechanism means that if Account A causes some memory to be allocated, and Account B causes that same memory to be de-allocated (e.g., through the use of calls to an Actor), then Account B will gain memory from A. We consider this a feature, not a bug: It incentivises participants to clean up state wherever possible and incentivises the writers of Actor code to consider their memory allocations and deallocations carefully.
**Note 2**: Observant system hackers may notice that the memory accounting mechanism means that if Account A causes some memory to be allocated, and Account B causes that same memory to be de-allocated (e.g., through the use of calls to an Actor), then Account B will gain memory from A. We consider this a feature, not a bug: It incentivises participants to clean up state wherever possible and encourages the writers of actor code to consider their memory allocations and deallocations carefully.

To ensure correct economic behaviour, it is necessary for free memory to have an economic cost. Therefore, Convex provides a **Memory Exchange** though which memory allocations may be traded. This has the following features:

Expand Down
4 changes: 2 additions & 2 deletions docs/overview/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Some answers to common questions can be found here.

Yes! Convex is free for anyone to use and build applications upon, and always will be. We are building Convex for everyone to support the Internet of Value.

To make use of the resources of the network, small transaction fees are charged using Convex Coins, which is the native utility token of the network. This is important for serveral reasons:
To make use of the resources of the network, small transaction fees are charged using Convex Coins, which is the native utility token of the network. This is important for several reasons:

- Compensate those who provide important secure infrastructure to the network (i.e. peer operators)
- Prevent denial of service attacks by people flooding the network with wasteful transactions. This makes it very expensive to launch such attacks.
Expand Down Expand Up @@ -64,7 +64,7 @@ It is a good idea to **keep data structures as simple as possible**. Ideally, Ac

## Is Convex a Blockchain?

Think of Convex and the undelying lattice technology as "beyond blockchain".
Think of Convex and the underlying lattice technology as "beyond blockchain".

Convex shares many common attributes with traditional public blockchains:

Expand Down
4 changes: 2 additions & 2 deletions docs/overview/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ The CVM is a highly optimised execution engine. Some notable points:
- CVM code is compiled down to efficient "Ops", where a typical transaction might require 10-50 Ops to be executed. This is effectively the "machine code" of the JVM, and corresponds to operations typical in an implementation of the Lambda Calculus - because of the power of the lambda calculus, we usually require fewer Ops than the equivalent for a stack-based machine
- We can rely on the JVM JIT to further compile key code paths down to efficient native code

The `OpBenckmark` is a microbenchmark of several different groups of Ops, and demonstrates that up to hundreds of millions of Ops can be executed per second on a single thread:
The `OpBenchmark` is a microbenchmark of several different groups of Ops, and demonstrates that up to hundreds of millions of Ops can be executed per second on a single thread:

```
Benchmark Mode Cnt Score Error Units
OpBenchmark.constant thrpt 5 522926192.803 ± 200159991.331 ops/s (a single Contsant op)
OpBenchmark.constant thrpt 5 522926192.803 ± 200159991.331 ops/s (a single Constant op)
OpBenchmark.emptyLoop thrpt 5 2180.943 ± 118.609 ops/s (a loop executing 1000 times)
OpBenchmark.simpleSum thrpt 5 8336440.019 ± 444054.388 ops/s (a sum involving dynamic lookup, 4 Ops)
OpBenchmark.simpleSumPrecompiled thrpt 5 21846062.388 ± 1823368.198 ops/s (a sum with constants, 4 Ops)
Expand Down
2 changes: 1 addition & 1 deletion docs/overview/use-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Convex is a general purpose, programmable decentralised network with global stat
Convex offers a uniquely powerful system for the development of tokenised assets and applications. Tokens in Convex usually support the [CAD029](cad/029_fungible/README.md) token standard, which offers multiple advantages over the common ERC20 standard.

Tokens can be used for:
- Payments in the form of stablecoins, flatcoins, nationcoins or other digital curreny types
- Payments in the form of stablecoins, flatcoins, nationcoins or other digital currency types
- Utility tokens for delivery of decentralised services
- Reward schemes and bonus programmes
- Governance of decentralised economic systems, e.g. with stake-weighted voting
Expand Down
4 changes: 2 additions & 2 deletions docs/products/convex-cli/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Convex CLI

The Convex CLI (Command Line Interface) is a powerful tool for interacting with Convex from the command line on Windows, Linux and MacOS. It's a handy tool for system administartors and peer operators who need to script interactions with the Convex Network.
The Convex CLI (Command Line Interface) is a powerful tool for interacting with Convex from the command line on Windows, Linux and MacOS. It's a handy tool for system administrators and peer operators who need to script interactions with the Convex Network.

![Convex CLI Screenshot](convex-cli.png)

Expand All @@ -24,7 +24,7 @@ To run the CLI, you simply need to run the following:
java -jar convex.jar <arguments>
```

It is usually more conveninet to have a script, alias or batch file which executes the Java command. This means that you can simply type `convex ....` from any directory to access the CLI. The remainder of this document assumes you are using such a script.
It is usually more convenient to have a script, alias or batch file which executes the Java command. This means that you can simply type `convex ....` from any directory to access the CLI. The remainder of this document assumes you are using such a script.

### Windows

Expand Down
29 changes: 29 additions & 0 deletions docs/products/convex-desktop/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Convex Desktop

The Convex CLI (Command Line Interface) is a powerful tool for interacting with Convex from the command line on Windows, Linux and MacOS. It's a handy tool for system administrators and peer operators who need to script interactions with the Convex Network.

```
![Convex Desktop Screenshot](convex-desktop.png)
```
## Installation

The Convex Desktop requires:
- A recent version of Java (21+, Java 22 recommended)
- A GUI based operating system (e.g. Windows, Linux or MacOS)
- A copy of the `convex.jar` executable jar file

Java is available from multiple providers, we recommend:
- [Oracle JDK](https://www.oracle.com/java/technologies/downloads/)
- [Eclipse Temurin JDK](https://adoptium.net/temurin/releases/)

Snapshots of the `convex.jar` file are currently available here: [Convex Snapshots](https://drive.google.com/drive/folders/1AZdyuZOmC70i_TtuEW3uEKvjYLOqIMiv?usp=sharing)

## Running Convex Desktop

If Java is correctly configured, you should be able to run Convex Desktop simply by double-clicking on the `convex.jar` file which will run Convex Desktop as an executable. On some systems, you may need to grant permissions to run a downloaded executable file.

Alternatively to run Convex Desktop, you can run the following commend from the command prompt, script or GUI shortcut:

```
java -jar convex.jar desktop
```
6 changes: 3 additions & 3 deletions docs/tutorial/convex-lisp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ The CVM is designed to be able to support many different languages and paradigms
- **Immutability**: Lisp's functional programming paradigm promotes immutability, which is essential for ensuring the integrity and consistency of decentralised systems where data must be replicated and distributed across multiple nodes.
- **Dynamic typing**: Lisp's dynamic typing allows for flexible data structures and easy modifications, crucial for adapting to the constantly evolving nature of decentralised systems. At the same time, Convex Lisp is **strongly typed**, avoiding the issues associated with weak typing.
- **Code is data**: representing code using its own data structures (also known as "homoiconicity") gives Lisp advanced **metaprogramming** capabilities the creation of domain-specific languages (DSLs) tailored to specific concepts, making it easier to reason about and implement complex economic mechanisms.
- **Interactive coding**: Lisp pineered the use of the REPL for highly interactive programming. With Convex, we've taken this a step further with a complete on-chain compiler so that everything on the CVM can be done with simple interactive Lisp commands.
- **Interactive coding**: Lisp pioneered the use of the REPL for highly interactive programming. With Convex, we've taken this a step further with a complete on-chain compiler so that everything on the CVM can be done with simple interactive Lisp commands.

## Inspirations

Lisp was originally created in the 1950s by John McCarthy and has maintained a deep-rooted appeal among hackers for its unique characteristics.

Convex Lisp was heavily inspired by [Clojure](https://clojure.org/), from which it borrows most basic and many core functions, and [Racket Scheme](https://racket-lang.org/) which inspired many of the more advanced metaprograming facilities.
Convex Lisp was heavily inspired by [Clojure](https://clojure.org/), from which it borrows most basic and many core functions, and [Racket Scheme](https://racket-lang.org/) which inspired many of the more advanced metaprogramming facilities.

## Interesting technical notes

- Convex Lisp is a **Lisp-1** (i.e. keeps function and data values in the same namespace).This is simpler than a Lisp-2 and seems more appropriate for a functional programming language, where functions are regularly treated as first class values.
- Convex Lisp is designed for **orthogonal persistence**. Developers don't need to care where data or code is stored: it is loaded and cached on demand. This powerful capability means that the CVM can operate code and data data structures much larger than system RAM without imposing any burden on developers.
- Convex Lisp data structures (and therefore code) are all represented as **Merkle trees** using strong cryptographic hashes. This has the ineteresting property of making all code and data **content-addressable** and cryptographically **verifiable**. As well as making Convex Lisp ideally suited for running on the lattice technology used by Convex, this opens interesting possibility for new kinds of systems based on immutable and verifiable distributed code bases.
- Convex Lisp data structures (and therefore code) are all represented as **Merkle trees** using strong cryptographic hashes. This has the interesting property of making all code and data **content-addressable** and cryptographically **verifiable**. As well as making Convex Lisp ideally suited for running on the lattice technology used by Convex, this opens interesting possibility for new kinds of systems based on immutable and verifiable distributed code bases.
23 changes: 15 additions & 8 deletions docs/tutorial/convex-lisp/lisp-cvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In the Gentle Lisp Introduction we covered the basic of the Convex Lisp language

## The Convex Virtual Machine

The CVM is a denctralised, deterministic VM. Because it is deterministic, any replicas of the CVM that execute the same transactions from the same initial state will produce identical results. This is a key part how the Convex network is able to provide a consistent, programmable global state. It also enforces cryptographic security, so that only authorised users can make use of protected services.
The CVM is a decentralised, deterministic VM. Because it is deterministic, any replicas of the CVM that execute the same transactions from the same initial state will produce identical results. This is a key part how the Convex network is able to provide a consistent, programmable global state. It also enforces cryptographic security, so that only authorised users can make use of protected services.

In practice, this means that developers can execute code on the CVM safe (including smart contracts and transactions involving valuable digital assets) in the knowledge that the the results are guaranteed by a robust, fault-tolerant global network with no centralised point of failure and strong security.

Expand Down Expand Up @@ -233,7 +233,7 @@ However if the account `#2055` itself attempted to collect the funds, it would r
=> 100000
```

### Important security note for Actors
### Important security note

Actor code runs in the account of the actor itself. In many circumstances, calling actor code can be considered "safe" in the sense that it cannot in general access assets owned by the calling account. However, there are some risks that you should be aware of:

Expand Down Expand Up @@ -282,9 +282,9 @@ If you use a library regularly, you may find it convenient to import it and give

### Deploying libraries

Deploying libraries is just like deploying an Actor, with a few key differences to note:
Deploying libraries is like deploying an Actor, with a few key differences to note:

- You don't need to `export` any functions (unless you really want to enable `call`)
- You don't need to make any functions `:callable`

```clojure
(def my-lib-address
Expand All @@ -298,12 +298,19 @@ Deploying libraries is just like deploying an Actor, with a few key differences
=> 5.0
```

### Important security note for libraries
### Important security note

A key difference between a `call` to an Actor function and running library code is the difference in *security context*:

- An Actor `call` runs code in the Actor's environment, with the Actor itself the current `*address*` (and the calling Account as `*caller*`)
- Library code runs in the environment of the current Account, i.e. `*address*` is unchanged
- An actor `call` runs code in the actor's account and environment, with the actor itself as the current `*address*` (and the calling account as `*caller*`)
- Library code runs in the environment of the current account, i.e. `*address*` is unchanged

As a result of this: **DO NOT RUN LIBRARY CODE YOU DO NOT TRUST**. Library code can do anything that your Account can, including transferring away all your coins and tokens, or calling arbitrary smart contracts. If you have any doubt about the trustworthiness of library code, do not use it from an Account that controls any valuable assets.
**DO NOT RUN LIBRARY CODE YOU DO NOT TRUST**. Library code executed in your account can do anything that your account can, including transferring away all your coins and tokens, or entering into arbitrary smart contracts on your behalf. If you have any doubt about the trustworthiness of library code, do not use it from an account that controls any valuable assets or resources.

If you don't trust a library but also don't expect it to make any state changes, you can wrap a call in `query` which will roll back any state changes made and just return the result. This is mostly safe since any malicious state changes will be undone (though beware that the library might still return malicious results, or deliberately burn juice to hit you with transactions fees...)

```clojure
(query (untrusted-library/dangerous-function))
=> "This is the result"
```

4 changes: 2 additions & 2 deletions docs/tutorial/convex-lisp/lisp-guide-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Expansion is the second phase of the compiler. Expansion takes the raw form data
'(foo :bar :baz) -> <Syntax Object>
```

In this phase, any macros are applied to the forms analyzed, which has the effect of replacing them with the macro expansion.
In this phase, any macros are applied to the forms analysed, which has the effect of replacing them with the macro expansion.

This means that arbitrary CVM code in macros *can* be executed during expansion - which in turn can be sometimes useful, e.g. in smart contract code that wishes to generate code based on analyzing the CVM state.
This means that arbitrary CVM code in macros *can* be executed during expansion - which in turn can be sometimes useful, e.g. in smart contract code that wishes to generate code based on analysing the CVM state.

Phase 2 expansion can be performed either on-chain or off-chain.

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/convex-lisp/lisp-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Using the [Sandbox](/sandbox) is the easiest way to experience Convex Lisp. We r

## Lisp expressions

All Lisp code is contructed from expressions, which can be evaluated to get a resulting value (or maybe an error, if something went wrong...). The classic Lisp expression is a list enclosed in parentheses `(...)` where the first element of the list is the function to be called and the following elemenst are the arguments. So to add two numbers with the `+` function you would do something like:
All Lisp code is constructed from expressions, which can be evaluated to get a resulting value (or maybe an error, if something went wrong...). The classic Lisp expression is a list enclosed in parentheses `(...)` where the first element of the list is the function to be called and the following elemenst are the arguments. So to add two numbers with the `+` function you would do something like:

```clojure
(+ 2 3)
Expand Down

0 comments on commit 959c261

Please sign in to comment.