diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 2196187e7..c7e3f46d9 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -33,6 +33,14 @@ 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 @@ -40,12 +48,13 @@ jobs: 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 }} diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index e4a92bb8c..a02ee4b3f 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -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 }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d4bd068a7..d8497dff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d6a226c1e..000000000 --- a/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM golang:1.18-alpine AS builder -RUN apk update && apk add --no-cache make git -WORKDIR /go/src/github.com/forbole/bdjuno -COPY . ./ - -###################################################### -## Enabe the lines below if chain supports cosmwasm ## -## module to properly build docker image ## -###################################################### -#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 make build - -################################################## -## Enabe line below if chain supports cosmwasm ## -## module to properly build docker image ## -################################################## -#RUN LINK_STATICALLY=true BUILD_TAGS="muslc" make build - - -FROM alpine:latest -################################################## -## Enabe line below if chain supports cosmwasm ## -## module to properly build docker image ## -################################################## -#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" ] \ No newline at end of file diff --git a/Dockerfile.cosmwasm b/Dockerfile.cosmwasm new file mode 100644 index 000000000..6fc372266 --- /dev/null +++ b/Dockerfile.cosmwasm @@ -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" ] \ No newline at end of file diff --git a/Dockerfile.default b/Dockerfile.default new file mode 100644 index 000000000..f58643e18 --- /dev/null +++ b/Dockerfile.default @@ -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" ] \ No newline at end of file diff --git a/database/gov_test.go b/database/gov_test.go index 1c8291413..19b901e9a 100644 --- a/database/gov_test.go +++ b/database/gov_test.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/go.mod b/go.mod index fc600dea7..51ccecba5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 416b68f72..0aa3805d3 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/modules/gov/expected_modules.go b/modules/gov/expected_modules.go index 5059ced2a..29cf7f1a4 100644 --- a/modules/gov/expected_modules.go +++ b/modules/gov/expected_modules.go @@ -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) diff --git a/modules/gov/handle_block.go b/modules/gov/handle_block.go index 9b16a05d5..1fff0db86 100644 --- a/modules/gov/handle_block.go +++ b/modules/gov/handle_block.go @@ -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 diff --git a/modules/gov/utils_proposal.go b/modules/gov/utils_proposal.go index 679514e20..b0c4b54e8 100644 --- a/modules/gov/utils_proposal.go +++ b/modules/gov/utils_proposal.go @@ -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 @@ -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) } diff --git a/modules/staking/utils_staking_pool.go b/modules/staking/utils_staking_pool.go index 9164ff6ed..bba59af11 100644 --- a/modules/staking/utils_staking_pool.go +++ b/modules/staking/utils_staking_pool.go @@ -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 diff --git a/types/gov.go b/types/gov.go index 64bdd6cc0..558bf3fdd 100644 --- a/types/gov.go +++ b/types/gov.go @@ -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, diff --git a/types/staking_pool_params.go b/types/staking_pool_params.go index b131be09f..ca6e5cab7 100644 --- a/types/staking_pool_params.go +++ b/types/staking_pool_params.go @@ -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