Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 committed Oct 19, 2023
2 parents 1122c2e + 4c51a36 commit 2f70a25
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 45 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
.vscode
node_modules
release
.DS_Store
/scripts/
test/.env
chain

build
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://help.github.com/articles/about-codeowners

* @johnletey @mbreithecker @troykessler
* @mbreithecker @troykessler @shifty11
16 changes: 16 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ You can verify the build information using the following command:
```shell
kyved info
```

### Building docker image

#### Root
To create a regular `kyve-network/kyve:${VERSION}` docker image with `kyved` binary only execute:
```bash
make docker-image
```
To create the corresponding debug image containing a `sh` shell execute `make docker-image-debug`.

#### Nonroot
To create a nonroot docker image `kyve-network/kyve:${VERSION}-nonroot` running with user `nonroot:65532`:
```bash
make docker-image-nonroot
```
To create the corresponding debug image `kyve-network/kyve:${VERSION}-debug-nonroot` execute `make docker-image-debug-nonroot`.
9 changes: 9 additions & 0 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: run all jobs
on: push

jobs:
lint:
uses: ./.github/workflows/lint.yml

test:
uses: ./.github/workflows/test.yml
44 changes: 27 additions & 17 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
on: push
name: lint
on:
workflow_call:

jobs:
buf:
runs-on: ubuntu-latest
steps:
# Run `git checkout`
- uses: actions/checkout@v3
# Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4
# Install `buf`
- uses: bufbuild/buf-setup-action@v1
- name: Install `buf`
uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
# Lint Protobuf files
- uses: bufbuild/buf-lint-action@v1
- name: Lint Protobuf files
uses: bufbuild/buf-lint-action@v1
with:
buf_token: ${{ secrets.BUF_TOKEN }}

# TODO(@john): Figure out why linting passes locally but not here.
# golangci:
# runs-on: ubuntu-latest
# steps:
# # Run `git checkout`
# - uses: actions/checkout@v3
# # Install `go`
# - uses: actions/setup-go@v3
# # Lint Go files
# - uses: golangci/golangci-lint-action@v3
# with:
# args: --timeout=10m
golangci:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4
# Setup Golang
- name: 🐿 Setup Golang
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
# Lint go files with golangci-lint
- name: Lint go files with golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=10m
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: test
on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Check out repository code
uses: actions/checkout@v4
# Setup Golang
- name: 🐿 Setup Golang
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
# Test & coverage report creation
- name: Test & coverage report creation
run: go test -cover -mod=readonly ./x/...
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG IMG_TAG=latest

# Compile the kyved binary
FROM golang:1.20-alpine AS kyved-builder

# Install make
RUN apk add --no-cache make

WORKDIR /go/src

# Install dependencies
COPY go.mod go.sum* ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download
COPY . .

ENV ENV=mainnet
RUN make install

# Copy binary to a distroless container
FROM gcr.io/distroless/static-debian11:$IMG_TAG

COPY --from=kyved-builder "/go/bin/kyved" /usr/local/bin/
EXPOSE 26656 26657 1317 9090

ENTRYPOINT ["kyved"]
41 changes: 33 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
COMMIT := $(shell git log -1 --format='%H')
GO_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1,2)
VERSION := v1.4.0 # $(shell echo $(shell git describe --tags) | sed 's/^v//')

# VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
VERSION := v1.4.0

TEAM_ALLOCATION := 165000000000000
ifeq ($(ENV),kaon)
Expand Down Expand Up @@ -73,6 +75,36 @@ release: ensure_environment ensure_version
@rm kyved
@echo "✅ Completed release creation!"

###############################################################################
### Docker Build ###
###############################################################################

# Build a release image
docker-image:
@DOCKER_BUILDKIT=1 docker build -t kyve-network/kyve:${VERSION} .
@echo "✅ Completed docker image build!"

