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

R4R: Replace GenTx with StdTx #2524

Merged
merged 84 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
38d0336
Add arg to PrintUnsignedStdTx() to actually operate in offline mode
Oct 11, 2018
36845cf
New func processStdTxs()
Oct 11, 2018
ffb5e46
New function to create genesis account from MsgCreateValidator
Oct 2, 2018
7060839
Remove gen-tx command
Oct 11, 2018
d365b11
Update gaia to work with auth.StdTx
Oct 17, 2018
cf63a53
Temporarily disable dead code
Oct 11, 2018
73138e5
Fix build failures
Oct 11, 2018
622acc1
Remove dead code
Oct 3, 2018
9879a17
Keep on cleaning up
Oct 11, 2018
0b76c47
Cleanup, return validators as they need to be written into genesis.json
Oct 11, 2018
8f3fc68
Cleanup, exclude node from persistent peers
Oct 11, 2018
bca74a2
Update test_helpers
Oct 11, 2018
e3c2157
Experimental branch
Oct 11, 2018
90aca4d
Modify gaiad init to allow auto-create of stdTx
Oct 11, 2018
73391ac
Fix FTBFS in democoin
Oct 7, 2018
7663114
Refactoring, fix test cases
Oct 11, 2018
5f654e7
Fix genesis tests
Oct 8, 2018
7a7120b
Remove server/testnet.go
Oct 11, 2018
a0b936a
Don't load node_key.json, which might not be available
Oct 11, 2018
d2b39fa
Add missing trailing new space
Oct 11, 2018
b5e709f
WIP!
Oct 17, 2018
2b054b1
So long GenTx
Oct 12, 2018
37dee50
Get rid of FlagOWK
Oct 12, 2018
34b8838
Get rid of FlagClientHome
Oct 12, 2018
0f3274f
FlagIP - ditto
Oct 12, 2018
1c1a327
Commit just not to lose history
Oct 14, 2018
8ab1f2f
Get the txs through DeliverTx
Oct 15, 2018
4b451a1
Add app.slashingKeeper.AddValidators at the end of genesis
Oct 15, 2018
52970e5
On InitChain(), Signature's account number must be 0
Oct 15, 2018
8a1296c
Add (tentative?) command to generate {node_key,priv_validator}.json f…
Oct 15, 2018
8afc1ae
Refactoring test_helpers
Oct 16, 2018
f4c2b39
WIP
Oct 16, 2018
12d5f48
Fix creation of accounts
Oct 16, 2018
5e70c2e
Fix coins
Oct 17, 2018
0901e03
Reintroduce gaiad testnet
Oct 16, 2018
eca8f1c
prompt user for passwords
Oct 16, 2018
bdac9ac
Fix monikers
Oct 16, 2018
875ffef
Fix all lcd_tests
Oct 16, 2018
df0e4a4
Switch tests output back on
Oct 16, 2018
bf206f3
Remove test_utils, NewTestGaiaAppGenState is now deprecated
Oct 17, 2018
3e81151
Fix all things :)
Oct 16, 2018
4796c99
Fix ./cmd/gaia/init tests
Oct 17, 2018
984da2a
Fix tests
Oct 17, 2018
93913ae
Fix democoind
Oct 17, 2018
45b6ff6
Get rid of FlagsAppGenState
Oct 17, 2018
f1e86a3
Fix more tests
Oct 17, 2018
db9c1d7
Fix integration tests, move DefaultKeyPass into app package
Oct 17, 2018
4c5b583
Rebased on develop
Oct 17, 2018
e0763c4
Refresh Gopkg.*
Oct 17, 2018
37bbf2d
Pin tendermint to 0.25.1
Oct 18, 2018
f8c2e75
Fix {base,demo}coin tests
Oct 18, 2018
a48bc86
Fix lintian warnings, formatting
Oct 18, 2018
6d19f4e
Make linter happy
Oct 18, 2018
142984a
Run make format
Oct 18, 2018
83f0503
Incorporate Jae/Chris comments
Oct 18, 2018
67bbc1a
Combine --genesis-format and --generate-only
Oct 18, 2018
7f2fab3
Improve sign command's --offline flag documentation
Oct 18, 2018
e5addfd
Rename ProcessStdTx as per Jae's comment - drop TODO comment followin…
Oct 18, 2018
05214f1
Remove dead code
Oct 18, 2018
88aafb3
Code cleanup
Oct 18, 2018
d1773d8
Moniker must be set
Oct 18, 2018
6c461e6
Code cleanup
Oct 18, 2018
a6340c4
Improve examples flags handling
Oct 18, 2018
b050686
Make linter happy
Oct 18, 2018
b87b6d4
Replace path with filepath
Oct 18, 2018
9c5d1c4
Call app.slashingKeeper.AddValidators() even if len(txs) == 0
Oct 18, 2018
a33a880
Refactoring, introduce gaiad init --skip-genesis, code cleanup
Oct 18, 2018
1db33c3
CLI refactoring
Oct 18, 2018
ee36213
Fix linter warnings, integration tests
Oct 18, 2018
898883f
Update PENDING.md
Oct 19, 2018
731d49a
Run make format
Oct 19, 2018
f2878af
Drop unnecessary workaround to make lcd_tests pass
Oct 19, 2018
e28be2f
Ensure GenTxsDir is not empty
Oct 19, 2018
75b13d0
Reintroduce gentx
Oct 19, 2018
d6d4b18
Fix FTBFS
Oct 19, 2018
3df8782
Simple name changes, GenesisState.Txs -> .GenTxs; OWK -> OverwriteKey…
jaekwon Oct 19, 2018
cbe5c00
Make linter happy
Oct 19, 2018
0641031
Update changelog
Oct 19, 2018
256919f
Update PENDING.md, docs
Oct 19, 2018
b2bb62e
Merge branch 'develop' into alessio/1890-replace-genesistx-with-stdtx…
cwgoes Oct 19, 2018
0164024
'make format'
cwgoes Oct 19, 2018
7ab120f
Start simulation at height 1, like Tendermint
cwgoes Oct 19, 2018
7a9c9d9
Ensure we never fetch from height 0
cwgoes Oct 19, 2018
aed1fba
Fix it the right way
cwgoes Oct 19, 2018
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: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@

