Skip to content

Commit

Permalink
Merge pull request #229 from CosmWasm/add-gaiaflex
Browse files Browse the repository at this point in the history
Add gaiaflex to Makefile and Dockerfile
  • Loading branch information
ethanfrey authored Jul 28, 2020
2 parents 23d1fd8 + f3cf373 commit de9ebe8
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 915 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
FROM cosmwasm/go-ext-builder:0.8.2-alpine AS rust-builder

RUN apk add git
# without this, build with LEDGER_ENABLED=false
RUN apk add libusb-dev linux-headers

# copy all code into /code
WORKDIR /code
Expand Down Expand Up @@ -34,19 +32,21 @@ COPY --from=rust-builder /lib/libgo_cosmwasm_muslc.a /lib/libgo_cosmwasm_muslc.a

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make build
# we also (temporarily) build the testnet binaries here
# we also (temporarily?) build the testnet binaries here
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make build-coral
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make build-gaiaflex

# --------------------------------------------------------
FROM alpine:3.12

COPY --from=go-builder /code/build/wasmd /usr/bin/wasmd
COPY --from=go-builder /code/build/wasmgovd /usr/bin/wasmgovd
COPY --from=go-builder /code/build/wasmcli /usr/bin/wasmcli

# testnet
COPY --from=go-builder /code/build/coral /usr/bin/coral
COPY --from=go-builder /code/build/corald /usr/bin/corald
COPY --from=go-builder /code/build/gaiaflex /usr/bin/gaiaflex
COPY --from=go-builder /code/build/gaiaflexd /usr/bin/gaiaflexd