# Build a release nonroot image
docker-image-nonroot:
@DOCKER_BUILDKIT=1 docker build \
--build-arg IMG_TAG="nonroot" \
-t kyve-network/kyve:${VERSION}-nonroot .
@echo "✅ Completed docker image build! (nonroot)"

# Build a release debug image
docker-image-debug:
@DOCKER_BUILDKIT=1 docker build \
--build-arg IMG_TAG="debug" \
-t kyve-network/kyve:${VERSION}-debug .
@echo "✅ Completed docker image build! (debug)"

# Build a release debug-nonroot image
docker-image-debug-nonroot:
@DOCKER_BUILDKIT=1 docker build \
--build-arg IMG_TAG="debug-nonroot" \
-t kyve-network/kyve:${VERSION}-debug-nonroot .
@echo "✅ Completed docker image build! (debug-nonroot)"

###############################################################################
### Checks ###
###############################################################################
Expand All @@ -91,7 +123,6 @@ endif
### Development ###
###############################################################################

# TODO(@john): Switch to the Docker image?
dev:
@ignite chain serve --reset-once --skip-proto --verbose

Expand All @@ -112,12 +143,6 @@ lint:
@go run $(golangci_lint_cmd) run --skip-dirs scripts --timeout=10m
@echo "✅ Completed linting!"

# TODO(@john): Can we remove this since we use GolangCI?
vet:
@echo "🤖 Running vet..."
@go vet ./...
@echo "✅ Completed vet!"

###############################################################################
### Protobuf ###
###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import (
group "github.com/cosmos/cosmos-sdk/x/group/module"
// IBC Core
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcClientHandler "github.com/cosmos/ibc-go/v7/modules/core/02-client" // TODO
ibcClientHandler "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcClientTypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcPortTypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcExported "github.com/cosmos/ibc-go/v7/modules/core/exported"
Expand Down Expand Up @@ -350,7 +350,7 @@ func NewKYVEApp(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icaControllerTypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icaHostTypes.SubModuleName)

