Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v0.52): SDK v0.52 + gordian integration #192

Draft
wants to merge 15 commits into
base: wip-release/v0.52
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions DELETEMEEEEEEEEEEEEE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## IBc Integration WIP

grpcurl -plaintext localhost:9092 list


grpcurl -plaintext localhost:9092 gordian.server.v1.GordianGRPC/GetBlocksWatermark



## Steps
- Get a Tx hash from the node
- Get Relayer to use gRPC client with gordian
- Get Interchaintest to also use the gRPC client
- Connect gordian to a cometbft chain
- Profit


```bash
go build -o gcosmos . && rm -rf ~/.simappv2/data/application.db/ && ./gcosmos start --g-http-addr 127.0.0.1:26657 --g-grpc-addr 127.0.0.1:9092
```
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CWD := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))

# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
VERSION := $(shell git tag --sort=taggerdate | tail -1)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
Expand Down Expand Up @@ -64,6 +64,9 @@ help: Makefile
template-staking: install
spawn new myproject --consensus=proof-of-stake --debug --bech32=cosmos --bin=appd --bypass-prompt --log-level=debug --org=reece

template-gordian-staking: install
spawn new myproject --consensus=pos --debug --bech32=cosmos --bin=appd --bypass-prompt --log-level=debug --org=reecepbcups --engine=gordian --disable=explorer

template-poa: install
spawn new myproject --consensus=proof-of-authority --debug --no-git --bin=rolld --bech32=roll --denom=uroll --bypass-prompt --log-level=debug

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ make install
GITHUB_USERNAME=rollchains

# Available Features:
# * tokenfactory,globalfee,ibc-packetforward,ibc-ratelimit,cosmwasm,wasm-light-client,optimistic-execution,ignite-cli,block-explorer
# * tokenfactory,globalfee,ibc-packetforward,ibc-ratelimit,cosmwasm,wasm-light-client,optimistic-execution,block-explorer

spawn new rollchain \
--consensus=proof-of-authority `# proof-of-authority,proof-of-stake,interchain-security` \
Expand Down
182 changes: 127 additions & 55 deletions cmd/spawn/new_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log/slog"
"strings"

