-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: simapp/v2 #20412
feat: simapp/v2 #20412
Changes from 101 commits
d530e80
0a15db8
8455318
62ded17
5c4a43a
decf4a2
dbf509e
d845064
ed638cd
cb2cc01
da38aff
2691838
faba9d1
35fd591
e394e18
cce35fc
d2241fa
15619d9
ca160d8
65db2cf
7308c68
2a12963
a7503e4
1eac3b2
2c3ce95
aa91391
d3b3a24
05942a0
3fd6eb3
a9ef4e4
290263f
00f6999
a63762e
4b86a66
04b8f98
73e00c0
e9e8ab8
b16d2bc
330b8ed
fc684c5
108978d
be3b27b
24e019b
2ca0c70
b427037
02947fa
5bf88be
e55810e
b50f50c
b029625
cbab735
2738109
92539ec
c95c217
bb09616
bb1c1cc
f1b9a29
c529edd
bf16d79
f235226
87d1c5b
aa21e93
52b883e
acfb730
aa0cebd
fd34264
2a2b3f1
2bb2b90
ce36a1c
44c465b
faf1450
a2312d0
591bb8e
1c074d3
6f36227
2ad7cbf
5a9e899
0a5b6d0
4f54b95
2759dab
fb32eaf
c6f6902
64a51f9
f59e682
99bc320
8ebdc82
eb6d1f6
921b627
d10b7dd
83440d8
08cf9af
68c61d5
959542e
88a2a0b
20ef626
e7178c6
14419bd
6ed4b0f
343258c
8c1e2d2
d914de2
6577d23
2dc02c0
03e791b
fd39547
b02723f
c73e11e
0243a83
40f9393
77e1603
921be8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -485,6 +485,30 @@ jobs: | |
cd simapp | ||
go test -mod=readonly -timeout 30m -tags='app_v1 norace ledger test_ledger_mock' ./... | ||
|
||
test-simapp-v2: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.22" | ||
check-latest: true | ||
cache: true | ||
cache-dependency-path: go.sum | ||
- uses: technote-space/[email protected] | ||
id: git_diff | ||
with: | ||
PATTERNS: | | ||
**/*.go | ||
go.mod | ||
go.sum | ||
**/go.mod | ||
**/go.sum | ||
- name: simapp-v2-smoke-test | ||
if: env.GIT_DIFF | ||
run: | | ||
./scripts/simapp-v2-init.sh | ||
|
||
test-collections: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ func (i *Info) Bytes() ([]byte, error) { | |
binary.LittleEndian.PutUint64(heightBytes, uint64(i.Height)) | ||
buf = append(buf, heightBytes...) | ||
|
||
// TODO; permit empty hash OK for genesis block? | ||
if len(i.Hash) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in baseapp empty hash is populated with hash("") @facundomedica would need to confirm this. If so then id propose we do the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to find where this happens, I'll add an issue to investigate it. |
||
i.Hash = make([]byte, hashSize) | ||
} | ||
// Encode Hash | ||
if len(i.Hash) != hashSize { | ||
return nil, errors.New("invalid hash size") | ||
|
@@ -44,6 +48,9 @@ func (i *Info) Bytes() ([]byte, error) { | |
binary.LittleEndian.PutUint64(timeBytes, uint64(i.Time.Unix())) | ||
buf = append(buf, timeBytes...) | ||
|
||
if len(i.AppHash) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
i.AppHash = make([]byte, hashSize) | ||
} | ||
// Encode AppHash | ||
if len(i.Hash) != hashSize { | ||
return nil, errors.New("invalid hash size") | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||||
|
||||||||||||||||||
set -o errexit | ||||||||||||||||||
set -o nounset | ||||||||||||||||||
set -x | ||||||||||||||||||
|
||||||||||||||||||
ROOT=$PWD | ||||||||||||||||||
SIMAPP_DIR="$ROOT/simapp/v2" | ||||||||||||||||||
|
||||||||||||||||||
SIMD="$ROOT/build/simdv2" | ||||||||||||||||||
CONFIG="${CONFIG:-$HOME/.simappv2/config}" | ||||||||||||||||||
|
||||||||||||||||||
cd "$SIMAPP_DIR" | ||||||||||||||||||
go build -o "$ROOT/build/simdv2" simdv2/main.go | ||||||||||||||||||
|
||||||||||||||||||
$SIMD init simapp-v2-node --chain-id simapp-v2-chain | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The verification script indicates that the expected directories (
Analysis chainConsider verifying the success of the Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the success of the `init` command.
# Test: Check if the `init` command executed successfully. Expect: No errors.
grep "Completed initializing" "$CONFIG/log.txt"
Length of output: 82 Script: #!/bin/bash
# Description: Verify the success of the `init` command by checking for expected directories or files.
# Expected directories or files created by the `init` command
EXPECTED_DIRS=("~/.simapp" "~/.simapp/config" "~/.simapp/data")
# Check if the expected directories exist
for dir in "${EXPECTED_DIRS[@]}"; do
if [ ! -d "$dir" ]; then
echo "Directory $dir does not exist. The init command may have failed."
else
echo "Directory $dir exists."
fi
done
Length of output: 740 |
||||||||||||||||||
|
||||||||||||||||||
cd "$CONFIG" | ||||||||||||||||||
|
||||||||||||||||||
# to enable the api server | ||||||||||||||||||
$SIMD config set app api.enable true | ||||||||||||||||||
|
||||||||||||||||||
# 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 | ||||||||||||||||||
|
||||||||||||||||||
# change the initial height to 2 to work around store/v2 and iavl limitations with a genesis block | ||||||||||||||||||
jq '.initial_height = 2' genesis.json > temp.json && mv temp.json genesis.json | ||||||||||||||||||
Comment on lines
+24
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimize the - jq '.app_state.gov.voting_params.voting_period = "600s"' genesis.json > temp.json && mv temp.json genesis.json
- jq '.app_state.mint.minter.inflation = "0.300000000000000000"' genesis.json > temp.json && mv temp.json genesis.json
- jq '.initial_height = 2' genesis.json > temp.json && mv temp.json genesis.json
+ jq '.app_state.gov.voting_params.voting_period = "600s" | .app_state.mint.minter.inflation = "0.300000000000000000" | .initial_height = 2' genesis.json > temp.json && mv temp.json genesis.json Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
$SIMD keys add test_validator --indiscreet | ||||||||||||||||||
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 | ||||||||||||||||||
|
||||||||||||||||||
$SIMD start & | ||||||||||||||||||
SIMD_PID=$! | ||||||||||||||||||
|
||||||||||||||||||
cnt=0 | ||||||||||||||||||
while ! $SIMD query block --type=height 5; do | ||||||||||||||||||
cnt=$((cnt + 1)) | ||||||||||||||||||
if [ $cnt -gt 30 ]; then | ||||||||||||||||||
kill -9 "$SIMD_PID" | ||||||||||||||||||
exit 1 | ||||||||||||||||||
fi | ||||||||||||||||||
sleep 1 | ||||||||||||||||||
done | ||||||||||||||||||
|
||||||||||||||||||
kill -9 "$SIMD_PID" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package cometbft | ||
|
||
/* TODO this has been failing for months, it needs to be re-written | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Address the failing test as indicated by the TODO comment. Would you like assistance in rewriting this test to ensure reliability? |
||
import ( | ||
"context" | ||
"testing" | ||
|
||
appmodulev2 "cosmossdk.io/core/appmodule/v2" | ||
corestore "cosmossdk.io/core/store" | ||
"cosmossdk.io/core/transaction" | ||
am "cosmossdk.io/server/v2/appmanager" | ||
ammstore "cosmossdk.io/server/v2/appmanager/store" | ||
"cosmossdk.io/server/v2/cometbft/mempool" | ||
"cosmossdk.io/server/v2/stf" | ||
"cosmossdk.io/server/v2/stf/branch" | ||
"cosmossdk.io/server/v2/stf/mock" | ||
"cosmossdk.io/store/v2/storage/pebbledb" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/protobuf/types/known/wrapperspb" | ||
) | ||
|
||
func TestConsensus(t *testing.T) { | ||
mockTx := mock.Tx{ | ||
Sender: []byte("sender"), | ||
Msg: wrapperspb.Bool(true), // msg does not matter at all because our handler does nothing. | ||
GasLimit: 100_000, | ||
} | ||
|
||
s := stf.NewSTF( | ||
func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) { | ||
err = kvSet(t, ctx, "exec") | ||
return nil, err | ||
}, | ||
func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) { | ||
err = kvSet(t, ctx, "query") | ||
return nil, err | ||
}, | ||
func(ctx context.Context, txs []mock.Tx) error { return nil }, | ||
func(ctx context.Context) error { | ||
return kvSet(t, ctx, "begin-block") | ||
}, | ||
func(ctx context.Context) error { | ||
return kvSet(t, ctx, "end-block") | ||
}, | ||
func(ctx context.Context, tx mock.Tx) error { | ||
return kvSet(t, ctx, "validate") | ||
}, | ||
func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { return nil, nil }, | ||
func(ctx context.Context, tx mock.Tx, success bool) error { | ||
return kvSet(t, ctx, "post-tx-exec") | ||
}, | ||
branch.DefaultNewWriterMap, | ||
) | ||
|
||
storageDB, err := pebbledb.New(t.TempDir()) | ||
require.NoError(t, err) | ||
ss, _ := ammstore.New(storageDB) | ||
|
||
b := am.Builder[mock.Tx]{ | ||
STF: s, | ||
DB: ss, | ||
ValidateTxGasLimit: 100_000, | ||
QueryGasLimit: 100_000, | ||
SimulationGasLimit: 100_000, | ||
} | ||
|
||
am, err := b.Build() | ||
require.NoError(t, err) | ||
|
||
mockStore := NewMockStore() | ||
|
||
c := NewConsensus[mock.Tx](am, mempool.NoOpMempool[mock.Tx]{}, mockStore, Config{}, mock.TxCodec{}, nil) | ||
|
||
t.Run("Check tx basic", func(t *testing.T) { | ||
res, err := c.CheckTx(context.Background(), &abci.CheckTxRequest{ | ||
Tx: mockTx.Bytes(), | ||
Type: 0, | ||
}) | ||
require.NotNil(t, res.GasUsed) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
var actorName = []byte("cookies") | ||
|
||
func kvSet(t *testing.T, ctx context.Context, v string) error { | ||
t.Helper() | ||
executionCtx := stf.GetExecutionContext(ctx) | ||
require.NotNil(t, executionCtx) | ||
state, err := executionCtx.State.GetWriter(actorName) | ||
require.NoError(t, err) | ||
return state.Set([]byte(v), []byte(v)) | ||
} | ||
|
||
func stateHas(t *testing.T, accountState corestore.ReaderMap, key string) { | ||
t.Helper() | ||
state, err := accountState.GetReader(actorName) | ||
require.NoError(t, err) | ||
has, err := state.Has([]byte(key)) | ||
require.NoError(t, err) | ||
require.Truef(t, has, "state did not have key: %s", key) | ||
} | ||
|
||
func stateNotHas(t *testing.T, accountState corestore.ReaderMap, key string) { | ||
t.Helper() | ||
state, err := accountState.GetReader(actorName) | ||
require.NoError(t, err) | ||
has, err := state.Has([]byte(key)) | ||
require.NoError(t, err) | ||
require.Falsef(t, has, "state was not supposed to have key: %s", key) | ||
} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ replace ( | |
cosmossdk.io/depinject => ../../../depinject | ||
cosmossdk.io/server/v2 => ../ | ||
cosmossdk.io/server/v2/appmanager => ../appmanager | ||
cosmossdk.io/store => ../../../store | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The paths specified in the
Analysis chainEnsure the paths in the Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the paths in the replace section of the go.mod file.
# Test: Check if paths are accessible. Expect: No errors or not found messages.
for path in ../../../api ../../../core ../../../core/testing ../../../depinject ../ ../appmanager ../../../store ../../../store/v2 ../../../x/accounts ../../../x/auth ../../../x/bank ../../../x/consensus ../../../x/staking; do
if [ ! -d "$path" ]; then
echo "Path $path not found."
fi
done
Length of output: 4262 |
||
cosmossdk.io/store/v2 => ../../../store/v2 | ||
cosmossdk.io/x/accounts => ../../../x/accounts | ||
cosmossdk.io/x/auth => ../../../x/auth | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
|
||
# `SimApp/v2` | ||
|
||
SimApp is an application built using the Cosmos SDK for testing and educational purposes. | ||
`SimApp/v2` demonstrate a runtime/v2, server/v2 and store/v2 wiring. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The
simapp-v2-init.sh
script includes some good practices such asset -o errexit
andset -o nounset
for error handling. However, it lacks comprehensive logging and detailed error messages. Here are some suggestions to improve the script:Initialization and Build Process:
go build
command.Configuration Changes:
jq
command to ensure the configuration changes are applied correctly.Key Management:
Genesis Setup:
Block Query Loop:
Would you like me to provide a revised version of the script with these improvements?
Analysis chain
Ensure that
simapp-v2-init.sh
includes proper error handling and logging to facilitate debugging and reliability.Would you like me to review the script for best practices in error handling and provide improvements?
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1362