Skip to content

Commit

Permalink
Merge branch 'main' into 0xkrane-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Jul 5, 2024
2 parents 92b2725 + 5da524f commit e6a421a
Show file tree
Hide file tree
Showing 24 changed files with 616 additions and 117 deletions.
5 changes: 1 addition & 4 deletions docs/learn/advanced/00-baseapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ management logic.

The `BaseApp` type holds many important parameters for any Cosmos SDK based application.

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/baseapp.go#L58-L182
```

Let us go through the most important components.

Expand Down Expand Up @@ -492,9 +490,8 @@ The `FinalizeBlock` ABCI function defined in `BaseApp` does the bulk of the stat

Instead of using their `checkState`, full-nodes use `finalizeblock`:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/baseapp.go#LL708-L743
```


Transaction execution within `FinalizeBlock` performs the **exact same steps as `CheckTx`**, with a little caveat at step 3 and the addition of a fifth step:

Expand Down
3 changes: 1 addition & 2 deletions docs/learn/advanced/01-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ simd tx send $MY_VALIDATOR_ADDRESS $RECIPIENT 1000stake

[gRPC](https://grpc.io) is the main component for the Cosmos SDK's RPC layer. Its principal usage is in the context of modules' [`Query` services](../../build/building-modules/04-query-services.md). However, the Cosmos SDK also exposes a few other module-agnostic gRPC services, one of them being the `Tx` service:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/proto/cosmos/tx/v1beta1/service.proto
```


The `Tx` service exposes a handful of utility functions, such as simulating a transaction or querying a transaction, and also one method to broadcast transactions.

Expand Down
6 changes: 3 additions & 3 deletions docs/learn/advanced/02-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/context.go#L41-L
`Events` by defining various `Types` and `Attributes` or use the common definitions found in `types/`. Clients can subscribe or query for these `Events`. These `Events` are collected throughout `FinalizeBlock` and are returned to CometBFT for indexing.
* **Priority:** The transaction priority, only relevant in `CheckTx`.
* **KV `GasConfig`:** Enables applications to set a custom `GasConfig` for the `KVStore`.
* **Transient KV `GasConfig`:** Enables applications to set a custom `GasConfig` for the transiant `KVStore`.
* **Transient KV `GasConfig`:** Enables applications to set a custom `GasConfig` for the transient `KVStore`.
* **StreamingManager:** The streamingManager field provides access to the streaming manager, which allows modules to subscribe to state changes emitted by the blockchain. The streaming manager is used by the state listening API, which is described in [ADR 038](https://docs.cosmos.network/main/architecture/adr-038-state-listening).
* **CometInfo:** A lightweight field that contains information about the current block, such as the block height, time, and hash. This information can be used for validating evidence, providing historical data, and enhancing the user experience. For further details see [here](https://github.com/cosmos/cosmos-sdk/blob/main/core/comet/service.go#L14).
* **HeaderInfo:** The `headerInfo` field contains information about the current block header, such as the chain ID, gas limit, and timestamp. For further details see [here](https://github.com/cosmos/cosmos-sdk/blob/main/core/header/service.go#L14).
Expand All @@ -54,7 +54,7 @@ Contexts are intended to be **immutable**; they should never be edited. Instead,
to create a child context from its parent using a `With` function. For example:

```go
childCtx = parentCtx.WithBlockHeader(header)
childCtx := parentCtx.WithBlockHeader(header)
```

The [Golang Context Package](https://pkg.go.dev/context) documentation instructs developers to
Expand All @@ -71,7 +71,7 @@ goes wrong. The pattern of usage for a Context is as follows:

1. A process receives a Context `ctx` from its parent process, which provides information needed to
perform the process.
2. The `ctx.ms` is a **branched store**, i.e. a branch of the [multistore](./04-store.md#multistore) is made so that the process can make changes to the state as it executes, without changing the original`ctx.ms`. This is useful to protect the underlying multistore in case the changes need to be reverted at some point in the execution.
2. The `ctx.ms` is a **branched store**, i.e. a branch of the [multistore](./04-store.md#multistore) is made so that the process can make changes to the state as it executes, without changing the original `ctx.ms`. This is useful to protect the underlying multistore in case the changes need to be reverted at some point in the execution.
3. The process may read and write from `ctx` as it is executing. It may call a subprocess and pass
`ctx` to it as needed.
4. When a subprocess returns, it checks if the result is a success or failure. If a failure, nothing
Expand Down
2 changes: 1 addition & 1 deletion docs/learn/advanced/03-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ simd start

As a reminder, the full-node is composed of three conceptual layers: the networking layer, the consensus layer and the application layer. The first two are generally bundled together in an entity called the consensus engine (CometBFT by default), while the third is the state-machine defined with the help of the Cosmos SDK. Currently, the Cosmos SDK uses CometBFT as the default consensus engine, meaning the start command is implemented to boot up a CometBFT node.

The flow of the `start` command is pretty straightforward. First, it retrieves the `config` from the `context` in order to open the `db` (a [`leveldb`](https://github.com/syndtr/goleveldb) instance by default). This `db` contains the latest known state of the application (empty if the application is started from the first time.
The flow of the `start` command is pretty straightforward. First, it retrieves the `config` from the `context` in order to open the `db` (a [`levelDB`](https://github.com/syndtr/goleveldb) instance by default). This `db` contains the latest known state of the application (empty if the application is started from the first time).

With the `db`, the `start` command creates a new instance of the application using an `appCreator` function:

Expand Down
2 changes: 0 additions & 2 deletions docs/learn/advanced/05-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/tx_msg.go#L91-L9

A standard implementation of both these objects can be found in the [`auth/tx` module](https://docs.cosmos.network/main/build/modules/auth#transactions):

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/auth/tx/decoder.go
```

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/auth/tx/encoder.go
Expand Down
2 changes: 0 additions & 2 deletions docs/learn/advanced/10-ocap.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ sumValue := externalModule.ComputeSumValue(*account)

In the Cosmos SDK, you can see the application of this principle in simapp.

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app.go
```

The following diagram shows the current dependencies between keepers.

Expand Down
2 changes: 1 addition & 1 deletion docs/learn/beginner/01-tx-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The command-line is an easy way to interact with an application, but `Tx` can al

## Transaction Broadcasting

This is the next phase, where a transactison is sent from a client (such as a wallet or a command-line interface) to the network of nodes. This process is consensus-agnostic, meaning it can work with various consensus engines.
This is the next phase, where a transaction is sent from a client (such as a wallet or a command-line interface) to the network of nodes. This process is consensus-agnostic, meaning it can work with various consensus engines.

Below are the steps involved in transaction broadcasting:

Expand Down
2 changes: 1 addition & 1 deletion docs/learn/beginner/02-query-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ One such tool is [grpcurl](https://github.com/fullstorydev/grpcurl), and a gRPC

```bash
grpcurl \
-plaintext # We want results in plain test
-plaintext # We want results in plain text
-import-path ./proto \ # Import these .proto files
-proto ./proto/cosmos/staking/v1beta1/query.proto \ # Look into this .proto file for the Query protobuf service
-d '{"address":"$MY_DELEGATOR"}' \ # Query arguments
Expand Down
2 changes: 1 addition & 1 deletion docs/learn/beginner/03-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ A few notes on the `Keyring` methods:
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/proto/cosmos/tx/v1beta1/tx.proto#L50-L66
```

* `NewAccount(uid, mnemonic, bip39Passphrase, hdPath string, algo SignatureAlgo) (*Record, error)` creates a new account based on the [`bip44 path`](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) and persists it on disk. The `PrivKey` is **never stored unencrypted**, instead it is [encrypted with a passphrase](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/crypto/armor.go) before being persisted. In the context of this method, the key type and sequence number refer to the segment of the BIP44 derivation path (for example, `0`, `1`, `2`, ...) that is used to derive a private and a public key from the mnemonic. Using the same mnemonic and derivation path, the same `PrivKey`, `PubKey` and `Address` is generated. The following keys are supported by the keyring:
* `NewAccount(uid, mnemonic, bip39Passphrase, hdPath string, algo SignatureAlgo) (*Record, error)` creates a new account based on the [`bip44 path`](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) and persists it on disk. The `PrivKey` is **never stored unencrypted**, instead it is [encrypted with a passphrase](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/crypto/armor.go) before being persisted. In the context of this method, the key type and sequence number refers to the segment of the BIP44 derivation path (for example, `0`, `1`, `2`, ...) that is used to derive a private and a public key from the mnemonic. Using the same mnemonic and derivation path, the same `PrivKey`, `PubKey` and `Address` is generated. The following keys are supported by the keyring:

* `secp256k1`
* `ed25519`
Expand Down
2 changes: 1 addition & 1 deletion docs/learn/intro/01-why-app-specific.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The list above contains a few examples that show how much flexibility applicatio

Decentralized applications built with Smart Contracts are inherently capped in performance by the underlying environment. For a decentralized application to optimise performance, it needs to be built as an application-specific blockchain. Next are some of the benefits an application-specific blockchain brings in terms of performance:

* Developers of application-specific blockchains can choose to operate with a novel consensus engine such as CometBFT BFT.
* Developers of application-specific blockchains can choose to operate with a novel consensus engine such as CometBFT.
* An application-specific blockchain only operates a single application, so that the application does not compete with others for computation and storage. This is the opposite of most non-sharded virtual-machine blockchains today, where smart contracts all compete for computation and storage.
* Even if a virtual-machine blockchain offered application-based sharding coupled with an efficient consensus algorithm, performance would still be limited by the virtual-machine itself. The real throughput bottleneck is the state-machine, and requiring transactions to be interpreted by a virtual-machine significantly increases the computational complexity of processing them.

Expand Down
17 changes: 17 additions & 0 deletions scripts/local-testnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -x

ROOT=$PWD

SIMD="$ROOT/build/simdv2"

COSMOS_BUILD_OPTIONS=v2 make build

$SIMD testnet init-files --chain-id=testing --output-dir="$HOME/.testnet" --validator-count=3 --keyring-backend=test --minimum-gas-prices=0.000001stake --commit-timeout=900ms --single-host

$SIMD start --log_level=info --home "$HOME/.testnet/node0/simdv2" &
$SIMD start --log_level=info --home "$HOME/.testnet/node1/simdv2" &
$SIMD start --log_level=info --home "$HOME/.testnet/node2/simdv2"
58 changes: 58 additions & 0 deletions server/v2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package serverv2

import (
"context"
"errors"
"fmt"
"net"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -47,3 +49,59 @@ func GetLoggerFromCmd(cmd *cobra.Command) corelog.Logger {

return logger
}

// ExternalIP https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go
// TODO there must be a better way to get external IP
func ExternalIP() (string, error) {
ifaces, err := net.Interfaces()
if err != nil {
return "", err
}

for _, iface := range ifaces {
if skipInterface(iface) {
continue
}
addrs, err := iface.Addrs()
if err != nil {
return "", err
}

for _, addr := range addrs {
ip := addrToIP(addr)
if ip == nil || ip.IsLoopback() {
continue
}
ip = ip.To4()
if ip == nil {
continue // not an ipv4 address
}
return ip.String(), nil
}
}
return "", errors.New("are you connected to the network?")
}

func skipInterface(iface net.Interface) bool {
if iface.Flags&net.FlagUp == 0 {
return true // interface down
}

if iface.Flags&net.FlagLoopback != 0 {
return true // loopback interface
}

return false
}

func addrToIP(addr net.Addr) net.IP {
var ip net.IP

switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
return ip
}
3 changes: 1 addition & 2 deletions simapp/simd/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"cosmossdk.io/simapp"
confixcmd "cosmossdk.io/tools/confix/cmd"
authcmd "cosmossdk.io/x/auth/client/cli"
banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand All @@ -40,7 +39,7 @@ func initRootCmd(

rootCmd.AddCommand(
genutilcli.InitCmd(moduleManager),
NewTestnetCmd(moduleManager, banktypes.GenesisBalancesIterator{}),
NewTestnetCmd(moduleManager),
debug.Cmd(),
confixcmd.ConfigCommand(),
pruning.Cmd(newApp),
Expand Down
15 changes: 7 additions & 8 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func addTestnetFlagsToCmd(cmd *cobra.Command) {

// NewTestnetCmd creates a root testnet command with subcommands to run an in-process testnet or initialize
// validator configuration files for running a multi-validator testnet in a separate process
func NewTestnetCmd(mm *module.Manager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
func NewTestnetCmd(mm *module.Manager) *cobra.Command {
testnetCmd := &cobra.Command{
Use: "testnet",
Short: "subcommands for starting or configuring local testnets",
Expand All @@ -113,13 +113,13 @@ func NewTestnetCmd(mm *module.Manager, genBalIterator banktypes.GenesisBalancesI
}

testnetCmd.AddCommand(testnetStartCmd())
testnetCmd.AddCommand(testnetInitFilesCmd(mm, genBalIterator))
testnetCmd.AddCommand(testnetInitFilesCmd(mm))

return testnetCmd
}

// testnetInitFilesCmd returns a cmd to initialize all files for CometBFT testnet and application
func testnetInitFilesCmd(mm *module.Manager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
func testnetInitFilesCmd(mm *module.Manager) *cobra.Command {
cmd := &cobra.Command{
Use: "init-files",
Short: "Initialize config directories & files for a multi-validator testnet running locally via separate processes (e.g. Docker Compose or similar)",
Expand Down Expand Up @@ -160,7 +160,7 @@ Example:
return err
}

return initTestnetFiles(clientCtx, cmd, config, mm, genBalIterator, args)
return initTestnetFiles(clientCtx, cmd, config, mm, args)
},
}

Expand Down Expand Up @@ -223,7 +223,6 @@ func initTestnetFiles(
cmd *cobra.Command,
nodeConfig *cmtconfig.Config,
mm *module.Manager,
genBalIterator banktypes.GenesisBalancesIterator,
args initArgs,
) error {
if args.chainID == "" {
Expand Down Expand Up @@ -399,7 +398,7 @@ func initTestnetFiles(

err := collectGenFiles(
clientCtx, nodeConfig, args.chainID, nodeIDs, valPubKeys, args.numValidators,
args.outputDir, args.nodeDirPrefix, args.nodeDaemonHome, genBalIterator,
args.outputDir, args.nodeDirPrefix, args.nodeDaemonHome,
rpcPort, p2pPortStart, args.singleMachine,
)
if err != nil {
Expand Down Expand Up @@ -463,7 +462,7 @@ func initGenFiles(
func collectGenFiles(
clientCtx client.Context, nodeConfig *cmtconfig.Config, chainID string,
nodeIDs []string, valPubKeys []cryptotypes.PubKey, numValidators int,
outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator,
outputDir, nodeDirPrefix, nodeDaemonHome string,
rpcPortStart, p2pPortStart int,
singleMachine bool,
) error {
Expand Down Expand Up @@ -492,7 +491,7 @@ func collectGenFiles(
return err
}

nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, appGenesis, genBalIterator, genutiltypes.DefaultMessageValidator,
nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, appGenesis, genutiltypes.DefaultMessageValidator,
clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Test_TestnetCmd(t *testing.T) {
ctx = context.WithValue(ctx, corectx.ViperContextKey, viper)
ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger)
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
cmd := testnetInitFilesCmd(moduleManager, banktypes.GenesisBalancesIterator{})
cmd := testnetInitFilesCmd(moduleManager)
cmd.SetArgs([]string{fmt.Sprintf("--%s=test", flags.FlagKeyringBackend), fmt.Sprintf("--output-dir=%s", home)})
err = cmd.ExecuteContext(ctx)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/math v1.3.0
cosmossdk.io/runtime/v2 v2.0.0-00010101000000-000000000000
cosmossdk.io/server/v2 v2.0.0-00010101000000-000000000000
cosmossdk.io/server/v2/cometbft v0.0.0-00010101000000-000000000000
Expand All @@ -31,15 +31,15 @@ require (
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000
cosmossdk.io/x/tx v0.13.3 // indirect
cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f
github.com/cometbft/cometbft v1.0.0-rc1 // indirect
github.com/cometbft/cometbft v1.0.0-rc1
github.com/cosmos/cosmos-db v1.0.2
// this version is not used as it is always replaced by the latest Cosmos SDK version
github.com/cosmos/cosmos-sdk v0.51.0
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"cosmossdk.io/simapp/v2"
confixcmd "cosmossdk.io/tools/confix/cmd"
authcmd "cosmossdk.io/x/auth/client/cli"
banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand Down Expand Up @@ -90,6 +91,7 @@ func initRootCmd[AppT serverv2.AppI[T], T transaction.Tx](
genutilcli.InitCmd(moduleManager),
debug.Cmd(),
confixcmd.ConfigCommand(),
NewTestnetCmd(moduleManager, banktypes.GenesisBalancesIterator{}),
// pruning.Cmd(newApp), // TODO add to comet server
// snapshot.Cmd(newApp), // TODO add to comet server
)
Expand Down
Loading

0 comments on commit e6a421a

Please sign in to comment.