Skip to content

Commit

Permalink
Merge pull request #117 from White-Whale-Defi-Platform/fix-statesync
Browse files Browse the repository at this point in the history
add statesync to root.go
  • Loading branch information
faddat committed Mar 17, 2023
2 parents ec842b2 + 6c270f4 commit 5155c0d
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 12 deletions.
82 changes: 82 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
run:
tests: true
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
enable:
- depguard
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- nolintlint
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused

# TODO: fix the sdkerrors.Wrap deprecation warning and re-enable staticcheck

issues:
exclude-rules:
- text: "Error return value of `flagSet.Set` is not checked"
linters:
- errcheck
- text: "SA1019: sdkerrors.Wrapf is deprecated: functionality of this package has been moved to it's own module"
linters:
- staticcheck
- text: "sdkerrors.Error is deprecated: the type has been moved to cosmossdk.io/errors module"
linters:
- staticcheck
- text: "sdkerrors.Wrap is deprecated: functionality of this package has been moved to it's own module"
linters:
- staticcheck
- text: "Use of weak random number generator"
linters:
- gosec
- text: "comment on exported var"
linters:
- golint
- text: "don't use an underscore in package name"
linters:
- golint
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
10 changes: 5 additions & 5 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ type HandlerOptions struct {

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") //nolint:staticcheck // ignore SA1019 // TODO: migrate to cosmossdk.io/errors
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") //nolint:staticcheck // ignore SA1019 // TODO: migrate to cosmossdk.io/errors
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") //nolint:staticcheck // ignore SA1019 // TODO: migrate to cosmossdk.io/errors
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") //nolint:staticcheck // ignore SA1019 // TODO: migrate to cosmossdk.io/errors
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.TXCounterStoreKey == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") //nolint:staticcheck // ignore SA1019 // TODO: migrate to cosmossdk.io/errors
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const (

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".migalood"
NodeDir = ".migalood"
// 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"
Expand Down Expand Up @@ -237,7 +237,7 @@ var (
// MigalooApp extended ABCI application
type MigalooApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino //nolint:staticcheck
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry

Expand Down Expand Up @@ -914,7 +914,7 @@ func (app *MigalooApp) ModuleAccountAddrs() map[string]bool {
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *MigalooApp) LegacyAmino() *codec.LegacyAmino { //nolint:staticcheck
func (app *MigalooApp) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}

Expand Down
4 changes: 2 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (app *MigalooApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint:errcheck
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
})

Expand All @@ -92,7 +92,7 @@ func (app *MigalooApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
if err != nil {
panic(err)
}
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) //nolint:errcheck
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
}

// clear validator slash events
Expand Down
1 change: 1 addition & 0 deletions app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func SetAddressPrefixes() {
cfg.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
cfg.SetAddressVerifier(wasmtypes.VerifyAddressLen())
}

func init() {
SetAddressPrefixes()
}
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{
func setup(t testing.TB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*MigalooApp, GenesisState) {
nodeHome := t.TempDir()
snapshotDir := filepath.Join(nodeHome, "data", "snapshots")
snapshotDB, err := dbm.NewDB("metadata", dbm.MemDBBackend, snapshotDir) //nolint:staticcheck
snapshotDB, err := dbm.NewDB("metadata", dbm.MemDBBackend, snapshotDir)
require.NoError(t, err)
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
require.NoError(t, err)
Expand Down
45 changes: 45 additions & 0 deletions cmd/migalood/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
"errors"
"io"
"os"
"path/filepath"

"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cast"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/snapshots"
"github.com/cosmos/cosmos-sdk/version"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/spf13/cobra"
tmcfg "github.com/tendermint/tendermint/config"
tmcli "github.com/tendermint/tendermint/libs/cli"
Expand All @@ -20,6 +25,9 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/White-Whale-Defi-Platform/migaloo-chain/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/app/params"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand Down Expand Up @@ -92,6 +100,8 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
func initTendermintConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()

cfg.P2P.Seeds = "20e1000e88125698264454a884812746c2eb4807@seeds.lavenderfive.com:12856,c936ae78abca1169362e068e3e94c87a0ace96c7@seeds.cros-nest.com:27656,ebc272824924ea1a27ea3183dd0b9ba713494f83@whitewhale-mainnet-seed.autostake.net:27096,ade4d8bc8cbe014af6ebdf3cb7b1e9ad36f412c0@seeds.polkachu.com:20756"

// these values put a higher strain on node memory
cfg.P2P.MaxNumInboundPeers = 320
cfg.P2P.MaxNumOutboundPeers = 40
Expand Down Expand Up @@ -247,11 +257,36 @@ type appCreator struct {

// newApp is an appCreator
func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
var cache sdk.MultiStorePersistentCache

if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
cache = store.NewCommitKVStoreCacheManager()
}

pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts)
if err != nil {
panic(err)
}

snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir) //nolint:staticcheck
if err != nil {
panic(err)
}
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
if err != nil {
panic(err)
}
var wasmOpts []wasm.Option
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}