"github.com/spf13/cobra"
Expand All @@ -15,12 +16,19 @@ var (
// - UI: uses the IsSelected
// - CLI: all are enabled by default. Must opt out.

DefaultConsensus = spawn.POA
ConsensusFeatures = items{
// Consensus (only 1 per app)
{ID: "proof-of-authority", IsSelected: true, IsConsensus: true, Details: "Proof-of-Authority consensus algorithm (permissioned network)"},
{ID: "proof-of-stake", IsSelected: false, IsConsensus: true, Details: "Proof-of-Stake consensus algorithm (permissionless network)"},
{ID: "interchain-security", IsSelected: false, IsConsensus: true, Details: "Cosmos Hub Interchain Security"},
// {ID: "ics-ethos", IsSelected: false, IsConsensus: true, Details: "Interchain-Security with Ethos ETH restaking"},
}

DefaultEngine = spawn.Gordian // TODO: must be productionized to use default
ConsensusEngines = items{
// only 1 per app
{ID: "gordian", IsSelected: true, Details: "Modular BFT engine"}, // TODO: must be productionized to use default
{ID: "cometbft", IsSelected: false, Details: "Standard Tendermint Core engine"},
}

SupportedFeatures = append(ConsensusFeatures, items{
Expand All @@ -31,7 +39,6 @@ var (
{ID: "cosmwasm", IsSelected: false, Details: "Cosmos smart contracts"},
{ID: "wasm-light-client", IsSelected: false, Details: "08 Wasm Light Client"},
{ID: "optimistic-execution", IsSelected: false, Details: "Pre-process blocks ahead of consensus request"},
{ID: "ignite-cli", IsSelected: false, Details: "Ignite-CLI Support"},
{ID: "block-explorer", IsSelected: true, Details: "Ping Pub Explorer"},
}...)

Expand All @@ -48,13 +55,15 @@ const (
FlagGithubOrg = "org"
FlagDisabled = "disable"
FlagConsensus = "consensus"
FlagEngine = "engine" // consensus-engine
FlagNoGit = "skip-git"
FlagBypassPrompt = "bypass-prompt"
)

func init() {
features := make([]string, 0)
consensus := make([]string, 0)
engines := make([]string, 0)

for _, feat := range SupportedFeatures {
if feat.IsConsensus {
Expand All @@ -64,12 +73,17 @@ func init() {
}
}

for _, feat := range ConsensusEngines {
engines = append(engines, feat.ID)
}

newChain.Flags().String(FlagWalletPrefix, "cosmos", "chain bech32 wallet prefix")
newChain.Flags().StringP(FlagBinDaemon, "b", "simd", "binary name")
newChain.Flags().String(FlagGithubOrg, "rollchains", "github organization")
newChain.Flags().String(FlagTokenDenom, "token", "bank token denomination")
newChain.Flags().StringSlice(FlagDisabled, []string{}, strings.Join(features, ","))
newChain.Flags().String(FlagConsensus, "", strings.Join(consensus, ",")) // must be set to nothing is nothing is set
newChain.Flags().String(FlagEngine, "", strings.Join(engines, ",")) // must be set to nothing is nothing is set
newChain.Flags().Bool(FlagDebugging, false, "enable debugging")
newChain.Flags().Bool(FlagNoGit, false, "ignore git init")
newChain.Flags().Bool(FlagBypassPrompt, false, "bypass UI prompt")
Expand All @@ -94,69 +108,22 @@ var newChain = &cobra.Command{
projName := strings.ToLower(args[0])
homeDir := "." + projName

disabled, _ := cmd.Flags().GetStringSlice(FlagDisabled)
walletPrefix, _ := cmd.Flags().GetString(FlagWalletPrefix)
binName, _ := cmd.Flags().GetString(FlagBinDaemon)
denom, _ := cmd.Flags().GetString(FlagTokenDenom)
ignoreGitInit, _ := cmd.Flags().GetBool(FlagNoGit)
githubOrg, _ := cmd.Flags().GetString(FlagGithubOrg)
consensus, _ := cmd.Flags().GetString(FlagConsensus)

bypassPrompt, _ := cmd.Flags().GetBool(FlagBypassPrompt)

// Show a UI to select the consensus algorithm (POS, POA, ICS) if a custom one was not specified.
if !bypassPrompt {
if len(consensus) == 0 {
text := "Consensus Selector (( enter to toggle ))"
items, err := selectItems(text, 0, SupportedFeatures, false, true, true)
if err != nil {
logger.Error("Error selecting consensus", "err", err)
return
}
consensus = items.String()
}
}
if len(consensus) == 0 {
consensus = spawn.POA // set the default if still none is provided
}

consensus = spawn.AliasName(consensus)
logger.Debug("Consensus selected", "consensus", consensus)

// Disable all consensus algorithms except the one selected.
disabledConsensus := make([]string, 0)
for _, feat := range ConsensusFeatures {
name := spawn.AliasName(feat.ID)
if name != consensus {
// if consensus is proof-of-authority, allow proof of stake
if consensus == spawn.POA && name == spawn.POS {
continue
} else if consensus == spawn.InterchainSecurity && name == spawn.POS {
continue
}

disabledConsensus = append(disabledConsensus, name)
}
}
logger.Debug("Disabled Consensuses", "disabled", disabledConsensus, "using", consensus)

// Disable all features not selected
// Show a UI if the user did not specific to bypass it, or if nothing is disabled.
if len(disabled) == 0 && !bypassPrompt {
text := "Feature Selector (( enter to toggle ))"
items, err := selectItems(text, 0, SupportedFeatures, true, false, false)
if err != nil {
logger.Error("Error selecting disabled", "err", err)
return
}
disabled = items.NOTSlice()

}
_, disabled := getSelectedAndDisabledFeatures(cmd, logger, bypassPrompt)
_, disabledConsensusAlgos := getConsensusAlgoAndAllDisabled(cmd, logger, bypassPrompt)
_, disabledEngines := getConsensusEngineAndAllDisabled(cmd, logger, bypassPrompt)

disabled = append(disabled, disabledConsensus...)
disabled = append(disabled, disabledConsensusAlgos...)
disabled = append(disabled, disabledEngines...)
disabled = spawn.NormalizeDisabledNames(disabled, parentDeps)

logger.Debug("Disabled features final", "features", disabled)
logger.Debug("Disabled features final", "features", disabledEngines)

cfg := &spawn.NewChainConfig{
ProjectName: projName,
Expand All @@ -177,6 +144,109 @@ var newChain = &cobra.Command{
},
}

func getSelectedAndDisabledFeatures(cmd *cobra.Command, logger *slog.Logger, bypassPrompt bool) ([]string, []string) {
disabled, _ := cmd.Flags().GetStringSlice(FlagDisabled)

// Disable all features not selected
// Show a UI if the user did not specific to bypass it, or if nothing is disabled.
if len(disabled) == 0 && !bypassPrompt {
text := "Feature Selector (( enter to toggle ))"
items, err := selectItems(text, 0, SupportedFeatures, true, false, false)
if err != nil {
logger.Error("Error selecting disabled", "err", err)
return nil, nil
}
disabled = items.NOTSlice()
}

enabled := make([]string, 0)
for _, feat := range SupportedFeatures {
if !feat.IsSelected {
continue
}
enabled = append(enabled, feat.ID)
}

logger.Debug("Disabled features", "disabled", disabled)
logger.Debug("Enabled features", "enabled", enabled)
return enabled, disabled
}

func getConsensusAlgoAndAllDisabled(cmd *cobra.Command, logger *slog.Logger, bypassPrompt bool) (string, []string) {
consensus, _ := cmd.Flags().GetString(FlagConsensus)

// Show a UI to select the consensus algorithm (POS, POA, ICS) if a custom one was not specified.
if !bypassPrompt {
if len(consensus) == 0 {
text := "Consensus Selector (( enter to toggle ))"
items, err := selectItems(text, 0, SupportedFeatures, false, true, true)
if err != nil {
logger.Error("Error selecting consensus", "err", err)
return "", nil
}
consensus = items.String()
}
}
if len(consensus) == 0 {
consensus = DefaultConsensus // set the default if still none is provided
}

consensus = spawn.AliasName(consensus)
logger.Debug("Consensus selected", "consensus", consensus)

// Disable all consensus algorithms except the one selected.
disabledConsensus := make([]string, 0)
for _, feat := range ConsensusFeatures {
name := spawn.AliasName(feat.ID)
if name != consensus {
// if consensus is proof-of-authority, allow proof of stake
if consensus == spawn.POA && name == spawn.POS {
continue
} else if consensus == spawn.InterchainSecurity && name == spawn.POS {
continue
}

disabledConsensus = append(disabledConsensus, name)
}
}
logger.Debug("Disabled Consensuses", "disabled", disabledConsensus, "using", consensus)
return consensus, disabledConsensus
}

func getConsensusEngineAndAllDisabled(cmd *cobra.Command, logger *slog.Logger, bypassPrompt bool) (string, []string) {
consensusEngine, _ := cmd.Flags().GetString(FlagEngine)
disabledEngines := make([]string, 0)

// Show a UI to select the consensus engines (Comet, Gordian) if one was not specified.
if !bypassPrompt {
if len(consensusEngine) == 0 {
text := "Engine Selector (( enter to toggle ))"
items, err := selectItems(text, 0, ConsensusEngines, false, false, true)
if err != nil {
logger.Error("Error selecting engine", "err", err)
return "", nil
}
consensusEngine = items.String()
}
}

// set the default is still none was provided
if len(consensusEngine) == 0 {
consensusEngine = DefaultEngine
}

// get the unselected engines
for _, feat := range ConsensusEngines {
name := spawn.AliasName(feat.ID)
if name != consensusEngine {
disabledEngines = append(disabledEngines, name)
}
}

logger.Debug("Disabled Consensus Engines", "using", consensusEngine, "disabled", disabledEngines)
return consensusEngine, disabledEngines
}

func normalizeWhitelistVarRun(f *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
case "bin", "daemon":
Expand All @@ -193,6 +263,8 @@ func normalizeWhitelistVarRun(f *pflag.FlagSet, name string) pflag.NormalizedNam
name = FlagWalletPrefix
case "organization", "namespace":
name = FlagGithubOrg
case "consensus-engine", "cengine", "c-engine", "bft":
name = FlagEngine
}

return pflag.NormalizedName(name)
Expand Down
2 changes: 1 addition & 1 deletion cmd/spawn/new_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestDisabledGeneration(t *testing.T) {
},
{
Name: "stdmix1",
Disabled: []string{spawn.GlobalFee, spawn.Ignite, spawn.TokenFactory},
Disabled: []string{spawn.GlobalFee, spawn.TokenFactory},
NotContainAny: []string{"TokenFactoryKeeper", "GlobalFeeKeeper"},
},
{
Expand Down
Loading
Loading