Skip to content

Commit

Permalink
Brings to light the millions protocol (#23)
Browse files Browse the repository at this point in the history
* Brings to light the millions protocol

* Sync with upstream

---------

Co-authored-by: Fabrice Bascoulergue <lebascou@users.noreply.github.com>
Co-authored-by: Segfault <5221072+Segfaultd@users.noreply.github.com>
  • Loading branch information
3 people authored May 22, 2023
1 parent 8598401 commit 7aef762
Show file tree
Hide file tree
Showing 246 changed files with 59,635 additions and 408 deletions.
7 changes: 0 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,5 @@ WORKDIR $CHAIN
# Copy over binaries from the build-env
COPY --from=build-env /go/bin/lumd /usr/bin/lumd

# Add the scripts
COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/init_node.py /usr/bin/init_node.py
COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_default_config.py /usr/bin/apply_default_config.py
COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_pruning_config.py /usr/bin/apply_pruning_config.py
COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_rpc_node_config.py /usr/bin/apply_rpc_node_config.py
COPY --from=build-env /go/src/github.com/lum-network/chain/scripts/apply_statesync_params.py /usr/bin/apply_statesync_params.py

# Run lumd by default, omit entrypoint to ease using container with chaincli
CMD ["lumd"]
22 changes: 6 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,20 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=lum \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

check_version:
ifneq ($(GO_MINOR_VERSION),18)
@echo "ERROR: Go version 1.18 is required for this version of Lum Network. Go 1.19 has changes that are believed to break consensus."
exit 1
endif
all: install

all: check_version install
format:
@gofmt -w .

lint:
@golangci-lint run --skip-dirs='(x/beam|x/dfract)'

install: go.sum
@echo "--> Installing lumd"
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/lumd

build: go.sum
@echo "--> Building lumd"
@go build -mod=readonly $(BUILD_FLAGS) ./cmd/lumd

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
Expand Down
137 changes: 119 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@ package app

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"

"github.com/lum-network/chain/x/icqueries"
icqueriestypes "github.com/lum-network/chain/x/icqueries/types"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types"
"github.com/lum-network/chain/x/dfract"
dfractclient "github.com/lum-network/chain/x/dfract/client"
"io"
"net/http"
"os"
"path/filepath"
millionsclient "github.com/lum-network/chain/x/millions/client"

"github.com/lum-network/chain/x/icacallbacks"
"github.com/lum-network/chain/x/millions"
millionstypes "github.com/lum-network/chain/x/millions/types"

ibcconnectiontypes "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -92,6 +105,8 @@ import (
ibc "github.com/cosmos/ibc-go/v5/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v5/modules/core/02-client/client"
ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host"

icacallbackstypes "github.com/lum-network/chain/x/icacallbacks/types"
)

var (
Expand All @@ -118,6 +133,9 @@ var (
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
dfractclient.ProposalHandler,
millionsclient.RegisterPoolProposalHandler,
millionsclient.UpdatePoolProposalHandler,
millionsclient.UpdateParamsProposalHandler,
},
),
params.AppModuleBasic{},
Expand All @@ -131,9 +149,12 @@ var (
transfer.AppModuleBasic{},
authzmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
icacallbacks.AppModuleBasic{},
icqueries.AppModuleBasic{},
beam.AppModuleBasic{},
airdrop.AppModuleBasic{},
dfract.AppModuleBasic{},
millions.AppModuleBasic{},
)

// module account permissions
Expand All @@ -147,8 +168,10 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
beamtypes.ModuleName: nil,
icqueriestypes.ModuleName: nil,
airdroptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
dfracttypes.ModuleName: {authtypes.Minter, authtypes.Burner},
millionstypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
}
)

