Skip to content

Commit

Permalink
Merge branch 'master' into releases/v0.21.x
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Jun 27, 2023
2 parents 5281256 + 9d4388e commit ac239a7
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 101 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/changelog-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
changelog-update:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'dependabot')
# TODO: feat: try to use author of the commit(s) to see if it's dependabot
# ${{ any(contains(commit.author.username, 'dependabot') for commit in github.event.commits) }}
steps:
- uses: actions/checkout@v3
with:
Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Protobuf Lint and Check Breakage
name: Protobuf
# Protobuf runs buf (https://buf.build/) lint and check-breakage
# This workflow is only run when a .proto file has been changed
on:
Expand All @@ -10,22 +10,24 @@ permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: bufbuild/[email protected]
- uses: bufbuild/buf-lint-action@v1
with:
input: "proto"
# # Commented out since the default linter settings are too strict.
# # We should figure out how to configure this linting action.
# lint:
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - uses: actions/checkout@v3
# - uses: bufbuild/[email protected]
# - uses: bufbuild/buf-lint-action@v1
# with:
# input: "proto"

break-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: bufbuild/buf-setup-action@v1.21.0
- uses: bufbuild/buf-setup-action@v1.22.0
- uses: bufbuild/buf-breaking-action@v1
with:
input: "proto"
against: "https://github.com/${{ github.repository }}.git#branch=${{ github.event.pull_request.base.ref }},ref=HEAD~1,subdir=proto"
against: "https://github.com/${{ github.repository }}.git#branch=${{ github.event.pull_request.base.ref }},ref=HEAD~1,subdir=proto"
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19

Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bump `github.com/spf13/cast` from 1.5.0 to 1.5.1 (#1358)
- Bump `github.com/stretchr/testify` from 1.8.2 to 1.8.4 (#1384, #1435)
- Bump `cosmossdk.io/math` from 1.0.0-beta.6 to 1.0.1 (#1394)
- Bump `google.golang.org/grpc` from 1.53.0 to 1.55.0 (#1395)
- Bump `google.golang.org/grpc` from 1.53.0 to 1.56.1 (#1395, #1437, #1443)
- Bump `github.com/gin-gonic/gin` from 1.8.1 to 1.9.1 (#1409)
- Bump `github.com/spf13/viper` from 1.15.0 to 1.16.0 (#1436)
- Bump `github.com/prometheus/client_golang` from 1.15.1 to 1.16.0 (#1431)
- Bump `github.com/cosmos/ibc-go/v7` from 7.1.0 to 7.2.0 (#1445)
- Bump `bufbuild/buf-setup-action` from 1.21.0 to 1.22.0 (#1449)
- Bump `google.golang.org/protobuf` from 1.30.0 to 1.31.0 (#1450)

### Breaking

Expand Down Expand Up @@ -175,6 +180,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1397](https://github.com/NibiruChain/nibiru/pull/1397) - fix: ensure margin is high enough when removing it
* [#1417](https://github.com/NibiruChain/nibiru/pull/1417) - fix: run end blocker on block end for perp v2
* [#1425](https://github.com/NibiruChain/nibiru/pull/1425) - fix: remove positions from state when closed with reverse position
* [#1441](https://github.com/NibiruChain/nibiru/pull/1441) - fix(oracle): ignore abstain votes in std dev calculation
* [#1446](https://github.com/NibiruChain/nibiru/pull/1446) - fix(cmd): Add custom InitCmd to set set desired Tendermint consensus params for each node.
* [#1452](https://github.com/NibiruChain/nibiru/pull/1452) - fix(oracle): continue with abci hook during error
* [#1451](https://github.com/NibiruChain/nibiru/pull/1451) - fix(perp): decrease position with zero size

## [v0.19.2](https://github.com/NibiruChain/nibiru/releases/tag/v0.19.2) - 2023-02-24

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ COPY . .

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
--mount=type=cache,target=/nibiru/temp \
make build

FROM alpine:latest
Expand Down
6 changes: 0 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
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"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
Expand Down Expand Up @@ -360,11 +359,6 @@ func NewNibiruApp(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.

app.upgradeKeeper.SetUpgradeHandler("v0.10.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// no-op
return fromVM, nil
})

// add test gRPC service for testing gRPC queries in isolation
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})

Expand Down
207 changes: 198 additions & 9 deletions cmd/nibid/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ import (

db "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"

"bufio"
"encoding/json"
"fmt"
"os"
"path/filepath"

tmcli "github.com/cometbft/cometbft/libs/cli"
tmrand "github.com/cometbft/cometbft/libs/rand"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
)

const (
Expand All @@ -13,24 +34,192 @@ const (

// FlagSeed defines a flag to initialize the private validator key from a specific seed.
FlagRecover = "recover"

// FlagDefaultBondDenom defines the default denom to use in the genesis file.
FlagDefaultBondDenom = "default-denom"
)

func customTendermintConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()

// Overwrite consensus config
ms := func(n time.Duration) time.Duration {
return n * time.Millisecond
}
consensus := cfg.Consensus
consensus.TimeoutPropose = ms(3_000)
consensus.TimeoutProposeDelta = ms(500)
consensus.TimeoutPrevote = ms(1_000)
consensus.TimeoutPrevoteDelta = ms(500)
consensus.TimeoutPrecommit = ms(1_000)
consensus.TimeoutPrecommitDelta = ms(500)
consensus.TimeoutCommit = ms(1_000)
cfg.Consensus.TimeoutPropose = ms(3_000)
cfg.Consensus.TimeoutProposeDelta = ms(500)
cfg.Consensus.TimeoutPrevote = ms(1_000)
cfg.Consensus.TimeoutPrevoteDelta = ms(500)
cfg.Consensus.TimeoutPrecommit = ms(1_000)
cfg.Consensus.TimeoutPrecommitDelta = ms(500)
cfg.Consensus.TimeoutCommit = ms(1_000)

cfg.DBBackend = string(db.RocksDBBackend)

return cfg
}

/*
InitCmd is a stand-in replacement for genutilcli.InitCmd that overwrites the
consensus configutation in the `config.toml` prior to writing it to the disk.
This helps keep consistency on between nodes without requiring extra work as
much manual work for node operators.
InitCmd returns a command that initializes all files needed for Tendermint
and the respective application.
Intended usage:
```go
import genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
import "github.com/spf13/cobra"
func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
a := appCreator{encodingConfig}
rootCmd.AddCommand(
InitCmd(app.ModuleBasics, app.DefaultNodeHome),
)
}
```
*/
func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "init [moniker]",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Long: `Initialize validators's and node's configuration files.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.Codec

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
config.SetRoot(clientCtx.HomeDir)

chainID, _ := cmd.Flags().GetString(sdkflags.FlagChainID)
switch {
case chainID != "":
case clientCtx.ChainID != "":
chainID = clientCtx.ChainID
default:
chainID = fmt.Sprintf("test-chain-%v", tmrand.Str(6))
}

// Get bip39 mnemonic
var mnemonic string
recover, _ := cmd.Flags().GetBool(FlagRecover)
if recover {
inBuf := bufio.NewReader(cmd.InOrStdin())
value, err := input.GetString("Enter your bip39 mnemonic", inBuf)
if err != nil {
return err
}

mnemonic = value
if !bip39.IsMnemonicValid(mnemonic) {
return errors.New("invalid mnemonic")
}
}

// Get initial height
initHeight, _ := cmd.Flags().GetInt64(sdkflags.FlagInitHeight)
if initHeight < 1 {
initHeight = 1
}

nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic)
if err != nil {
return err
}

config.Moniker = args[0]

genFile := config.GenesisFile()
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite)
defaultDenom, _ := cmd.Flags().GetString(FlagDefaultBondDenom)

// use os.Stat to check if the file exists
_, err = os.Stat(genFile)
if !overwrite && !os.IsNotExist(err) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}

// Overwrites the SDK default denom for side-effects
if defaultDenom != "" {
sdk.DefaultBondDenom = defaultDenom
}
appGenState := mbm.DefaultGenesis(cdc)

appState, err := json.MarshalIndent(appGenState, "", " ")
if err != nil {
return errors.Wrap(err, "Failed to marshal default genesis state")
}

genDoc := &tmtypes.GenesisDoc{}
if _, err := os.Stat(genFile); err != nil {
if !os.IsNotExist(err) {
return err
}
} else {
genDoc, err = tmtypes.GenesisDocFromFile(genFile)
if err != nil {
return errors.Wrap(err, "Failed to read genesis doc from file")
}
}

genDoc.ChainID = chainID
genDoc.Validators = nil
genDoc.AppState = appState
genDoc.InitialHeight = initHeight

if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil {
return errors.Wrap(err, "Failed to export genesis file")
}

toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState)

customCfg := customTendermintConfig()
config.Consensus = customCfg.Consensus
config.DBBackend = customCfg.DBBackend
tmcfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)
return displayInfo(toPrint)
},
}

cmd.Flags().String(tmcli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating")
cmd.Flags().String(sdkflags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(FlagDefaultBondDenom, "", "genesis file default denomination, if left blank default value is 'stake'")
cmd.Flags().Int64(sdkflags.FlagInitHeight, 1, "specify the initial block height at genesis")

return cmd
}

type printInfo struct {
Moniker string `json:"moniker" yaml:"moniker"`
ChainID string `json:"chain_id" yaml:"chain_id"`
NodeID string `json:"node_id" yaml:"node_id"`
GenTxsDir string `json:"gentxs_dir" yaml:"gentxs_dir"`
AppMessage json.RawMessage `json:"app_message" yaml:"app_message"`
}

func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.RawMessage) printInfo {
return printInfo{
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
GenTxsDir: genTxsDir,
AppMessage: appMessage,
}
}

func displayInfo(info printInfo) error {
out, err := json.MarshalIndent(info, "", " ")
if err != nil {
return err
}

_, err = fmt.Fprintf(os.Stderr, "%s\n", sdk.MustSortJSON(out))

return err
}
2 changes: 1 addition & 1 deletion cmd/nibid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Args:
func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
a := appCreator{encodingConfig}
rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
InitCmd(app.ModuleBasics, app.DefaultNodeHome),
AddGenesisAccountCmd(app.DefaultNodeHome),
perpv2cli.AddMarketGenesisCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
Expand Down
7 changes: 5 additions & 2 deletions contrib/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fi

# Configure broadcast mode
echo_info "Configuring broadcast mode..."
if $BINARY config broadcast-mode block; then
if $BINARY config broadcast-mode sync; then
echo_success "Successfully configured broadcast-mode"
else
echo_error "Failed to configure broadcast mode"
Expand Down Expand Up @@ -230,6 +230,9 @@ else
exit 1
fi

# set validator as sudoer
add_genesis_param '.app_state.sudo.sudoers.root = "nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"'

# hack for localnet since we don't have a pricefeeder yet
add_genesis_param '.app_state.oracle.exchange_rates[0].pair = "ubtc:unusd"'
add_genesis_param '.app_state.oracle.exchange_rates[0].exchange_rate = "20000"'
Expand All @@ -238,4 +241,4 @@ add_genesis_param '.app_state.oracle.exchange_rates[1].exchange_rate = "2000"'

# Start the network
echo_info "Starting $CHAIN_ID in $CHAIN_DIR..."
$BINARY start --db_backend goleveldb --home "$CHAIN_DIR" --pruning nothing
$BINARY start --home "$CHAIN_DIR" --pruning nothing
Loading

0 comments on commit ac239a7

Please sign in to comment.