// TODO(@john): Seal x/capability keeper.
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authKeeper.NewAccountKeeper(
Expand Down Expand Up @@ -389,7 +389,7 @@ func NewKYVEApp(
appCodec,
keys[mintTypes.StoreKey],
app.StakingKeeper,
&app.StakersKeeper, // TODO(@john)
&app.StakersKeeper, // This is a pointer because the stakers keeper is not initialized yet.
app.AccountKeeper,
app.BankKeeper,
authTypes.FeeCollectorName,
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v1_4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
upgradeTypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

//nolint:all
//goland:noinspection GoDeprecation
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand Down
2 changes: 1 addition & 1 deletion cmd/kyved/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewRootCmd(encodingConfig kyveApp.EncodingConfig) *cobra.Command {
tmCli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
config.Cmd(),
pruning.PruningCmd(ac.createApp),
pruning.Cmd(ac.createApp, kyveApp.DefaultNodeHome),

rpc.StatusCommand(),
queryCommand(),
Expand Down
18 changes: 13 additions & 5 deletions testutil/integration/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/KYVENetwork/chain/x/delegation"
delegationtypes "github.com/KYVENetwork/chain/x/delegation/types"
globalTypes "github.com/KYVENetwork/chain/x/global/types"
"github.com/KYVENetwork/chain/x/pool"
poolmodule "github.com/KYVENetwork/chain/x/pool"
querytypes "github.com/KYVENetwork/chain/x/query/types"
"github.com/KYVENetwork/chain/x/stakers"
stakertypes "github.com/KYVENetwork/chain/x/stakers/types"
Expand All @@ -25,8 +25,7 @@ import (
func (suite *KeeperTestSuite) PerformValidityChecks() {
// verify pool module
suite.VerifyPoolModuleFundingStates()
// TODO(@troy,@max): Figure out a better way to check this when disabling pools.
// suite.VerifyPoolQueries()
suite.VerifyPoolQueries()
suite.VerifyPoolGenesisImportExport()

// verify funders module
Expand Down Expand Up @@ -80,6 +79,15 @@ func (suite *KeeperTestSuite) VerifyPoolQueries() {
poolsQuery = append(poolsQuery, activePoolsQuery.Pools...)
poolsQuery = append(poolsQuery, disabledPoolsQuery.Pools...)

// sort pools by id
for i := range poolsQuery {
for j := range poolsQuery {
if poolsQuery[i].Id < poolsQuery[j].Id {
poolsQuery[i], poolsQuery[j] = poolsQuery[j], poolsQuery[i]
}
}
}

Expect(activePoolsQueryErr).To(BeNil())
Expect(disabledPoolsQueryErr).To(BeNil())

Expand Down Expand Up @@ -137,15 +145,15 @@ func (suite *KeeperTestSuite) VerifyPoolQueries() {
}

func (suite *KeeperTestSuite) VerifyPoolGenesisImportExport() {
genState := pool.ExportGenesis(suite.Ctx(), suite.App().PoolKeeper)
genState := poolmodule.ExportGenesis(suite.Ctx(), suite.App().PoolKeeper)

// Delete all entries in Pool Store
store := suite.Ctx().KVStore(suite.App().PoolKeeper.StoreKey())
suite.deleteStore(store)

err := genState.Validate()
Expect(err).To(BeNil())
pool.InitGenesis(suite.Ctx(), suite.App().PoolKeeper, *genState)
poolmodule.InitGenesis(suite.Ctx(), suite.App().PoolKeeper, *genState)
}

// =====================
Expand Down
22 changes: 19 additions & 3 deletions x/delegation/keeper/msg_server_delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST CASES - msg_server_delegate.go
* Payout delegators
* Don't pay out rewards twice
* Delegate to validator with 0 $KYVE
* TODO(@max): Delegate to multiple validators
* Delegate to multiple validators
*/

Expand Down Expand Up @@ -276,6 +276,16 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() {
})

// ACT
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[1],
Staker: i.ALICE,
Amount: 200 * i.KYVE,
})
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[1],
Staker: i.BOB,
Amount: 200 * i.KYVE,
})
s.RunTxDelegatorSuccess(&types.MsgDelegate{
Creator: i.DUMMY[1],
Staker: i.CHARLIE,
Expand All @@ -286,8 +296,14 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() {
s.PerformValidityChecks()

poolModuleBalance := s.GetBalanceFromModule(types.ModuleName)
Expect(poolModuleBalance).To(Equal(200*i.KYVE + aliceSelfDelegation + bobSelfDelegation))
Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(800 * i.KYVE))
Expect(poolModuleBalance).To(Equal(600*i.KYVE + aliceSelfDelegation + bobSelfDelegation))
Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(400 * i.KYVE))

aliceDelegation := s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)
Expect(aliceDelegation).To(Equal(200*i.KYVE + aliceSelfDelegation))

bobDelegation := s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.BOB)
Expect(bobDelegation).To(Equal(200*i.KYVE + bobSelfDelegation))

charlieDelegation := s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.CHARLIE)
Expect(charlieDelegation).To(Equal(200 * i.KYVE))
Expand Down
8 changes: 5 additions & 3 deletions x/delegation/keeper/msg_server_undelegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ TEST CASES - msg_server_undelegate.go
* JoinA, Slash, JoinB, PayoutReward
* Slash twice
* Start unbonding, slash twice, payout, await undelegation
TODO(@max): joinA slash joinB slash -> remaining delegation
*/

var _ = Describe("msg_server_undelegate.go", Ordered, func() {
Expand Down Expand Up @@ -501,6 +498,11 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() {
// ASSERT
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(666_666_666)))
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(2_666_666_666)))

// must be the same as before
Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)).To(Equal((50 + 25) * i.KYVE))
Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(5 * i.KYVE))
Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(20 * i.KYVE))
})

It("Slash twice", func() {
Expand Down
Loading

0 comments on commit 2f70a25

Please sign in to comment.