Skip to content

Commit

Permalink
Merge pull request #28 from bze-alphateam/feature/v6.1
Browse files Browse the repository at this point in the history
v6.1
  • Loading branch information
faneaatiku committed Nov 12, 2023
2 parents 7e8ff7e + 00b01bd commit e8157ad
Show file tree
Hide file tree
Showing 19 changed files with 2,072 additions and 4,430 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PACKAGES=$(shell go list ./... | grep -v '/simulation')
PACKAGE_NAME:=github.com/bze-alphateam/bze-v5
GOLANG_CROSS_VERSION = v1.19.3
GOLANG_CROSS_VERSION = v1.20.8
VERSION := $(shell echo $(shell git describe --tags 2>/dev/null ) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
NETWORK ?= mainnet
COVERAGE ?= coverage.txt
BUILDDIR ?= $(CURDIR)/build
LEDGER_ENABLED ?= true
LEDGER_ENABLED ?= false

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=bze \
-X github.com/cosmos/cosmos-sdk/version.AppName=bzed \
Expand Down Expand Up @@ -54,16 +54,16 @@ build-win64: check-version check-network go.sum

build-linux: check-version check-network go.sum
ifeq ($(OS), Linux)
GOOS=linux GOARCH=amd64 $(MAKE) build
GOOS=linux GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/linux-amd64/bzed ./cmd/bzed
else
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/linux-amd64/bzed ./cmd/bzed
endif

build-linux-arm64: check-version check-network go.sum
ifeq ($(OS), Linux)
GOOS=linux GOARCH=arm64 $(MAKE) build
GOOS=linux GOARCH=arm64 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/linux-arm64/bzed ./cmd/bzed
else
LEDGER_ENABLED=false GOOS=linux GOARCH=arm64 $(MAKE) build
LEDGER_ENABLED=false GOOS=linux GOARCH=arm64 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/linux-arm64/bzed ./cmd/bzed
endif

build-mac: check-version check-network go.sum
Expand All @@ -75,9 +75,9 @@ endif

build-mac-arm64: check-version check-network go.sum
ifeq ($(OS), Darwin)
LEDGER_ENABLED=false GOOS=darwin GOARCH=arm64 $(MAKE) build
LEDGER_ENABLED=false GOOS=darwin GOARCH=arm64 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/darwin-arm64/bzed ./cmd/bzed
else
LEDGER_ENABLED=false GOOS=darwin GOARCH=arm64 $(MAKE) build
LEDGER_ENABLED=false GOOS=darwin GOARCH=arm64 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/darwin-arm64/bzed ./cmd/bzed
endif

build-all: check-version lint all build-win64 build-mac build-mac-arm64 build-linux build-linux-arm64 compress-build
Expand All @@ -101,9 +101,9 @@ test: check-network

# look into .golangci.yml for enabling / disabling linters
lint:
@echo "--> Running linter"
@golangci-lint run
@go mod verify
@#echo "--> Running linter"
@#golangci-lint run
@#go mod verify

# a trick to make all the lint commands execute, return error when at least one fails.
# golangci-lint is run in standalone job in ci
Expand All @@ -113,8 +113,8 @@ lint-ci:

# Add check to make sure we are using the proper Go version before proceeding with anything
check-version:
@if ! go version | grep -q "go1.19"; then \
echo "\033[0;31mERROR:\033[0m Go version 1.19 is required for compiling bzed. It looks like you are using" "$(shell go version) \nThere are potential consensus-breaking changes that can occur when running binaries compiled with different versions of Go. Please download Go version 1.19 and retry. Thank you!"; \
@if ! go version | grep -q "go1.20"; then \
echo "\033[0;31mERROR:\033[0m Go version 1.20 is required for compiling bzed. It looks like you are using" "$(shell go version) \nThere are potential consensus-breaking changes that can occur when running binaries compiled with different versions of Go. Please download Go version 1.20 and retry. Thank you!"; \
exit 1; \
fi

Expand Down
78 changes: 42 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
v512 "github.com/bze-alphateam/bze/app/upgrades/v512"
v600 "github.com/bze-alphateam/bze/app/upgrades/v600"
v610 "github.com/bze-alphateam/bze/app/upgrades/v610"

"io"
"net/http"
Expand Down Expand Up @@ -76,35 +77,31 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v2/modules/core"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/v2/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
ibcporttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
"github.com/cosmos/ibc-go/v4/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v4/modules/core"
ibcclient "github.com/cosmos/ibc-go/v4/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/v4/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
ibcporttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/tendermint/starport/starport/pkg/cosmoscmd"
"github.com/tendermint/starport/starport/pkg/openapiconsole"

"github.com/bze-alphateam/bze/docs"
scavengemodule "github.com/bze-alphateam/bze/x/scavenge"
scavengemodulekeeper "github.com/bze-alphateam/bze/x/scavenge/keeper"
scavengemoduletypes "github.com/bze-alphateam/bze/x/scavenge/types"

cointrunkmodule "github.com/bze-alphateam/bze/x/cointrunk"
cointrunkmoduleclient "github.com/bze-alphateam/bze/x/cointrunk/client"
cointrunkmodulekeeper "github.com/bze-alphateam/bze/x/cointrunk/keeper"
cointrunkmoduletypes "github.com/bze-alphateam/bze/x/cointrunk/types"
scavengemodule "github.com/bze-alphateam/bze/x/scavenge"
scavengemodulekeeper "github.com/bze-alphateam/bze/x/scavenge/keeper"
scavengemoduletypes "github.com/bze-alphateam/bze/x/scavenge/types"

burnermodule "github.com/bze-alphateam/bze/x/burner"
burnermoduleclient "github.com/bze-alphateam/bze/x/burner/client"
Expand Down Expand Up @@ -186,10 +183,15 @@ var (
burnermoduletypes.ModuleName: {authtypes.Burner},
// this line is used by starport scaffolding # stargate/app/maccPerms
}

// a map of modules allowed to receive external funds
// this list will be excluded from bank/distribution modules blocked addresses
allowedModules = map[string]struct{}{
burnermoduletypes.ModuleName: {},
}
)

