Skip to content

Commit

Permalink
Merge branch 'v1.x' into mergify/bp/v1.x/pr-3709
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Jul 19, 2024
2 parents 2cab538 + 3474812 commit af9d2b0
Show file tree
Hide file tree
Showing 47 changed files with 2,871 additions and 698 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: 1.22.3
go-version: 1.22.4
- name: Create .release-env file
run: |-
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' >> .release-env
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ name: lint
on:
workflow_call:

env:
GO_VERSION: '1.22.3'

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 8
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'
- uses: technote-space/get-diff-action@v6.1.2
with:
# This job will pass without running if go.mod, go.sum, and *.go
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ on:
# runs every day at 6am UTC
- cron: "0 6 * * *"

env:
GO_VERSION: '1.22.3'

jobs:
e2e-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'

- name: Setup kubeconfig
env:
Expand Down
27 changes: 12 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ name: test
on:
workflow_call:

env:
GO_VERSION: '1.22.3'

jobs:
test-short:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'

- name: Run tests in short mode
run: make test-short
Expand All @@ -22,23 +19,23 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'

- name: Run unit tests
run: make test

test-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'

- name: Generate coverage.txt
run: make test-coverage
Expand All @@ -51,11 +48,11 @@ jobs:
test-race:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'

- name: Run unit tests in race mode
run: make test-race
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@ changelog:
exclude:
- "^docs:"
- "^test:"
release:
prerelease: auto
git:
prerelease_suffix: "-"
prerelease_suffix: "-rc*"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# stage 1 Generate celestia-appd Binary
FROM docker.io/golang:1.22.3-alpine3.19 as builder
FROM docker.io/golang:1.22.4-alpine3.19 as builder
# hadolint ignore=DL3018
RUN apk update && apk add --no-cache \
gcc \
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DOCKER_PROTO_BUILDER := docker run -v $(shell pwd):/workspace --workdir /workspa
PROJECTNAME=$(shell basename "$(PWD)")
HTTPS_GIT := https://github.com/celestiaorg/celestia-app.git
PACKAGE_NAME := github.com/celestiaorg/celestia-app
GOLANG_CROSS_VERSION ?= v1.22.3
GOLANG_CROSS_VERSION ?= v1.22.4

# process linker flags
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=celestia-app \
Expand Down Expand Up @@ -120,7 +120,7 @@ test-short:
## test-race: Run unit tests in race mode.
test-race:
@echo "--> Running tests in race mode"
@go test ./... -v -race -skip "TestPrepareProposalConsistency|TestIntegrationTestSuite|TestQGBRPCQueries|TestSquareSizeIntegrationTest|TestStandardSDKIntegrationTestSuite|TestTxsimCommandFlags|TestTxsimCommandEnvVar|TestMintIntegrationTestSuite|TestQGBCLI|TestUpgrade|TestMaliciousTestNode|TestMaxTotalBlobSizeSuite|TestQGBIntegrationSuite|TestSignerTestSuite|TestPriorityTestSuite|TestTimeInPrepareProposalContext|TestConcurrentTxSubmission"
@go test ./... -v -race -skip "TestPrepareProposalConsistency|TestIntegrationTestSuite|TestQGBRPCQueries|TestSquareSizeIntegrationTest|TestStandardSDKIntegrationTestSuite|TestTxsimCommandFlags|TestTxsimCommandEnvVar|TestMintIntegrationTestSuite|TestQGBCLI|TestUpgrade|TestMaliciousTestNode|TestMaxTotalBlobSizeSuite|TestQGBIntegrationSuite|TestSignerTestSuite|TestPriorityTestSuite|TestTimeInPrepareProposalContext|TestConcurrentTxSubmission|TestTxClientTestSuite|Test_testnode"
.PHONY: test-race

## test-bench: Run unit tests in bench mode.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ node | | | |

### Source