Expand Down Expand Up @@ -226,9 +249,10 @@ func New(
keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, icahosttypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey,
beamtypes.StoreKey, airdroptypes.StoreKey, dfracttypes.StoreKey,
icacallbackstypes.StoreKey, icqueriestypes.StoreKey,
beamtypes.StoreKey, airdroptypes.StoreKey, dfracttypes.StoreKey, millionstypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -280,10 +304,14 @@ func New(
ica.NewAppModule(nil, app.ICAHostKeeper),
params.NewAppModule(*app.ParamsKeeper),
app.transferModule,
ica.NewAppModule(app.ICAControllerKeeper, app.ICAHostKeeper),
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
beam.NewAppModule(appCodec, *app.BeamKeeper),
airdrop.NewAppModule(appCodec, *app.AirdropKeeper),
dfract.NewAppModule(appCodec, *app.DFractKeeper),
millions.NewAppModule(appCodec, *app.MillionsKeeper),
icacallbacks.NewAppModule(appCodec, *app.ICACallbacksKeeper, app.AccountKeeper, app.BankKeeper),
icqueries.NewAppModule(appCodec, *app.ICQueriesKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -310,9 +338,12 @@ func New(
paramstypes.ModuleName,
vestingtypes.ModuleName,
ibctransfertypes.ModuleName,
icqueriestypes.ModuleName,
icacallbackstypes.ModuleName,
beamtypes.ModuleName,
airdroptypes.ModuleName,
dfracttypes.ModuleName,
millionstypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -335,9 +366,12 @@ func New(
ibchost.ModuleName,
icatypes.ModuleName,
ibctransfertypes.ModuleName,
icqueriestypes.ModuleName,
icacallbackstypes.ModuleName,
beamtypes.ModuleName,
airdroptypes.ModuleName,
dfracttypes.ModuleName,
millionstypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -365,9 +399,12 @@ func New(
paramstypes.ModuleName,
vestingtypes.ModuleName,
authz.ModuleName,
icqueriestypes.ModuleName,
icacallbackstypes.ModuleName,
beamtypes.ModuleName,
airdroptypes.ModuleName,
dfracttypes.ModuleName,
millionstypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand All @@ -393,6 +430,7 @@ func New(
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
beam.NewAppModule(appCodec, *app.BeamKeeper),
dfract.NewAppModule(appCodec, *app.DFractKeeper),
millions.NewAppModule(appCodec, *app.MillionsKeeper),
)
app.sm.RegisterStoreDecoders()

Expand Down Expand Up @@ -428,6 +466,35 @@ func New(
// Name returns the name of the App
func (app *App) Name() string { return app.BaseApp.Name() }

// GetBaseApp returns the base app of the application
func (app *App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }

// GetStakingKeeper implements the TestingApp interface.
func (app *App) GetStakingKeeper() ibctestingtypes.StakingKeeper {
return *app.StakingKeeper
}

// GetTransferKeeper implements the TestingApp interface.
func (app *App) GetTransferKeeper() *ibctransferkeeper.Keeper {
return app.TransferKeeper
}

// GetIBCKeeper implements the TestingApp interface.
func (app *App) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetScopedIBCKeeper implements the TestingApp interface.
func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.ScopedIBCKeeper
}

// GetTxConfig implements the TestingApp interface.
func (app *App) GetTxConfig() client.TxConfig {
cfg := MakeEncodingConfig()
return cfg.TxConfig
}

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
Expand Down Expand Up @@ -465,14 +532,7 @@ func (app *App) ModuleAccountAddrs() map[string]bool {

// BlockedModuleAccountAddrs returns all the app's blocked module account addresses
func (app *App) BlockedModuleAccountAddrs() map[string]bool {
// By default no one can receive funds
modAccAddrs := app.ModuleAccountAddrs()

// Remove module accounts that are ALLOWED to receive funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(beamtypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(dfracttypes.ModuleName).String())

modAccAddrs := make(map[string]bool)
return modAccAddrs
}

Expand Down Expand Up @@ -648,10 +708,43 @@ func (app *App) registerUpgradeHandlers() {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

app.UpgradeKeeper.SetUpgradeHandler("v1.3.1", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Apply the new dfract params map
app.DFractKeeper.SetParams(ctx, dfracttypes.DefaultParams())
app.Logger().Info("v1.3.1 upgrade applied")
app.UpgradeKeeper.SetUpgradeHandler("v1.4.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Get the actual params
icaHostParams := app.ICAHostKeeper.GetParams(ctx)

// Patch the parameters - Enable the controller and patch the allowed messages for host
icaControllerParams := icacontrollertypes.Params{
ControllerEnabled: true,
}
icaHostParams.AllowMessages = append(icaHostParams.AllowMessages,
// Change: added dfract and millions messages
sdk.MsgTypeURL(&dfracttypes.MsgDeposit{}),
sdk.MsgTypeURL(&millionstypes.MsgDeposit{}),
sdk.MsgTypeURL(&millionstypes.MsgDepositRetry{}),
sdk.MsgTypeURL(&millionstypes.MsgClaimPrize{}),
sdk.MsgTypeURL(&millionstypes.MsgWithdrawDeposit{}),
sdk.MsgTypeURL(&millionstypes.MsgWithdrawDepositRetry{}),
sdk.MsgTypeURL(&millionstypes.MsgDrawRetry{}),
)

// Apply patched parameters
app.ICAHostKeeper.SetParams(ctx, icaHostParams)
app.ICAControllerKeeper.SetParams(ctx, icaControllerParams)

// Set the ICA Callbacks, ICQueries and Millions modules versions so InitGenesis is not run
fromVM[icacallbackstypes.ModuleName] = app.mm.Modules[icacallbackstypes.ModuleName].ConsensusVersion()
fromVM[icqueriestypes.ModuleName] = app.mm.Modules[icqueriestypes.ModuleName].ConsensusVersion()
fromVM[millionstypes.ModuleName] = app.mm.Modules[millionstypes.ModuleName].ConsensusVersion()

// Apply initial millions state
genState := millionstypes.DefaultGenesisState()
app.MillionsKeeper.SetParams(ctx, genState.Params)
app.MillionsKeeper.SetNextPoolID(ctx, genState.NextPoolId)
app.MillionsKeeper.SetNextDepositID(ctx, genState.NextDepositId)
app.MillionsKeeper.SetNextPrizeID(ctx, genState.NextPrizeId)
app.MillionsKeeper.SetNextWithdrawalID(ctx, genState.NextWithdrawalId)

app.Logger().Info("v1.4.0 upgrade applied: Millions module enabled and ICA configuration updated.")
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

Expand Down Expand Up @@ -697,4 +790,12 @@ func (app *App) registerUpgradeHandlers() {
}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

if upgradeInfo.Name == "v1.4.0" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// We create 3 new modules: ICA Callbacks, ICQueries, Millions
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{icacallbackstypes.StoreKey, icqueriestypes.StoreKey, millionstypes.StoreKey},
}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
3 changes: 3 additions & 0 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

//nolint:errcheck
app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
return false
})

// reinitialize all delegations
for _, del := range dels {
//nolint:errcheck
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
//nolint:errcheck
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
}

Expand Down
Loading

0 comments on commit 7aef762

Please sign in to comment.