Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine Local Development Setup #124

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
ARG VARIANT="bullseye"
FROM golang:1.20.4
FROM golang:1.21

ARG DEBIAN_FRONTEND=noninteractive

Expand All @@ -14,10 +14,6 @@ RUN apt-get -y install --no-install-recommends vim
# WASM dependencies + Rustup
RUN apt-get -y install --no-install-recommends binaryen

# Cosmos dependencies
# Sadly Ignite + Cosmos SDK v0.47.x is broken atm
# RUN curl https://get.ignite.com/cli@nightly! | bash

# Go language extension dependencies
RUN go install github.com/cweill/gotests/[email protected]
RUN go install github.com/fatih/[email protected]
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:

permissions:
contents: read
repository-projects: read
packages: read

concurrency:
group: ci-${{ github.ref }}-tests
Expand All @@ -18,6 +20,9 @@ concurrency:
jobs:
build:
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/sedaprotocol/vrf-go
PAT: ${{ secrets.PAT }}
strategy:
matrix:
arch: [amd64, arm64]
Expand Down Expand Up @@ -46,6 +51,9 @@ jobs:
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
- name: Configure private token
run: |
git config --global url."https://${PAT}@github.com/".insteadOf "https://github.com/"
- name: Compile
if: steps.cache-binaries.outputs.cache-hit != 'true' && env.GIT_DIFF
run: |
Expand All @@ -54,6 +62,9 @@ jobs:
tests:
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/sedaprotocol/vrf-go
PAT: ${{ secrets.PAT }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
Expand All @@ -62,6 +73,7 @@ jobs:
check-latest: true
cache: true
cache-dependency-path: go.sum
- run: git config --global url.https://${PAT}@github.com/.insteadOf https://github.com/
- uses: technote-space/[email protected]
id: git_diff
with:
Expand All @@ -84,20 +96,29 @@ jobs:

test-e2e:
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/sedaprotocol/vrf-go
USERNAME: hacheigriega
PAT: ${{ secrets.PAT }}
timeout-minutes: 10
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.21"
- uses: actions/checkout@v4
- run: git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Build e2e Docker Image
run: make docker-build-e2e
- name: Test E2E
run: make test-e2e

- name: Create .netrc file
run: |
echo "machine github.com" > ${GITHUB_WORKSPACE}/.netrc
echo " login ${USERNAME}" >> ${GITHUB_WORKSPACE}/.netrc
echo " password ${PAT}" >> ${GITHUB_WORKSPACE}/.netrc
chmod 600 ${GITHUB_WORKSPACE}/.netrc
- name: Test e2e
run: |
make test-e2e
10 changes: 9 additions & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ To see test coverage:
make cover-html
```

To run end-to-end tests:
To run end-to-end tests, you first need to create a file `.netrc` containing GitHub credentials in the project root. This enables an access to the private repositories during the Docker build process. The `.netrc` file should look as follows:
```bash
machine github.com
login <YOUR_USERNAME>
password <YOUR_GITHUB_TOKEN>
```

Change the permissions of `.netrc` and run e2e with the following commands:
```bash
chmod 600 .netrc
make test-e2e
```
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ cover-html: test-unit-cover
@go tool cover -html=$(TEST_COVERAGE_PROFILE)

docker-build-e2e:
@docker build -t sedaprotocol/seda-chaind-e2e -f dockerfiles/Dockerfile.e2e .
@docker build \
-t sedaprotocol/seda-chaind-e2e \
-f dockerfiles/Dockerfile.e2e .

.PHONY: cover-html run-tests $(TEST_TARGETS) test test-race docker-build-e2e

Expand Down
57 changes: 41 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -97,7 +98,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -128,6 +128,7 @@ import (
"github.com/sedaprotocol/seda-chain/x/randomness/keeper"
randomnesskeeper "github.com/sedaprotocol/seda-chain/x/randomness/keeper"
randomnesstypes "github.com/sedaprotocol/seda-chain/x/randomness/types"
customstaking "github.com/sedaprotocol/seda-chain/x/staking"
wasmstorage "github.com/sedaprotocol/seda-chain/x/wasm-storage"
wasmstoragekeeper "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper"
wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types"
Expand Down Expand Up @@ -264,7 +265,6 @@ type App struct {
mm *module.Manager
bmm module.BasicManager

// sm is the simulation manager
sm *module.SimulationManager
configurator module.Configurator
}
Expand Down Expand Up @@ -303,7 +303,12 @@ func NewApp(
std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

// TO-DO
// building BaseApp
nonceMempool := mempool.NewSenderNonceMempool()
mempoolOpt := baseapp.SetMempool(nonceMempool)
baseAppOptions = append(baseAppOptions, mempoolOpt)

bApp := baseapp.NewBaseApp(Name, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
Expand All @@ -313,12 +318,14 @@ func NewApp(
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, authz.ModuleName, banktypes.StoreKey, stakingtypes.StoreKey,
crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
feegrant.StoreKey, evidencetypes.StoreKey, circuittypes.StoreKey,
ibctransfertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey, group.StoreKey,
icacontrollertypes.StoreKey, consensusparamtypes.StoreKey, wasmstoragetypes.StoreKey,
wasmtypes.StoreKey, randomnesstypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey,
feegrant.StoreKey, evidencetypes.StoreKey, circuittypes.StoreKey, group.StoreKey,
capabilitytypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
wasmstoragetypes.StoreKey, randomnesstypes.StoreKey,
)

tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

Expand Down Expand Up @@ -561,13 +568,11 @@ func NewApp(
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

var wasmOpts []wasmkeeper.Option

randomnessQueryPlugin := keeper.NewQuerierImpl(app.RandomnessKeeper)
queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: keeper.SeedQueryPlugin(randomnessQueryPlugin),
})
wasmOpts = append([]wasm.Option{queryPluginOpt}, wasmOpts...)
wasmOpts := []wasmkeeper.Option{queryPluginOpt}

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
Expand Down Expand Up @@ -670,7 +675,7 @@ func NewApp(
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil, app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
customstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()),
evidence.NewAppModule(app.EvidenceKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
Expand All @@ -687,10 +692,10 @@ func NewApp(
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, nil), // always be last to make sure that it checks for all invariants and not only part of them
)

// // bmm defines the module BasicManager is in charge of setting up basic,
// // non-dependant module elements, such as codec registration and genesis verification.
// // By default it is composed of all the module from the module manager.
// // Additionally, app module basics can be overwritten by passing them as argument.
// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default it is composed of all the module from the module manager.
// Additionally, app module basics can be overwritten by passing them as argument.
app.bmm = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
Expand Down Expand Up @@ -794,7 +799,6 @@ func NewApp(
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
circuittypes.ModuleName,
wasmstoragetypes.ModuleName,
// ibc modules
capabilitytypes.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -861,6 +865,27 @@ func NewApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

// Pseudorandomness beacon
app.SetPrepareProposal(
randomnesskeeper.PrepareProposalHandler(
txConfig,
homePath,
cast.ToString(appOpts.Get("priv_validator_key_file")),
app.RandomnessKeeper,
app.AccountKeeper,
app.StakingKeeper,
nonceMempool,
),
)

app.SetProcessProposal(
randomnesskeeper.ProcessProposalHandler(
txConfig,
app.RandomnessKeeper,
app.StakingKeeper,
),
)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
17 changes: 17 additions & 0 deletions app/params/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package params

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
17 changes: 16 additions & 1 deletion cmd/seda-chaind/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"

cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/crypto/secp256k1"
cmtos "github.com/cometbft/cometbft/libs/os"
"github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -64,7 +65,21 @@ func readInMnemonic(cmd *cobra.Command) (string, error) {
return mnemonic, nil
}

// If validator key file exists, create and save an empty validator state file.
func generateValidatorWithSecp256k1Key(config *cfg.Config) error {
pvKeyFile := config.PrivValidatorKeyFile()
if err := os.MkdirAll(filepath.Dir(pvKeyFile), 0o777); err != nil {
return fmt.Errorf("could not create directory %q: %w", filepath.Dir(pvKeyFile), err)
}
pvStateFile := config.PrivValidatorStateFile()
if err := os.MkdirAll(filepath.Dir(pvStateFile), 0o777); err != nil {
return fmt.Errorf("could not create directory %q: %w", filepath.Dir(pvStateFile), err)
}

pv := privval.NewFilePV(secp256k1.GenPrivKey(), config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
pv.Save()
return nil
}

func configureValidatorFiles(config *cfg.Config) error {
keyFilePath := config.PrivValidatorKeyFile()
if err := os.MkdirAll(filepath.Dir(keyFilePath), 0o777); err != nil {
Expand Down
24 changes: 23 additions & 1 deletion cmd/seda-chaind/cmd/init_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/cli"
cmtos "github.com/cometbft/cometbft/libs/os"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -81,6 +82,16 @@ func newNetworkCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Comma
initHeight = 1
}

// Before initializing the node, if a mnemonic is not given and
// the private validator key file does not exist, create a validator
// using a key generated on secp256k1.
if len(mnemonic) == 0 && !cmtos.FileExists(config.PrivValidatorKeyFile()) {
err = generateValidatorWithSecp256k1Key(config)
if err != nil {
return err
}
}

// initialize node
nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic)
if err != nil {
Expand Down Expand Up @@ -179,12 +190,23 @@ $ %s init join moniker --network devnet
return fmt.Errorf("unsupported network type: %s", network)
}

// configure validator files
// TO-DO remove (See: https://github.com/sedaprotocol/seda-chain/pull/76#issuecomment-1762303200)
// If validator key file exists, create and save an empty validator state file.
err = configureValidatorFiles(config)
if err != nil {
return err
}

// Before initializing the node, if a mnemonic is not given and
// the private validator key file does not exist, create a validator
// using a key generated on secp256k1.
if len(mnemonic) == 0 && !cmtos.FileExists(config.PrivValidatorKeyFile()) {
err = generateValidatorWithSecp256k1Key(config)
if err != nil {
return err
}
}

// initialize the node
nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion dockerfiles/Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ ARG GIT_COMMIT
RUN apk add --no-cache \
ca-certificates \
build-base \
linux-headers
linux-headers \
git

# Download go dependencies
COPY .netrc /root/
RUN chmod 600 /root/.netrc

WORKDIR /seda-chain
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
Expand Down
2 changes: 1 addition & 1 deletion docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34685,7 +34685,7 @@ paths:

This rpc is deprecated now that IBC has its own replacement

(https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54)
(https://github.com/cosmos/ibc-go/v8/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54)
operationId: CosmosUpgradeV1Beta1UpgradedConsensusState
responses:
'200':
Expand Down
Loading