snapshotOptions := snapshottypes.NewSnapshotOptions(
cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval)),
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)),
)

skipUpgradeHeights := make(map[int64]bool)
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
Expand All @@ -269,6 +304,16 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
app.GetEnabledProposals(),
appOpts,
wasmOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetInterBlockCache(cache),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
baseapp.SetInterBlockCache(cache),
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/migalood/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func writeFile(name string, dir string, contents []byte) error {
return err
}

err = os.WriteFile(file, contents, 0o644) // nolint: gosec
err = os.WriteFile(file, contents, 0o644) //nolint: gosec
if err != nil {
return err
}
Expand Down
53 changes: 53 additions & 0 deletions scripts/statesync.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# microtick and bitcanna contributed significantly here.
# invoke this script in your migaloo-chain folder like this:
# bash scripts/statesync.bash
set -uxe

# Set Golang environment variables.
export GOPATH=~/go
export PATH=$PATH:~/go/bin

# Install Migaloo.
go install ./...

# NOTE: ABOVE YOU CAN USE ALTERNATIVE DATABASES, HERE ARE THE EXACT COMMANDS
# go install -ldflags '-w -s -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb' -tags rocksdb ./...
# go install -ldflags '-w -s -X github.com/cosmos/cosmos-sdk/types.DBBackend=badgerdb' -tags badgerdb ./...
# go install -ldflags '-w -s -X github.com/cosmos/cosmos-sdk/types.DBBackend=boltdb' -tags boltdb ./...

# Initialize chain.
migalood init test

# get genesis
wget -O ~/.migalood/config/genesis.json https://github.com/White-Whale-Defi-Platform/migaloo-chain/raw/release/v2.0.x/networks/mainnet/genesis.json


# Set minimum gas price.
sed -i '' 's/minimum-gas-prices = ""/minimum-gas-prices = "0.0025uwhale"/' "$HOME/.migalood/config/app.toml"

# Get "trust_hash" and "trust_height".
INTERVAL=1000
LATEST_HEIGHT=$(curl -s https://rpc-whitewhale-h93nh9ykmqnzbrez-ie.internalendpoints.notional.ventures/block | jq -r .result.block.header.height)
BLOCK_HEIGHT=$((LATEST_HEIGHT-INTERVAL))
TRUST_HASH=$(curl -s "https://rpc-whitewhale-h93nh9ykmqnzbrez-ie.internalendpoints.notional.ventures/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

# Print out block and transaction hash from which to sync state.
echo "trust_height: $BLOCK_HEIGHT"
echo "trust_hash: $TRUST_HASH"

# Export state sync variables.
export MIGALOOD_STATESYNC_ENABLE=true
export MIGALOOD_P2P_MAX_NUM_OUTBOUND_PEERS=200
# replace the url below with a working one
export MIGALOOD_STATESYNC_RPC_SERVERS="https://rpc-whitewhale-h93nh9ykmqnzbrez-ie.internalendpoints.notional.ventures:443,http://65.108.5.173:2481"
export MIGALOOD_STATESYNC_TRUST_HEIGHT=$BLOCK_HEIGHT
export MIGALOOD_STATESYNC_TRUST_HASH=$TRUST_HASH

# Fetch and set list of seeds from chain registry.
MIGALOOD_P2P_SEEDS=$(curl -s https://raw.githubusercontent.com/cosmos/chain-registry/master/migaloo/chain.json | jq -r '[foreach .peers.seeds[] as $item (""; "\($item.id)@\($item.address)")] | join(",")')
export MIGALOOD_P2P_SEEDS


# Start chain.
migalood start --x-crisis-skip-assert-invariants --minimum-gas-prices 0.00001uwhale
Empty file modified scripts/testnode.sh
100644 → 100755
Empty file.

0 comments on commit 5155c0d

Please sign in to comment.