1. [Install Go](https://go.dev/doc/install) 1.22.3
1. [Install Go](https://go.dev/doc/install) 1.22.4
1. Clone this repo
1. Install the celestia-app CLI

Expand Down Expand Up @@ -119,7 +119,7 @@ See <https://docs.celestia.org/category/celestia-app> for more information
### Tools
1. Install [golangci-lint](https://golangci-lint.run/usage/install/)
1. Install [golangci-lint](https://golangci-lint.run/welcome/install/)
1. Install [markdownlint](https://github.com/DavidAnson/markdownlint)
1. Install [hadolint](https://github.com/hadolint/hadolint)
1. Install [yamllint](https://yamllint.readthedocs.io/en/stable/quickstart.html)
Expand Down
208 changes: 208 additions & 0 deletions app/consistent_apphash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
package app_test

import (
"fmt"
"testing"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/pkg/user"
testutil "github.com/celestiaorg/celestia-app/test/util"
"github.com/celestiaorg/celestia-app/test/util/blobfactory"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proto/tendermint/version"
coretypes "github.com/tendermint/tendermint/types"
)

type SdkTx struct {
sdkMsgs []sdk.Msg
txOptions []user.TxOption
}

type BlobTx struct {
author string
blobs []*tmproto.Blob
txOptions []user.TxOption
}

// TestConsistentAppHash executes a set of txs, generates an app hash,
// and compares it against a previously generated hash from the same set of transactions.
// App hashes across different commits should be consistent.
func TestConsistentAppHash(t *testing.T) {
// App hash produced from executing txs on this branch
expectedAppHash := []byte{9, 208, 117, 101, 108, 61, 146, 58, 26, 190, 199, 124, 76, 178, 84, 74, 54, 159, 76, 187, 2, 169, 128, 87, 70, 78, 8, 192, 28, 144, 116, 117}

// Initialize testApp
testApp := testutil.NewTestApp()

enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
// Create deterministic keys
kr, pubKeys := deterministicKeyRing(enc.Codec)

recs, err := kr.List()
require.NoError(t, err)
accountNames := make([]string, 0, len(recs))

// Get the name of the records
for _, rec := range recs {
accountNames = append(accountNames, rec.Name)
}

// Apply genesis state to the app.
_, _, err = testutil.SetupDeterministicGenesisState(testApp, pubKeys, 1_000_000_000, app.DefaultInitialConsensusParams())
require.NoError(t, err)

// Query keyring account infos
accountInfos := queryAccountInfo(testApp, accountNames, kr)

// Create accounts for the signer
accounts := make([]*user.Account, 0, len(accountInfos))
for i, accountInfo := range accountInfos {
account := user.NewAccount(accountNames[i], accountInfo.AccountNum, accountInfo.Sequence)
accounts = append(accounts, account)
}

// Create a signer with keyring accounts
signer, err := user.NewTxSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, accounts...)
require.NoError(t, err)

amount := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1000)))

// Create an SDK Tx
sdkTx := SdkTx{
sdkMsgs: []sdk.Msg{
banktypes.NewMsgSend(signer.Account(accountNames[0]).Address(),
signer.Account(accountNames[1]).Address(),
amount),
},
txOptions: blobfactory.DefaultTxOpts(),
}

// Create a Blob Tx
blobTx := BlobTx{
author: accountNames[2],
blobs: []*tmproto.Blob{New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)},
txOptions: blobfactory.DefaultTxOpts(),
}

// Create SDK Tx
rawSdkTx, err := signer.CreateTx(sdkTx.sdkMsgs, sdkTx.txOptions...)
require.NoError(t, err)

// Create Blob Tx
rawBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...)
require.NoError(t, err)

// BeginBlock
header := tmproto.Header{
Version: version.Consensus{App: 1},
Height: testApp.LastBlockHeight() + 1,
}
testApp.BeginBlock(abci.RequestBeginBlock{Header: header})

// Deliver SDK Tx
resp := testApp.DeliverTx(abci.RequestDeliverTx{Tx: rawSdkTx})
require.EqualValues(t, 0, resp.Code, resp.Log)

// Deliver Blob Tx
blob, isBlobTx := coretypes.UnmarshalBlobTx(rawBlobTx)
require.True(t, isBlobTx)
resp = testApp.DeliverTx(abci.RequestDeliverTx{Tx: blob.Tx})
require.EqualValues(t, 0, resp.Code, resp.Log)

// EndBlock
testApp.EndBlock(abci.RequestEndBlock{Height: header.Height})

// Commit the state
testApp.Commit()

// Get the app hash
appHash := testApp.LastCommitID().Hash

// Require that the app hash is equal to the app hash produced on a different commit
require.Equal(t, expectedAppHash, appHash)
}

// fixedNamespace returns a hardcoded namespace
func fixedNamespace() appns.Namespace {
return appns.Namespace{
Version: 0,
ID: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 67, 154, 200, 228, 130, 74, 147, 162, 11},
}
}

