Skip to content

Commit

Permalink
Merge branch cosmos/v0.44.x
Browse files Browse the repository at this point in the history
  • Loading branch information
maiquanghiep committed Mar 7, 2023
1 parent ed219fc commit 8a7f993
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 65 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,28 @@ jobs:
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Determine Dockerfile to use
run: |
if [[ -f Dockerfile.cosmwasm ]]; then
export DOCKERFILE=Dockerfile.cosmwasm
else
export DOCKERFILE=Dockerfile.default
fi
echo "DOCKERFILE=${DOCKERFILE}" >> $GITHUB_ENV
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: .
file: "./${{ env.DOCKERFILE }}"
push: true
tags: ${{ steps.prep.outputs.tags }}
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.0.2
- uses: amannn/action-semantic-pull-request@v5.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#### CI
- ([\#508](https://github.com/forbole/bdjuno/pull/508)) Upgrade workflow golangci version to v1.50.1


#### Parse Command
- ([\#492](https://github.com/forbole/bdjuno/pull/492)) Add parse command for periodic tasks: `x/bank` total supply, `x/distribution` community pool, `x/mint` inflation, `pricefeed` token price and price history, `x/staking` staking pool

Expand All @@ -23,6 +22,7 @@
- ([\#465](https://github.com/forbole/bdjuno/pull/465)) Get open proposal ids in deposit or voting period by block time instead of current time
- ([\#489](https://github.com/forbole/bdjuno/pull/489)) Remove block height foreign key from proposal_vote and proposal_deposit tables and add column timestamp
- ([\#499](https://github.com/forbole/bdjuno/pull/499)) Check if proposal has passed voting end time before marking it invalid
- ([\#523](https://github.com/forbole/bdjuno/pull/523)) Update proposal snapshots handling on block

#### Daily refetch
- ([\#454](https://github.com/forbole/bdjuno/pull/454)) Added `daily refetch` module to refetch missing blocks every day
Expand Down
36 changes: 0 additions & 36 deletions Dockerfile

This file was deleted.

22 changes: 22 additions & 0 deletions Dockerfile.cosmwasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


FROM golang:1.18-alpine AS builder
RUN apk update && apk add --no-cache make git
WORKDIR /go/src/github.com/forbole/bdjuno
COPY . ./

RUN apk update && apk add --no-cache ca-certificates build-base git
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 9ecb037336bd56076573dc18c26631a9d2099a7f2b40dc04b6cae31ffb4c8f9a
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 6e4de7ba9bad4ae9679c7f9ecf7e283dd0160e71567c6a7be6ae47c81ebe7f32
## Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc`
RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a
RUN go mod download
RUN LINK_STATICALLY=true BUILD_TAGS="muslc" make build

FROM alpine:latest
RUN apk update && apk add --no-cache ca-certificates build-base
WORKDIR /bdjuno
COPY --from=builder /go/src/github.com/forbole/bdjuno/build/bdjuno /usr/bin/bdjuno
CMD [ "bdjuno" ]
11 changes: 11 additions & 0 deletions Dockerfile.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.18-alpine AS builder
RUN apk update && apk add --no-cache make git
WORKDIR /go/src/github.com/forbole/bdjuno
COPY . ./
RUN go mod download
RUN make build

FROM alpine:latest
WORKDIR /bdjuno
COPY --from=builder /go/src/github.com/forbole/bdjuno/build/bdjuno /usr/bin/bdjuno
CMD [ "bdjuno" ]
16 changes: 4 additions & 12 deletions database/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,9 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveProposalStakingPoolSnapshot() {
// ----------------------------------------------------------------------------------------------------------------
// Save snapshot

snapshot := types.NewProposalStakingPoolSnapshot(1, types.NewPool(
snapshot := types.NewProposalStakingPoolSnapshot(1, types.NewPoolSnapshot(
sdk.NewInt(100),
sdk.NewInt(200),
sdk.NewInt(20),
sdk.NewInt(30),
10,
))
err := suite.database.SaveProposalStakingPoolSnapshot(snapshot)
Expand All @@ -557,11 +555,9 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveProposalStakingPoolSnapshot() {
// ----------------------------------------------------------------------------------------------------------------
// Update with lower height

err = suite.database.SaveProposalStakingPoolSnapshot(types.NewProposalStakingPoolSnapshot(1, types.NewPool(
err = suite.database.SaveProposalStakingPoolSnapshot(types.NewProposalStakingPoolSnapshot(1, types.NewPoolSnapshot(
sdk.NewInt(200),
sdk.NewInt(500),
sdk.NewInt(14),
sdk.NewInt(10),
9,
)))
suite.Require().NoError(err)
Expand All @@ -580,11 +576,9 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveProposalStakingPoolSnapshot() {
// ----------------------------------------------------------------------------------------------------------------
// Update with same height

err = suite.database.SaveProposalStakingPoolSnapshot(types.NewProposalStakingPoolSnapshot(1, types.NewPool(
err = suite.database.SaveProposalStakingPoolSnapshot(types.NewProposalStakingPoolSnapshot(1, types.NewPoolSnapshot(
sdk.NewInt(500),
sdk.NewInt(1000),
sdk.NewInt(20),
sdk.NewInt(30),
10,
)))
suite.Require().NoError(err)
Expand All @@ -603,11 +597,9 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveProposalStakingPoolSnapshot() {
// ----------------------------------------------------------------------------------------------------------------
// Update with higher height

err = suite.database.SaveProposalStakingPoolSnapshot(types.NewProposalStakingPoolSnapshot(1, types.NewPool(
err = suite.database.SaveProposalStakingPoolSnapshot(types.NewProposalStakingPoolSnapshot(1, types.NewPoolSnapshot(
sdk.NewInt(1000),
sdk.NewInt(2000),
sdk.NewInt(80),
sdk.NewInt(40),
11,
)))
suite.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/proullon/ramsql v0.0.0-20181213202341-817cee58a244
github.com/rs/zerolog v1.28.0
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/tendermint/tendermint v0.34.26
google.golang.org/grpc v1.52.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
Expand Down
1 change: 1 addition & 0 deletions modules/gov/expected_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type SlashingModule interface {

type StakingModule interface {
GetStakingPool(height int64) (*types.Pool, error)
GetStakingPoolSnapshot(height int64) (*types.PoolSnapshot, error)
GetValidatorsWithStatus(height int64, status string) ([]stakingtypes.Validator, []types.Validator, error)
GetValidatorsVotingPowers(height int64, vals *tmctypes.ResultValidators) ([]types.ValidatorVotingPower, error)
GetValidatorsStatuses(height int64, validators []stakingtypes.Validator) ([]types.ValidatorStatus, error)
Expand Down
9 changes: 7 additions & 2 deletions modules/gov/handle_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ func (m *Module) updateProposals(height int64, blockTime time.Time, blockVals *t
return fmt.Errorf("error while updating proposal: %s", err)
}

err = m.UpdateProposalSnapshots(height, blockVals, id)
err = m.UpdateProposalValidatorStatusesSnapshot(height, blockVals, id)
if err != nil {
return fmt.Errorf("error while updating proposal snapshots: %s", err)
return fmt.Errorf("error while updating proposal validator statuses snapshots: %s", err)
}

err = m.UpdateProposalStakingPoolSnapshot(height, blockVals, id)
if err != nil {
return fmt.Errorf("error while updating proposal validator statuses snapshots: %s", err)
}
}
return nil
Expand Down
16 changes: 10 additions & 6 deletions modules/gov/utils_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ func (m *Module) UpdateProposal(height int64, blockTime time.Time, id uint64) er
return nil
}

func (m *Module) UpdateProposalSnapshots(height int64, blockVals *tmctypes.ResultValidators, id uint64) error {
err := m.updateProposalStakingPoolSnapshot(height, id)
func (m *Module) UpdateProposalValidatorStatusesSnapshot(height int64, blockVals *tmctypes.ResultValidators, id uint64) error {
err := m.updateProposalValidatorStatusesSnapshot(height, id, blockVals)
if err != nil {
return fmt.Errorf("error while updating proposal staking pool snapshot: %s", err)
return fmt.Errorf("error while updating proposal validator statuses snapshot: %s", err)
}

err = m.updateProposalValidatorStatusesSnapshot(height, id, blockVals)
return nil
}

func (m *Module) UpdateProposalStakingPoolSnapshot(height int64, blockVals *tmctypes.ResultValidators, id uint64) error {
err := m.updateProposalStakingPoolSnapshot(height, id)
if err != nil {
return fmt.Errorf("error while updating proposal validator statuses snapshot: %s", err)
return fmt.Errorf("error while updating proposal staking pool snapshot: %s", err)
}

return nil
Expand Down Expand Up @@ -197,7 +201,7 @@ func (m *Module) updateAccounts(proposal govtypesv1beta1.Proposal) error {
// updateProposalStakingPoolSnapshot updates the staking pool snapshot associated with the gov
// proposal having the provided id
func (m *Module) updateProposalStakingPoolSnapshot(height int64, proposalID uint64) error {
pool, err := m.stakingModule.GetStakingPool(height)
pool, err := m.stakingModule.GetStakingPoolSnapshot(height)
if err != nil {
return fmt.Errorf("error while getting staking pool: %s", err)
}
Expand Down
9 changes: 9 additions & 0 deletions modules/staking/utils_staking_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ func (m *Module) GetStakingPool(height int64) (*types.Pool, error) {
return types.NewPool(pool.BondedTokens, pool.NotBondedTokens, unbondingTokens, stakedNotBondedTokens, height), nil
}

func (m *Module) GetStakingPoolSnapshot(height int64) (*types.PoolSnapshot, error) {
pool, err := m.source.GetPool(height)
if err != nil {
return nil, fmt.Errorf("error while getting staking pool snapshot: %s", err)
}

return types.NewPoolSnapshot(pool.BondedTokens, pool.NotBondedTokens, height), nil
}

func (m *Module) getTotalUnbondingDelegationsFromValidator(height int64, valOperatorAddress string) []stakingtypes.UnbondingDelegation {
var unbondingDelegations []stakingtypes.UnbondingDelegation
var nextKey []byte
Expand Down
4 changes: 2 additions & 2 deletions types/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ func NewTallyResult(
// ProposalStakingPoolSnapshot contains the data about a single staking pool snapshot to be associated with a proposal
type ProposalStakingPoolSnapshot struct {
ProposalID uint64
Pool *Pool
Pool *PoolSnapshot
}

// NewProposalStakingPoolSnapshot returns a new ProposalStakingPoolSnapshot instance
func NewProposalStakingPoolSnapshot(proposalID uint64, pool *Pool) ProposalStakingPoolSnapshot {
func NewProposalStakingPoolSnapshot(proposalID uint64, pool *PoolSnapshot) ProposalStakingPoolSnapshot {
return ProposalStakingPoolSnapshot{
ProposalID: proposalID,
Pool: pool,
Expand Down
16 changes: 16 additions & 0 deletions types/staking_pool_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ func NewPool(bondedTokens, notBondedTokens, unbondingTokens, stakedNotBondedToke
}
}

// PoolSnapshot contains the data of the staking pool snapshot at the given height
type PoolSnapshot struct {
BondedTokens sdkmath.Int
NotBondedTokens sdkmath.Int
Height int64
}

// NewPoolSnapshot allows to build a new PoolSnapshot instance
func NewPoolSnapshot(bondedTokens, notBondedTokens sdkmath.Int, height int64) *PoolSnapshot {
return &PoolSnapshot{
BondedTokens: bondedTokens,
NotBondedTokens: notBondedTokens,
Height: height,
}
}

// --------------------------------------------------------------------------------------------------------------------

// StakingParams represents the parameters of the x/staking module
Expand Down

0 comments on commit 8a7f993

Please sign in to comment.