[[override]]
name = "github.com/tendermint/tendermint"
version = "=0.25.0"
version = "=0.25.1-rc0"

## deps without releases:

[[constraint]]
[[override]]
name = "golang.org/x/crypto"
source = "https://github.com/tendermint/crypto"
revision = "3764759f34a542a3aef74d6b02e35be7ab893bba"
Expand Down
8 changes: 8 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ BREAKING CHANGES
* [cli] [\#2190](https://github.com/cosmos/cosmos-sdk/issues/2190) `gaiacli init --gen-txs` is now `gaiacli init --with-txs` to reduce confusion
* [cli] \#2073 --from can now be either an address or a key name
* [cli] [\#1184](https://github.com/cosmos/cosmos-sdk/issues/1184) Subcommands reorganisation, see [\#2390](https://github.com/cosmos/cosmos-sdk/pull/2390) for a comprehensive list of changes.
* [cli] [\#2524](https://github.com/cosmos/cosmos-sdk/issues/2524) Add support offline mode to `gaiacli tx sign`. Lookups are not performed if the flag `--offline` is on.

* Gaia
* Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013)
Expand All @@ -45,6 +46,12 @@ BREAKING CHANGES
* [x/slashing] \#2430 Simulate more slashes, check if validator is jailed before jailing
* [x/stake] \#2393 Removed `CompleteUnbonding` and `CompleteRedelegation` Msg types, and instead added unbonding/redelegation queues to endblocker
* [x/stake] \#1673 Validators are no longer deleted until they can no longer possibly be slashed
* [\#1890](https://github.com/cosmos/cosmos-sdk/issues/1890) Start chain with initial state + sequence of transactions
* [cli] Rename `gaiad init gentx` to `gaiad gentx`.
* [cli] Add `--skip-genesis` flag to `gaiad init` to prevent `genesis.json` generation.
* Drop `GenesisTx` in favor of a signed `StdTx` with only one `MsgCreateValidator` message.
* [cli] Port `gaiad init` and `gaiad testnet` to work with `StdTx` genesis transactions.
* [cli] Add `--moniker` flag to `gaiad init` to override moniker when generating `genesis.json` - i.e. it takes effect when running with the `--with-txs` flag, it is ignored otherwise.

* SDK
* [core] \#2219 Update to Tendermint 0.24.0
Expand Down Expand Up @@ -115,6 +122,7 @@ FEATURES
* [cli] \#2220 Add `gaiacli config` feature to interactively create CLI config files to reduce the number of required flags
* [stake][cli] [\#1672](https://github.com/cosmos/cosmos-sdk/issues/1672) Introduced
new commission flags for validator commands `create-validator` and `edit-validator`.
* [stake][cli] [\#1890](https://github.com/cosmos/cosmos-sdk/issues/1890) Add `--genesis-format` flag to `gaiacli tx create-validator` to produce transactions in genesis-friendly format.

* Gaia
* [cli] #2170 added ability to show the node's address via `gaiad tendermint show-address`
Expand Down
2 changes: 1 addition & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func TestValidatorsQuery(t *testing.T) {
require.Equal(t, 1, len(operAddrs))

validators := getValidators(t, port)
require.Equal(t, len(validators), 1)
require.Equal(t, 1, len(validators), fmt.Sprintf("%+v", validators))

// make sure all the validators were found (order unknown because sorted by operator addr)
foundVal := false
Expand Down
66 changes: 35 additions & 31 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/tendermint/tendermint/crypto/secp256k1"
"io/ioutil"
"net"
"net/http"
Expand All @@ -14,7 +16,7 @@ import (
"testing"

"github.com/cosmos/cosmos-sdk/client"
keys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/keys"
gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
Expand All @@ -26,6 +28,7 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"

txbuilder "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
abci "github.com/tendermint/tendermint/abci/types"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
Expand Down Expand Up @@ -205,42 +208,43 @@ func InitializeTestLCD(

genesisFile := config.GenesisFile()
genDoc, err := tmtypes.GenesisDocFromFile(genesisFile)
require.NoError(t, err)

// append initial (proposing) validator
genDoc.Validators[0] = tmtypes.GenesisValidator{
PubKey: privVal.GetPubKey(),
Power: 100, // create enough power to enable 2/3 voting power
Name: "validator-1",
}
require.Nil(t, err)
genDoc.Validators = nil
genDoc.SaveAs(genesisFile)
genTxs := []json.RawMessage{}

// append any additional (non-proposing) validators
for i := 1; i < nValidators; i++ {
genDoc.Validators = append(genDoc.Validators,
tmtypes.GenesisValidator{
PubKey: ed25519.GenPrivKey().PubKey(),
Power: 1,
Name: fmt.Sprintf("validator-%d", i+1),
},
for i := 0; i < nValidators; i++ {
operPrivKey := secp256k1.GenPrivKey()
operAddr := operPrivKey.PubKey().Address()
pubKey := privVal.PubKey
delegation := 100
if i > 0 {
pubKey = ed25519.GenPrivKey().PubKey()
delegation = 1
}
msg := stake.NewMsgCreateValidator(
sdk.ValAddress(operAddr),
pubKey,
sdk.NewCoin("steak", sdk.NewInt(int64(delegation))),
stake.Description{Moniker: fmt.Sprintf("validator-%d", i+1)},
stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
)
}

var appGenTxs []json.RawMessage

for _, gdValidator := range genDoc.Validators {
operAddr := ed25519.GenPrivKey().PubKey().Address()
pk := gdValidator.PubKey

valConsPubKeys = append(valConsPubKeys, pk)
stdSignMsg := txbuilder.StdSignMsg{
ChainID: genDoc.ChainID,
Msgs: []sdk.Msg{msg},
}
sig, err := operPrivKey.Sign(stdSignMsg.Bytes())
require.Nil(t, err)
tx := auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, []auth.StdSignature{{Signature: sig, PubKey: operPrivKey.PubKey()}}, "")
txBytes, err := cdc.MarshalJSON(tx)
require.Nil(t, err)
genTxs = append(genTxs, txBytes)
valConsPubKeys = append(valConsPubKeys, pubKey)
valOperAddrs = append(valOperAddrs, sdk.ValAddress(operAddr))

appGenTx, _, _, err := gapp.GaiaAppGenTxNF(cdc, pk, sdk.AccAddress(operAddr), gdValidator.Name)
require.NoError(t, err)

appGenTxs = append(appGenTxs, appGenTx)
}

genesisState, err := gapp.NewTestGaiaAppGenState(cdc, appGenTxs[:], genDoc.Validators, valOperAddrs)
genesisState, err := gapp.GaiaAppGenState(cdc, genTxs)
require.NoError(t, err)

// add some tokens to init accounts
Expand Down
9 changes: 5 additions & 4 deletions client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func PrintUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msg

// SignStdTx appends a signature to a StdTx and returns a copy of a it. If appendSig
// is false, it replaces the signatures already attached with the new signature.
func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, stdTx auth.StdTx, appendSig bool) (auth.StdTx, error) {
// Don't perform online validation or lookups if offline is true.
func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, stdTx auth.StdTx, appendSig bool, offline bool) (auth.StdTx, error) {
alessio marked this conversation as resolved.
Show resolved Hide resolved
var signedStdTx auth.StdTx

keybase, err := keys.GetKeyBase()
Expand All @@ -122,18 +123,18 @@ func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string,

// Check whether the address is a signer
if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) {
fmt.Fprintf(os.Stderr, "WARNING: The generated transaction's intended signer does not match the given signer: '%v'", name)
fmt.Fprintf(os.Stderr, "WARNING: The generated transaction's intended signer does not match the given signer: '%v'\n", name)
}

if txBldr.AccountNumber == 0 {
if !offline && txBldr.AccountNumber == 0 {
accNum, err := cliCtx.GetAccountNumber(addr)
if err != nil {
return signedStdTx, err
}
txBldr = txBldr.WithAccountNumber(accNum)
}

if txBldr.Sequence == 0 {
if !offline && txBldr.Sequence == 0 {
accSeq, err := cliCtx.GetAccountSequence(addr)
if err != nil {
return signedStdTx, err
Expand Down
52 changes: 43 additions & 9 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ package app

import (
"encoding/json"
"io"
"os"

abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"

"fmt"
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -21,10 +13,20 @@ import (
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
"io"
"os"
"sort"
)

const (
appName = "GaiaApp"
// DefaultKeyPass contains the default key password for genesis transactions
DefaultKeyPass = "12345678"
alessio marked this conversation as resolved.
Show resolved Hide resolved
)

// default home directories for expected binaries
Expand Down Expand Up @@ -238,6 +240,38 @@ func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
panic(err) // TODO find a way to do this w/o panics
}

if len(genesisState.GenTxs) > 0 {
for _, genTx := range genesisState.GenTxs {
var tx auth.StdTx
err = app.cdc.UnmarshalJSON(genTx, &tx)
if err != nil {
panic(err)
}
bz := app.cdc.MustMarshalBinary(tx)
res := app.BaseApp.DeliverTx(bz)
if !res.IsOK() {
alessio marked this conversation as resolved.
Show resolved Hide resolved
panic(res.Log)
}
}

validators = app.stakeKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
}
app.slashingKeeper.AddValidators(ctx, validators)

// sanity check
if len(req.Validators) > 0 {
if len(req.Validators) != len(validators) {
alessio marked this conversation as resolved.
Show resolved Hide resolved
panic(fmt.Errorf("len(RequestInitChain.Validators) != len(validators) (%d != %d) ", len(req.Validators), len(validators)))
}
sort.Sort(abci.ValidatorUpdates(req.Validators))
sort.Sort(abci.ValidatorUpdates(validators))
for i, val := range validators {
if !val.Equal(req.Validators[i]) {
panic(fmt.Errorf("validators[%d] != req.Validators[%d] ", i, i))
}
}
}

return abci.ResponseInitChain{
Validators: validators,
}
Expand Down
Loading