// deterministicKeyRing returns a deterministic keyring and a list of deterministic public keys
func deterministicKeyRing(cdc codec.Codec) (keyring.Keyring, []types.PubKey) {
mnemonics := []string{
"great myself congress genuine scale muscle view uncover pipe miracle sausage broccoli lonely swap table foam brand turtle comic gorilla firm mad grunt hazard",
"cheap job month trigger flush cactus chest juice dolphin people limit crunch curious secret object beach shield snake hunt group sketch cousin puppy fox",
"oil suffer bamboo one better attack exist dolphin relief enforce cat asset raccoon lava regret found love certain plunge grocery accuse goat together kiss",
"giraffe busy subject doll jump drama sea daring again club spend toe mind organ real liar permit refuse change opinion donkey job cricket speed",
"fee vapor thing fish fan memory negative raven cram win quantum ozone job mirror shoot sting quiz black apart funny sort cancel friend curtain",
"skin beef review pilot tooth act any alarm there only kick uniform ticket material cereal radar ethics list unlock method coral smooth street frequent",
"ecology scout core guard load oil school effort near alcohol fancy save cereal owner enforce impact sand husband trophy solve amount fish festival sell",
"used describe angle twin amateur pyramid bitter pool fluid wing erode rival wife federal curious drink battle put elbow mandate another token reveal tone",
"reason fork target chimney lift typical fine divorce mixture web robot kiwi traffic stove miss crane welcome camp bless fuel october riot pluck ordinary",
"undo logic mobile modify master force donor rose crumble forget plate job canal waste turn damp sure point deposit hazard quantum car annual churn",
"charge subway treat loop donate place loan want grief leg message siren joy road exclude match empty enforce vote meadow enlist vintage wool involve",
}
kb := keyring.NewInMemory(cdc)
pubKeys := make([]types.PubKey, len(mnemonics))
for idx, mnemonic := range mnemonics {
rec, err := kb.NewAccount(fmt.Sprintf("account-%d", idx), mnemonic, "", "", hd.Secp256k1)
if err != nil {
panic(err)
}
pubKey, err := rec.GetPubKey()
if err != nil {
panic(err)
}
pubKeys[idx] = pubKey
}
return kb, pubKeys
}

func getAddress(account string, kr keyring.Keyring) sdk.AccAddress {
rec, err := kr.Key(account)
if err != nil {
panic(err)
}
addr, err := rec.GetAddress()
if err != nil {
panic(err)
}
return addr
}

func queryAccountInfo(capp *app.App, accs []string, kr keyring.Keyring) []blobfactory.AccountInfo {
infos := make([]blobfactory.AccountInfo, len(accs))
for i, acc := range accs {
addr := getAddress(acc, kr)
accI := testutil.DirectQueryAccount(capp, addr)
infos[i] = blobfactory.AccountInfo{
AccountNum: accI.GetAccountNumber(),
Sequence: accI.GetSequence(),
}
}
return infos
}

// New creates a new tmproto.Blob from the provided data
func New(ns appns.Namespace, blob []byte, shareVersion uint8) *tmproto.Blob {
return &tmproto.Blob{
NamespaceId: ns.ID,
Data: blob,
ShareVersion: uint32(shareVersion),
NamespaceVersion: uint32(ns.Version),
}
}
Loading

0 comments on commit af9d2b0

Please sign in to comment.