var (
_ cosmoscmd.CosmosApp = (*App)(nil)
_ servertypes.Application = (*App)(nil)
)

Expand Down Expand Up @@ -259,10 +261,10 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) cosmoscmd.App {
) *App {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand Down Expand Up @@ -333,7 +335,7 @@ func New(
app.AuthzKeeper = &authzKeeper

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.GetBlockedAddresses(),
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
Expand All @@ -344,7 +346,7 @@ func New(
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
&stakingKeeper, authtypes.FeeCollectorName, app.GetBlockedAddresses(),
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
Expand Down Expand Up @@ -372,7 +374,7 @@ func New(
// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
Expand Down Expand Up @@ -431,9 +433,10 @@ func New(
&stakingKeeper, govRouter,
)

transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -610,6 +613,11 @@ func (app *App) setupUpgradeHandlers() {
v600.CreateUpgradeHandler(&app.CointrunkKeeper),
)

app.UpgradeKeeper.SetUpgradeHandler(
v610.UpgradeName,
v610.CreateUpgradeHandler(),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
Expand Down Expand Up @@ -657,10 +665,16 @@ func (app *App) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

// ModuleAccountAddrs returns all the app's module account addresses.
func (app *App) ModuleAccountAddrs() map[string]bool {
// GetBlockedAddresses returns all addresses that should be blocked from direct sending
func (app *App) GetBlockedAddresses() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
// from the list of modules exclude the allowed ones (if any)
_, ok := allowedModules[acc]
if ok {
continue
}

modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}

Expand Down Expand Up @@ -735,7 +749,8 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig

// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml"))
//removed by SDK upgrade
//apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml"))
}

// RegisterTxService implements the Application.RegisterTxService method.
Expand All @@ -748,15 +763,6 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}
return dupMaccPerms
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
Expand Down
48 changes: 48 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package app

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry codectypes.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// MakeEncodingConfig creates an EncodingConfig instance
func NewEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

encodingConfig := EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}

return encodingConfig
}

// MakeEncodingConfig creates an EncodingConfig instance; registers types with codec and interface
// registry
func MakeEncodingConfig() EncodingConfig {
encodingConfig := NewEncodingConfig()

std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)

return encodingConfig
}
16 changes: 16 additions & 0 deletions app/upgrades/v610/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package v610

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const UpgradeName = "v6.1.0"

func CreateUpgradeHandler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// nothing to do
return vm, nil
}
}
18 changes: 18 additions & 0 deletions cmd/bzed/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import sdk "github.com/cosmos/cosmos-sdk/types"

// Define prefixes for addresses and public keys
func setAddressPrefixes(accountAddressPrefix string) {
accountPubKeyPrefix := accountAddressPrefix + "pub"
validatorAddressPrefix := accountAddressPrefix + "valoper"
validatorPubKeyPrefix := accountAddressPrefix + "valoperpub"
consNodeAddressPrefix := accountAddressPrefix + "valcons"
consNodePubKeyPrefix := accountAddressPrefix + "valconspub"

config := sdk.GetConfig()
config.SetBech32PrefixForAccount(accountAddressPrefix, accountPubKeyPrefix)
config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
config.Seal()
}
21 changes: 21 additions & 0 deletions cmd/bzed/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import serverconfig "github.com/cosmos/cosmos-sdk/server/config"

// Generate contents for `app.toml`. Take the default template and config, append custom parameters
func initAppConfig() (string, interface{}) {
template := serverconfig.DefaultConfigTemplate
cfg := serverconfig.DefaultConfig()

// The SDK's default minimum gas price is set to "" (empty value) inside app.toml. If left empty
// by validators, the node will halt on startup. However, the chain developer can set a default
// app.toml value for their validators here.
//
// In summary:
// - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their own app.toml config,
// - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their own app.toml to override,
// or use this default value.
cfg.MinGasPrices = "0ubze"

return template, cfg
}

0 comments on commit e8157ad

Please sign in to comment.