Skip to content

Commit

Permalink
possible init chain solution
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Apr 2, 2024
1 parent c3932b1 commit 54038a9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
28 changes: 28 additions & 0 deletions scripts/simapp-v1-clean-start.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
ROOT=$PWD
SIMD="go run ./simd/main.go"

cd simapp
$SIMD init aurn-node --chain-id aurn-chain

cd ~/.simapp/config

# to enable the api server
sed -i '.bak' '/\[api\]/,+3 s/enable = false/enable = true/' app.toml

# to change the voting_period
jq '.app_state.gov.voting_params.voting_period = "600s"' genesis.json > temp.json && mv temp.json genesis.json

# to change the inflation
jq '.app_state.mint.minter.inflation = "0.300000000000000000"' genesis.json > temp.json && mv temp.json genesis.json

cd "$ROOT"/simapp
$SIMD keys add test_validator --keyring-backend test
VALIDATOR_ADDRESS=$($SIMD keys show test_validator -a --keyring-backend test)

$SIMD genesis add-genesis-account "$VALIDATOR_ADDRESS" 1000000000stake
$SIMD genesis gentx test_validator 1000000000stake --keyring-backend test
$SIMD genesis collect-gentxs
4 changes: 4 additions & 0 deletions server/v2/appmanager/appmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (a AppManager[T]) Query(ctx context.Context, version uint64, request transa
return a.stf.Query(ctx, queryState, a.config.QueryGasLimit, request)
}

func (a AppManager[T]) Message(ctx context.Context, message transaction.Type) (transaction.Type, error) {
return a.stf.Message(ctx, message)
}

// QueryWithState executes a query with the provided state. This allows to process a query
// independently of the db state. For example, it can be used to process a query with temporary
// and uncommitted state
Expand Down
20 changes: 20 additions & 0 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"sync/atomic"

consensusv1 "cosmossdk.io/api/cosmos/consensus/v1"
Expand Down Expand Up @@ -233,6 +234,25 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abci.RequestInitChain

c.chainID = req.ChainId

// On a new chain, we consider the init chain block height as 0, even though
// req.InitialHeight is 1 by default.
// TODO

// Store the consensus params in the BaseApp's param store. Note, this must be
// done after the finalizeBlockState and context have been set as it's persisted
// to state.
if req.ConsensusParams != nil {
_, err := c.app.Message(ctx, &consensustypes.MsgUpdateParams{
Block: req.ConsensusParams.Block,
Evidence: req.ConsensusParams.Evidence,
Validator: req.ConsensusParams.Validator,
Abci: req.ConsensusParams.Abci,
})
if err != nil {
return nil, err
}
}

// TODO: populate
return &abci.ResponseInitChain{
ConsensusParams: req.ConsensusParams,
Expand Down
2 changes: 1 addition & 1 deletion server/v2/cometbft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (
github.com/cosmos/gogoproto v1.4.12
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
Expand Down Expand Up @@ -157,6 +156,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion server/v2/cometbft/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ func (c *Consensus[T]) validateFinalizeBlockHeight(req *abci.RequestFinalizeBloc
return nil
}

// GetConsensusParams makes a query to the consensus module in order to get the latest consensus parameters from committed state
// GetConsensusParams makes a query to the consensus module in order to get the latest consensus
// parameters from committed state
func (c *Consensus[T]) GetConsensusParams(ctx context.Context) (*cmtproto.ConsensusParams, error) {
cs := &cmtproto.ConsensusParams{}
latestVersion, err := c.store.GetLatestVersion()

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of err is never used.
Expand Down
10 changes: 9 additions & 1 deletion server/v2/stf/stf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
stfgas "cosmossdk.io/server/v2/stf/gas"
)

var _ STF[transaction.Tx] = STF[transaction.Tx]{} // Ensure STF implements STFI.
var _ STFI[transaction.Tx] = STF[transaction.Tx]{} // Ensure STF implements STFI.

// STFI defines the state transition handler used by AppManager to execute
// state transitions over some state. STF never writes to state, instead
Expand All @@ -39,6 +39,10 @@ type STFI[T transaction.Tx] interface {
gasLimit uint64,
queryRequest transaction.Type,
) (queryResponse transaction.Type, err error)
Message(
ctx context.Context,
msg transaction.Type,
) (response transaction.Type, err error)
// ValidateTx validates the TX.
ValidateTx(ctx context.Context, state store.ReaderMap, gasLimit uint64, tx T, hs header.Service) appmanager.TxResult
}
Expand Down Expand Up @@ -438,6 +442,10 @@ func (s STF[T]) Query(
return s.handleQuery(queryCtx, req)
}

func (s STF[T]) Message(ctx context.Context, msg transaction.Type) (response transaction.Type, err error) {
return s.handleMsg(ctx, msg)
}

// clone clones STF.
func (s STF[T]) clone() STF[T] {
return STF[T]{
Expand Down

0 comments on commit 54038a9

Please sign in to comment.