COPY docker/* /opt/
RUN chmod +x /opt/*.sh
Expand Down
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,59 @@ coral_ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=coral \
-X github.com/CosmWasm/wasmd/app.NodeDir=.corald \
-X github.com/CosmWasm/wasmd/app.Bech32Prefix=coral \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"
# we could consider enabling governance override?
# -X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin \
coral_ldflags += $(LDFLAGS)
coral_ldflags := $(strip $(coral_ldflags))

flex_ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=gaiaflex \
-X github.com/cosmos/cosmos-sdk/version.ServerName=gaiaflexd \
-X github.com/cosmos/cosmos-sdk/version.ClientName=gaiaflex \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true \
-X github.com/CosmWasm/wasmd/app.CLIDir=.gaiaflex \
-X github.com/CosmWasm/wasmd/app.NodeDir=.gaiaflexd \
-X github.com/CosmWasm/wasmd/app.Bech32Prefix=cosmos \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

flex_ldflags += $(LDFLAGS)
flex_ldflags := $(strip $(flex_ldflags))

BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(ldflags)' -trimpath
CORAL_BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(coral_ldflags)' -trimpath
FLEX_BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(flex_ldflags)' -trimpath

all: install lint test

build: go.sum
ifeq ($(OS),Windows_NT)
# wasmd nodes not supported on windows, maybe the cli?
# wasmd nodes not supported on windows, maybe the cli?
go build -mod=readonly $(BUILD_FLAGS) -o build/wasmcli.exe ./cmd/wasmcli
else
go build -mod=readonly $(BUILD_FLAGS) -o build/wasmd ./cmd/wasmd
go build -mod=readonly $(BUILD_FLAGS) -o build/wasmgovd ./cmd/wasmgovd
go build -mod=readonly $(BUILD_FLAGS) -o build/wasmcli ./cmd/wasmcli
endif

build-coral: go.sum
ifeq ($(OS),Windows_NT)
# wasmd nodes not supported on windows, maybe the cli?
# wasmd nodes not supported on windows, maybe the cli?
go build -mod=readonly $(CORAL_BUILD_FLAGS) -o build/coral.exe ./cmd/wasmcli
else
go build -mod=readonly $(CORAL_BUILD_FLAGS) -o build/corald ./cmd/wasmd
go build -mod=readonly $(CORAL_BUILD_FLAGS) -o build/coral ./cmd/wasmcli
endif

build-gaiaflex: go.sum
ifeq ($(OS),Windows_NT)
# wasmd nodes not supported on windows, maybe the cli?
go build -mod=readonly $(FLEX_BUILD_FLAGS) -o build/gaiaflex.exe ./cmd/wasmcli
else
go build -mod=readonly $(FLEX_BUILD_FLAGS) -o build/gaiaflexd ./cmd/wasmd
go build -mod=readonly $(FLEX_BUILD_FLAGS) -o build/gaiaflex ./cmd/wasmcli
endif

build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build

Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ docker run --rm -it \
cosmwasm/wasmd:latest ./logs.sh
```

## Runtime flags

We provide a number of variables in `app/app.go` that are intended to be set via `-ldflags -X ...`
compile-time flags. This enables us to avoid copying a new binary directory over for each small change
to the configuration.

Available flags:

* `-X github.com/CosmWasm/wasmd/app.CLIDir=.coral` - set the config directory for the cli (default `~/.wasmcli`)
* `-X github.com/CosmWasm/wasmd/app.NodeDir=.corald` - set the config/data directory for the node (default `~/.wasmd`)
* `-X github.com/CosmWasm/wasmd/app.Bech32Prefix=coral` - set the bech32 prefix for all accounts (default `cosmos`)
* `-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true` - enable all x/wasm governance proposals (default `false`)
* `-X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin` -
enable a subset of the x/wasm governance proposal types (overrides `ProposalsEnabled`)

Examples:

* [`wasmd`](./Makefile#L50-L55) is a generic, permissionless version using the `cosmos` bech32 prefix
* [`gaiaflex`](./Makefile#L78-L87) is a generic, *permissioned* version using the `cosmos` bech32 prefix
* [`coral`](./Makefile#L63-L71) is a permissionless version designed for a specific testnet, with a `coral` bech32 prefix

## Genesis Configuration

@alpe we should document all the genesis config for x/wasm even more.

Tip: if you want to lock this down to a permisisoned network, the following script can edit the genesis file
to only allow permissioned use of code upload or instantiating. (Make sure you set `app.ProposalsEnabled=true`
in this binary):

`sed -i 's/permission": "Everybody"/permission": "Nobody"/' .../config/genesis.json`

## Contributors

Much thanks to all who have contributed to this project, from this app, to the `cosmwasm` framework, to example contracts and documentation.
Expand Down
26 changes: 26 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
Expand Down Expand Up @@ -44,8 +45,33 @@ var (
CLIDir = ".wasmcli"
NodeDir = ".wasmd"
Bech32Prefix = sdk.Bech32MainPrefix

// If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
ProposalsEnabled = "false"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasm.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
}
return wasm.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
// any overrides above
Expand Down
38 changes: 35 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package app

import (
"github.com/magiconair/properties/assert"
"os"
"testing"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
db "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"

abci "github.com/tendermint/tendermint/abci/types"
db "github.com/tendermint/tm-db"

"github.com/CosmWasm/wasmd/x/wasm"
)

func TestWasmdExport(t *testing.T) {
Expand All @@ -37,6 +38,37 @@ func TestBlackListedAddrs(t *testing.T) {
}
}

func TestGetEnabledProposals(t *testing.T) {
cases := map[string]struct {
proposalsEnabled string
specificEnabled string
expected []wasm.ProposalType
}{
"all disabled": {
proposalsEnabled: "false",
expected: wasm.DisableAllProposals,
},
"all enabled": {
proposalsEnabled: "true",
expected: wasm.EnableAllProposals,
},
"some enabled": {
proposalsEnabled: "okay",
specificEnabled: "StoreCode,InstantiateContract",
expected: []wasm.ProposalType{wasm.ProposalTypeStoreCode, wasm.ProposalTypeInstantiateContract},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ProposalsEnabled = tc.proposalsEnabled
EnableSpecificProposals = tc.specificEnabled
proposals := GetEnabledProposals()
assert.Equal(t, tc.expected, proposals)
})
}
}

func setGenesis(gapp *WasmApp) error {
genesisState := simapp.NewDefaultGenesisState()
genesisState[wasm.ModuleName] = wasm.AppModuleBasic{}.DefaultGenesis()
Expand Down
8 changes: 4 additions & 4 deletions cmd/wasmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -90,7 +89,8 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
}

return app.NewWasmApp(logger, db, traceStore, true, invCheckPeriod,
wasm.DisableAllProposals, skipUpgradeHeights,
app.GetEnabledProposals(),
skipUpgradeHeights,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
baseapp.SetHaltHeight(viper.GetUint64(server.FlagHaltHeight)),
Expand All @@ -103,14 +103,14 @@ func exportAppStateAndTMValidators(
) (json.RawMessage, []tmtypes.GenesisValidator, error) {

if height != -1 {
gapp := app.NewWasmApp(logger, db, traceStore, false, uint(1), wasm.DisableAllProposals, nil)
gapp := app.NewWasmApp(logger, db, traceStore, false, uint(1), app.GetEnabledProposals(), nil)
err := gapp.LoadHeight(height)
if err != nil {
return nil, nil, err
}
return gapp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}

gapp := app.NewWasmApp(logger, db, traceStore, true, uint(1), wasm.DisableAllProposals, nil)
gapp := app.NewWasmApp(logger, db, traceStore, true, uint(1), app.GetEnabledProposals(), nil)
return gapp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}
3 changes: 1 addition & 2 deletions cmd/wasmd/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/server"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -92,7 +91,7 @@ func replayTxs(rootDir string) error {
fmt.Fprintln(os.Stderr, "Creating application")
gapp := app.NewWasmApp(
// TODO: do we want to set skipUpgradeHieghts here?
ctx.Logger, appDB, traceStoreWriter, true, uint(1), wasm.DisableAllProposals, nil,
ctx.Logger, appDB, traceStoreWriter, true, uint(1), app.GetEnabledProposals(), nil,
baseapp.SetPruning(storetypes.PruneEverything))

// Genesis
Expand Down
Loading

0 comments on commit de9ebe8

Please sign in to comment.