From 57356beab6d18041ab15cab49acf8118137fd85a Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 20 Mar 2017 08:57:15 +0100 Subject: [PATCH 01/67] Use WrapXxx to safelt construct XxxS structs --- cmd/commands/tx.go | 4 ++-- glide.lock | 2 +- plugins/counter/counter_test.go | 2 +- tests/tendermint/main.go | 4 ++-- tests/tmsp/tmsp_test.go | 6 +++--- types/test_helpers.go | 8 ++++---- types/tx.go | 30 ++++++++---------------------- types/tx_test.go | 2 +- 8 files changed, 22 insertions(+), 36 deletions(-) diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 2e12be06ec..0fe0cd731b 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -123,7 +123,7 @@ func sendTxCmd(cmd *cobra.Command, args []string) error { // sign that puppy signBytes := tx.SignBytes(chainIDFlag) - tx.Inputs[0].Signature = crypto.SignatureS{privKey.Sign(signBytes)} + tx.Inputs[0].Signature = crypto.WrapSignature(privKey.Sign(signBytes)) fmt.Println("Signed SendTx:") fmt.Println(string(wire.JSONBytes(tx))) @@ -179,7 +179,7 @@ func AppTx(name string, data []byte) error { Data: data, } - tx.Input.Signature = crypto.SignatureS{privKey.Sign(tx.SignBytes(chainIDFlag))} + tx.Input.Signature = crypto.WrapSignature(privKey.Sign(tx.SignBytes(chainIDFlag))) fmt.Println("Signed AppTx:") fmt.Println(string(wire.JSONBytes(tx))) diff --git a/glide.lock b/glide.lock index 4c67c14d60..6d57797f72 100644 --- a/glide.lock +++ b/glide.lock @@ -70,7 +70,7 @@ imports: - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 0ca2c6fdb0706001ca4c4b9b80c9f428e8cf39da + version: 8ff4ce222d32c2328ff0d2bf121fcd34254c03c1 - name: github.com/tendermint/go-data version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 - name: github.com/tendermint/go-db diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index f7c658a9af..6d8168bd7b 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -53,7 +53,7 @@ func TestCounterPlugin(t *testing.T) { signBytes := tx.SignBytes(chainID) // t.Logf("Sign bytes: %X\n", signBytes) sig := test1PrivAcc.Sign(signBytes) - tx.Input.Signature = crypto.SignatureS{sig} + tx.Input.Signature = crypto.WrapSignature(sig) // t.Logf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx})) // Write request diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 73ace4ef88..53416c2357 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -67,7 +67,7 @@ func main() { // Sign request signBytes := tx.SignBytes(chainID) sig := root.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) //fmt.Println("tx:", tx) // Write request @@ -118,7 +118,7 @@ func main() { // Sign request signBytes := tx.SignBytes(chainID) sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) //fmt.Println("tx:", tx) // Write request diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index 86b4bfbf24..e78f978b2b 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -50,7 +50,7 @@ func TestSendTx(t *testing.T) { signBytes := tx.SignBytes(chainID) // t.Log("Sign bytes: %X\n", signBytes) sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) // t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(types.TxS{tx})) // Write request @@ -102,7 +102,7 @@ func TestSequence(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request @@ -146,7 +146,7 @@ func TestSequence(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request diff --git a/types/test_helpers.go b/types/test_helpers.go index 81e639ee10..02f96b7814 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -12,9 +12,9 @@ import ( func PrivAccountFromSecret(secret string) PrivAccount { privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret)) privAccount := PrivAccount{ - PrivKeyS: crypto.PrivKeyS{privKey}, + PrivKeyS: crypto.WrapPrivKey(privKey), Account: Account{ - PubKey: crypto.PubKeyS{privKey.PubKey()}, + PubKey: crypto.WrapPubKey(privKey.PubKey()), }, } return privAccount @@ -31,9 +31,9 @@ func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount { } privKey := crypto.GenPrivKeyEd25519() - pubKey := crypto.PubKeyS{privKey.PubKey()} + pubKey := crypto.WrapPubKey(privKey.PubKey()) privAccs[i] = PrivAccount{ - PrivKeyS: crypto.PrivKeyS{privKey}, + PrivKeyS: crypto.WrapPrivKey(privKey), Account: Account{ PubKey: pubKey, Balance: Coins{Coin{"", balance}}, diff --git a/types/tx.go b/types/tx.go index d4925bbb65..5b0eb84ba5 100644 --- a/types/tx.go +++ b/types/tx.go @@ -104,13 +104,7 @@ func NewTxInput(pubKey crypto.PubKey, coins Coins, sequence int) TxInput { Sequence: sequence, } if sequence == 1 { - // safely wrap if needed - // TODO: extract this as utility function? - ps, ok := pubKey.(crypto.PubKeyS) - if !ok { - ps = crypto.PubKeyS{pubKey} - } - input.PubKey = ps + input.PubKey = crypto.WrapPubKey(pubKey) } return input } @@ -151,25 +145,21 @@ type SendTx struct { func (tx *SendTx) SignBytes(chainID string) []byte { signBytes := wire.BinaryBytes(chainID) sigz := make([]crypto.Signature, len(tx.Inputs)) - for i, input := range tx.Inputs { - sigz[i] = input.Signature.Signature - tx.Inputs[i].Signature.Signature = nil + for i := range tx.Inputs { + sigz[i] = tx.Inputs[i].Signature + tx.Inputs[i].Signature = crypto.Signature{} } signBytes = append(signBytes, wire.BinaryBytes(tx)...) for i := range tx.Inputs { - tx.Inputs[i].Signature.Signature = sigz[i] + tx.Inputs[i].Signature = sigz[i] } return signBytes } func (tx *SendTx) SetSignature(addr []byte, sig crypto.Signature) bool { - sigs, ok := sig.(crypto.SignatureS) - if !ok { - sigs = crypto.SignatureS{sig} - } for i, input := range tx.Inputs { if bytes.Equal(input.Address, addr) { - tx.Inputs[i].Signature = sigs + tx.Inputs[i].Signature = crypto.WrapSignature(sig) return true } } @@ -193,18 +183,14 @@ type AppTx struct { func (tx *AppTx) SignBytes(chainID string) []byte { signBytes := wire.BinaryBytes(chainID) sig := tx.Input.Signature - tx.Input.Signature.Signature = nil + tx.Input.Signature = crypto.WrapSignature(nil) signBytes = append(signBytes, wire.BinaryBytes(tx)...) tx.Input.Signature = sig return signBytes } func (tx *AppTx) SetSignature(sig crypto.Signature) bool { - sigs, ok := sig.(crypto.SignatureS) - if !ok { - sigs = crypto.SignatureS{sig} - } - tx.Input.Signature = sigs + tx.Input.Signature = crypto.WrapSignature(sig) return true } diff --git a/types/tx_test.go b/types/tx_test.go index 71033cc9e7..fb4da2598d 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -109,7 +109,7 @@ func TestSendTxJSON(t *testing.T) { sig := test1PrivAcc.Sign(signBytes) // we handle both raw sig and wrapped sig the same tx.SetSignature(test1PrivAcc.PubKey.Address(), sig) - tx2.SetSignature(test1PrivAcc.PubKey.Address(), crypto.SignatureS{sig}) + tx2.SetSignature(test1PrivAcc.PubKey.Address(), crypto.WrapSignature(sig)) assert.Equal(tx, tx2) // let's marshal / unmarshal this with signature From 0665a2e8a6e18715d8de5db5f3ccb6c36e4fa05c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 21 Mar 2017 21:52:42 +0100 Subject: [PATCH 02/67] Clean up all XxxS structs to Xxx --- glide.lock | 4 ++-- state/execution.go | 2 +- types/account.go | 8 ++++---- types/test_helpers.go | 13 +++++++------ types/tx.go | 10 +++++----- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/glide.lock b/glide.lock index 6d57797f72..579db86b76 100644 --- a/glide.lock +++ b/glide.lock @@ -70,9 +70,9 @@ imports: - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 8ff4ce222d32c2328ff0d2bf121fcd34254c03c1 + version: 3e1dba7ab762bb689123eec30c468967f077a6a4 - name: github.com/tendermint/go-data - version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 + version: 9fbf0684fefc4fad580992394a0bcf47c1b3d77e - name: github.com/tendermint/go-db version: 9643f60bc2578693844aacf380a7c32e4c029fee - name: github.com/tendermint/go-events diff --git a/state/execution.go b/state/execution.go index eb7f3c6906..f642b80521 100644 --- a/state/execution.go +++ b/state/execution.go @@ -244,7 +244,7 @@ func validateInputAdvanced(acc *types.Account, signBytes []byte, in types.TxInpu return abci.ErrBaseInsufficientFunds.AppendLog(cmn.Fmt("balance is %v, tried to send %v", balance, in.Coins)) } // Check signatures - if !acc.PubKey.VerifyBytes(signBytes, in.Signature.Signature) { + if !acc.PubKey.VerifyBytes(signBytes, in.Signature) { return abci.ErrBaseInvalidSignature.AppendLog(cmn.Fmt("SignBytes: %X", signBytes)) } return abci.OK diff --git a/types/account.go b/types/account.go index b3478fce0c..d1e62d8321 100644 --- a/types/account.go +++ b/types/account.go @@ -7,9 +7,9 @@ import ( ) type Account struct { - PubKey crypto.PubKeyS `json:"pub_key"` // May be nil, if not known. - Sequence int `json:"sequence"` - Balance Coins `json:"coins"` + PubKey crypto.PubKey `json:"pub_key"` // May be nil, if not known. + Sequence int `json:"sequence"` + Balance Coins `json:"coins"` } func (acc *Account) Copy() *Account { @@ -31,7 +31,7 @@ func (acc *Account) String() string { //---------------------------------------- type PrivAccount struct { - crypto.PrivKeyS + crypto.PrivKey Account } diff --git a/types/test_helpers.go b/types/test_helpers.go index 02f96b7814..23e46cdc9b 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -10,11 +10,12 @@ import ( // Creates a PrivAccount from secret. // The amount is not set. func PrivAccountFromSecret(secret string) PrivAccount { - privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret)) + privKey := crypto.WrapPrivKey( + crypto.GenPrivKeyEd25519FromSecret([]byte(secret))) privAccount := PrivAccount{ - PrivKeyS: crypto.WrapPrivKey(privKey), + PrivKey: privKey, Account: Account{ - PubKey: crypto.WrapPubKey(privKey.PubKey()), + PubKey: privKey.PubKey(), }, } return privAccount @@ -30,10 +31,10 @@ func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount { balance += cmn.RandInt64() % (maxAmount - minAmount) } - privKey := crypto.GenPrivKeyEd25519() - pubKey := crypto.WrapPubKey(privKey.PubKey()) + privKey := crypto.WrapPrivKey(crypto.GenPrivKeyEd25519()) + pubKey := privKey.PubKey() privAccs[i] = PrivAccount{ - PrivKeyS: crypto.WrapPrivKey(privKey), + PrivKey: privKey, Account: Account{ PubKey: pubKey, Balance: Coins{Coin{"", balance}}, diff --git a/types/tx.go b/types/tx.go index 5b0eb84ba5..f8366b0337 100644 --- a/types/tx.go +++ b/types/tx.go @@ -64,11 +64,11 @@ func (p *TxS) UnmarshalJSON(data []byte) (err error) { //----------------------------------------------------------------------------- type TxInput struct { - Address data.Bytes `json:"address"` // Hash of the PubKey - Coins Coins `json:"coins"` // - Sequence int `json:"sequence"` // Must be 1 greater than the last committed TxInput - Signature crypto.SignatureS `json:"signature"` // Depends on the PubKey type and the whole Tx - PubKey crypto.PubKeyS `json:"pub_key"` // Is present iff Sequence == 0 + Address data.Bytes `json:"address"` // Hash of the PubKey + Coins Coins `json:"coins"` // + Sequence int `json:"sequence"` // Must be 1 greater than the last committed TxInput + Signature crypto.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx + PubKey crypto.PubKey `json:"pub_key"` // Is present iff Sequence == 0 } func (txIn TxInput) ValidateBasic() abci.Result { From 787cf0ebac0be52795f71082d5a9b446412fb219 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 21 Mar 2017 22:50:23 +0100 Subject: [PATCH 03/67] Update to patched go-p2p, tendermint, fix a few tests --- app/genesis_test.go | 2 +- cmd/commands/key.go | 7 ++++--- glide.lock | 4 ++-- plugins/ibc/ibc_test.go | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/genesis_test.go b/app/genesis_test.go index 74ca22e61b..4fec4b6db7 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -38,7 +38,7 @@ func TestLoadGenesis(t *testing.T) { assert.EqualValues("blank", acct.Balance[0].Denom) // and public key is parsed properly - apk := acct.PubKey.PubKey + apk := acct.PubKey.Unwrap() require.NotNil(apk) epk, ok := apk.(crypto.PubKeyEd25519) if assert.True(ok) { diff --git a/cmd/commands/key.go b/cmd/commands/key.go index 91678f625f..b2674ca824 100644 --- a/cmd/commands/key.go +++ b/cmd/commands/key.go @@ -75,13 +75,14 @@ func (k *Key) Sign(msg []byte) crypto.Signature { // Generates a new validator with private key. func genKey() *Key { privKey := crypto.GenPrivKeyEd25519() - addrBytes := privKey.PubKey().Address() + pubKey := privKey.PubKey() + addrBytes := pubKey.Address() var addr Address copy(addr[:], addrBytes) return &Key{ Address: addr, - PubKey: crypto.PubKeyS{privKey.PubKey()}, - PrivKey: crypto.PrivKeyS{privKey}, + PubKey: pubKey, + PrivKey: privKey.Wrap(), } } diff --git a/glide.lock b/glide.lock index 579db86b76..493deda79d 100644 --- a/glide.lock +++ b/glide.lock @@ -86,7 +86,7 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: 17124989a93774833df33107fbf17157a7f8ef31 + version: a163fddbdd2541793d22402afb113e6ccb391774 subpackages: - upnp - name: github.com/tendermint/go-rpc @@ -107,7 +107,7 @@ imports: - app - client - name: github.com/tendermint/tendermint - version: 6bcd4242f1f336e2b2ef4f644fabaf56222b34d0 + version: 936e66867aecf92595b1f8615361b2867d9a69e6 subpackages: - blockchain - cmd/tendermint/commands diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 9439f43784..4b220f1890 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -30,7 +30,7 @@ func genGenesisDoc(chainID string, numVals int) (*tm.GenesisDoc, []types.PrivAcc name := cmn.Fmt("%v_val_%v", chainID, i) privAcc := types.PrivAccountFromSecret(name) genDoc.Validators = append(genDoc.Validators, tm.GenesisValidator{ - PubKey: privAcc.PubKey.PubKey, + PubKey: privAcc.PubKey, Amount: 1, Name: name, }) @@ -268,9 +268,9 @@ func TestIBCPluginBadCommit(t *testing.T) { // Update a chain with a broken commit // Modify the first byte of the first signature - sig := commit.Precommits[0].Signature.(crypto.SignatureEd25519) + sig := commit.Precommits[0].Signature.Unwrap().(crypto.SignatureEd25519) sig[0] += 1 - commit.Precommits[0].Signature = sig + commit.Precommits[0].Signature = crypto.WrapSignature(sig) res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ Header: header, Commit: commit, From b6ebf9f8b82a4b8f69bc2befaa0f9579b9e64e73 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 10 Apr 2017 16:32:30 +0200 Subject: [PATCH 04/67] Update to latest go-crypto, adjust code and tests --- cmd/commands/key.go | 6 +++--- cmd/commands/tx.go | 5 ++--- glide.lock | 37 ++++++++++++++------------------- glide.yaml | 2 +- plugins/counter/counter_test.go | 4 +--- plugins/ibc/ibc_test.go | 2 +- tests/tendermint/main.go | 7 +++---- tests/tmsp/tmsp_test.go | 7 +++---- types/test_helpers.go | 6 +++--- types/tx.go | 8 +++---- types/tx_test.go | 4 ++-- 11 files changed, 39 insertions(+), 49 deletions(-) diff --git a/cmd/commands/key.go b/cmd/commands/key.go index b2674ca824..e27a705ed5 100644 --- a/cmd/commands/key.go +++ b/cmd/commands/key.go @@ -62,9 +62,9 @@ func (a *Address) UnmarshalJSON(addrHex []byte) error { } type Key struct { - Address Address `json:"address"` - PubKey crypto.PubKeyS `json:"pub_key"` - PrivKey crypto.PrivKeyS `json:"priv_key"` + Address Address `json:"address"` + PubKey crypto.PubKey `json:"pub_key"` + PrivKey crypto.PrivKey `json:"priv_key"` } // Implements Signer diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 0fe0cd731b..73f81c6b18 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -8,7 +8,6 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/basecoin/types" - crypto "github.com/tendermint/go-crypto" client "github.com/tendermint/go-rpc/client" wire "github.com/tendermint/go-wire" @@ -123,7 +122,7 @@ func sendTxCmd(cmd *cobra.Command, args []string) error { // sign that puppy signBytes := tx.SignBytes(chainIDFlag) - tx.Inputs[0].Signature = crypto.WrapSignature(privKey.Sign(signBytes)) + tx.Inputs[0].Signature = privKey.Sign(signBytes) fmt.Println("Signed SendTx:") fmt.Println(string(wire.JSONBytes(tx))) @@ -179,7 +178,7 @@ func AppTx(name string, data []byte) error { Data: data, } - tx.Input.Signature = crypto.WrapSignature(privKey.Sign(tx.SignBytes(chainIDFlag))) + tx.Input.Signature = privKey.Sign(tx.SignBytes(chainIDFlag)) fmt.Println("Signed AppTx:") fmt.Println(string(wire.JSONBytes(tx))) diff --git a/glide.lock b/glide.lock index 493deda79d..0bf033970d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,18 +1,18 @@ -hash: c6e5febc35b5fd1003066820defb8a089db048b407239dad9faf44553fdc15e8 -updated: 2017-04-21T12:55:42.7004558-04:00 +hash: e7876b7cb70f79356bf2809547a78b1074b9f6f032e0ba861a65f8e7a6625832 +updated: 2017-04-10T20:27:50.460915186+02:00 imports: - name: github.com/btcsuite/btcd version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: - btcec - name: github.com/BurntSushi/toml - version: b26d9c308763d68093482582cea63d69be07a0f0 + version: 99064174e013895bbd9b025c31100bd1d9b590ca - name: github.com/ebuchman/fail-test version: 95f809107225be108efcf10a3509e4ea6ceef3c4 - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf - version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef + version: 69b215d01a5606c843240eab4937eab3acee6530 subpackages: - proto - ptypes/any @@ -25,15 +25,11 @@ imports: - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 - name: github.com/mattn/go-colorable - version: ded68f7a9561c023e790de24279db7ebf473ea80 + version: acb9493f2794fd0f820de7a27a217dafbb1b65ea - name: github.com/mattn/go-isatty - version: fc9e8d8ef48496124e79ae0df75490096eccf6fe + version: 9622e0cc9d8f9be434ca605520ff9a16808fee47 - name: github.com/pkg/errors - version: ff09b135c25aae272398c51a07235b90a75aa4f0 -- name: github.com/spf13/cobra - version: 10f6b9d7e1631a54ad07c5c0fb71c28a1abfd3c2 -- name: github.com/spf13/pflag - version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51 + version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -66,13 +62,13 @@ imports: - name: github.com/tendermint/go-clist version: 3baa390bbaf7634251c42ad69a8682e7e3990552 - name: github.com/tendermint/go-common - version: f9e3db037330c8a8d61d3966de8473eaf01154fa + version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 3e1dba7ab762bb689123eec30c468967f077a6a4 + version: c410fc5e246e9accf95c6e80cb3c6aca2280755c - name: github.com/tendermint/go-data - version: 9fbf0684fefc4fad580992394a0bcf47c1b3d77e + version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 - name: github.com/tendermint/go-db version: 9643f60bc2578693844aacf380a7c32e4c029fee - name: github.com/tendermint/go-events @@ -86,7 +82,7 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: a163fddbdd2541793d22402afb113e6ccb391774 + version: b5f314ffed65c81bd019ba1dd2bae0e95f3937f3 subpackages: - upnp - name: github.com/tendermint/go-rpc @@ -107,7 +103,7 @@ imports: - app - client - name: github.com/tendermint/tendermint - version: 936e66867aecf92595b1f8615361b2867d9a69e6 + version: c49b331ba8315725d213712ed0410b5c9eb5ba0f subpackages: - blockchain - cmd/tendermint/commands @@ -126,7 +122,7 @@ imports: - types - version - name: golang.org/x/crypto - version: 96846453c37f0876340a66a47f3f75b1f3a6cd2d + version: 40541ccb1c6e64c947ed6f606b8a6cb4b67d7436 subpackages: - curve25519 - nacl/box @@ -137,7 +133,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: c8c74377599bd978aee1cf3b9b63a8634051cec2 + version: d379faa25cbdc04d653984913a2ceb43b0bc46d7 subpackages: - context - http2 @@ -147,7 +143,7 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: ea9bcade75cb975a0b9738936568ab388b845617 + version: e48874b42435b4347fc52bdee0424a52abc974d7 subpackages: - unix - name: golang.org/x/text @@ -162,13 +158,12 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: 6914ab1e338c92da4218a23d27fcd03d0ad78d46 + version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98 subpackages: - codes - credentials - grpclog - internal - - keepalive - metadata - naming - peer diff --git a/glide.yaml b/glide.yaml index 87735c19c9..fb7d64d704 100644 --- a/glide.yaml +++ b/glide.yaml @@ -17,7 +17,7 @@ import: - package: github.com/tendermint/merkleeyes version: develop - package: github.com/tendermint/tendermint - version: develop + version: unstable - package: github.com/tendermint/abci version: develop - package: github.com/gorilla/websocket diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index 6d8168bd7b..f1c7d9d354 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -9,7 +9,6 @@ import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/app" "github.com/tendermint/basecoin/types" - crypto "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" eyescli "github.com/tendermint/merkleeyes/client" ) @@ -52,8 +51,7 @@ func TestCounterPlugin(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) // t.Logf("Sign bytes: %X\n", signBytes) - sig := test1PrivAcc.Sign(signBytes) - tx.Input.Signature = crypto.WrapSignature(sig) + tx.Input.Signature = test1PrivAcc.Sign(signBytes) // t.Logf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx})) // Write request diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 4b220f1890..16ea283b4e 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -270,7 +270,7 @@ func TestIBCPluginBadCommit(t *testing.T) { // Modify the first byte of the first signature sig := commit.Precommits[0].Signature.Unwrap().(crypto.SignatureEd25519) sig[0] += 1 - commit.Precommits[0].Signature = crypto.WrapSignature(sig) + commit.Precommits[0].Signature = sig.Wrap() res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ Header: header, Commit: commit, diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 53416c2357..fa58b8f009 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -7,8 +7,7 @@ import ( "github.com/gorilla/websocket" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" - crypto "github.com/tendermint/go-crypto" - rpcclient "github.com/tendermint/go-rpc/client" + "github.com/tendermint/go-rpc/client" "github.com/tendermint/go-rpc/types" wire "github.com/tendermint/go-wire" _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types @@ -67,7 +66,7 @@ func main() { // Sign request signBytes := tx.SignBytes(chainID) sig := root.Sign(signBytes) - tx.Inputs[0].Signature = crypto.WrapSignature(sig) + tx.Inputs[0].Signature = sig //fmt.Println("tx:", tx) // Write request @@ -118,7 +117,7 @@ func main() { // Sign request signBytes := tx.SignBytes(chainID) sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = crypto.WrapSignature(sig) + tx.Inputs[0].Signature = sig //fmt.Println("tx:", tx) // Write request diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index e78f978b2b..606b48e923 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -9,7 +9,6 @@ import ( "github.com/tendermint/basecoin/app" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" - crypto "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" eyescli "github.com/tendermint/merkleeyes/client" ) @@ -50,7 +49,7 @@ func TestSendTx(t *testing.T) { signBytes := tx.SignBytes(chainID) // t.Log("Sign bytes: %X\n", signBytes) sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = crypto.WrapSignature(sig) + tx.Inputs[0].Signature = sig // t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(types.TxS{tx})) // Write request @@ -102,7 +101,7 @@ func TestSequence(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = crypto.WrapSignature(sig) + tx.Inputs[0].Signature = sig // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request @@ -146,7 +145,7 @@ func TestSequence(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = crypto.WrapSignature(sig) + tx.Inputs[0].Signature = sig // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request diff --git a/types/test_helpers.go b/types/test_helpers.go index 23e46cdc9b..381ebda119 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -10,8 +10,8 @@ import ( // Creates a PrivAccount from secret. // The amount is not set. func PrivAccountFromSecret(secret string) PrivAccount { - privKey := crypto.WrapPrivKey( - crypto.GenPrivKeyEd25519FromSecret([]byte(secret))) + privKey := + crypto.GenPrivKeyEd25519FromSecret([]byte(secret)).Wrap() privAccount := PrivAccount{ PrivKey: privKey, Account: Account{ @@ -31,7 +31,7 @@ func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount { balance += cmn.RandInt64() % (maxAmount - minAmount) } - privKey := crypto.WrapPrivKey(crypto.GenPrivKeyEd25519()) + privKey := crypto.GenPrivKeyEd25519().Wrap() pubKey := privKey.PubKey() privAccs[i] = PrivAccount{ PrivKey: privKey, diff --git a/types/tx.go b/types/tx.go index f8366b0337..3b45a03646 100644 --- a/types/tx.go +++ b/types/tx.go @@ -104,7 +104,7 @@ func NewTxInput(pubKey crypto.PubKey, coins Coins, sequence int) TxInput { Sequence: sequence, } if sequence == 1 { - input.PubKey = crypto.WrapPubKey(pubKey) + input.PubKey = pubKey } return input } @@ -159,7 +159,7 @@ func (tx *SendTx) SignBytes(chainID string) []byte { func (tx *SendTx) SetSignature(addr []byte, sig crypto.Signature) bool { for i, input := range tx.Inputs { if bytes.Equal(input.Address, addr) { - tx.Inputs[i].Signature = crypto.WrapSignature(sig) + tx.Inputs[i].Signature = sig return true } } @@ -183,14 +183,14 @@ type AppTx struct { func (tx *AppTx) SignBytes(chainID string) []byte { signBytes := wire.BinaryBytes(chainID) sig := tx.Input.Signature - tx.Input.Signature = crypto.WrapSignature(nil) + tx.Input.Signature = crypto.Signature{} signBytes = append(signBytes, wire.BinaryBytes(tx)...) tx.Input.Signature = sig return signBytes } func (tx *AppTx) SetSignature(sig crypto.Signature) bool { - tx.Input.Signature = crypto.WrapSignature(sig) + tx.Input.Signature = sig return true } diff --git a/types/tx_test.go b/types/tx_test.go index fb4da2598d..72bc81ae4d 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - crypto "github.com/tendermint/go-crypto" + cmn "github.com/tendermint/go-common" data "github.com/tendermint/go-data" ) @@ -109,7 +109,7 @@ func TestSendTxJSON(t *testing.T) { sig := test1PrivAcc.Sign(signBytes) // we handle both raw sig and wrapped sig the same tx.SetSignature(test1PrivAcc.PubKey.Address(), sig) - tx2.SetSignature(test1PrivAcc.PubKey.Address(), crypto.WrapSignature(sig)) + tx2.SetSignature(test1PrivAcc.PubKey.Address(), sig) assert.Equal(tx, tx2) // let's marshal / unmarshal this with signature From 1a6fae6af6339ad616f2907df591370996155d5a Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 26 Apr 2017 01:08:31 -0400 Subject: [PATCH 05/67] update import paths for repo merge --- app/app.go | 2 +- app/genesis.go | 4 ++-- app/genesis_test.go | 4 ++-- app/log.go | 2 +- cmd/commands/ibc.go | 2 +- cmd/commands/init.go | 2 +- cmd/commands/log.go | 2 +- cmd/commands/query.go | 2 +- cmd/commands/start.go | 2 +- cmd/commands/tx.go | 2 +- cmd/commands/utils.go | 4 ++-- plugins/ibc/ibc.go | 4 ++-- plugins/ibc/ibc_test.go | 4 ++-- scripts/print_txs.go | 6 +++--- state/execution.go | 4 ++-- state/log.go | 2 +- state/state.go | 2 +- tests/tendermint/main.go | 6 +++--- tests/tmsp/tmsp_test.go | 2 +- types/kvstore.go | 2 +- types/test_helpers.go | 2 +- types/tx.go | 6 +++--- types/tx_test.go | 4 ++-- 23 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/app.go b/app/app.go index fe17736697..3a28f7f7ea 100644 --- a/app/app.go +++ b/app/app.go @@ -5,7 +5,7 @@ import ( "strings" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/go-common" + . "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" diff --git a/app/genesis.go b/app/genesis.go index ad8b2b6c9e..e4d838de2d 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -5,7 +5,7 @@ import ( "github.com/pkg/errors" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" //tmtypes "github.com/tendermint/tendermint/types" ) @@ -65,7 +65,7 @@ func loadGenesis(filePath string) (*FullGenesisDoc, error) { // tmGenesis := new(tmtypes.GenesisDoc) // err = wire.ReadJSONBytes(bytes, tmGenesis) - // the basecoin genesis go-data :) + // the basecoin genesis go-wire/data :) genDoc := new(FullGenesisDoc) err = json.Unmarshal(bytes, genDoc) if err != nil { diff --git a/app/genesis_test.go b/app/genesis_test.go index 4fec4b6db7..df47827465 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-crypto" eyescli "github.com/tendermint/merkleeyes/client" ) @@ -52,7 +52,7 @@ func TestParseGenesisList(t *testing.T) { bytes, err := cmn.ReadFile(genesisFilepath) require.Nil(err, "loading genesis file %+v", err) - // the basecoin genesis go-data :) + // the basecoin genesis go-wire/data :) genDoc := new(FullGenesisDoc) err = json.Unmarshal(bytes, genDoc) require.Nil(err, "unmarshaling genesis file %+v", err) diff --git a/app/log.go b/app/log.go index 52dc2ddfa4..1337bcdfc6 100644 --- a/app/log.go +++ b/app/log.go @@ -1,7 +1,7 @@ package app import ( - "github.com/tendermint/go-logger" + "github.com/tendermint/tmlibs/logger" ) var log = logger.New("module", "app") diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index 8b0938826b..bd3efe5ea8 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -10,7 +10,7 @@ import ( "github.com/tendermint/basecoin/plugins/ibc" - "github.com/tendermint/go-merkle" + "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" tmtypes "github.com/tendermint/tendermint/types" ) diff --git a/cmd/commands/init.go b/cmd/commands/init.go index f7fae72e6c..acd967dcda 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" ) //commands diff --git a/cmd/commands/log.go b/cmd/commands/log.go index 720e168b57..3300562c80 100644 --- a/cmd/commands/log.go +++ b/cmd/commands/log.go @@ -1,7 +1,7 @@ package commands import ( - "github.com/tendermint/go-logger" + "github.com/tendermint/tmlibs/logger" ) var log = logger.New("module", "commands") diff --git a/cmd/commands/query.go b/cmd/commands/query.go index 7d79c2f1f2..fa96756a42 100644 --- a/cmd/commands/query.go +++ b/cmd/commands/query.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/tendermint/go-merkle" + "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" tmtypes "github.com/tendermint/tendermint/types" ) diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 4578738ceb..340ee46c90 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/abci/server" - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" eyes "github.com/tendermint/merkleeyes/client" tmcfg "github.com/tendermint/tendermint/config/tendermint" diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 73f81c6b18..d8edcd08e6 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/basecoin/types" - client "github.com/tendermint/go-rpc/client" + client "github.com/tendermint/tendermint/rpc/client" wire "github.com/tendermint/go-wire" ctypes "github.com/tendermint/tendermint/rpc/core/types" ) diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index 0f263d82a8..e31847a899 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -14,8 +14,8 @@ import ( "github.com/tendermint/basecoin/types" abci "github.com/tendermint/abci/types" - cmn "github.com/tendermint/go-common" - client "github.com/tendermint/go-rpc/client" + cmn "github.com/tendermint/tmlibs/common" + client "github.com/tendermint/tendermint/rpc/client" wire "github.com/tendermint/go-wire" ctypes "github.com/tendermint/tendermint/rpc/core/types" tmtypes "github.com/tendermint/tendermint/types" diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 25f5a6da86..9f2bac6243 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -8,8 +8,8 @@ import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/go-common" - merkle "github.com/tendermint/go-merkle" + cmn "github.com/tendermint/tmlibs/common" + merkle "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" tm "github.com/tendermint/tendermint/types" ) diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 16ea283b4e..58c7086482 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" crypto "github.com/tendermint/go-crypto" - "github.com/tendermint/go-merkle" + "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" tm "github.com/tendermint/tendermint/types" diff --git a/scripts/print_txs.go b/scripts/print_txs.go index 689173a907..bf8ddce362 100644 --- a/scripts/print_txs.go +++ b/scripts/print_txs.go @@ -9,9 +9,9 @@ import ( "time" "github.com/gorilla/websocket" - cmn "github.com/tendermint/go-common" - "github.com/tendermint/go-rpc/client" - "github.com/tendermint/go-rpc/types" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tendermint/rpc/client" + "github.com/tendermint/tendermint/rpc/types" "github.com/tendermint/go-wire" _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types ) diff --git a/state/execution.go b/state/execution.go index f642b80521..c950a628e6 100644 --- a/state/execution.go +++ b/state/execution.go @@ -3,8 +3,8 @@ package state import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/go-common" - "github.com/tendermint/go-events" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/events" ) // If the tx is invalid, a TMSP error will be returned. diff --git a/state/log.go b/state/log.go index 5b102b5703..0a23513248 100644 --- a/state/log.go +++ b/state/log.go @@ -1,7 +1,7 @@ package state import ( - "github.com/tendermint/go-logger" + "github.com/tendermint/tmlibs/logger" ) var log = logger.New("module", "state") diff --git a/state/state.go b/state/state.go index 68a7c36243..5555dae913 100644 --- a/state/state.go +++ b/state/state.go @@ -3,7 +3,7 @@ package state import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - . "github.com/tendermint/go-common" + . "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" ) diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index fa58b8f009..137cd6c215 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -6,9 +6,9 @@ import ( "github.com/gorilla/websocket" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/go-common" - "github.com/tendermint/go-rpc/client" - "github.com/tendermint/go-rpc/types" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tendermint/rpc/client" + "github.com/tendermint/tendermint/rpc/types" wire "github.com/tendermint/go-wire" _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types ) diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index 606b48e923..0efb9143e3 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/basecoin/app" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-wire" eyescli "github.com/tendermint/merkleeyes/client" ) diff --git a/types/kvstore.go b/types/kvstore.go index 15088bdfb3..a795d7dd1f 100644 --- a/types/kvstore.go +++ b/types/kvstore.go @@ -4,7 +4,7 @@ import ( "container/list" "fmt" - . "github.com/tendermint/go-common" + . "github.com/tendermint/tmlibs/common" ) type KVStore interface { diff --git a/types/test_helpers.go b/types/test_helpers.go index 381ebda119..ccd46074ac 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -3,7 +3,7 @@ package types // Helper functions for testing import ( - cmn "github.com/tendermint/go-common" + cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-crypto" ) diff --git a/types/tx.go b/types/tx.go index 3b45a03646..7b1b547a0b 100644 --- a/types/tx.go +++ b/types/tx.go @@ -5,9 +5,9 @@ import ( "encoding/json" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/go-common" + . "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-crypto" - "github.com/tendermint/go-data" + "github.com/tendermint/go-wire/data" "github.com/tendermint/go-wire" ) @@ -37,7 +37,7 @@ func (_ *AppTx) AssertIsTx() {} var txMapper data.Mapper -// register both private key types with go-data (and thus go-wire) +// register both private key types with go-wire/data (and thus go-wire) func init() { txMapper = data.NewMapper(TxS{}). RegisterImplementation(&SendTx{}, TxNameSend, TxTypeSend). diff --git a/types/tx_test.go b/types/tx_test.go index 72bc81ae4d..092652d1b8 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - cmn "github.com/tendermint/go-common" - data "github.com/tendermint/go-data" + cmn "github.com/tendermint/tmlibs/common" + data "github.com/tendermint/go-wire/data" ) var chainID string = "test_chain" From acc9a79daa8f82c5bc33e95a1e5f5fa147c95ec1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 26 Apr 2017 01:20:16 -0400 Subject: [PATCH 06/67] glide update --- glide.lock | 136 +++++++++++++++++++++++++++++++---------------------- glide.yaml | 44 ++++++++++++----- 2 files changed, 113 insertions(+), 67 deletions(-) diff --git a/glide.lock b/glide.lock index 0bf033970d..72ae44cf98 100644 --- a/glide.lock +++ b/glide.lock @@ -1,35 +1,68 @@ -hash: e7876b7cb70f79356bf2809547a78b1074b9f6f032e0ba861a65f8e7a6625832 -updated: 2017-04-10T20:27:50.460915186+02:00 +hash: 5c7309b2f219a9bb24b39b57531478ee12341c358d373ee070ff0381fcb92752 +updated: 2017-04-26T01:15:31.969288035-04:00 imports: - name: github.com/btcsuite/btcd version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: - btcec -- name: github.com/BurntSushi/toml - version: 99064174e013895bbd9b025c31100bd1d9b590ca - name: github.com/ebuchman/fail-test version: 95f809107225be108efcf10a3509e4ea6ceef3c4 +- name: github.com/fsnotify/fsnotify + version: 4da3e2cfbabc9f751898f250b49f2439785783a1 - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf - version: 69b215d01a5606c843240eab4937eab3acee6530 + version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef subpackages: - proto - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/gorilla/websocket - version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13 + version: a91eba7f97777409bc2c443f5534d41dd20c5720 +- name: github.com/hashicorp/hcl + version: 7fa7fff964d035e8a162cce3a164b3ad02ad651b + subpackages: + - hcl/ast + - hcl/parser + - hcl/scanner + - hcl/strconv + - hcl/token + - json/parser + - json/scanner + - json/token - name: github.com/inconshreveable/mousetrap version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 +- name: github.com/magiconair/properties + version: 51463bfca2576e06c62a8504b5c0f06d61312647 - name: github.com/mattn/go-colorable - version: acb9493f2794fd0f820de7a27a217dafbb1b65ea + version: ded68f7a9561c023e790de24279db7ebf473ea80 - name: github.com/mattn/go-isatty - version: 9622e0cc9d8f9be434ca605520ff9a16808fee47 + version: fc9e8d8ef48496124e79ae0df75490096eccf6fe +- name: github.com/mitchellh/mapstructure + version: cc8532a8e9a55ea36402aa21efdf403a60d34096 +- name: github.com/pelletier/go-buffruneio + version: c37440a7cf42ac63b919c752ca73a85067e05992 +- name: github.com/pelletier/go-toml + version: fe206efb84b2bc8e8cfafe6b4c1826622be969e3 - name: github.com/pkg/errors - version: 645ef00459ed84a119197bfb8d8205042c6df63d + version: ff09b135c25aae272398c51a07235b90a75aa4f0 +- name: github.com/spf13/afero + version: 9be650865eab0c12963d8753212f4f9c66cdcf12 + subpackages: + - mem +- name: github.com/spf13/cast + version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 +- name: github.com/spf13/cobra + version: 6ed17b5128e8932c9ecd4c3970e8ea5e60a418ac +- name: github.com/spf13/jwalterweatherman + version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 +- name: github.com/spf13/pflag + version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51 +- name: github.com/spf13/viper + version: 0967fc9aceab2ce9da34061253ac10fb99bba5b2 - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -46,7 +79,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 56e13d87f4e3ec1ea756957d6b23caa6ebcf0998 + version: c709d3cc857929a8dd36a90da3640122d7e75770 subpackages: - client - example/dummy @@ -57,53 +90,24 @@ imports: subpackages: - edwards25519 - extra25519 -- name: github.com/tendermint/go-autofile - version: 48b17de82914e1ec2f134ce823ba426337d2c518 -- name: github.com/tendermint/go-clist - version: 3baa390bbaf7634251c42ad69a8682e7e3990552 -- name: github.com/tendermint/go-common - version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c -- name: github.com/tendermint/go-config - version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: c410fc5e246e9accf95c6e80cb3c6aca2280755c -- name: github.com/tendermint/go-data - version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 -- name: github.com/tendermint/go-db - version: 9643f60bc2578693844aacf380a7c32e4c029fee -- name: github.com/tendermint/go-events - version: f8ffbfb2be3483e9e7927495590a727f51c0c11f -- name: github.com/tendermint/go-flowrate - version: a20c98e61957faa93b4014fbd902f20ab9317a6a - subpackages: - - flowrate -- name: github.com/tendermint/go-logger - version: cefb3a45c0bf3c493a04e9bcd9b1540528be59f2 -- name: github.com/tendermint/go-merkle - version: 714d4d04557fd068a7c2a1748241ce8428015a96 -- name: github.com/tendermint/go-p2p - version: b5f314ffed65c81bd019ba1dd2bae0e95f3937f3 - subpackages: - - upnp -- name: github.com/tendermint/go-rpc - version: 559613689d56eaa423b19a3a4158546beb4857de - subpackages: - - client - - server - - types + version: 9b95da8fa4187f6799558d89b271dc8ab6485615 - name: github.com/tendermint/go-wire - version: c1c9a57ab8038448ddea1714c0698f8051e5748c + version: 334005c236d19c632fb5f073f9de3b0fab6a522b + subpackages: + - data - name: github.com/tendermint/log15 version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: - term - name: github.com/tendermint/merkleeyes - version: 9fb76efa5aebe773a598f97e68e75fe53d520e70 + version: 6fd69aa0871a4e685a5570aa7ab3d12e4068a722 subpackages: - app - client + - iavl - name: github.com/tendermint/tendermint - version: c49b331ba8315725d213712ed0410b5c9eb5ba0f + version: 098646c5ff604705b7b082a89227ee78f3547fed subpackages: - blockchain - cmd/tendermint/commands @@ -111,18 +115,36 @@ imports: - consensus - mempool - node + - p2p + - p2p/upnp - proxy - - rpc/core + - rpc + - rpc/client - rpc/core/types - - rpc/grpc + - rpc/server + - rpc/tendermint/core + - rpc/tendermint/core/types + - rpc/tendermint/grpc + - rpc/types - state - state/txindex - state/txindex/kv - state/txindex/null - types - version +- name: github.com/tendermint/tmlibs + version: df250b69416a35a943a6e2a92118667e9ef031d4 + subpackages: + - autofile + - clist + - common + - db + - events + - flowrate + - logger + - merkle - name: golang.org/x/crypto - version: 40541ccb1c6e64c947ed6f606b8a6cb4b67d7436 + version: c7af5bf2638a1164f2eb5467c39c6cffbd13a02e subpackages: - curve25519 - nacl/box @@ -133,7 +155,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: d379faa25cbdc04d653984913a2ceb43b0bc46d7 + version: da118f7b8e5954f39d0d2130ab35d4bf0e3cb344 subpackages: - context - http2 @@ -143,11 +165,11 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: e48874b42435b4347fc52bdee0424a52abc974d7 + version: 9f30dcbe5be197894515a338a9bda9253567ea8f subpackages: - unix - name: golang.org/x/text - version: 19e3104b43db45fca0303f489a9536087b184802 + version: a9a820217f98f7c8a207ec1e45a874e1fe12c478 subpackages: - secure/bidirule - transform @@ -158,12 +180,14 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98 + version: c73e0165df8e5495c523feb93a8a6c19b9452817 subpackages: - codes - credentials + - grpclb/grpc_lb_v1 - grpclog - internal + - keepalive - metadata - naming - peer @@ -171,9 +195,11 @@ imports: - status - tap - transport +- name: gopkg.in/yaml.v2 + version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: - name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 + version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -181,7 +207,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 + version: 4d4bfba8f1d1027c4fdbe371823030df51419987 subpackages: - assert - require diff --git a/glide.yaml b/glide.yaml index fb7d64d704..fd91126b45 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,24 +1,44 @@ package: github.com/tendermint/basecoin import: -- package: github.com/tendermint/go-common +- package: github.com/gorilla/websocket +- package: github.com/pkg/errors +- package: github.com/spf13/cobra +- package: github.com/spf13/pflag +- package: github.com/tendermint/abci version: develop + subpackages: + - server + - types - package: github.com/tendermint/go-crypto version: develop -- package: github.com/tendermint/go-events - version: develop -- package: github.com/tendermint/go-logger - version: develop -- package: github.com/tendermint/go-data - version: develop -- package: github.com/tendermint/go-rpc - version: develop - package: github.com/tendermint/go-wire version: develop + subpackages: + - data - package: github.com/tendermint/merkleeyes version: develop + subpackages: + - client + - iavl - package: github.com/tendermint/tendermint version: unstable -- package: github.com/tendermint/abci + subpackages: + - cmd/tendermint/commands + - config/tendermint + - node + - proxy + - rpc/client + - rpc/core/types + - rpc/types + - types +- package: github.com/tendermint/tmlibs version: develop -- package: github.com/gorilla/websocket - version: v1.1.0 + subpackages: + - common + - events + - logger +testImport: +- package: github.com/stretchr/testify + subpackages: + - assert + - require From 9c391a08a96d9f016b6529cb79856a6cf25cc968 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 26 Apr 2017 01:20:29 -0400 Subject: [PATCH 07/67] fix some imports --- cmd/commands/ibc.go | 4 ++-- cmd/commands/query.go | 4 ++-- cmd/commands/tx.go | 2 +- cmd/commands/utils.go | 2 +- plugins/ibc/ibc_test.go | 8 ++++---- scripts/print_txs.go | 2 +- tests/tendermint/main.go | 2 +- types/test_helpers.go | 4 ++-- types/tx_test.go | 1 - 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index bd3efe5ea8..fa6d4758cc 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -10,8 +10,8 @@ import ( "github.com/tendermint/basecoin/plugins/ibc" - "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" + "github.com/tendermint/merkleeyes/iavl" tmtypes "github.com/tendermint/tendermint/types" ) @@ -229,7 +229,7 @@ func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) error { } var packet ibc.Packet - proof := new(merkle.IAVLProof) + proof := new(iavl.IAVLProof) err = wire.ReadBinaryBytes(packetBytes, &packet) if err != nil { diff --git a/cmd/commands/query.go b/cmd/commands/query.go index fa96756a42..1b46a6617a 100644 --- a/cmd/commands/query.go +++ b/cmd/commands/query.go @@ -8,8 +8,8 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" + "github.com/tendermint/merkleeyes/iavl" tmtypes "github.com/tendermint/tendermint/types" ) @@ -202,7 +202,7 @@ func verifyCmd(cmd *cobra.Command, args []string) error { return errors.Errorf("Proof (%v) is invalid hex: %v\n", proofFlag, err) } - proof, err := merkle.ReadProof(proofBytes) + proof, err := iavl.ReadProof(proofBytes) if err != nil { return errors.Errorf("Error unmarshalling proof: %v\n", err) } diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index d8edcd08e6..0ee0896b01 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -11,7 +11,7 @@ import ( client "github.com/tendermint/tendermint/rpc/client" wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" + ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" ) //commands diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index e31847a899..b0e8b2cc89 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -17,7 +17,7 @@ import ( cmn "github.com/tendermint/tmlibs/common" client "github.com/tendermint/tendermint/rpc/client" wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" + ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" tmtypes "github.com/tendermint/tendermint/types" ) diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 58c7086482..53864e62cf 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -9,12 +9,12 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/tmlibs/common" crypto "github.com/tendermint/go-crypto" - "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" + "github.com/tendermint/merkleeyes/iavl" tm "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" ) // NOTE: PrivAccounts are sorted by Address, @@ -192,7 +192,7 @@ func TestIBCPlugin(t *testing.T) { Prove: true, }) assert.Nil(err) - var proof *merkle.IAVLProof + var proof *iavl.IAVLProof err = wire.ReadBinaryBytes(resQuery.Proof, &proof) assert.Nil(err) @@ -379,7 +379,7 @@ func TestIBCPluginBadProof(t *testing.T) { Prove: true, }) assert.Nil(err) - var proof *merkle.IAVLProof + var proof *iavl.IAVLProof err = wire.ReadBinaryBytes(resQuery.Proof, &proof) assert.Nil(err) diff --git a/scripts/print_txs.go b/scripts/print_txs.go index bf8ddce362..de3a2ebd9b 100644 --- a/scripts/print_txs.go +++ b/scripts/print_txs.go @@ -13,7 +13,7 @@ import ( "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/types" "github.com/tendermint/go-wire" - _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types + _ "github.com/tendermint/tendermint/rpc/tendermint/core/types" // Register RPCResponse > Result types ) func main() { diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 137cd6c215..0d994d45eb 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -10,7 +10,7 @@ import ( "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/types" wire "github.com/tendermint/go-wire" - _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types + _ "github.com/tendermint/tendermint/rpc/tendermint/core/types" // Register RPCResponse > Result types ) func main() { diff --git a/types/test_helpers.go b/types/test_helpers.go index ccd46074ac..ffd3ce931f 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -3,8 +3,8 @@ package types // Helper functions for testing import ( - cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-crypto" + cmn "github.com/tendermint/tmlibs/common" ) // Creates a PrivAccount from secret. @@ -100,6 +100,6 @@ func GetTx(seq int, accOut PrivAccount, accsIn ...PrivAccount) *SendTx { func SignTx(chainID string, tx *SendTx, accs ...PrivAccount) { signBytes := tx.SignBytes(chainID) for i, _ := range tx.Inputs { - tx.Inputs[i].Signature = crypto.SignatureS{accs[i].Sign(signBytes)} + tx.Inputs[i].Signature = accs[i].Sign(signBytes) } } diff --git a/types/tx_test.go b/types/tx_test.go index 092652d1b8..79ce9b90a3 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - cmn "github.com/tendermint/tmlibs/common" data "github.com/tendermint/go-wire/data" ) From e4be4dd7ce723cabce58d052cad248c1ad9b23f1 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 27 Apr 2017 16:12:01 +0200 Subject: [PATCH 08/67] Tendermint dependency now latest develop, not unstable --- glide.lock | 8 ++++---- glide.yaml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/glide.lock b/glide.lock index 72ae44cf98..5b75d07098 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 5c7309b2f219a9bb24b39b57531478ee12341c358d373ee070ff0381fcb92752 -updated: 2017-04-26T01:15:31.969288035-04:00 +hash: 782a5a86373a2d9521fc03129ce6c6ee6c7ab7ffcdaf0d0afb7fecc5e2cfdb97 +updated: 2017-04-27T16:08:07.098092597+02:00 imports: - name: github.com/btcsuite/btcd version: 4b348c1d33373d672edd83fc576892d0e46686d2 @@ -107,7 +107,7 @@ imports: - client - iavl - name: github.com/tendermint/tendermint - version: 098646c5ff604705b7b082a89227ee78f3547fed + version: 1781a521470f47872876b031d2c6098be4c9c7e9 subpackages: - blockchain - cmd/tendermint/commands @@ -120,8 +120,8 @@ imports: - proxy - rpc - rpc/client - - rpc/core/types - rpc/server + - rpc/tendermint/client - rpc/tendermint/core - rpc/tendermint/core/types - rpc/tendermint/grpc diff --git a/glide.yaml b/glide.yaml index fd91126b45..1e3270fdd0 100644 --- a/glide.yaml +++ b/glide.yaml @@ -21,14 +21,14 @@ import: - client - iavl - package: github.com/tendermint/tendermint - version: unstable + version: develop subpackages: - cmd/tendermint/commands - config/tendermint - node - proxy - - rpc/client - - rpc/core/types + - rpc/tendermint/core/types + - rpc/tendermint/client - rpc/types - types - package: github.com/tendermint/tmlibs From 525cb4c80b56de52715b80b0766c68aa7be20c31 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 27 Apr 2017 12:52:47 -0400 Subject: [PATCH 09/67] fix tendermint rpc link --- cmd/commands/tx.go | 4 ++-- cmd/commands/utils.go | 4 ++-- glide.lock | 48 +++++++++++++++++++--------------------- glide.yaml | 6 ++--- scripts/print_txs.go | 6 ++--- tests/tendermint/main.go | 6 ++--- 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 0ee0896b01..2982328064 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -9,9 +9,9 @@ import ( "github.com/tendermint/basecoin/types" - client "github.com/tendermint/tendermint/rpc/client" + client "github.com/tendermint/tendermint/rpc/lib/client" wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" + ctypes "github.com/tendermint/tendermint/rpc/core/types" ) //commands diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index b0e8b2cc89..7b43ce9a90 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -15,9 +15,9 @@ import ( abci "github.com/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" - client "github.com/tendermint/tendermint/rpc/client" + client "github.com/tendermint/tendermint/rpc/lib/client" wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types" + ctypes "github.com/tendermint/tendermint/rpc/core/types" tmtypes "github.com/tendermint/tendermint/types" ) diff --git a/glide.lock b/glide.lock index 5b75d07098..f6772847ae 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 782a5a86373a2d9521fc03129ce6c6ee6c7ab7ffcdaf0d0afb7fecc5e2cfdb97 -updated: 2017-04-27T16:08:07.098092597+02:00 +hash: ab7d4136802bfb9c56c25d6c384ce65891adfda2f2fc338fb4532ecc8e85ad40 +updated: 2017-04-27T12:49:42.595893036-04:00 imports: - name: github.com/btcsuite/btcd version: 4b348c1d33373d672edd83fc576892d0e46686d2 @@ -19,9 +19,9 @@ imports: - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/gorilla/websocket - version: a91eba7f97777409bc2c443f5534d41dd20c5720 + version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13 - name: github.com/hashicorp/hcl - version: 7fa7fff964d035e8a162cce3a164b3ad02ad651b + version: 630949a3c5fa3c613328e1b8256052cbc2327c9b subpackages: - hcl/ast - hcl/parser @@ -42,11 +42,11 @@ imports: - name: github.com/mattn/go-isatty version: fc9e8d8ef48496124e79ae0df75490096eccf6fe - name: github.com/mitchellh/mapstructure - version: cc8532a8e9a55ea36402aa21efdf403a60d34096 + version: 53818660ed4955e899c0bcafa97299a388bd7c8e - name: github.com/pelletier/go-buffruneio version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: fe206efb84b2bc8e8cfafe6b4c1826622be969e3 + version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors version: ff09b135c25aae272398c51a07235b90a75aa4f0 - name: github.com/spf13/afero @@ -56,13 +56,13 @@ imports: - name: github.com/spf13/cast version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra - version: 6ed17b5128e8932c9ecd4c3970e8ea5e60a418ac + version: 10f6b9d7e1631a54ad07c5c0fb71c28a1abfd3c2 - name: github.com/spf13/jwalterweatherman version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 - name: github.com/spf13/pflag version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51 - name: github.com/spf13/viper - version: 0967fc9aceab2ce9da34061253ac10fb99bba5b2 + version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -107,7 +107,7 @@ imports: - client - iavl - name: github.com/tendermint/tendermint - version: 1781a521470f47872876b031d2c6098be4c9c7e9 + version: 1310c7264750efa8939680536098ded9f9e8df74 subpackages: - blockchain - cmd/tendermint/commands @@ -118,14 +118,13 @@ imports: - p2p - p2p/upnp - proxy - - rpc - - rpc/client - - rpc/server - - rpc/tendermint/client - - rpc/tendermint/core - - rpc/tendermint/core/types - - rpc/tendermint/grpc - - rpc/types + - rpc/core + - rpc/core/types + - rpc/grpc + - rpc/lib + - rpc/lib/client + - rpc/lib/server + - rpc/lib/types - state - state/txindex - state/txindex/kv @@ -144,7 +143,7 @@ imports: - logger - merkle - name: golang.org/x/crypto - version: c7af5bf2638a1164f2eb5467c39c6cffbd13a02e + version: 96846453c37f0876340a66a47f3f75b1f3a6cd2d subpackages: - curve25519 - nacl/box @@ -155,7 +154,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: da118f7b8e5954f39d0d2130ab35d4bf0e3cb344 + version: c8c74377599bd978aee1cf3b9b63a8634051cec2 subpackages: - context - http2 @@ -165,11 +164,11 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: 9f30dcbe5be197894515a338a9bda9253567ea8f + version: ea9bcade75cb975a0b9738936568ab388b845617 subpackages: - unix - name: golang.org/x/text - version: a9a820217f98f7c8a207ec1e45a874e1fe12c478 + version: 19e3104b43db45fca0303f489a9536087b184802 subpackages: - secure/bidirule - transform @@ -180,11 +179,10 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: c73e0165df8e5495c523feb93a8a6c19b9452817 + version: 6914ab1e338c92da4218a23d27fcd03d0ad78d46 subpackages: - codes - credentials - - grpclb/grpc_lb_v1 - grpclog - internal - keepalive @@ -199,7 +197,7 @@ imports: version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: - name: github.com/davecgh/go-spew - version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 + version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -207,7 +205,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 4d4bfba8f1d1027c4fdbe371823030df51419987 + version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require diff --git a/glide.yaml b/glide.yaml index 1e3270fdd0..e232139b58 100644 --- a/glide.yaml +++ b/glide.yaml @@ -27,9 +27,9 @@ import: - config/tendermint - node - proxy - - rpc/tendermint/core/types - - rpc/tendermint/client - - rpc/types + - rpc/core/types + - rpc/lib/client + - rpc/lib/types - types - package: github.com/tendermint/tmlibs version: develop diff --git a/scripts/print_txs.go b/scripts/print_txs.go index de3a2ebd9b..d31e70ffa5 100644 --- a/scripts/print_txs.go +++ b/scripts/print_txs.go @@ -10,10 +10,10 @@ import ( "github.com/gorilla/websocket" cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tendermint/rpc/client" - "github.com/tendermint/tendermint/rpc/types" + "github.com/tendermint/tendermint/rpc/lib/client" + "github.com/tendermint/tendermint/rpc/lib/types" "github.com/tendermint/go-wire" - _ "github.com/tendermint/tendermint/rpc/tendermint/core/types" // Register RPCResponse > Result types + _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types ) func main() { diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 0d994d45eb..1213cc4c57 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -7,10 +7,10 @@ import ( "github.com/gorilla/websocket" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tendermint/rpc/client" - "github.com/tendermint/tendermint/rpc/types" + "github.com/tendermint/tendermint/rpc/lib/client" + "github.com/tendermint/tendermint/rpc/lib/types" wire "github.com/tendermint/go-wire" - _ "github.com/tendermint/tendermint/rpc/tendermint/core/types" // Register RPCResponse > Result types + _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types ) func main() { From b02bc358b16a9562a6463382829fa1d1fc2c7291 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 27 Apr 2017 21:14:40 +0200 Subject: [PATCH 10/67] Update basecoin init configs for tendermint 0.10 --- cmd/commands/init.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/commands/init.go b/cmd/commands/init.go index acd967dcda..3c8a5a8a35 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -76,14 +76,14 @@ var PrivValJSON = `{ "last_signature": null, "last_signbytes": "", "last_step": 0, - "priv_key": [ - 1, - "D07ABE82A8B15559A983B2DB5D4842B2B6E4D6AF58B080005662F424F17D68C17B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" - ], - "pub_key": [ - 1, - "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" - ] + "priv_key": { + "type": "ed25519", + "data": "D07ABE82A8B15559A983B2DB5D4842B2B6E4D6AF58B080005662F424F17D68C17B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + }, + "pub_key": { + "type": "ed25519", + "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + } }` var GenesisJSON = `{ @@ -94,10 +94,10 @@ var GenesisJSON = `{ { "amount": 10, "name": "", - "pub_key": [ - 1, - "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" - ] + "pub_key": { + "type": "ed25519", + "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + } } ], "app_options": { From b907d34dea3fae754a10136704ce6ec9781318e7 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 27 Apr 2017 23:17:06 +0200 Subject: [PATCH 11/67] Imported basecli wholesale --- cmd/basecli/adapters.go | 156 ++++++++++++++++++++++++++++++++++++++++ cmd/basecli/main.go | 47 ++++++++++++ cmd/basecli/sendtx.go | 60 ++++++++++++++++ glide.lock | 55 ++++++++++++-- glide.yaml | 13 ++++ 5 files changed, 326 insertions(+), 5 deletions(-) create mode 100644 cmd/basecli/adapters.go create mode 100644 cmd/basecli/main.go create mode 100644 cmd/basecli/sendtx.go diff --git a/cmd/basecli/adapters.go b/cmd/basecli/adapters.go new file mode 100644 index 0000000000..b0b10d2fc4 --- /dev/null +++ b/cmd/basecli/adapters.go @@ -0,0 +1,156 @@ +package main + +import ( + "encoding/hex" + "encoding/json" + + "github.com/pkg/errors" + flag "github.com/spf13/pflag" + "github.com/spf13/viper" + btypes "github.com/tendermint/basecoin/types" + keycmd "github.com/tendermint/go-crypto/cmd" + wire "github.com/tendermint/go-wire" + lightclient "github.com/tendermint/light-client" + "github.com/tendermint/light-client/commands" + "github.com/tendermint/light-client/proofs" +) + +type AccountPresenter struct{} + +func (_ AccountPresenter) MakeKey(str string) ([]byte, error) { + res, err := hex.DecodeString(str) + if err == nil { + res = append([]byte("base/a/"), res...) + } + return res, err +} + +func (_ AccountPresenter) ParseData(raw []byte) (interface{}, error) { + var acc *btypes.Account + err := wire.ReadBinaryBytes(raw, &acc) + return acc, err +} + +type BaseTxPresenter struct { + proofs.RawPresenter // this handles MakeKey as hex bytes +} + +func (_ BaseTxPresenter) ParseData(raw []byte) (interface{}, error) { + var tx btypes.TxS + err := wire.ReadBinaryBytes(raw, &tx) + return tx, err +} + +// SendTXReader allows us to create SendTx +type SendTxReader struct { + ChainID string +} + +func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { + var tx btypes.SendTx + err := json.Unmarshal(data, &tx) + send := SendTx{ + chainID: t.ChainID, + Tx: &tx, + } + return &send, errors.Wrap(err, "parse sendtx") +} + +type SendTxMaker struct{} + +func (m SendTxMaker) MakeReader() (lightclient.TxReader, error) { + chainID := viper.GetString(commands.ChainFlag) + return SendTxReader{ChainID: chainID}, nil +} + +type SendFlags struct { + To string + Amount string + Fee string + Gas int64 + Sequence int +} + +func (m SendTxMaker) Flags() (*flag.FlagSet, interface{}) { + fs := flag.NewFlagSet("foobar", flag.ContinueOnError) + fs.String("to", "", "Destination address for the bits") + fs.String("amount", "", "Coins to send in the format ,...") + fs.String("fee", "", "Coins for the transaction fee of the format ") + fs.Int64("gas", 0, "Amount of gas for this transaction") + fs.Int("sequence", -1, "Sequence number for this transaction") + return fs, &SendFlags{} +} + +func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { + data := flags.(*SendFlags) + + // parse to and from addresses + to, err := hex.DecodeString(StripHex(data.To)) + if err != nil { + return nil, errors.Errorf("To address is invalid hex: %v\n", err) + } + + // TODO: figure out a cleaner way to do this... until then + // just close your eyes and continue... + manager := keycmd.GetKeyManager() + name := viper.GetString("name") + info, err := manager.Get(name) + + //parse the fee and amounts into coin types + feeCoin, err := btypes.ParseCoin(data.Fee) + if err != nil { + return nil, err + } + amountCoins, err := btypes.ParseCoins(data.Amount) + if err != nil { + return nil, err + } + + // craft the tx + input := btypes.TxInput{ + Address: info.Address, + Coins: amountCoins, + Sequence: data.Sequence, + } + if data.Sequence == 1 { + input.PubKey = info.PubKey + } + output := btypes.TxOutput{ + Address: to, + Coins: amountCoins, + } + tx := btypes.SendTx{ + Gas: data.Gas, + Fee: feeCoin, + Inputs: []btypes.TxInput{input}, + Outputs: []btypes.TxOutput{output}, + } + + // wrap it in the proper signer thing... + send := SendTx{ + chainID: t.ChainID, + Tx: &tx, + } + return &send, nil +} + +/** copied from basecoin cli - put in common somewhere? **/ + +// Returns true for non-empty hex-string prefixed with "0x" +func isHex(s string) bool { + if len(s) > 2 && s[:2] == "0x" { + _, err := hex.DecodeString(s[2:]) + if err != nil { + return false + } + return true + } + return false +} + +func StripHex(s string) string { + if isHex(s) { + return s[2:] + } + return s +} diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go new file mode 100644 index 0000000000..2ecb8c75ea --- /dev/null +++ b/cmd/basecli/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "os" + + "github.com/spf13/cobra" + keycmd "github.com/tendermint/go-crypto/cmd" + "github.com/tendermint/light-client/commands" + "github.com/tendermint/light-client/commands/proofs" + "github.com/tendermint/light-client/commands/seeds" + "github.com/tendermint/light-client/commands/txs" +) + +// BaseCli represents the base command when called without any subcommands +var BaseCli = &cobra.Command{ + Use: "basecli", + Short: "Light client for tendermint", + Long: `Basecli is an version of tmcli including custom logic to +present a nice (not raw hex) interface to the basecoin blockchain structure. + +This is a useful tool, but also serves to demonstrate how one can configure +tmcli to work for any custom abci app. +`, +} + +func init() { + commands.AddBasicFlags(BaseCli) + + // set up the various commands to use + BaseCli.AddCommand(keycmd.RootCmd) + BaseCli.AddCommand(commands.InitCmd) + BaseCli.AddCommand(seeds.RootCmd) + proofs.StatePresenters.Register("account", AccountPresenter{}) + proofs.TxPresenters.Register("base", BaseTxPresenter{}) + BaseCli.AddCommand(proofs.RootCmd) + txs.Register("send", SendTxMaker{}) + BaseCli.AddCommand(txs.RootCmd) +} + +func main() { + keycmd.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli")) + BaseCli.Execute() + // err := BaseCli.Execute() + // if err != nil { + // fmt.Printf("%+v\n", err) + // } +} diff --git a/cmd/basecli/sendtx.go b/cmd/basecli/sendtx.go new file mode 100644 index 0000000000..5f0ae78882 --- /dev/null +++ b/cmd/basecli/sendtx.go @@ -0,0 +1,60 @@ +package main + +import ( + "github.com/pkg/errors" + bc "github.com/tendermint/basecoin/types" + crypto "github.com/tendermint/go-crypto" + keys "github.com/tendermint/go-crypto/keys" + wire "github.com/tendermint/go-wire" +) + +type SendTx struct { + chainID string + signers []crypto.PubKey + Tx *bc.SendTx +} + +var _ keys.Signable = &SendTx{} + +// SignBytes returned the unsigned bytes, needing a signature +func (s *SendTx) SignBytes() []byte { + return s.Tx.SignBytes(s.chainID) +} + +// Sign will add a signature and pubkey. +// +// Depending on the Signable, one may be able to call this multiple times for multisig +// Returns error if called with invalid data or too many times +func (s *SendTx) Sign(pubkey crypto.PubKey, sig crypto.Signature) error { + addr := pubkey.Address() + set := s.Tx.SetSignature(addr, sig) + if !set { + return errors.Errorf("Cannot add signature for address %X", addr) + } + s.signers = append(s.signers, pubkey) + return nil +} + +// Signers will return the public key(s) that signed if the signature +// is valid, or an error if there is any issue with the signature, +// including if there are no signatures +func (s *SendTx) Signers() ([]crypto.PubKey, error) { + if len(s.signers) == 0 { + return nil, errors.New("No signatures on SendTx") + } + return s.signers, nil +} + +// TxBytes returns the transaction data as well as all signatures +// It should return an error if Sign was never called +func (s *SendTx) TxBytes() ([]byte, error) { + // TODO: verify it is signed + + // Code and comment from: basecoin/cmd/commands/tx.go + // Don't you hate having to do this? + // How many times have I lost an hour over this trick?! + txBytes := wire.BinaryBytes(struct { + bc.Tx `json:"unwrap"` + }{s.Tx}) + return txBytes, nil +} diff --git a/glide.lock b/glide.lock index f6772847ae..553f293582 100644 --- a/glide.lock +++ b/glide.lock @@ -1,6 +1,8 @@ -hash: ab7d4136802bfb9c56c25d6c384ce65891adfda2f2fc338fb4532ecc8e85ad40 -updated: 2017-04-27T12:49:42.595893036-04:00 +hash: f4077fecc95e11f007adea022a38441a2e1c5d51d75ebab0fc9a296052ee5a6b +updated: 2017-04-27T23:14:26.934716255+02:00 imports: +- name: github.com/bgentry/speakeasy + version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd - name: github.com/btcsuite/btcd version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: @@ -9,6 +11,12 @@ imports: version: 95f809107225be108efcf10a3509e4ea6ceef3c4 - name: github.com/fsnotify/fsnotify version: 4da3e2cfbabc9f751898f250b49f2439785783a1 +- name: github.com/go-playground/locales + version: 1e5f1161c6416a5ff48840eb8724a394e48cc534 + subpackages: + - currency +- name: github.com/go-playground/universal-translator + version: 71201497bace774495daed26a3874fd339e0b538 - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf @@ -18,6 +26,12 @@ imports: - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 +- name: github.com/gorilla/context + version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 +- name: github.com/gorilla/handlers + version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221 +- name: github.com/gorilla/mux + version: 392c28fe23e1c45ddba891b0320b3b5df220beea - name: github.com/gorilla/websocket version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13 - name: github.com/hashicorp/hcl @@ -48,7 +62,7 @@ imports: - name: github.com/pelletier/go-toml version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors - version: ff09b135c25aae272398c51a07235b90a75aa4f0 + version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/spf13/afero version: 9be650865eab0c12963d8753212f4f9c66cdcf12 subpackages: @@ -90,18 +104,46 @@ imports: subpackages: - edwards25519 - extra25519 +- name: github.com/tendermint/go-common + version: f9e3db037330c8a8d61d3966de8473eaf01154fa - name: github.com/tendermint/go-crypto - version: 9b95da8fa4187f6799558d89b271dc8ab6485615 + version: 197a2b270fd94ee03824b158e738fce62862d0b8 + subpackages: + - cmd + - keys + - keys/cmd + - keys/cryptostore + - keys/server + - keys/server/types + - keys/storage/filestorage + - keys/storage/memstorage +- name: github.com/tendermint/go-db + version: 9643f60bc2578693844aacf380a7c32e4c029fee +- name: github.com/tendermint/go-merkle + version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-wire version: 334005c236d19c632fb5f073f9de3b0fab6a522b subpackages: - data + - data/base58 +- name: github.com/tendermint/light-client + version: d13e97e756e914fe9c6c1b23ea639b51f1d5bf40 + subpackages: + - certifiers + - certifiers/client + - certifiers/files + - commands + - commands/proofs + - commands/seeds + - commands/tx + - commands/txs + - proofs - name: github.com/tendermint/log15 version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: - term - name: github.com/tendermint/merkleeyes - version: 6fd69aa0871a4e685a5570aa7ab3d12e4068a722 + version: 0fab643ccac1a3f93b90e0e2682a5d1b9d17f8c4 subpackages: - app - client @@ -118,6 +160,7 @@ imports: - p2p - p2p/upnp - proxy + - rpc/client - rpc/core - rpc/core/types - rpc/grpc @@ -193,6 +236,8 @@ imports: - status - tap - transport +- name: gopkg.in/go-playground/validator.v9 + version: 6d8c18553ea1ac493d049edd6f102f52e618f085 - name: gopkg.in/yaml.v2 version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: diff --git a/glide.yaml b/glide.yaml index e232139b58..0abe9430da 100644 --- a/glide.yaml +++ b/glide.yaml @@ -11,10 +11,23 @@ import: - types - package: github.com/tendermint/go-crypto version: develop + subpackages: + - keys/cmd + - keys/cryptostore + - keys/server + - keys/storage/filestorage + - keys/storage/memstorage - package: github.com/tendermint/go-wire version: develop subpackages: - data +- package: github.com/tendermint/light-client + version: develop + subpackages: + - commands + - commands/proofs + - commands/seeds + - commands/tx - package: github.com/tendermint/merkleeyes version: develop subpackages: From f5a5a42af5a77b3f943d9c7ce1ce41aad27bb73d Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Sat, 29 Apr 2017 18:32:56 -0400 Subject: [PATCH 12/67] fix missing merkleeyes hash in lock --- glide.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glide.lock b/glide.lock index 553f293582..11dc1934f1 100644 --- a/glide.lock +++ b/glide.lock @@ -143,7 +143,7 @@ imports: subpackages: - term - name: github.com/tendermint/merkleeyes - version: 0fab643ccac1a3f93b90e0e2682a5d1b9d17f8c4 + version: d0aa363fd4e015e509038c3a0ec493bc62ee0b8a subpackages: - app - client From 76b95800455ce960b564bcd27c2c871eb88afce3 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 30 Apr 2017 15:21:41 -0700 Subject: [PATCH 13/67] Fix tabs in init files --- cmd/commands/init.go | 60 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 3c8a5a8a35..3f2cfd29ba 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -70,20 +70,20 @@ func initCmd(cmd *cobra.Command, args []string) error { } var PrivValJSON = `{ - "address": "7A956FADD20D3A5B2375042B2959F8AB172A058F", - "last_height": 0, - "last_round": 0, - "last_signature": null, - "last_signbytes": "", - "last_step": 0, - "priv_key": { + "address": "7A956FADD20D3A5B2375042B2959F8AB172A058F", + "last_height": 0, + "last_round": 0, + "last_signature": null, + "last_signbytes": "", + "last_step": 0, + "priv_key": { "type": "ed25519", - "data": "D07ABE82A8B15559A983B2DB5D4842B2B6E4D6AF58B080005662F424F17D68C17B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" - }, + "data": "D07ABE82A8B15559A983B2DB5D4842B2B6E4D6AF58B080005662F424F17D68C17B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + }, "pub_key": { "type": "ed25519", - "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" - } + "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + } }` var GenesisJSON = `{ @@ -96,7 +96,7 @@ var GenesisJSON = `{ "name": "", "pub_key": { "type": "ed25519", - "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + "data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" } } ], @@ -117,25 +117,25 @@ var GenesisJSON = `{ }` var Key1JSON = `{ - "address": "1B1BE55F969F54064628A63B9559E7C21C925165", - "priv_key": { - "type": "ed25519", - "data": "C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" - }, - "pub_key": { - "type": "ed25519", - "data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" - } + "address": "1B1BE55F969F54064628A63B9559E7C21C925165", + "priv_key": { + "type": "ed25519", + "data": "C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" + }, + "pub_key": { + "type": "ed25519", + "data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" + } }` var Key2JSON = `{ - "address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090", - "priv_key": { - "type": "ed25519", - "data": "34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" - }, - "pub_key": { - "type": "ed25519", - "data": "352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" - } + "address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090", + "priv_key": { + "type": "ed25519", + "data": "34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" + }, + "pub_key": { + "type": "ed25519", + "data": "352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8" + } }` From 354ea8ffd792d70320d3a93286bdd6f23e57ec6f Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 30 Apr 2017 16:13:12 -0700 Subject: [PATCH 14/67] Guide minor fixes --- docs/guide/basecoin-basics.md | 6 +++--- docs/guide/basecoin-plugins.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/basecoin-basics.md b/docs/guide/basecoin-basics.md index fb2e50291f..c2b974df93 100644 --- a/docs/guide/basecoin-basics.md +++ b/docs/guide/basecoin-basics.md @@ -111,7 +111,7 @@ type Coin struct { Accounts are serialized and stored in a Merkle tree under the key `base/a/
`, where `
` is the address of the account. Typically, the address of the account is the 20-byte `RIPEMD160` hash of the public key, but other formats are acceptable as well, -as defined in the [tendermint crypto library](https://github.com/tendermint/go-crypto). +as defined in the [Tendermint crypto library](https://github.com/tendermint/go-crypto). The Merkle tree used in Basecoin is a balanced, binary search tree, which we call an [IAVL tree](https://github.com/tendermint/go-merkle). ## Transactions @@ -150,8 +150,8 @@ This is slightly different from Ethereum's concept of `Gas` and `GasPrice`, where `Fee = Gas x GasPrice`. In Basecoin, the `Gas` and `Fee` are independent, and the `GasPrice` is implicit. -In Tendermint, the `Fee` is meant to be used by the validators to inform the ordering -of transactions, like in bitcoin. And the `Gas` is meant to be used by the application +In Basecoin, the `Fee` is meant to be used by the validators to inform the ordering +of transactions, like in Bitcoin. And the `Gas` is meant to be used by the application plugin to control its execution. There is currently no means to pass `Fee` information to the Tendermint validators, but it will come soon... diff --git a/docs/guide/basecoin-plugins.md b/docs/guide/basecoin-plugins.md index cc78d246ae..4e1c2251c1 100644 --- a/docs/guide/basecoin-plugins.md +++ b/docs/guide/basecoin-plugins.md @@ -144,7 +144,7 @@ to whatever your plugin tool is going to be called. Next is the `cmd.go`. This is where we extend the tool with any new commands and flags we need to send transactions to our plugin. Note the `init()` function, where we register a new transaction subcommand with `RegisterTxSubcommand`, -and where we load the plugin into the basecoin app with `RegisterStartPlugin`. +and where we load the plugin into the Basecoin app with `RegisterStartPlugin`. Finally is the `plugin.go`, where we provide an implementation of the `Plugin` interface. The most important part of the implementation is the `RunTx` method, which determines the meaning of the data From 57f610a6a7c49dacc8dc63f9372f64f64517b616 Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Tue, 9 May 2017 14:35:06 +0200 Subject: [PATCH 15/67] Spellfix --- docs/go_basics.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/go_basics.md b/docs/go_basics.md index 1364bcb052..4744b1bff3 100644 --- a/docs/go_basics.md +++ b/docs/go_basics.md @@ -98,7 +98,7 @@ make install make test ``` -Great! Now when I run `tendermint` I have the newest of the new, the develop branch! But please not that this branch is not considered production ready and may have issues. This should only be done if you want to develop code for the future and run locally. +Great! Now when I run `tendermint` I have the newest of the new, the develop branch! But please note that this branch is not considered production ready and may have issues. This should only be done if you want to develop code for the future and run locally. But wait, I want to mix and match. There is a bugfix in `go-p2p:persistent_peer` that I want to use with tendermint. How to compile this. I will show with a simple example, please update the repo and commit numbers for your usecase. Also, make sure these branches are compatible, so if `persistent_peer` is close to `master` it should work. But if it is 15 commits ahead, you will probably need the `develop` branch of tendermint to compile with it. But I assume you know your way around git and can figure that out. @@ -129,4 +129,3 @@ Great, now you just compiled the master branch of tendermint along with the bugf Okay, that's it, with this info you should be able to follow along and trouble-shoot any issues you have with the rest of the guide. - From 73435303afb3bf6a773e2db64016bce530cc0321 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 12 May 2017 20:29:13 +0200 Subject: [PATCH 16/67] Fix basecoin cli to newest tendermint develop (0.10) --- cmd/basecoin/main.go | 6 +++- cmd/commands/init.go | 5 ++-- cmd/commands/key.go | 5 +++- cmd/commands/reset.go | 16 ++++++---- cmd/commands/start.go | 36 ++++++++++++---------- cmd/commands/tx.go | 13 ++------ cmd/commands/utils.go | 68 ++++++++---------------------------------- glide.lock | 69 ++++++++++++++++++------------------------- 8 files changed, 85 insertions(+), 133 deletions(-) diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 5b37ab7fef..37a6e2da72 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -1,9 +1,12 @@ package main import ( + "os" + "github.com/spf13/cobra" "github.com/tendermint/basecoin/cmd/commands" + "github.com/tendermint/tmlibs/cli" ) func main() { @@ -25,5 +28,6 @@ func main() { commands.VersionCmd, ) - commands.ExecuteWithDebug(RootCmd) + cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin")) + cmd.Execute() } diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 3f2cfd29ba..9bd4e76ec1 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -6,7 +6,9 @@ import ( "path" "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/tendermint/tmlibs/cli" cmn "github.com/tendermint/tmlibs/common" ) @@ -33,8 +35,7 @@ func setupFile(path, data string, perm os.FileMode) (int, error) { } func initCmd(cmd *cobra.Command, args []string) error { - rootDir := BasecoinRoot("") - + rootDir := viper.GetString(cli.HomeFlag) cmn.EnsureDir(rootDir, 0777) // initalize basecoin diff --git a/cmd/commands/key.go b/cmd/commands/key.go index e27a705ed5..d0d2009d83 100644 --- a/cmd/commands/key.go +++ b/cmd/commands/key.go @@ -10,8 +10,10 @@ import ( //"github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/tendermint/go-crypto" + "github.com/tendermint/tmlibs/cli" ) //commands @@ -87,7 +89,8 @@ func genKey() *Key { } func LoadKey(keyFile string) (*Key, error) { - filePath := path.Join(BasecoinRoot(""), keyFile) + rootDir := viper.GetString(cli.HomeFlag) + filePath := path.Join(rootDir, keyFile) keyJSONBytes, err := ioutil.ReadFile(filePath) if err != nil { return nil, err diff --git a/cmd/commands/reset.go b/cmd/commands/reset.go index 7c532fbefb..296e58ad12 100644 --- a/cmd/commands/reset.go +++ b/cmd/commands/reset.go @@ -1,10 +1,13 @@ package commands import ( - "github.com/spf13/cobra" + "os" - tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" - tmcfg "github.com/tendermint/tendermint/config/tendermint" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/tendermint/tendermint/config" + "github.com/tendermint/tmlibs/cli" ) var UnsafeResetAllCmd = &cobra.Command{ @@ -14,8 +17,9 @@ var UnsafeResetAllCmd = &cobra.Command{ } func unsafeResetAllCmd(cmd *cobra.Command, args []string) error { - basecoinDir := BasecoinRoot("") - tmConfig := tmcfg.GetConfig(basecoinDir) - tmcmd.ResetAll(tmConfig, log) + rootDir := viper.GetString(cli.HomeFlag) + // wipe out rootdir if it exists before recreating it + os.RemoveAll(rootDir) + config.EnsureRoot(rootDir) return nil } diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 340ee46c90..472ba89d37 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -7,12 +7,15 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/tendermint/abci/server" - cmn "github.com/tendermint/tmlibs/common" eyes "github.com/tendermint/merkleeyes/client" + "github.com/tendermint/tmlibs/cli" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/logger" - tmcfg "github.com/tendermint/tendermint/config/tendermint" + "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/proxy" tmtypes "github.com/tendermint/tendermint/types" @@ -49,12 +52,12 @@ func init() { } func startCmd(cmd *cobra.Command, args []string) error { - basecoinDir := BasecoinRoot("") + rootDir := viper.GetString(cli.HomeFlag) // Connect to MerkleEyes var eyesCli *eyes.Client if eyesFlag == "local" { - eyesCli = eyes.NewLocalClient(path.Join(basecoinDir, "data", "merkleeyes.db"), EyesCacheSize) + eyesCli = eyes.NewLocalClient(path.Join(rootDir, "data", "merkleeyes.db"), EyesCacheSize) } else { var err error eyesCli, err = eyes.NewClient(eyesFlag) @@ -78,7 +81,7 @@ func startCmd(cmd *cobra.Command, args []string) error { // else, assume it's been loaded if basecoinApp.GetState().GetChainID() == "" { // If genesis file exists, set key-value options - genesisFile := path.Join(basecoinDir, "genesis.json") + genesisFile := path.Join(rootDir, "genesis.json") if _, err := os.Stat(genesisFile); err == nil { err := basecoinApp.LoadGenesis(genesisFile) if err != nil { @@ -97,12 +100,11 @@ func startCmd(cmd *cobra.Command, args []string) error { } else { log.Notice("Starting Basecoin with Tendermint", "chain_id", chainID) // start the app with tendermint in-process - return startTendermint(basecoinDir, basecoinApp) + return startTendermint(rootDir, basecoinApp) } } func startBasecoinABCI(basecoinApp *app.Basecoin) error { - // Start the ABCI listener svr, err := server.NewServer(addrFlag, "socket", basecoinApp) if err != nil { @@ -118,18 +120,20 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error { } func startTendermint(dir string, basecoinApp *app.Basecoin) error { - - // Get configuration - tmConfig := tmcfg.GetConfig(dir) - // logger.SetLogLevel("notice") //config.GetString("log_level")) - // parseFlags(config, args[1:]) // Command line overrides + cfg := config.DefaultConfig() + err := viper.Unmarshal(cfg) + if err != nil { + return err + } + cfg.SetRoot(cfg.RootDir) + config.EnsureRoot(cfg.RootDir) + logger.SetLogLevel(cfg.LogLevel) // Create & start tendermint node - privValidatorFile := tmConfig.GetString("priv_validator_file") - privValidator := tmtypes.LoadOrGenPrivValidator(privValidatorFile) - n := node.NewNode(tmConfig, privValidator, proxy.NewLocalClientCreator(basecoinApp)) + privValidator := tmtypes.LoadOrGenPrivValidator(cfg.PrivValidator) + n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp)) - _, err := n.Start() + _, err = n.Start() if err != nil { return err } diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 2982328064..eae7f36a6f 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -9,9 +9,8 @@ import ( "github.com/tendermint/basecoin/types" - client "github.com/tendermint/tendermint/rpc/lib/client" wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" + "github.com/tendermint/tendermint/rpc/client" ) //commands @@ -193,23 +192,17 @@ func AppTx(name string, data []byte) error { // broadcast the transaction to tendermint func broadcastTx(tx types.Tx) ([]byte, string, error) { - - tmResult := new(ctypes.TMResult) - uriClient := client.NewURIClient(txNodeFlag) - + httpClient := client.NewHTTP(txNodeFlag, "/websocket") // Don't you hate having to do this? // How many times have I lost an hour over this trick?! txBytes := []byte(wire.BinaryBytes(struct { types.Tx `json:"unwrap"` }{tx})) - - _, err := uriClient.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult) + res, err := httpClient.BroadcastTxCommit(txBytes) if err != nil { return nil, "", errors.Errorf("Error on broadcast tx: %v", err) } - res := (*tmResult).(*ctypes.ResultBroadcastTxCommit) - // if it fails check, we don't even get a delivertx back! if !res.CheckTx.Code.IsOK() { r := res.CheckTx diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index 7b43ce9a90..0e6b0948f8 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -3,8 +3,6 @@ package commands import ( "encoding/hex" "fmt" - "os" - "path" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -14,41 +12,11 @@ import ( "github.com/tendermint/basecoin/types" abci "github.com/tendermint/abci/types" - cmn "github.com/tendermint/tmlibs/common" - client "github.com/tendermint/tendermint/rpc/lib/client" wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" + "github.com/tendermint/tendermint/rpc/client" tmtypes "github.com/tendermint/tendermint/types" ) -//This variable can be overwritten by plugin applications -// if they require a different working directory -var DefaultHome = ".basecoin" - -func BasecoinRoot(rootDir string) string { - if rootDir == "" { - rootDir = os.Getenv("BCHOME") - } - if rootDir == "" { - rootDir = path.Join(os.Getenv("HOME"), DefaultHome) - } - return rootDir -} - -//Add debugging flag and execute the root command -func ExecuteWithDebug(RootCmd *cobra.Command) { - - var debug bool - RootCmd.SilenceUsage = true - RootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enables stack trace error messages") - - //note that Execute() prints the error if encountered, so no need to reprint the error, - // only if we want the full stack trace - if err := RootCmd.Execute(); err != nil && debug { - cmn.Exit(fmt.Sprintf("%+v\n", err)) - } -} - //Quickly registering flags can be quickly achieved through using the utility functions //RegisterFlags, and RegisterPersistentFlags. Ex: // flags := []Flag2Register{ @@ -130,24 +98,16 @@ func StripHex(s string) string { return s } -func Query(tmAddr string, key []byte) (*abci.ResponseQuery, error) { - uriClient := client.NewURIClient(tmAddr) - tmResult := new(ctypes.TMResult) - - params := map[string]interface{}{ - "path": "/key", - "data": key, - "prove": true, - } - _, err := uriClient.Call("abci_query", params, tmResult) +func Query(tmAddr string, key []byte) (*abci.ResultQuery, error) { + httpClient := client.NewHTTP(tmAddr, "/websocket") + res, err := httpClient.ABCIQuery("/key", key, true) if err != nil { return nil, errors.Errorf("Error calling /abci_query: %v", err) } - res := (*tmResult).(*ctypes.ResultABCIQuery) - if !res.Response.Code.IsOK() { - return nil, errors.Errorf("Query got non-zero exit code: %v. %s", res.Response.Code, res.Response.Log) + if !res.Code.IsOK() { + return nil, errors.Errorf("Query got non-zero exit code: %v. %s", res.Code, res.Log) } - return &res.Response, nil + return res.ResultQuery, nil } // fetch the account by querying the app @@ -176,17 +136,13 @@ func getAcc(tmAddr string, address []byte) (*types.Account, error) { } func getHeaderAndCommit(tmAddr string, height int) (*tmtypes.Header, *tmtypes.Commit, error) { - tmResult := new(ctypes.TMResult) - uriClient := client.NewURIClient(tmAddr) - - method := "commit" - _, err := uriClient.Call(method, map[string]interface{}{"height": height}, tmResult) + httpClient := client.NewHTTP(tmAddr, "/websocket") + res, err := httpClient.Commit(height) if err != nil { - return nil, nil, errors.Errorf("Error on %s: %v", method, err) + return nil, nil, errors.Errorf("Error on commit: %v", err) } - resCommit := (*tmResult).(*ctypes.ResultCommit) - header := resCommit.Header - commit := resCommit.Commit + header := res.Header + commit := res.Commit return header, commit, nil } diff --git a/glide.lock b/glide.lock index 11dc1934f1..79f06761bc 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: f4077fecc95e11f007adea022a38441a2e1c5d51d75ebab0fc9a296052ee5a6b -updated: 2017-04-27T23:14:26.934716255+02:00 +hash: c887040d9aa1545d4d2c45db78032ab5e132c4eebed14e757573e7f7103fc162 +updated: 2017-04-27T20:02:48.730032774-04:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd @@ -7,6 +7,12 @@ imports: version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: - btcec +- name: github.com/BurntSushi/toml + version: b26d9c308763d68093482582cea63d69be07a0f0 +- name: github.com/davecgh/go-spew + version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 + subpackages: + - spew - name: github.com/ebuchman/fail-test version: 95f809107225be108efcf10a3509e4ea6ceef3c4 - name: github.com/fsnotify/fsnotify @@ -63,6 +69,10 @@ imports: version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d +- name: github.com/pmezard/go-difflib + version: d8ed2627bdf02c080bf22230dbb337003b7aba2d + subpackages: + - difflib - name: github.com/spf13/afero version: 9be650865eab0c12963d8753212f4f9c66cdcf12 subpackages: @@ -77,6 +87,11 @@ imports: version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51 - name: github.com/spf13/viper version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb +- name: github.com/stretchr/testify + version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 + subpackages: + - assert + - require - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -93,7 +108,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: c709d3cc857929a8dd36a90da3640122d7e75770 + version: 8d8e35ae537538c9cf6808be3ca9dd7dab81b7f6 subpackages: - client - example/dummy @@ -104,10 +119,8 @@ imports: subpackages: - edwards25519 - extra25519 -- name: github.com/tendermint/go-common - version: f9e3db037330c8a8d61d3966de8473eaf01154fa - name: github.com/tendermint/go-crypto - version: 197a2b270fd94ee03824b158e738fce62862d0b8 + version: e71bbb2509b586f0b24f120b6ba57f32aefa1579 subpackages: - cmd - keys @@ -117,43 +130,29 @@ imports: - keys/server/types - keys/storage/filestorage - keys/storage/memstorage -- name: github.com/tendermint/go-db - version: 9643f60bc2578693844aacf380a7c32e4c029fee -- name: github.com/tendermint/go-merkle - version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-wire - version: 334005c236d19c632fb5f073f9de3b0fab6a522b + version: b53add0b622662731985485f3a19be7f684660b8 subpackages: - data - data/base58 - name: github.com/tendermint/light-client - version: d13e97e756e914fe9c6c1b23ea639b51f1d5bf40 - subpackages: - - certifiers - - certifiers/client - - certifiers/files - - commands - - commands/proofs - - commands/seeds - - commands/tx - - commands/txs - - proofs + version: e55dc347586218ba5691267d3dc959c6f4943836 - name: github.com/tendermint/log15 version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: - term - name: github.com/tendermint/merkleeyes - version: d0aa363fd4e015e509038c3a0ec493bc62ee0b8a + version: c722818b460381bc5b82e38c73ff6e22a9df624d subpackages: - app - client - iavl + - testutil - name: github.com/tendermint/tendermint - version: 1310c7264750efa8939680536098ded9f9e8df74 + version: d2ae7e164af0bb9eb3dbeec3e0b54bbee440f537 subpackages: - blockchain - - cmd/tendermint/commands - - config/tendermint + - config/tendermint_test - consensus - mempool - node @@ -168,6 +167,7 @@ imports: - rpc/lib/client - rpc/lib/server - rpc/lib/types + - rpc/test - state - state/txindex - state/txindex/kv @@ -175,7 +175,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: df250b69416a35a943a6e2a92118667e9ef031d4 + version: 706b9fbd671d5d49ecf1b2ea3bb34e51d61ff091 subpackages: - autofile - clist @@ -240,17 +240,4 @@ imports: version: 6d8c18553ea1ac493d049edd6f102f52e618f085 - name: gopkg.in/yaml.v2 version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b -testImports: -- name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 - subpackages: - - spew -- name: github.com/pmezard/go-difflib - version: d8ed2627bdf02c080bf22230dbb337003b7aba2d - subpackages: - - difflib -- name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 - subpackages: - - assert - - require +testImports: [] From 2324f5d76654a75cc1114b2bdf5bc0424e5ee333 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 12 May 2017 20:54:50 +0200 Subject: [PATCH 17/67] Fix all tests with new tendermint style --- cmd/basecli/main.go | 9 +++------ cmd/counter/main.go | 6 +++++- docs/guide/src/example-plugin/cmd.go | 2 -- docs/guide/src/example-plugin/main.go | 7 +++++-- tests/tendermint/main.go | 21 +++++++++++++-------- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 2ecb8c75ea..22fb4d212d 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -9,6 +9,7 @@ import ( "github.com/tendermint/light-client/commands/proofs" "github.com/tendermint/light-client/commands/seeds" "github.com/tendermint/light-client/commands/txs" + "github.com/tendermint/tmlibs/cli" ) // BaseCli represents the base command when called without any subcommands @@ -38,10 +39,6 @@ func init() { } func main() { - keycmd.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli")) - BaseCli.Execute() - // err := BaseCli.Execute() - // if err != nil { - // fmt.Printf("%+v\n", err) - // } + cmd := cli.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli")) + cmd.Execute() } diff --git a/cmd/counter/main.go b/cmd/counter/main.go index 8a96b50ed7..2f6c5ca404 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -1,9 +1,12 @@ package main import ( + "os" + "github.com/spf13/cobra" "github.com/tendermint/basecoin/cmd/commands" + "github.com/tendermint/tmlibs/cli" ) func main() { @@ -24,5 +27,6 @@ func main() { commands.QuickVersionCmd("0.1.0"), ) - commands.ExecuteWithDebug(RootCmd) + cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin")) + cmd.Execute() } diff --git a/docs/guide/src/example-plugin/cmd.go b/docs/guide/src/example-plugin/cmd.go index 11a6f6bc06..b439176266 100644 --- a/docs/guide/src/example-plugin/cmd.go +++ b/docs/guide/src/example-plugin/cmd.go @@ -24,8 +24,6 @@ var ( //Called during CLI initialization func init() { - commands.DefaultHome = ".basecoin-example-plugin" - //Set the Plugin Flags ExamplePluginTxCmd.Flags().BoolVar(&validFlag, "valid", false, "Set this to make transaction valid") diff --git a/docs/guide/src/example-plugin/main.go b/docs/guide/src/example-plugin/main.go index e2892bd7d8..328e22025b 100644 --- a/docs/guide/src/example-plugin/main.go +++ b/docs/guide/src/example-plugin/main.go @@ -1,9 +1,12 @@ package main import ( + "os" + "github.com/spf13/cobra" "github.com/tendermint/basecoin/cmd/commands" + "github.com/tendermint/tmlibs/cli" ) func main() { @@ -27,6 +30,6 @@ func main() { commands.UnsafeResetAllCmd, ) - //Run the root command - commands.ExecuteWithDebug(RootCmd) + cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin-example-plugin")) + cmd.Execute() } diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 1213cc4c57..04a39f9f67 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -6,11 +6,11 @@ import ( "github.com/gorilla/websocket" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tendermint/rpc/lib/client" - "github.com/tendermint/tendermint/rpc/lib/types" wire "github.com/tendermint/go-wire" _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types + "github.com/tendermint/tendermint/rpc/lib/client" + "github.com/tendermint/tendermint/rpc/lib/types" + cmn "github.com/tendermint/tmlibs/common" ) func main() { @@ -71,11 +71,13 @@ func main() { // Write request txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) - request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) - //request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) + request, err := rpctypes.MapToRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) + if err != nil { + cmn.Exit("cannot encode request: " + err.Error()) + } reqBytes := wire.JSONBytes(request) //fmt.Print(".") - err := ws.WriteMessage(websocket.TextMessage, reqBytes) + err = ws.WriteMessage(websocket.TextMessage, reqBytes) if err != nil { cmn.Exit("writing websocket request: " + err.Error()) } @@ -122,10 +124,13 @@ func main() { // Write request txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) - request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) + request, err := rpctypes.MapToRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) + if err != nil { + cmn.Exit("cannot encode request: " + err.Error()) + } reqBytes := wire.JSONBytes(request) //fmt.Print(".") - err := ws.WriteMessage(websocket.TextMessage, reqBytes) + err = ws.WriteMessage(websocket.TextMessage, reqBytes) if err != nil { cmn.Exit("writing websocket request: " + err.Error()) } From 5aec321b76eec17097561fa2a32d45085e431876 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 12 May 2017 21:47:18 +0200 Subject: [PATCH 18/67] Fix start command --- cmd/commands/start.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 472ba89d37..17b3ec4a1a 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -18,7 +18,7 @@ import ( "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/proxy" - tmtypes "github.com/tendermint/tendermint/types" + "github.com/tendermint/tendermint/types" "github.com/tendermint/basecoin/app" ) @@ -130,7 +130,7 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error { logger.SetLogLevel(cfg.LogLevel) // Create & start tendermint node - privValidator := tmtypes.LoadOrGenPrivValidator(cfg.PrivValidator) + privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile()) n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp)) _, err = n.Start() @@ -138,10 +138,7 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error { return err } - // Wait forever - cmn.TrapSignal(func() { - // Cleanup - n.Stop() - }) + // Trap signal, run forever. + n.RunForever() return nil } From 93c4e4d82a6213bee0c26e00652271713e70c9bf Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 12 May 2017 22:15:20 +0200 Subject: [PATCH 19/67] Add basic info on using basecli --- cmd/basecli/README.md | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 cmd/basecli/README.md diff --git a/cmd/basecli/README.md b/cmd/basecli/README.md new file mode 100644 index 0000000000..c30ea5b888 --- /dev/null +++ b/cmd/basecli/README.md @@ -0,0 +1,68 @@ +# Basic run through of using basecli.... + +To keep things clear, let's have two shells... + +`$` is for basecoin (server), `%` is for basecli (client) + +## Set up a clean basecoin, but don't start the chain + +``` +$ export BCHOME=~/.demoserve +$ basecoin init +``` + +## Set up your basecli with a new key + +``` +% export BCHOME=~/.democli +% basecli keys new demo +% basecli keys get demo -o json +``` + +And set up a few more keys for fun... + +``` +% basecli keys new buddy +% basecli keys list +% ME=`basecli keys get demo -o json | jq .address | tr -d '"'` +% YOU=`basecli keys get buddy -o json | jq .address | tr -d '"'` +``` + +## Update genesis so you are rich, and start + +``` +$ vi $BCHOME/genesis.json +-> cut/paste your pubkey from the results above + +$ basecoin start +``` + +## Connect your basecli the first time + +``` +% basecli init --chainid test_chain_id --node localhost:45567 +``` + +## Check your balances... + +``` +% basecli proof state get --app=account --key=$ME +% basecli proof state get --app=account --key=$YOU +``` + +## Send the money + +``` +% basecli tx send --name demo --amount 1000mycoin --sequence 1 --to $YOU +-> copy hash to HASH +% basecli proof tx get --key $HASH + +% basecli proof tx get --key $HASH --app base +% basecli proof state get --key $YOU --app account +``` + +## Any questions??? + +``` +% basecli seeds show --height 1767 +``` From d0be11682bf3e4fe87a3ec6133ef7fed5033d2a4 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Sat, 13 May 2017 15:07:53 +0200 Subject: [PATCH 20/67] Embed light-client proxy --- cmd/basecli/main.go | 2 ++ glide.lock | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 22fb4d212d..baaf630dac 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -7,6 +7,7 @@ import ( keycmd "github.com/tendermint/go-crypto/cmd" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/commands/proofs" + "github.com/tendermint/light-client/commands/proxy" "github.com/tendermint/light-client/commands/seeds" "github.com/tendermint/light-client/commands/txs" "github.com/tendermint/tmlibs/cli" @@ -36,6 +37,7 @@ func init() { BaseCli.AddCommand(proofs.RootCmd) txs.Register("send", SendTxMaker{}) BaseCli.AddCommand(txs.RootCmd) + BaseCli.AddCommand(proxy.RootCmd) } func main() { diff --git a/glide.lock b/glide.lock index 79f06761bc..ccdb3e0b79 100644 --- a/glide.lock +++ b/glide.lock @@ -136,7 +136,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: e55dc347586218ba5691267d3dc959c6f4943836 + version: 6a786b321c0634e801e692af93491b75866cb0cd - name: github.com/tendermint/log15 version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: @@ -149,7 +149,7 @@ imports: - iavl - testutil - name: github.com/tendermint/tendermint - version: d2ae7e164af0bb9eb3dbeec3e0b54bbee440f537 + version: 07fe3e2f1345767fda9f31045da19bd277935afb subpackages: - blockchain - config/tendermint_test From 1d6f11aba7b0d9dbcf3af9e20b74b60f23b3d2e2 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Sat, 13 May 2017 19:32:42 +0200 Subject: [PATCH 21/67] Fixed demo test script --- demo/data/chain1/genesis.json | 8 ++++---- demo/data/chain1/priv_validator.json | 17 +---------------- demo/data/chain2/genesis.json | 8 ++++---- demo/data/chain2/priv_validator.json | 17 +---------------- demo/start.sh | 14 +++++++------- 5 files changed, 17 insertions(+), 47 deletions(-) diff --git a/demo/data/chain1/genesis.json b/demo/data/chain1/genesis.json index d50161a5aa..284572eb37 100644 --- a/demo/data/chain1/genesis.json +++ b/demo/data/chain1/genesis.json @@ -6,10 +6,10 @@ { "amount": 10, "name": "", - "pub_key": [ - 1, - "D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" - ] + "pub_key": { + "type": "ed25519", + "data":"D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" + } } ], "app_options": { diff --git a/demo/data/chain1/priv_validator.json b/demo/data/chain1/priv_validator.json index 1ea10c12da..55db06f4bc 100644 --- a/demo/data/chain1/priv_validator.json +++ b/demo/data/chain1/priv_validator.json @@ -1,16 +1 @@ -{ - "address": "EBB0B4A899973C524A6BB18A161056A55F590F41", - "last_height": 0, - "last_round": 0, - "last_signature": null, - "last_signbytes": "", - "last_step": 0, - "priv_key": [ - 1, - "5FFDC1EA5FA2CA4A0A5503C86D2D348C5B401AD80FAA1899508F1ED00D8982E8D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" - ], - "pub_key": [ - 1, - "D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" - ] -} \ No newline at end of file +{"address":"EBB0B4A899973C524A6BB18A161056A55F590F41","pub_key":{"type":"ed25519","data":"D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A"},"last_height":0,"last_round":0,"last_step":0,"last_signature":null,"priv_key":{"type":"ed25519","data":"5FFDC1EA5FA2CA4A0A5503C86D2D348C5B401AD80FAA1899508F1ED00D8982E8D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A"}} \ No newline at end of file diff --git a/demo/data/chain2/genesis.json b/demo/data/chain2/genesis.json index c534617562..3ff94b9933 100644 --- a/demo/data/chain2/genesis.json +++ b/demo/data/chain2/genesis.json @@ -6,10 +6,10 @@ { "amount": 10, "name": "", - "pub_key": [ - 1, - "9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" - ] + "pub_key": { + "type": "ed25519", + "data": "9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" + } } ], "app_options": { diff --git a/demo/data/chain2/priv_validator.json b/demo/data/chain2/priv_validator.json index 8b3eb7e348..12eb625259 100644 --- a/demo/data/chain2/priv_validator.json +++ b/demo/data/chain2/priv_validator.json @@ -1,16 +1 @@ -{ - "address": "D42CFCB9C42DF9A73143EEA89255D1DF027B6240", - "last_height": 0, - "last_round": 0, - "last_signature": null, - "last_signbytes": "", - "last_step": 0, - "priv_key": [ - 1, - "6353FAF4ADEB03EA496A9EAE5BE56C4C6A851CB705401788184FDC9198413C2C9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" - ], - "pub_key": [ - 1, - "9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F" - ] -} \ No newline at end of file +{"address":"D42CFCB9C42DF9A73143EEA89255D1DF027B6240","pub_key":{"type":"ed25519","data":"9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F"},"last_height":0,"last_round":0,"last_step":0,"last_signature":null,"priv_key":{"type":"ed25519","data":"6353FAF4ADEB03EA496A9EAE5BE56C4C6A851CB705401788184FDC9198413C2C9A76DDE4CA4EE660C073D288DBE4F8A128F23857881A95F18167682D47E7058F"}} \ No newline at end of file diff --git a/demo/start.sh b/demo/start.sh index 3bd214a032..4ce2305ec4 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -41,7 +41,7 @@ function waitForNode() { exit 1 fi echo "...... still waiting on $addr" - sleep 1 + sleep 1 curl -s $addr/status > /dev/null ERR=$? i=$((i+1)) @@ -52,12 +52,12 @@ function waitForNode() { function waitForBlock() { addr=$1 - b1=`curl -s $addr/status | jq .result[1].latest_block_height` + b1=`curl -s $addr/status | jq .result.latest_block_height` b2=$b1 while [ "$b2" == "$b1" ]; do echo "Waiting for node $addr to commit a block ..." sleep 1 - b2=`curl -s $addr/status | jq .result[1].latest_block_height` + b2=`curl -s $addr/status | jq .result.latest_block_height` done } @@ -83,11 +83,11 @@ echo "" echo "... starting chains" echo "" # start the first node -TMROOT=$BCHOME1 tendermint node --skip_upnp --log_level=info &> $LOG_DIR/chain1_tendermint.log & +TMROOT=$BCHOME1 tendermint node --p2p.skip_upnp --log_level=info &> $LOG_DIR/chain1_tendermint.log & BCHOME=$BCHOME1 basecoin start --without-tendermint &> $LOG_DIR/chain1_basecoin.log & # start the second node -TMROOT=$BCHOME2 tendermint node --skip_upnp --log_level=info --node_laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> $LOG_DIR/chain2_tendermint.log & +TMROOT=$BCHOME2 tendermint node --p2p.skip_upnp --log_level=info --p2p.laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> $LOG_DIR/chain2_tendermint.log & BCHOME=$BCHOME2 basecoin start --address tcp://localhost:36658 --without-tendermint &> $LOG_DIR/chain2_basecoin.log & echo "" @@ -99,7 +99,7 @@ waitForNode localhost:36657 # TODO: remove the sleep # Without it we sometimes get "Account bytes are empty for address: 053BA0F19616AFF975C8756A2CBFF04F408B4D47" -sleep 3 +sleep 3 echo "... registering chain1 on chain2" echo "" @@ -143,7 +143,7 @@ echo "" echo "... querying for block data" echo "" # get the header and commit for the height -HEADER_AND_COMMIT=$(basecoin block $HEIGHT) +HEADER_AND_COMMIT=$(basecoin block $HEIGHT) HEADER=$(echo $HEADER_AND_COMMIT | jq .hex.header) HEADER=$(removeQuotes $HEADER) COMMIT=$(echo $HEADER_AND_COMMIT | jq .hex.commit) From 4a1920a2a723cdd73d8e3d0672cd43faa19be44f Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 13 May 2017 20:03:46 -0400 Subject: [PATCH 22/67] exit code on error --- cmd/basecoin/main.go | 4 +++- demo/data/chain1/config.toml | 2 +- demo/data/chain2/config.toml | 2 +- demo/start.sh | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 37a6e2da72..76ba6d5e93 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -29,5 +29,7 @@ func main() { ) cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin")) - cmd.Execute() + if err := cmd.Execute(); err != nil { + os.Exit(1) + } } diff --git a/demo/data/chain1/config.toml b/demo/data/chain1/config.toml index 9b97202d12..e2bcb49fff 100644 --- a/demo/data/chain1/config.toml +++ b/demo/data/chain1/config.toml @@ -7,5 +7,5 @@ node_laddr = "tcp://0.0.0.0:46656" seeds = "" fast_sync = true db_backend = "leveldb" -log_level = "notice" +log_level = "info" rpc_laddr = "tcp://0.0.0.0:46657" diff --git a/demo/data/chain2/config.toml b/demo/data/chain2/config.toml index 9b97202d12..e2bcb49fff 100644 --- a/demo/data/chain2/config.toml +++ b/demo/data/chain2/config.toml @@ -7,5 +7,5 @@ node_laddr = "tcp://0.0.0.0:46656" seeds = "" fast_sync = true db_backend = "leveldb" -log_level = "notice" +log_level = "info" rpc_laddr = "tcp://0.0.0.0:46657" diff --git a/demo/start.sh b/demo/start.sh index 4ce2305ec4..20335f7392 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -23,6 +23,13 @@ fi set -u +function ifExit() { + if [[ "$?" != 0 ]]; then + echo "FAIL" + exit 1 + fi +} + function removeQuotes() { temp="${1%\"}" temp="${temp#\"}" @@ -84,11 +91,15 @@ echo "... starting chains" echo "" # start the first node TMROOT=$BCHOME1 tendermint node --p2p.skip_upnp --log_level=info &> $LOG_DIR/chain1_tendermint.log & +ifExit BCHOME=$BCHOME1 basecoin start --without-tendermint &> $LOG_DIR/chain1_basecoin.log & +ifExit # start the second node TMROOT=$BCHOME2 tendermint node --p2p.skip_upnp --log_level=info --p2p.laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> $LOG_DIR/chain2_tendermint.log & +ifExit BCHOME=$BCHOME2 basecoin start --address tcp://localhost:36658 --without-tendermint &> $LOG_DIR/chain2_basecoin.log & +ifExit echo "" echo "... waiting for chains to start" @@ -105,6 +116,7 @@ echo "... registering chain1 on chain2" echo "" # register chain1 on chain2 basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS2 register --ibc_chain_id $CHAIN_ID1 --genesis $BCHOME1/genesis.json +ifExit echo "" echo "... creating egress packet on chain1" @@ -112,12 +124,14 @@ echo "" # create a packet on chain1 destined for chain2 PAYLOAD="DEADBEEF" #TODO basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS1 packet create --ibc_from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --ibc_sequence 1 +ifExit echo "" echo "... querying for packet data" echo "" # query for the packet data and proof QUERY_RESULT=$(basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1) +ifExit HEIGHT=$(echo $QUERY_RESULT | jq .height) PACKET=$(echo $QUERY_RESULT | jq .value) PROOF=$(echo $QUERY_RESULT | jq .proof) @@ -144,6 +158,7 @@ echo "... querying for block data" echo "" # get the header and commit for the height HEADER_AND_COMMIT=$(basecoin block $HEIGHT) +ifExit HEADER=$(echo $HEADER_AND_COMMIT | jq .hex.header) HEADER=$(removeQuotes $HEADER) COMMIT=$(echo $HEADER_AND_COMMIT | jq .hex.commit) @@ -158,18 +173,21 @@ echo "... updating state of chain1 on chain2" echo "" # update the state of chain1 on chain2 basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS2 update --header 0x$HEADER --commit 0x$COMMIT +ifExit echo "" echo "... posting packet from chain1 on chain2" echo "" # post the packet from chain1 to chain2 basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS2 packet post --ibc_from $CHAIN_ID1 --height $HEIGHT --packet 0x$PACKET --proof 0x$PROOF +ifExit echo "" echo "... checking if the packet is present on chain2" echo "" # query for the packet on chain2 basecoin query --node tcp://localhost:36657 ibc,ingress,test_chain_2,test_chain_1,1 +ifExit echo "" echo "DONE!" From 78593078ba0ae0675055e195b442eb119f14281b Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 13 May 2017 20:04:53 -0400 Subject: [PATCH 23/67] fix genesis format --- app/genesis.go | 6 +--- plugins/ibc/ibc.go | 13 +++---- plugins/ibc/ibc_test.go | 79 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 82 insertions(+), 16 deletions(-) diff --git a/app/genesis.go b/app/genesis.go index e4d838de2d..d7fb2996af 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -4,9 +4,9 @@ import ( "encoding/json" "github.com/pkg/errors" + "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/tmlibs/common" - //tmtypes "github.com/tendermint/tendermint/types" ) func (app *Basecoin) LoadGenesis(path string) error { @@ -61,10 +61,6 @@ func loadGenesis(filePath string) (*FullGenesisDoc, error) { return nil, errors.Wrap(err, "loading genesis file") } - // the tendermint genesis is go-wire - // tmGenesis := new(tmtypes.GenesisDoc) - // err = wire.ReadJSONBytes(bytes, tmGenesis) - // the basecoin genesis go-wire/data :) genDoc := new(FullGenesisDoc) err = json.Unmarshal(bytes, genDoc) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 9f2bac6243..7502792898 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -2,15 +2,17 @@ package ibc import ( "bytes" + "encoding/json" "errors" "net/url" "strings" abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/tmlibs/common" - merkle "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/go-wire" + merkle "github.com/tendermint/merkleeyes/iavl" + cmn "github.com/tendermint/tmlibs/common" + + "github.com/tendermint/basecoin/types" tm "github.com/tendermint/tendermint/types" ) @@ -202,9 +204,8 @@ func (sm *IBCStateMachine) runRegisterChainTx(tx IBCRegisterChainTx) { chainGen := tx.BlockchainGenesis // Parse genesis - var chainGenDoc = &tm.GenesisDoc{} - var err error - wire.ReadJSONPtr(&chainGenDoc, []byte(chainGen.Genesis), &err) + chainGenDoc := new(tm.GenesisDoc) + err := json.Unmarshal([]byte(chainGen.Genesis), chainGenDoc) if err != nil { sm.res.Code = IBCCodeEncodingError sm.res.Log = "Genesis doc couldn't be parsed: " + err.Error() diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 53864e62cf..1853a3a72d 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -2,19 +2,23 @@ package ibc import ( "bytes" + "encoding/json" "sort" "strings" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/types" crypto "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" "github.com/tendermint/merkleeyes/iavl" - tm "github.com/tendermint/tendermint/types" cmn "github.com/tendermint/tmlibs/common" + + "github.com/tendermint/basecoin/types" + tm "github.com/tendermint/tendermint/types" ) // NOTE: PrivAccounts are sorted by Address, @@ -64,8 +68,68 @@ func (pas PrivAccountsByAddress) Swap(i, j int) { //-------------------------------------------------------------------------------- +var testGenesisDoc = `{ + "app_hash": "", + "chain_id": "test_chain_1", + "genesis_time": "0001-01-01T00:00:00.000Z", + "validators": [ + { + "amount": 10, + "name": "", + "pub_key": { + "type": "ed25519", + "data":"D6EBB92440CF375054AA59BCF0C99D596DEEDFFB2543CAE1BA1908B72CF9676A" + } + } + ], + "app_options": { + "accounts": [ + { + "pub_key": { + "type": "ed25519", + "data": "B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF" + }, + "coins": [ + { + "denom": "mycoin", + "amount": 9007199254740992 + } + ] + } + ] + } +}` + +func TestIBCGenesisFromString(t *testing.T) { + assert := assert.New(t) + + eyesClient := eyes.NewLocalClient("", 0) + store := types.NewKVCache(eyesClient) + store.SetLogging() // Log all activity + + ibcPlugin := New() + ctx := types.CallContext{ + CallerAddress: nil, + CallerAccount: nil, + Coins: types.Coins{}, + } + + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ + BlockchainGenesis{ + ChainID: "test_chain", + Genesis: testGenesisDoc, + }, + }})) + assert.True(res.IsOK(), res.Log) + t.Log(">>", strings.Join(store.GetLogLines(), "\n")) + store.ClearLogLines() +} + +//-------------------------------------------------------------------------------- + func TestIBCPlugin(t *testing.T) { assert := assert.New(t) + require := require.New(t) eyesClient := eyes.NewLocalClient("", 0) store := types.NewKVCache(eyesClient) @@ -80,7 +144,8 @@ func TestIBCPlugin(t *testing.T) { chainID_1 := "test_chain" genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) - genDocJSON_1 := wire.JSONBytesPretty(genDoc_1) + genDocJSON_1, err := json.Marshal(genDoc_1) + require.Nil(err) // Register a malformed chain res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ @@ -210,6 +275,7 @@ func TestIBCPlugin(t *testing.T) { func TestIBCPluginBadCommit(t *testing.T) { assert := assert.New(t) + require := require.New(t) eyesClient := eyes.NewLocalClient("", 0) store := types.NewKVCache(eyesClient) @@ -224,7 +290,8 @@ func TestIBCPluginBadCommit(t *testing.T) { chainID_1 := "test_chain" genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) - genDocJSON_1 := wire.JSONBytesPretty(genDoc_1) + genDocJSON_1, err := json.Marshal(genDoc_1) + require.Nil(err) // Successfully register a chain res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ @@ -283,6 +350,7 @@ func TestIBCPluginBadCommit(t *testing.T) { func TestIBCPluginBadProof(t *testing.T) { assert := assert.New(t) + require := require.New(t) eyesClient := eyes.NewLocalClient("", 0) store := types.NewKVCache(eyesClient) @@ -297,7 +365,8 @@ func TestIBCPluginBadProof(t *testing.T) { chainID_1 := "test_chain" genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) - genDocJSON_1 := wire.JSONBytesPretty(genDoc_1) + genDocJSON_1, err := json.Marshal(genDoc_1) + require.Nil(err) // Successfully register a chain res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ From ab93d969bc5d497dcd2463c12440f0b0a77e15a9 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Sun, 14 May 2017 20:44:35 +0200 Subject: [PATCH 24/67] Fixed typos in readme --- cmd/basecli/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/basecli/README.md b/cmd/basecli/README.md index c30ea5b888..2d8fc23b3e 100644 --- a/cmd/basecli/README.md +++ b/cmd/basecli/README.md @@ -40,7 +40,7 @@ $ basecoin start ## Connect your basecli the first time ``` -% basecli init --chainid test_chain_id --node localhost:45567 +% basecli init --chainid test_chain_id --node tcp://localhost:46657 ``` ## Check your balances... @@ -65,4 +65,9 @@ $ basecoin start ``` % basecli seeds show --height 1767 +% basecli proxy --serve tcp://localhost:7890 +... + +curl localhost:7890/status +curl localhost:7890/block\?height=20 ``` From 41ef8af108ca011413b4111550c4f5d0e939bde9 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 1 May 2017 18:03:54 +0400 Subject: [PATCH 25/67] new logging --- app/app.go | 19 ++++--- app/app_test.go | 5 +- app/genesis.go | 4 +- app/log.go | 7 --- cmd/basecoin/main.go | 5 ++ cmd/commands/init.go | 4 +- cmd/commands/log.go | 7 --- cmd/commands/root.go | 11 ++++ cmd/commands/start.go | 25 ++++++--- cmd/counter/main.go | 5 ++ glide.lock | 109 ++++++++++++++++++++++------------------ glide.yaml | 19 +++---- state/execution.go | 11 ++-- state/execution_test.go | 3 +- state/log.go | 7 --- tests/tmsp/tmsp_test.go | 6 ++- 16 files changed, 143 insertions(+), 104 deletions(-) delete mode 100644 app/log.go delete mode 100644 cmd/commands/log.go create mode 100644 cmd/commands/root.go delete mode 100644 state/log.go diff --git a/app/app.go b/app/app.go index 3a28f7f7ea..5a9e37ea83 100644 --- a/app/app.go +++ b/app/app.go @@ -5,9 +5,10 @@ import ( "strings" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/tmlibs/common" - "github.com/tendermint/go-wire" + wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" + . "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" sm "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" @@ -24,6 +25,7 @@ type Basecoin struct { state *sm.State cacheState *sm.State plugins *types.Plugins + logger log.Logger } func NewBasecoin(eyesCli *eyes.Client) *Basecoin { @@ -34,9 +36,14 @@ func NewBasecoin(eyesCli *eyes.Client) *Basecoin { state: state, cacheState: nil, plugins: plugins, + logger: log.NewNopLogger(), } } +func (app *Basecoin) SetLogger(l log.Logger) { + app.logger = l +} + // XXX For testing, not thread safe! func (app *Basecoin) GetState() *sm.State { return app.state.CacheWrap() @@ -60,7 +67,7 @@ func (app *Basecoin) SetOption(key string, value string) string { if plugin == nil { return "Invalid plugin name: " + pluginName } - log.Notice("SetOption on plugin", "plugin", pluginName, "key", key, "value", value) + app.logger.Info("SetOption on plugin", "plugin", pluginName, "key", key, "value", value) return plugin.SetOption(app.state, key, value) } else { // Set option on basecoin @@ -75,7 +82,7 @@ func (app *Basecoin) SetOption(key string, value string) string { return "Error decoding acc message: " + err.Error() } app.state.SetAccount(acc.PubKey.Address(), &acc) - log.Notice("SetAccount", "addr", acc.PubKey.Address(), "acc", acc) + app.logger.Info("SetAccount", "addr", acc.PubKey.Address(), "acc", acc) return "Success" } @@ -97,7 +104,7 @@ func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) { } // Validate and exec tx - res = sm.ExecTx(app.state, app.plugins, tx, false, nil) + res = sm.ExecTx(app.state, app.plugins, tx, false, nil, app.logger.With("module", "state")) if res.IsErr() { return res.PrependLog("Error in DeliverTx") } @@ -118,7 +125,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) { } // Validate tx - res = sm.ExecTx(app.cacheState, app.plugins, tx, true, nil) + res = sm.ExecTx(app.cacheState, app.plugins, tx, true, nil, app.logger.With("module", "state")) if res.IsErr() { return res.PrependLog("Error in CheckTx") } diff --git a/app/app_test.go b/app/app_test.go index 011d9d7561..c56708e2b3 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -10,8 +10,9 @@ import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - "github.com/tendermint/go-wire" + wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" + "github.com/tendermint/tmlibs/log" ) //-------------------------------------------------------- @@ -56,6 +57,7 @@ func (at *appTest) reset() { eyesCli := eyes.NewLocalClient("", 0) at.app = NewBasecoin(eyesCli) + at.app.SetLogger(log.TestingLogger().With("module", "app")) res := at.app.SetOption("base/chain_id", at.chainID) require.EqualValues(at.t, res, "Success") @@ -104,6 +106,7 @@ func TestSetOption(t *testing.T) { eyesCli := eyes.NewLocalClient("", 0) app := NewBasecoin(eyesCli) + app.SetLogger(log.TestingLogger().With("module", "app")) //testing ChainID chainID := "testChain" diff --git a/app/genesis.go b/app/genesis.go index d7fb2996af..f1c36914f8 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -26,13 +26,13 @@ func (app *Basecoin) LoadGenesis(path string) error { } r := app.SetOption("base/account", string(accBytes)) // TODO: SetOption returns an error - log.Notice("Done setting Account via SetOption", "result", r) + app.logger.Info("Done setting Account via SetOption", "result", r) } // set plugin options for _, kv := range genDoc.AppOptions.pluginOptions { r := app.SetOption(kv.Key, kv.Value) - log.Notice("Done setting Plugin key-value pair via SetOption", "result", r, "k", kv.Key, "v", kv.Value) + app.logger.Info("Done setting Plugin key-value pair via SetOption", "result", r, "k", kv.Key, "v", kv.Value) } return nil } diff --git a/app/log.go b/app/log.go deleted file mode 100644 index 1337bcdfc6..0000000000 --- a/app/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package app - -import ( - "github.com/tendermint/tmlibs/logger" -) - -var log = logger.New("module", "app") diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 76ba6d5e93..0dc07d9e6e 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -7,6 +7,11 @@ import ( "github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/tmlibs/cli" + "github.com/tendermint/tmlibs/log" +) + +var ( + logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") ) func main() { diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 9bd4e76ec1..3bcfd54266 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -62,9 +62,9 @@ func initCmd(cmd *cobra.Command, args []string) error { } if (mod1 + mod2 + mod3 + mod4) > 0 { - log.Notice("Initialized Basecoin", "genesis", genesisFile, "key", key1File) + logger.Info("Initialized Basecoin", "genesis", genesisFile, "key", key1File) } else { - log.Notice("Already initialized", "priv_validator", privValFile) + logger.Info("Already initialized", "priv_validator", privValFile) } return nil diff --git a/cmd/commands/log.go b/cmd/commands/log.go deleted file mode 100644 index 3300562c80..0000000000 --- a/cmd/commands/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import ( - "github.com/tendermint/tmlibs/logger" -) - -var log = logger.New("module", "commands") diff --git a/cmd/commands/root.go b/cmd/commands/root.go new file mode 100644 index 0000000000..ff70f19807 --- /dev/null +++ b/cmd/commands/root.go @@ -0,0 +1,11 @@ +package commands + +import ( + "os" + + "github.com/tendermint/tmlibs/log" +) + +var ( + logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") +) diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 17b3ec4a1a..83601e0d1b 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -13,7 +13,7 @@ import ( eyes "github.com/tendermint/merkleeyes/client" "github.com/tendermint/tmlibs/cli" cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/logger" + "github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/node" @@ -68,6 +68,7 @@ func startCmd(cmd *cobra.Command, args []string) error { // Create Basecoin app basecoinApp := app.NewBasecoin(eyesCli) + basecoinApp.SetLogger(logger.With("module", "app")) // register IBC plugn basecoinApp.RegisterPlugin(NewIBCPlugin()) @@ -94,11 +95,11 @@ func startCmd(cmd *cobra.Command, args []string) error { chainID := basecoinApp.GetState().GetChainID() if withoutTendermintFlag { - log.Notice("Starting Basecoin without Tendermint", "chain_id", chainID) + logger.Info("Starting Basecoin without Tendermint", "chain_id", chainID) // run just the abci app/server return startBasecoinABCI(basecoinApp) } else { - log.Notice("Starting Basecoin with Tendermint", "chain_id", chainID) + logger.Info("Starting Basecoin with Tendermint", "chain_id", chainID) // start the app with tendermint in-process return startTendermint(rootDir, basecoinApp) } @@ -110,6 +111,7 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error { if err != nil { return errors.Errorf("Error creating listener: %v\n", err) } + svr.SetLogger(logger.With("module", "abci-server")) // Wait forever cmn.TrapSignal(func() { @@ -127,11 +129,22 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error { } cfg.SetRoot(cfg.RootDir) config.EnsureRoot(cfg.RootDir) - logger.SetLogLevel(cfg.LogLevel) + + var tmLogger log.Logger + switch cfg.LogLevel { + case "info": + tmLogger = log.NewFilter(logger, log.AllowInfo()) + case "debug": + tmLogger = log.NewFilter(logger, log.AllowDebug()) + case "error": + tmLogger = log.NewFilter(logger, log.AllowError()) + default: + panic(fmt.Sprintf("Unexpected log level \"%v\", expect either \"info\", \"debug\" or \"error\"")) + } // Create & start tendermint node - privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile()) - n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp)) + privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile(), tmLogger) + n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp), tmLogger.With("module", "node")) _, err = n.Start() if err != nil { diff --git a/cmd/counter/main.go b/cmd/counter/main.go index 2f6c5ca404..a79e9da6d0 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -7,6 +7,11 @@ import ( "github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/tmlibs/cli" + "github.com/tendermint/tmlibs/log" +) + +var ( + logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") ) func main() { diff --git a/glide.lock b/glide.lock index ccdb3e0b79..426bbe8d0d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,22 +1,26 @@ -hash: c887040d9aa1545d4d2c45db78032ab5e132c4eebed14e757573e7f7103fc162 -updated: 2017-04-27T20:02:48.730032774-04:00 +hash: f191c6891478db6a905646e5e3de5d9b7f9ca4e06967035470acc17fbec826d1 +updated: 2017-05-13T15:14:28.531764948Z imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd - name: github.com/btcsuite/btcd - version: 4b348c1d33373d672edd83fc576892d0e46686d2 + version: 1ae306021e323ae11c71ffb8546fbd9019e6cb6f subpackages: - btcec - name: github.com/BurntSushi/toml version: b26d9c308763d68093482582cea63d69be07a0f0 -- name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 - subpackages: - - spew - name: github.com/ebuchman/fail-test version: 95f809107225be108efcf10a3509e4ea6ceef3c4 - name: github.com/fsnotify/fsnotify version: 4da3e2cfbabc9f751898f250b49f2439785783a1 +- name: github.com/go-kit/kit + version: d67bb4c202e3b91377d1079b110a6c9ce23ab2f8 + subpackages: + - log + - log/level + - log/term +- name: github.com/go-logfmt/logfmt + version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 - name: github.com/go-playground/locales version: 1e5f1161c6416a5ff48840eb8724a394e48cc534 subpackages: @@ -24,9 +28,9 @@ imports: - name: github.com/go-playground/universal-translator version: 71201497bace774495daed26a3874fd339e0b538 - name: github.com/go-stack/stack - version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 + version: 7a2f19628aabfe68f0766b59e74d6315f8347d22 - name: github.com/golang/protobuf - version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef + version: b50ceb1fa9818fa4d78b016c2d4ae025593a7ce3 subpackages: - proto - ptypes/any @@ -35,13 +39,13 @@ imports: - name: github.com/gorilla/context version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 - name: github.com/gorilla/handlers - version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221 + version: 13d73096a474cac93275c679c7b8a2dc17ddba82 - name: github.com/gorilla/mux version: 392c28fe23e1c45ddba891b0320b3b5df220beea - name: github.com/gorilla/websocket - version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13 + version: a91eba7f97777409bc2c443f5534d41dd20c5720 - name: github.com/hashicorp/hcl - version: 630949a3c5fa3c613328e1b8256052cbc2327c9b + version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca subpackages: - hcl/ast - hcl/parser @@ -55,24 +59,18 @@ imports: version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 +- name: github.com/kr/logfmt + version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 - name: github.com/magiconair/properties version: 51463bfca2576e06c62a8504b5c0f06d61312647 -- name: github.com/mattn/go-colorable - version: ded68f7a9561c023e790de24279db7ebf473ea80 -- name: github.com/mattn/go-isatty - version: fc9e8d8ef48496124e79ae0df75490096eccf6fe - name: github.com/mitchellh/mapstructure - version: 53818660ed4955e899c0bcafa97299a388bd7c8e + version: cc8532a8e9a55ea36402aa21efdf403a60d34096 - name: github.com/pelletier/go-buffruneio version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a + version: 685a1f1cb7a66b9cadbe8f1ac49d9f8f567d6a9d - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d -- name: github.com/pmezard/go-difflib - version: d8ed2627bdf02c080bf22230dbb337003b7aba2d - subpackages: - - difflib - name: github.com/spf13/afero version: 9be650865eab0c12963d8753212f4f9c66cdcf12 subpackages: @@ -80,18 +78,13 @@ imports: - name: github.com/spf13/cast version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra - version: 10f6b9d7e1631a54ad07c5c0fb71c28a1abfd3c2 + version: 3454e0e28e69c1b8effa6b5123c8e4185e20d696 - name: github.com/spf13/jwalterweatherman - version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 + version: 8f07c835e5cc1450c082fe3a439cf87b0cbb2d99 - name: github.com/spf13/pflag - version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51 + version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 - name: github.com/spf13/viper - version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb -- name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 - subpackages: - - assert - - require + version: 0967fc9aceab2ce9da34061253ac10fb99bba5b2 - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -108,7 +101,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 8d8e35ae537538c9cf6808be3ca9dd7dab81b7f6 + version: b662bc7d3439b3c2cce615e8c3502b762e133dbf subpackages: - client - example/dummy @@ -124,35 +117,38 @@ imports: subpackages: - cmd - keys - - keys/cmd - keys/cryptostore - keys/server - keys/server/types - keys/storage/filestorage - - keys/storage/memstorage - name: github.com/tendermint/go-wire - version: b53add0b622662731985485f3a19be7f684660b8 + version: 82d31b6afb3c438639bffc5e1c7318b9a55285b3 subpackages: - data - data/base58 - name: github.com/tendermint/light-client version: 6a786b321c0634e801e692af93491b75866cb0cd -- name: github.com/tendermint/log15 - version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: - - term + - certifiers + - certifiers/client + - certifiers/files + - commands + - commands/proofs + - commands/proxy + - commands/seeds + - commands/txs + - proofs - name: github.com/tendermint/merkleeyes version: c722818b460381bc5b82e38c73ff6e22a9df624d subpackages: - app - client - iavl - - testutil - name: github.com/tendermint/tendermint - version: 07fe3e2f1345767fda9f31045da19bd277935afb + version: c5bccc5474f6ecc2f083c7e34e9ccb1be2de5312 subpackages: - blockchain - - config/tendermint_test + - config - consensus - mempool - node @@ -167,7 +163,6 @@ imports: - rpc/lib/client - rpc/lib/server - rpc/lib/types - - rpc/test - state - state/txindex - state/txindex/kv @@ -175,18 +170,20 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: 706b9fbd671d5d49ecf1b2ea3bb34e51d61ff091 + version: 8f5a175ff4c869fedde710615a11f5745ff69bf3 subpackages: - autofile + - cli - clist - common - db - events - flowrate + - log - logger - merkle - name: golang.org/x/crypto - version: 96846453c37f0876340a66a47f3f75b1f3a6cd2d + version: ab89591268e0c8b748cbe4047b00197516011af5 subpackages: - curve25519 - nacl/box @@ -197,7 +194,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: c8c74377599bd978aee1cf3b9b63a8634051cec2 + version: c9b681d35165f1995d6f3034e61f8761d4b90c99 subpackages: - context - http2 @@ -207,11 +204,11 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: ea9bcade75cb975a0b9738936568ab388b845617 + version: 9c9d83fe39ed3fd2d9249fcf6b755891fff54b03 subpackages: - unix - name: golang.org/x/text - version: 19e3104b43db45fca0303f489a9536087b184802 + version: 470f45bf29f4147d6fbd7dfd0a02a848e49f5bf4 subpackages: - secure/bidirule - transform @@ -222,10 +219,11 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: 6914ab1e338c92da4218a23d27fcd03d0ad78d46 + version: a0c3e72252b6fbf4826bb143e450eb05588a9d6d subpackages: - codes - credentials + - grpclb/grpc_lb_v1 - grpclog - internal - keepalive @@ -240,4 +238,17 @@ imports: version: 6d8c18553ea1ac493d049edd6f102f52e618f085 - name: gopkg.in/yaml.v2 version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b -testImports: [] +testImports: +- name: github.com/davecgh/go-spew + version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 + subpackages: + - spew +- name: github.com/pmezard/go-difflib + version: d8ed2627bdf02c080bf22230dbb337003b7aba2d + subpackages: + - difflib +- name: github.com/stretchr/testify + version: 4d4bfba8f1d1027c4fdbe371823030df51419987 + subpackages: + - assert + - require diff --git a/glide.yaml b/glide.yaml index 0abe9430da..95d84c8113 100644 --- a/glide.yaml +++ b/glide.yaml @@ -4,6 +4,7 @@ import: - package: github.com/pkg/errors - package: github.com/spf13/cobra - package: github.com/spf13/pflag +- package: github.com/spf13/viper - package: github.com/tendermint/abci version: develop subpackages: @@ -12,11 +13,8 @@ import: - package: github.com/tendermint/go-crypto version: develop subpackages: - - keys/cmd - - keys/cryptostore - - keys/server - - keys/storage/filestorage - - keys/storage/memstorage + - cmd + - keys - package: github.com/tendermint/go-wire version: develop subpackages: @@ -27,19 +25,20 @@ import: - commands - commands/proofs - commands/seeds - - commands/tx + - commands/txs + - proofs - package: github.com/tendermint/merkleeyes version: develop subpackages: - client - iavl - package: github.com/tendermint/tendermint - version: develop + version: feature/new-logging subpackages: - - cmd/tendermint/commands - - config/tendermint + - config - node - proxy + - rpc/client - rpc/core/types - rpc/lib/client - rpc/lib/types @@ -47,8 +46,10 @@ import: - package: github.com/tendermint/tmlibs version: develop subpackages: + - cli - common - events + - log - logger testImport: - package: github.com/stretchr/testify diff --git a/state/execution.go b/state/execution.go index c950a628e6..40bb706bb4 100644 --- a/state/execution.go +++ b/state/execution.go @@ -5,10 +5,11 @@ import ( "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/events" + "github.com/tendermint/tmlibs/log" ) // If the tx is invalid, a TMSP error will be returned. -func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable) abci.Result { +func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable, logger log.Logger) abci.Result { chainID := state.GetChainID() @@ -95,11 +96,11 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e signBytes := tx.SignBytes(chainID) res = validateInputAdvanced(inAcc, signBytes, tx.Input) if res.IsErr() { - log.Info(cmn.Fmt("validateInputAdvanced failed on %X: %v", tx.Input.Address, res)) + logger.Info(cmn.Fmt("validateInputAdvanced failed on %X: %v", tx.Input.Address, res)) return res.PrependLog("in validateInputAdvanced()") } if !tx.Input.Coins.IsGTE(types.Coins{tx.Fee}) { - log.Info(cmn.Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) + logger.Info(cmn.Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) return abci.ErrBaseInsufficientFunds.AppendLog(cmn.Fmt("input coins is %v, but fee is %v", tx.Input.Coins, types.Coins{tx.Fee})) } @@ -131,7 +132,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e res = plugin.RunTx(cache, ctx, tx.Data) if res.IsOK() { cache.CacheSync() - log.Info("Successful execution") + logger.Info("Successful execution") // Fire events /* if evc != nil { @@ -144,7 +145,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e } */ } else { - log.Info("AppTx failed", "error", res) + logger.Info("AppTx failed", "error", res) // Just return the coins and return. inAccCopy.Balance = inAccCopy.Balance.Plus(coins) // But take the gas diff --git a/state/execution_test.go b/state/execution_test.go index 249380b9fe..0f07d52da9 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -7,6 +7,7 @@ import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" + "github.com/tendermint/tmlibs/log" ) //-------------------------------------------------------- @@ -42,7 +43,7 @@ func (et *execTest) exec(tx *types.SendTx, checkTx bool) (res abci.Result, inGot initBalIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance initBalOut := et.state.GetAccount(et.accOut.Account.PubKey.Address()).Balance - res = ExecTx(et.state, nil, tx, checkTx, nil) + res = ExecTx(et.state, nil, tx, checkTx, nil, log.TestingLogger().With("module", "state")) endBalIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance endBalOut := et.state.GetAccount(et.accOut.Account.PubKey.Address()).Balance diff --git a/state/log.go b/state/log.go deleted file mode 100644 index 0a23513248..0000000000 --- a/state/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package state - -import ( - "github.com/tendermint/tmlibs/logger" -) - -var log = logger.New("module", "state") diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index 0efb9143e3..19b32341b7 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -8,15 +8,17 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/basecoin/app" "github.com/tendermint/basecoin/types" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/go-wire" + wire "github.com/tendermint/go-wire" eyescli "github.com/tendermint/merkleeyes/client" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) func TestSendTx(t *testing.T) { eyesCli := eyescli.NewLocalClient("", 0) chainID := "test_chain_id" bcApp := app.NewBasecoin(eyesCli) + bcApp.SetLogger(log.TestingLogger().With("module", "app")) bcApp.SetOption("base/chain_id", chainID) // t.Log(bcApp.Info()) From f2e452435aff24728cfcdf99c0bcd0defcdc30e7 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Sat, 13 May 2017 18:11:06 +0200 Subject: [PATCH 26/67] use helper func --- cmd/commands/start.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 83601e0d1b..77537a0395 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -130,16 +130,9 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error { cfg.SetRoot(cfg.RootDir) config.EnsureRoot(cfg.RootDir) - var tmLogger log.Logger - switch cfg.LogLevel { - case "info": - tmLogger = log.NewFilter(logger, log.AllowInfo()) - case "debug": - tmLogger = log.NewFilter(logger, log.AllowDebug()) - case "error": - tmLogger = log.NewFilter(logger, log.AllowError()) - default: - panic(fmt.Sprintf("Unexpected log level \"%v\", expect either \"info\", \"debug\" or \"error\"")) + tmLogger, err := log.NewFilterByLevel(logger, cfg.LogLevel) + if err != nil { + return err } // Create & start tendermint node From 59c3d05dfa0906047ec69c32fa948652f4b5facd Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 27 Apr 2017 20:09:12 -0400 Subject: [PATCH 27/67] updates for structs using data.Bytes --- cmd/commands/utils.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index 0e6b0948f8..d1bf91bbff 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -8,12 +8,15 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" + abci "github.com/tendermint/abci/types" + wire "github.com/tendermint/go-wire" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" - abci "github.com/tendermint/abci/types" - wire "github.com/tendermint/go-wire" - "github.com/tendermint/tendermint/rpc/client" + ctypes "github.com/tendermint/tendermint/rpc/core/types" + client "github.com/tendermint/tendermint/rpc/lib/client" tmtypes "github.com/tendermint/tendermint/types" ) From c92c9de3429a8f76ebf7a96be64359470b666df3 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 13 May 2017 20:37:37 -0400 Subject: [PATCH 28/67] update glide --- cmd/commands/utils.go | 4 +--- glide.lock | 40 +++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index d1bf91bbff..ae1f49aaa4 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -10,13 +10,11 @@ import ( abci "github.com/tendermint/abci/types" wire "github.com/tendermint/go-wire" - cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" - ctypes "github.com/tendermint/tendermint/rpc/core/types" - client "github.com/tendermint/tendermint/rpc/lib/client" + client "github.com/tendermint/tendermint/rpc/client" tmtypes "github.com/tendermint/tendermint/types" ) diff --git a/glide.lock b/glide.lock index 426bbe8d0d..864049e981 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,14 @@ -hash: f191c6891478db6a905646e5e3de5d9b7f9ca4e06967035470acc17fbec826d1 -updated: 2017-05-13T15:14:28.531764948Z +hash: 997e4cc3339141ee01aa2adf656425a49ebf117e6ca9e81ba72b8f94fee3e86e +updated: 2017-05-13T20:36:21.806338886-04:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd - name: github.com/btcsuite/btcd - version: 1ae306021e323ae11c71ffb8546fbd9019e6cb6f + version: b8df516b4b267acf2de46be593a9d948d1d2c420 subpackages: - btcec +- name: github.com/btcsuite/fastsha256 + version: 637e656429416087660c84436a2a035d69d54e2e - name: github.com/BurntSushi/toml version: b26d9c308763d68093482582cea63d69be07a0f0 - name: github.com/ebuchman/fail-test @@ -28,9 +30,9 @@ imports: - name: github.com/go-playground/universal-translator version: 71201497bace774495daed26a3874fd339e0b538 - name: github.com/go-stack/stack - version: 7a2f19628aabfe68f0766b59e74d6315f8347d22 + version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf - version: b50ceb1fa9818fa4d78b016c2d4ae025593a7ce3 + version: 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8 subpackages: - proto - ptypes/any @@ -39,13 +41,13 @@ imports: - name: github.com/gorilla/context version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 - name: github.com/gorilla/handlers - version: 13d73096a474cac93275c679c7b8a2dc17ddba82 + version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221 - name: github.com/gorilla/mux version: 392c28fe23e1c45ddba891b0320b3b5df220beea - name: github.com/gorilla/websocket version: a91eba7f97777409bc2c443f5534d41dd20c5720 - name: github.com/hashicorp/hcl - version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca + version: a4b07c25de5ff55ad3b8936cea69a79a3d95a855 subpackages: - hcl/ast - hcl/parser @@ -68,7 +70,7 @@ imports: - name: github.com/pelletier/go-buffruneio version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: 685a1f1cb7a66b9cadbe8f1ac49d9f8f567d6a9d + version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/spf13/afero @@ -78,11 +80,11 @@ imports: - name: github.com/spf13/cast version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra - version: 3454e0e28e69c1b8effa6b5123c8e4185e20d696 + version: db6b9a8b3f3f400c8ecb4a4d7d02245b8facad66 - name: github.com/spf13/jwalterweatherman - version: 8f07c835e5cc1450c082fe3a439cf87b0cbb2d99 + version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 - name: github.com/spf13/pflag - version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 + version: 80fe0fb4eba54167e2ccae1c6c950e72abf61b73 - name: github.com/spf13/viper version: 0967fc9aceab2ce9da34061253ac10fb99bba5b2 - name: github.com/syndtr/goleveldb @@ -127,7 +129,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: 6a786b321c0634e801e692af93491b75866cb0cd + version: 27a1b070321ae8d6931a5dddc380f890a66b2e61 subpackages: - certifiers - certifiers/client @@ -145,7 +147,7 @@ imports: - client - iavl - name: github.com/tendermint/tendermint - version: c5bccc5474f6ecc2f083c7e34e9ccb1be2de5312 + version: f14f16729797cc364b194e0e37301b784814e909 subpackages: - blockchain - config @@ -183,7 +185,7 @@ imports: - logger - merkle - name: golang.org/x/crypto - version: ab89591268e0c8b748cbe4047b00197516011af5 + version: 1f22c0103821b9390939b6776727195525381532 subpackages: - curve25519 - nacl/box @@ -194,7 +196,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: c9b681d35165f1995d6f3034e61f8761d4b90c99 + version: feeb485667d1fdabe727840fe00adc22431bc86e subpackages: - context - http2 @@ -204,7 +206,7 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: 9c9d83fe39ed3fd2d9249fcf6b755891fff54b03 + version: 50c6bc5e4292a1d4e65c6e9be5f53be28bcbe28e subpackages: - unix - name: golang.org/x/text @@ -219,7 +221,7 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: a0c3e72252b6fbf4826bb143e450eb05588a9d6d + version: 844f573616520565fdc6fb4db242321b5456fd6d subpackages: - codes - credentials @@ -240,7 +242,7 @@ imports: version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: - name: github.com/davecgh/go-spew - version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 + version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -248,7 +250,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 4d4bfba8f1d1027c4fdbe371823030df51419987 + version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require From e42849b4b897a23711ff75409c31948328436099 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Sun, 14 May 2017 11:24:33 +0200 Subject: [PATCH 29/67] move logger to state also remove redundant root.go logger --- app/app.go | 5 +++-- cmd/basecoin/main.go | 5 ----- cmd/counter/main.go | 6 ------ state/execution.go | 12 +++++------- state/execution_test.go | 3 ++- state/state.go | 11 +++++++++-- state/state_test.go | 4 ++++ 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/app.go b/app/app.go index 5a9e37ea83..94d37c43db 100644 --- a/app/app.go +++ b/app/app.go @@ -42,6 +42,7 @@ func NewBasecoin(eyesCli *eyes.Client) *Basecoin { func (app *Basecoin) SetLogger(l log.Logger) { app.logger = l + app.state.SetLogger(l.With("module", "state")) } // XXX For testing, not thread safe! @@ -104,7 +105,7 @@ func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) { } // Validate and exec tx - res = sm.ExecTx(app.state, app.plugins, tx, false, nil, app.logger.With("module", "state")) + res = sm.ExecTx(app.state, app.plugins, tx, false, nil) if res.IsErr() { return res.PrependLog("Error in DeliverTx") } @@ -125,7 +126,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) { } // Validate tx - res = sm.ExecTx(app.cacheState, app.plugins, tx, true, nil, app.logger.With("module", "state")) + res = sm.ExecTx(app.cacheState, app.plugins, tx, true, nil) if res.IsErr() { return res.PrependLog("Error in CheckTx") } diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 0dc07d9e6e..76ba6d5e93 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -7,11 +7,6 @@ import ( "github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/tmlibs/cli" - "github.com/tendermint/tmlibs/log" -) - -var ( - logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") ) func main() { diff --git a/cmd/counter/main.go b/cmd/counter/main.go index a79e9da6d0..8254fce271 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -7,15 +7,9 @@ import ( "github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/tmlibs/cli" - "github.com/tendermint/tmlibs/log" -) - -var ( - logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") ) func main() { - var RootCmd = &cobra.Command{ Use: "counter", Short: "demo plugin for basecoin", diff --git a/state/execution.go b/state/execution.go index 40bb706bb4..246246846d 100644 --- a/state/execution.go +++ b/state/execution.go @@ -5,12 +5,10 @@ import ( "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/events" - "github.com/tendermint/tmlibs/log" ) // If the tx is invalid, a TMSP error will be returned. -func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable, logger log.Logger) abci.Result { - +func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable) abci.Result { chainID := state.GetChainID() // Exec tx @@ -96,11 +94,11 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e signBytes := tx.SignBytes(chainID) res = validateInputAdvanced(inAcc, signBytes, tx.Input) if res.IsErr() { - logger.Info(cmn.Fmt("validateInputAdvanced failed on %X: %v", tx.Input.Address, res)) + state.logger.Info(cmn.Fmt("validateInputAdvanced failed on %X: %v", tx.Input.Address, res)) return res.PrependLog("in validateInputAdvanced()") } if !tx.Input.Coins.IsGTE(types.Coins{tx.Fee}) { - logger.Info(cmn.Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) + state.logger.Info(cmn.Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) return abci.ErrBaseInsufficientFunds.AppendLog(cmn.Fmt("input coins is %v, but fee is %v", tx.Input.Coins, types.Coins{tx.Fee})) } @@ -132,7 +130,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e res = plugin.RunTx(cache, ctx, tx.Data) if res.IsOK() { cache.CacheSync() - logger.Info("Successful execution") + state.logger.Info("Successful execution") // Fire events /* if evc != nil { @@ -145,7 +143,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e } */ } else { - logger.Info("AppTx failed", "error", res) + state.logger.Info("AppTx failed", "error", res) // Just return the coins and return. inAccCopy.Balance = inAccCopy.Balance.Plus(coins) // But take the gas diff --git a/state/execution_test.go b/state/execution_test.go index 0f07d52da9..b8e526ae48 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -43,7 +43,7 @@ func (et *execTest) exec(tx *types.SendTx, checkTx bool) (res abci.Result, inGot initBalIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance initBalOut := et.state.GetAccount(et.accOut.Account.PubKey.Address()).Balance - res = ExecTx(et.state, nil, tx, checkTx, nil, log.TestingLogger().With("module", "state")) + res = ExecTx(et.state, nil, tx, checkTx, nil) endBalIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance endBalOut := et.state.GetAccount(et.accOut.Account.PubKey.Address()).Balance @@ -64,6 +64,7 @@ func (et *execTest) reset() { et.store = types.NewMemKVStore() et.state = NewState(et.store) + et.state.SetLogger(log.TestingLogger()) et.state.SetChainID(et.chainID) // NOTE we dont run acc2State here diff --git a/state/state.go b/state/state.go index 5555dae913..835ff088b2 100644 --- a/state/state.go +++ b/state/state.go @@ -3,9 +3,10 @@ package state import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - . "github.com/tendermint/tmlibs/common" - "github.com/tendermint/go-wire" + wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" + . "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" ) // CONTRACT: State should be quick to copy. @@ -15,6 +16,7 @@ type State struct { store types.KVStore readCache map[string][]byte // optional, for caching writes to store writeCache *types.KVCache // optional, for caching writes w/o writing to store + logger log.Logger } func NewState(store types.KVStore) *State { @@ -23,9 +25,14 @@ func NewState(store types.KVStore) *State { store: store, readCache: make(map[string][]byte), writeCache: nil, + logger: log.NewNopLogger(), } } +func (s *State) SetLogger(l log.Logger) { + s.logger = l +} + func (s *State) SetChainID(chainID string) { s.chainID = chainID s.store.Set([]byte("base/chain_id"), []byte(chainID)) diff --git a/state/state_test.go b/state/state_test.go index 1d35f2c4f6..dae620027a 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -6,6 +6,7 @@ import ( "github.com/tendermint/basecoin/types" eyes "github.com/tendermint/merkleeyes/client" + "github.com/tendermint/tmlibs/log" "github.com/stretchr/testify/assert" ) @@ -16,6 +17,7 @@ func TestState(t *testing.T) { //States and Stores for tests store := types.NewMemKVStore() state := NewState(store) + state.SetLogger(log.TestingLogger()) cache := state.CacheWrap() eyesCli := eyes.NewLocalClient("", 0) @@ -29,12 +31,14 @@ func TestState(t *testing.T) { reset := func() { store = types.NewMemKVStore() state = NewState(store) + state.SetLogger(log.TestingLogger()) cache = state.CacheWrap() } //set the state to using the eyesCli instead of MemKVStore useEyesCli := func() { state = NewState(eyesCli) + state.SetLogger(log.TestingLogger()) cache = state.CacheWrap() } From 1e92e7c5c3df5669211b0ee495689d36e847fecf Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Sun, 14 May 2017 20:54:52 +0200 Subject: [PATCH 30/67] Update light-client for fixes with websocket in proxy --- glide.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glide.lock b/glide.lock index 864049e981..5fc8dd6b73 100644 --- a/glide.lock +++ b/glide.lock @@ -129,7 +129,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: 27a1b070321ae8d6931a5dddc380f890a66b2e61 + version: 1653de52744254fabdc698b6741a0ae4068761cf subpackages: - certifiers - certifiers/client From fdd7addb67b608d69f094a949316894768475870 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 16 May 2017 15:45:10 +0200 Subject: [PATCH 31/67] update deps (point tendermint to develop) --- glide.lock | 46 ++++++++++++++++++++++------------------------ glide.yaml | 2 +- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/glide.lock b/glide.lock index 5fc8dd6b73..5afaddaefb 100644 --- a/glide.lock +++ b/glide.lock @@ -1,14 +1,12 @@ hash: 997e4cc3339141ee01aa2adf656425a49ebf117e6ca9e81ba72b8f94fee3e86e -updated: 2017-05-13T20:36:21.806338886-04:00 +updated: 2017-05-16T13:41:59.92225084Z imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd - name: github.com/btcsuite/btcd - version: b8df516b4b267acf2de46be593a9d948d1d2c420 + version: 1ae306021e323ae11c71ffb8546fbd9019e6cb6f subpackages: - btcec -- name: github.com/btcsuite/fastsha256 - version: 637e656429416087660c84436a2a035d69d54e2e - name: github.com/BurntSushi/toml version: b26d9c308763d68093482582cea63d69be07a0f0 - name: github.com/ebuchman/fail-test @@ -30,9 +28,9 @@ imports: - name: github.com/go-playground/universal-translator version: 71201497bace774495daed26a3874fd339e0b538 - name: github.com/go-stack/stack - version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 + version: 7a2f19628aabfe68f0766b59e74d6315f8347d22 - name: github.com/golang/protobuf - version: 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8 + version: b50ceb1fa9818fa4d78b016c2d4ae025593a7ce3 subpackages: - proto - ptypes/any @@ -41,13 +39,13 @@ imports: - name: github.com/gorilla/context version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 - name: github.com/gorilla/handlers - version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221 + version: 13d73096a474cac93275c679c7b8a2dc17ddba82 - name: github.com/gorilla/mux version: 392c28fe23e1c45ddba891b0320b3b5df220beea - name: github.com/gorilla/websocket version: a91eba7f97777409bc2c443f5534d41dd20c5720 - name: github.com/hashicorp/hcl - version: a4b07c25de5ff55ad3b8936cea69a79a3d95a855 + version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca subpackages: - hcl/ast - hcl/parser @@ -70,7 +68,7 @@ imports: - name: github.com/pelletier/go-buffruneio version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a + version: 685a1f1cb7a66b9cadbe8f1ac49d9f8f567d6a9d - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/spf13/afero @@ -80,11 +78,11 @@ imports: - name: github.com/spf13/cast version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 - name: github.com/spf13/cobra - version: db6b9a8b3f3f400c8ecb4a4d7d02245b8facad66 + version: 3454e0e28e69c1b8effa6b5123c8e4185e20d696 - name: github.com/spf13/jwalterweatherman - version: fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66 + version: 8f07c835e5cc1450c082fe3a439cf87b0cbb2d99 - name: github.com/spf13/pflag - version: 80fe0fb4eba54167e2ccae1c6c950e72abf61b73 + version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 - name: github.com/spf13/viper version: 0967fc9aceab2ce9da34061253ac10fb99bba5b2 - name: github.com/syndtr/goleveldb @@ -103,7 +101,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: b662bc7d3439b3c2cce615e8c3502b762e133dbf + version: 5dabeffb35c027d7087a12149685daa68989168b subpackages: - client - example/dummy @@ -115,7 +113,7 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: e71bbb2509b586f0b24f120b6ba57f32aefa1579 + version: a42b10e0feb465eb56fbc6bb5b71d57ef646ec57 subpackages: - cmd - keys @@ -124,12 +122,12 @@ imports: - keys/server/types - keys/storage/filestorage - name: github.com/tendermint/go-wire - version: 82d31b6afb3c438639bffc5e1c7318b9a55285b3 + version: 7f81de645283af7c62f17eafe3ef13b38cc0836b subpackages: - data - data/base58 - name: github.com/tendermint/light-client - version: 1653de52744254fabdc698b6741a0ae4068761cf + version: c003b47d43fd79dcec14e5cdaf353cc461fa7cb7 subpackages: - certifiers - certifiers/client @@ -147,7 +145,7 @@ imports: - client - iavl - name: github.com/tendermint/tendermint - version: f14f16729797cc364b194e0e37301b784814e909 + version: e1792c1ea521ff6c10f79d7865a027024978b629 subpackages: - blockchain - config @@ -172,7 +170,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: 8f5a175ff4c869fedde710615a11f5745ff69bf3 + version: 812d9f9b84d1dfe4cb46ce021b3a2d97b48d1292 subpackages: - autofile - cli @@ -185,7 +183,7 @@ imports: - logger - merkle - name: golang.org/x/crypto - version: 1f22c0103821b9390939b6776727195525381532 + version: ab89591268e0c8b748cbe4047b00197516011af5 subpackages: - curve25519 - nacl/box @@ -196,7 +194,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: feeb485667d1fdabe727840fe00adc22431bc86e + version: c9b681d35165f1995d6f3034e61f8761d4b90c99 subpackages: - context - http2 @@ -206,7 +204,7 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: 50c6bc5e4292a1d4e65c6e9be5f53be28bcbe28e + version: 9c9d83fe39ed3fd2d9249fcf6b755891fff54b03 subpackages: - unix - name: golang.org/x/text @@ -221,7 +219,7 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: 844f573616520565fdc6fb4db242321b5456fd6d + version: a0c3e72252b6fbf4826bb143e450eb05588a9d6d subpackages: - codes - credentials @@ -242,7 +240,7 @@ imports: version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: - name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 + version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -250,7 +248,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 + version: 4d4bfba8f1d1027c4fdbe371823030df51419987 subpackages: - assert - require diff --git a/glide.yaml b/glide.yaml index 95d84c8113..b050008553 100644 --- a/glide.yaml +++ b/glide.yaml @@ -33,7 +33,7 @@ import: - client - iavl - package: github.com/tendermint/tendermint - version: feature/new-logging + version: develop subpackages: - config - node From 698347a4aa4de7cc21b7f9b5916ddb12e2cb63ef Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 16:01:58 +0200 Subject: [PATCH 32/67] Demo on develop version of tendermint --- demo/start.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demo/start.sh b/demo/start.sh index 20335f7392..5bda96febc 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -4,7 +4,8 @@ set -e cd $GOPATH/src/github.com/tendermint/basecoin/demo LOG_DIR="." -TM_VERSION="v0.9.2" +TM_VERSION="develop" +#TM_VERSION="v0.10.0" if [[ "$CIRCLECI" == "true" ]]; then # set log dir From 0c1cf83a7b1725f4b46155ca6b18aa8997510b43 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 16:20:36 +0200 Subject: [PATCH 33/67] debug circle --- circle.yml | 17 ++++++++--------- demo/start.sh | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/circle.yml b/circle.yml index f24f3ab383..67530b1d8a 100644 --- a/circle.yml +++ b/circle.yml @@ -1,26 +1,25 @@ machine: environment: - GOPATH: /home/ubuntu/.go_workspace - REPO: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME + GOPATH: "$HOME/.go_project" + PROJECT_PARENT_PATH: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME" + REPO: "$PROJECT_PARENT_PATH/$CIRCLE_PROJECT_REPONAME" hosts: circlehost: 127.0.0.1 localhost: 127.0.0.1 -checkout: - post: - - rm -rf $REPO - - mkdir -p $HOME/.go_workspace/src/github.com/$CIRCLE_PROJECT_USERNAME - - mv $HOME/$CIRCLE_PROJECT_REPONAME $REPO - dependencies: override: - go get github.com/Masterminds/glide - go version - glide --version - - "cd $REPO && glide install && go install ./cmd/basecoin" + - mkdir -p "$PROJECT_PARENT_PATH" + - ln -sf "$HOME/$CIRCLE_PROJECT_REPONAME/" "$REPO" + - env test: override: + - "cd $REPO && glide install && go install ./cmd/basecoin" + - ls $GOPATH/bin - "cd $REPO && make test" - "cd $REPO/demo && bash start.sh" diff --git a/demo/start.sh b/demo/start.sh index 5bda96febc..561d370c97 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -18,6 +18,7 @@ if [[ "$CIRCLECI" == "true" ]]; then git checkout $TM_VERSION glide install go install ./cmd/tendermint + ls $GOPATH/bin popd set -e fi @@ -28,7 +29,7 @@ function ifExit() { if [[ "$?" != 0 ]]; then echo "FAIL" exit 1 - fi + fi } function removeQuotes() { From 94703fa95bffda4cf7f15e6ccc5bd747ce075392 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 16:43:49 +0200 Subject: [PATCH 34/67] more debug --- circle.yml | 2 +- demo/start.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 67530b1d8a..afaa5f831d 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,6 @@ machine: environment: - GOPATH: "$HOME/.go_project" + GOPATH: "$HOME/.go_workspace" PROJECT_PARENT_PATH: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME" REPO: "$PROJECT_PARENT_PATH/$CIRCLE_PROJECT_REPONAME" hosts: diff --git a/demo/start.sh b/demo/start.sh index 561d370c97..3f03a14cd2 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -18,7 +18,14 @@ if [[ "$CIRCLECI" == "true" ]]; then git checkout $TM_VERSION glide install go install ./cmd/tendermint - ls $GOPATH/bin + echo "----" + echo $PATH + echo $GOPATH/bin + ls -l $GOPATH/bin + which basecoin + ls -l $(dirname `which basecoin`) + which tendermint + echo "----" popd set -e fi From 4a380bb6e89983a4d0a4d26f6580b3933bf99c34 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 18:52:43 +0200 Subject: [PATCH 35/67] Start abci server when running --without-tendermint --- circle.yml | 1 + cmd/commands/start.go | 1 + 2 files changed, 2 insertions(+) diff --git a/circle.yml b/circle.yml index afaa5f831d..3e8710ca9e 100644 --- a/circle.yml +++ b/circle.yml @@ -3,6 +3,7 @@ machine: GOPATH: "$HOME/.go_workspace" PROJECT_PARENT_PATH: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME" REPO: "$PROJECT_PARENT_PATH/$CIRCLE_PROJECT_REPONAME" + PATH: "$GOPATH/bin:$PATH" hosts: circlehost: 127.0.0.1 localhost: 127.0.0.1 diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 77537a0395..7db4bf14d4 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -112,6 +112,7 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error { return errors.Errorf("Error creating listener: %v\n", err) } svr.SetLogger(logger.With("module", "abci-server")) + svr.Start() // Wait forever cmn.TrapSignal(func() { From 2f37d5b63571f0a3930507e3c0cb9cb8f1d41821 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 19:00:45 +0200 Subject: [PATCH 36/67] Remove lots of circle debug statements --- demo/start.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/demo/start.sh b/demo/start.sh index 3f03a14cd2..f15a5fd5bd 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -18,14 +18,6 @@ if [[ "$CIRCLECI" == "true" ]]; then git checkout $TM_VERSION glide install go install ./cmd/tendermint - echo "----" - echo $PATH - echo $GOPATH/bin - ls -l $GOPATH/bin - which basecoin - ls -l $(dirname `which basecoin`) - which tendermint - echo "----" popd set -e fi From 4207275d1871ae44be020e343364cd0089ff62d9 Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Mon, 1 May 2017 03:05:54 -0400 Subject: [PATCH 37/67] basecli cleanup glide fix int int --- cmd/basecli/adapters.go | 40 ++++++++++++++++++++++------------------ cmd/basecli/main.go | 22 +++++++++++----------- glide.yaml | 2 +- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/cmd/basecli/adapters.go b/cmd/basecli/adapters.go index b0b10d2fc4..4398b9731d 100644 --- a/cmd/basecli/adapters.go +++ b/cmd/basecli/adapters.go @@ -7,7 +7,10 @@ import ( "github.com/pkg/errors" flag "github.com/spf13/pflag" "github.com/spf13/viper" + + "github.com/tendermint/basecoin/state" btypes "github.com/tendermint/basecoin/types" + keycmd "github.com/tendermint/go-crypto/cmd" wire "github.com/tendermint/go-wire" lightclient "github.com/tendermint/light-client" @@ -20,7 +23,7 @@ type AccountPresenter struct{} func (_ AccountPresenter) MakeKey(str string) ([]byte, error) { res, err := hex.DecodeString(str) if err == nil { - res = append([]byte("base/a/"), res...) + res = state.AccountKey(res) } return res, err } @@ -41,21 +44,6 @@ func (_ BaseTxPresenter) ParseData(raw []byte) (interface{}, error) { return tx, err } -// SendTXReader allows us to create SendTx -type SendTxReader struct { - ChainID string -} - -func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { - var tx btypes.SendTx - err := json.Unmarshal(data, &tx) - send := SendTx{ - chainID: t.ChainID, - Tx: &tx, - } - return &send, errors.Wrap(err, "parse sendtx") -} - type SendTxMaker struct{} func (m SendTxMaker) MakeReader() (lightclient.TxReader, error) { @@ -72,7 +60,8 @@ type SendFlags struct { } func (m SendTxMaker) Flags() (*flag.FlagSet, interface{}) { - fs := flag.NewFlagSet("foobar", flag.ContinueOnError) + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.String("to", "", "Destination address for the bits") fs.String("amount", "", "Coins to send in the format ,...") fs.String("fee", "", "Coins for the transaction fee of the format ") @@ -81,6 +70,21 @@ func (m SendTxMaker) Flags() (*flag.FlagSet, interface{}) { return fs, &SendFlags{} } +// SendTXReader allows us to create SendTx +type SendTxReader struct { + ChainID string +} + +func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { + var tx btypes.SendTx + err := json.Unmarshal(data, &tx) + send := SendTx{ + chainID: t.ChainID, + Tx: &tx, + } + return &send, errors.Wrap(err, "parse sendtx") +} + func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { data := flags.(*SendFlags) @@ -134,7 +138,7 @@ func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { return &send, nil } -/** copied from basecoin cli - put in common somewhere? **/ +/** TODO copied from basecoin cli - put in common somewhere? **/ // Returns true for non-empty hex-string prefixed with "0x" func isHex(s string) bool { diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index baaf630dac..79aa4c4bf2 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -7,7 +7,6 @@ import ( keycmd "github.com/tendermint/go-crypto/cmd" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/commands/proofs" - "github.com/tendermint/light-client/commands/proxy" "github.com/tendermint/light-client/commands/seeds" "github.com/tendermint/light-client/commands/txs" "github.com/tendermint/tmlibs/cli" @@ -25,22 +24,23 @@ tmcli to work for any custom abci app. `, } -func init() { +func main() { commands.AddBasicFlags(BaseCli) - // set up the various commands to use - BaseCli.AddCommand(keycmd.RootCmd) - BaseCli.AddCommand(commands.InitCmd) - BaseCli.AddCommand(seeds.RootCmd) + //initialize proofs and txs proofs.StatePresenters.Register("account", AccountPresenter{}) proofs.TxPresenters.Register("base", BaseTxPresenter{}) - BaseCli.AddCommand(proofs.RootCmd) txs.Register("send", SendTxMaker{}) - BaseCli.AddCommand(txs.RootCmd) - BaseCli.AddCommand(proxy.RootCmd) -} -func main() { + // set up the various commands to use + BaseCli.AddCommand( + keycmd.RootCmd, + commands.InitCmd, + seeds.RootCmd, + proofs.RootCmd, + txs.RootCmd, + ) + cmd := cli.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli")) cmd.Execute() } diff --git a/glide.yaml b/glide.yaml index b050008553..718b80e6d9 100644 --- a/glide.yaml +++ b/glide.yaml @@ -44,7 +44,7 @@ import: - rpc/lib/types - types - package: github.com/tendermint/tmlibs - version: develop + version: basecoin-cli subpackages: - cli - common From 0843c4428bfbc6782959a7ede27b2a0a0d6ebbe9 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 20:21:55 +0200 Subject: [PATCH 38/67] Cleanup merge --- cmd/basecli/main.go | 2 ++ glide.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 79aa4c4bf2..8b97b76b65 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -7,6 +7,7 @@ import ( keycmd "github.com/tendermint/go-crypto/cmd" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/commands/proofs" + "github.com/tendermint/light-client/commands/proxy" "github.com/tendermint/light-client/commands/seeds" "github.com/tendermint/light-client/commands/txs" "github.com/tendermint/tmlibs/cli" @@ -39,6 +40,7 @@ func main() { seeds.RootCmd, proofs.RootCmd, txs.RootCmd, + proxy.RootCmd, ) cmd := cli.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli")) diff --git a/glide.yaml b/glide.yaml index 718b80e6d9..b050008553 100644 --- a/glide.yaml +++ b/glide.yaml @@ -44,7 +44,7 @@ import: - rpc/lib/types - types - package: github.com/tendermint/tmlibs - version: basecoin-cli + version: develop subpackages: - cli - common From a32bf5475fdbcb81aade84cf4d8c3c2e362358f7 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 21:40:07 +0200 Subject: [PATCH 39/67] Start working on apptx for counter in basecli --- cmd/basecli/adapters.go | 8 +++--- cmd/basecli/apptx.go | 59 +++++++++++++++++++++++++++++++++++++++++ cmd/basecli/counter.go | 24 +++++++++++++++++ cmd/basecli/main.go | 1 + cmd/counter/main.go | 4 ++- types/tx.go | 6 ++--- 6 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 cmd/basecli/apptx.go create mode 100644 cmd/basecli/counter.go diff --git a/cmd/basecli/adapters.go b/cmd/basecli/adapters.go index 4398b9731d..5b4869acdc 100644 --- a/cmd/basecli/adapters.go +++ b/cmd/basecli/adapters.go @@ -8,14 +8,14 @@ import ( flag "github.com/spf13/pflag" "github.com/spf13/viper" - "github.com/tendermint/basecoin/state" - btypes "github.com/tendermint/basecoin/types" - keycmd "github.com/tendermint/go-crypto/cmd" wire "github.com/tendermint/go-wire" lightclient "github.com/tendermint/light-client" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/proofs" + + "github.com/tendermint/basecoin/state" + btypes "github.com/tendermint/basecoin/types" ) type AccountPresenter struct{} @@ -44,6 +44,8 @@ func (_ BaseTxPresenter) ParseData(raw []byte) (interface{}, error) { return tx, err } +/******** SendTx *********/ + type SendTxMaker struct{} func (m SendTxMaker) MakeReader() (lightclient.TxReader, error) { diff --git a/cmd/basecli/apptx.go b/cmd/basecli/apptx.go new file mode 100644 index 0000000000..9c9523fc47 --- /dev/null +++ b/cmd/basecli/apptx.go @@ -0,0 +1,59 @@ +package main + +import ( + "github.com/pkg/errors" + + crypto "github.com/tendermint/go-crypto" + keys "github.com/tendermint/go-crypto/keys" + wire "github.com/tendermint/go-wire" + + bc "github.com/tendermint/basecoin/types" +) + +type AppTx struct { + chainID string + signers []crypto.PubKey + Tx *bc.AppTx +} + +var _ keys.Signable = &AppTx{} + +// SignBytes returned the unsigned bytes, needing a signature +func (s *AppTx) SignBytes() []byte { + return s.Tx.SignBytes(s.chainID) +} + +// Sign will add a signature and pubkey. +// +// Depending on the Signable, one may be able to call this multiple times for multisig +// Returns error if called with invalid data or too many times +func (s *AppTx) Sign(pubkey crypto.PubKey, sig crypto.Signature) error { + if len(s.signers) > 0 { + return errors.New("AppTx already signed") + } + s.Tx.SetSignature(sig) + s.signers = []crypto.PubKey{pubkey} + return nil +} + +// Signers will return the public key(s) that signed if the signature +// is valid, or an error if there is any issue with the signature, +// including if there are no signatures +func (s *AppTx) Signers() ([]crypto.PubKey, error) { + if len(s.signers) == 0 { + return nil, errors.New("No signatures on AppTx") + } + return s.signers, nil +} + +// TxBytes returns the transaction data as well as all signatures +// It should return an error if Sign was never called +func (s *AppTx) TxBytes() ([]byte, error) { + // TODO: verify it is signed + + // Code and comment from: basecoin/cmd/commands/tx.go + // Don't you hate having to do this? + // How many times have I lost an hour over this trick?! + txBytes := wire.BinaryBytes(bc.TxS{s.Tx}) + return txBytes, nil +} diff --git a/cmd/basecli/counter.go b/cmd/basecli/counter.go new file mode 100644 index 0000000000..15608b9e95 --- /dev/null +++ b/cmd/basecli/counter.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + wire "github.com/tendermint/go-wire" + + "github.com/tendermint/basecoin/plugins/counter" +) + +type CounterPresenter struct{} + +func (_ CounterPresenter) MakeKey(str string) ([]byte, error) { + key := counter.New().StateKey() + fmt.Println(string(key)) + return key, nil +} + +func (_ CounterPresenter) ParseData(raw []byte) (interface{}, error) { + fmt.Println("Data", len(raw)) + var cp counter.CounterPluginState + err := wire.ReadBinaryBytes(raw, &cp) + return cp, err +} diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 8b97b76b65..a8f3a8419f 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -30,6 +30,7 @@ func main() { //initialize proofs and txs proofs.StatePresenters.Register("account", AccountPresenter{}) + proofs.StatePresenters.Register("counter", CounterPresenter{}) proofs.TxPresenters.Register("base", BaseTxPresenter{}) txs.Register("send", SendTxMaker{}) diff --git a/cmd/counter/main.go b/cmd/counter/main.go index 8254fce271..083535733f 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -16,6 +16,7 @@ func main() { } RootCmd.AddCommand( + commands.InitCmd, commands.StartCmd, commands.TxCmd, commands.QueryCmd, @@ -23,7 +24,8 @@ func main() { commands.VerifyCmd, commands.BlockCmd, commands.AccountCmd, - commands.QuickVersionCmd("0.1.0"), + commands.UnsafeResetAllCmd, + commands.VersionCmd, ) cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin")) diff --git a/types/tx.go b/types/tx.go index 7b1b547a0b..ed3e2ca0c9 100644 --- a/types/tx.go +++ b/types/tx.go @@ -5,10 +5,10 @@ import ( "encoding/json" abci "github.com/tendermint/abci/types" - . "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire/data" "github.com/tendermint/go-wire" + "github.com/tendermint/go-wire/data" + . "github.com/tendermint/tmlibs/common" ) /* @@ -46,7 +46,7 @@ func init() { // TxS add json serialization to Tx type TxS struct { - Tx + Tx `json:"unwrap"` } func (p TxS) MarshalJSON() ([]byte, error) { From 41c0f7cb692e10940bfc40fd1982c03c0493e0b6 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 23:47:36 +0200 Subject: [PATCH 40/67] Owa! nil logger -> crash on CheckTx :( --- state/state.go | 1 + 1 file changed, 1 insertion(+) diff --git a/state/state.go b/state/state.go index 835ff088b2..fbec5ae8e0 100644 --- a/state/state.go +++ b/state/state.go @@ -78,6 +78,7 @@ func (s *State) CacheWrap() *State { store: cache, readCache: nil, writeCache: cache, + logger: s.logger, } } From ab6e5c3da2afc042d3dd29907a8e7ad8da297c42 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 16 May 2017 23:53:58 +0200 Subject: [PATCH 41/67] Add counter app to basecli --- cmd/basecli/adapters.go | 70 +++++++++++++++++++++++++++++++++++++++++ cmd/basecli/counter.go | 65 ++++++++++++++++++++++++++++++++++++-- cmd/basecli/main.go | 2 ++ 3 files changed, 134 insertions(+), 3 deletions(-) diff --git a/cmd/basecli/adapters.go b/cmd/basecli/adapters.go index 5b4869acdc..56dfdae0ba 100644 --- a/cmd/basecli/adapters.go +++ b/cmd/basecli/adapters.go @@ -140,6 +140,76 @@ func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { return &send, nil } +/******** AppTx *********/ + +type AppFlags struct { + Fee string + Gas int64 + Amount string + Sequence int +} + +func AppFlagSet() (*flag.FlagSet, AppFlags) { + fs := flag.NewFlagSet("", flag.ContinueOnError) + + fs.String("amount", "", "Coins to send in the format ,...") + fs.String("fee", "", "Coins for the transaction fee of the format ") + fs.Int64("gas", 0, "Amount of gas for this transaction") + fs.Int("sequence", -1, "Sequence number for this transaction") + return fs, AppFlags{} +} + +// AppTxReader allows us to create AppTx +type AppTxReader struct { + ChainID string +} + +func (t AppTxReader) ReadTxJSON(data []byte) (interface{}, error) { + return nil, errors.New("Not implemented...") +} + +func (t AppTxReader) ReadTxFlags(data *AppFlags, app string, appData []byte) (interface{}, error) { + // TODO: figure out a cleaner way to do this... until then + // just close your eyes and continue... + manager := keycmd.GetKeyManager() + name := viper.GetString("name") + info, err := manager.Get(name) + + //parse the fee and amounts into coin types + feeCoin, err := btypes.ParseCoin(data.Fee) + if err != nil { + return nil, err + } + amountCoins, err := btypes.ParseCoins(data.Amount) + if err != nil { + return nil, err + } + + // craft the tx + input := btypes.TxInput{ + Address: info.Address, + Coins: amountCoins, + Sequence: data.Sequence, + } + if data.Sequence == 1 { + input.PubKey = info.PubKey + } + tx := btypes.AppTx{ + Gas: data.Gas, + Fee: feeCoin, + Input: input, + Name: app, + Data: appData, + } + + // wrap it in the proper signer thing... + send := AppTx{ + chainID: t.ChainID, + Tx: &tx, + } + return &send, nil +} + /** TODO copied from basecoin cli - put in common somewhere? **/ // Returns true for non-empty hex-string prefixed with "0x" diff --git a/cmd/basecli/counter.go b/cmd/basecli/counter.go index 15608b9e95..7a6c9cc67a 100644 --- a/cmd/basecli/counter.go +++ b/cmd/basecli/counter.go @@ -1,24 +1,83 @@ package main import ( - "fmt" + flag "github.com/spf13/pflag" + "github.com/spf13/viper" wire "github.com/tendermint/go-wire" + lightclient "github.com/tendermint/light-client" + "github.com/tendermint/light-client/commands" + "github.com/tendermint/light-client/commands/txs" "github.com/tendermint/basecoin/plugins/counter" + btypes "github.com/tendermint/basecoin/types" ) type CounterPresenter struct{} func (_ CounterPresenter) MakeKey(str string) ([]byte, error) { key := counter.New().StateKey() - fmt.Println(string(key)) return key, nil } func (_ CounterPresenter) ParseData(raw []byte) (interface{}, error) { - fmt.Println("Data", len(raw)) var cp counter.CounterPluginState err := wire.ReadBinaryBytes(raw, &cp) return cp, err } + +/**** build out the tx ****/ + +var ( + _ txs.ReaderMaker = CounterTxMaker{} + _ lightclient.TxReader = CounterTxReader{} +) + +type CounterTxMaker struct{} + +func (m CounterTxMaker) MakeReader() (lightclient.TxReader, error) { + chainID := viper.GetString(commands.ChainFlag) + return CounterTxReader{AppTxReader{ChainID: chainID}}, nil +} + +// define flags + +type CounterFlags struct { + AppFlags `mapstructure:",squash"` + Valid bool + CountFee string +} + +func (m CounterTxMaker) Flags() (*flag.FlagSet, interface{}) { + fs, app := AppFlagSet() + fs.String("countfee", "", "Coins to send in the format ,...") + fs.Bool("valid", false, "Is count valid?") + return fs, &CounterFlags{AppFlags: app} +} + +// parse flags + +type CounterTxReader struct { + App AppTxReader +} + +func (t CounterTxReader) ReadTxJSON(data []byte) (interface{}, error) { + // TODO: something. maybe? + return t.App.ReadTxJSON(data) +} + +func (t CounterTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { + data := flags.(*CounterFlags) + countFee, err := btypes.ParseCoins(data.CountFee) + if err != nil { + return nil, err + } + + ctx := counter.CounterTx{ + Valid: viper.GetBool("valid"), + Fee: countFee, + } + txBytes := wire.BinaryBytes(ctx) + + return t.App.ReadTxFlags(&data.AppFlags, counter.New().Name(), txBytes) +} diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index a8f3a8419f..0652e96110 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -32,7 +32,9 @@ func main() { proofs.StatePresenters.Register("account", AccountPresenter{}) proofs.StatePresenters.Register("counter", CounterPresenter{}) proofs.TxPresenters.Register("base", BaseTxPresenter{}) + txs.Register("send", SendTxMaker{}) + txs.Register("counter", CounterTxMaker{}) // set up the various commands to use BaseCli.AddCommand( From a8866bdd2df10d6735567081cd8711e7ce61327e Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 17 May 2017 01:14:31 +0200 Subject: [PATCH 42/67] Reorg basecli for nicer apptx reusage --- cmd/basecli/{ => commands}/adapters.go | 33 +++++++++----------------- cmd/basecli/{ => commands}/apptx.go | 2 +- cmd/basecli/{ => commands}/sendtx.go | 2 +- cmd/basecli/{ => counter}/counter.go | 24 ++++++++++--------- cmd/basecli/main.go | 14 +++++++---- glide.lock | 2 +- 6 files changed, 36 insertions(+), 41 deletions(-) rename cmd/basecli/{ => commands}/adapters.go (84%) rename cmd/basecli/{ => commands}/apptx.go (98%) rename cmd/basecli/{ => commands}/sendtx.go (99%) rename cmd/basecli/{ => counter}/counter.go (74%) diff --git a/cmd/basecli/adapters.go b/cmd/basecli/commands/adapters.go similarity index 84% rename from cmd/basecli/adapters.go rename to cmd/basecli/commands/adapters.go index 56dfdae0ba..f475456741 100644 --- a/cmd/basecli/adapters.go +++ b/cmd/basecli/commands/adapters.go @@ -1,4 +1,4 @@ -package main +package commands import ( "encoding/hex" @@ -8,7 +8,7 @@ import ( flag "github.com/spf13/pflag" "github.com/spf13/viper" - keycmd "github.com/tendermint/go-crypto/cmd" + crypto "github.com/tendermint/go-crypto" wire "github.com/tendermint/go-wire" lightclient "github.com/tendermint/light-client" "github.com/tendermint/light-client/commands" @@ -77,7 +77,8 @@ type SendTxReader struct { ChainID string } -func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { +func (t SendTxReader) ReadTxJSON(data []byte, pk crypto.PubKey) (interface{}, error) { + // TODO: use pk info to help construct data var tx btypes.SendTx err := json.Unmarshal(data, &tx) send := SendTx{ @@ -87,7 +88,7 @@ func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { return &send, errors.Wrap(err, "parse sendtx") } -func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { +func (t SendTxReader) ReadTxFlags(flags interface{}, pk crypto.PubKey) (interface{}, error) { data := flags.(*SendFlags) // parse to and from addresses @@ -96,12 +97,6 @@ func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { return nil, errors.Errorf("To address is invalid hex: %v\n", err) } - // TODO: figure out a cleaner way to do this... until then - // just close your eyes and continue... - manager := keycmd.GetKeyManager() - name := viper.GetString("name") - info, err := manager.Get(name) - //parse the fee and amounts into coin types feeCoin, err := btypes.ParseCoin(data.Fee) if err != nil { @@ -114,12 +109,12 @@ func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { // craft the tx input := btypes.TxInput{ - Address: info.Address, + Address: pk.Address(), Coins: amountCoins, Sequence: data.Sequence, } if data.Sequence == 1 { - input.PubKey = info.PubKey + input.PubKey = pk } output := btypes.TxOutput{ Address: to, @@ -164,17 +159,11 @@ type AppTxReader struct { ChainID string } -func (t AppTxReader) ReadTxJSON(data []byte) (interface{}, error) { +func (t AppTxReader) ReadTxJSON(data []byte, pk crypto.PubKey) (interface{}, error) { return nil, errors.New("Not implemented...") } -func (t AppTxReader) ReadTxFlags(data *AppFlags, app string, appData []byte) (interface{}, error) { - // TODO: figure out a cleaner way to do this... until then - // just close your eyes and continue... - manager := keycmd.GetKeyManager() - name := viper.GetString("name") - info, err := manager.Get(name) - +func (t AppTxReader) ReadTxFlags(data *AppFlags, app string, appData []byte, pk crypto.PubKey) (interface{}, error) { //parse the fee and amounts into coin types feeCoin, err := btypes.ParseCoin(data.Fee) if err != nil { @@ -187,12 +176,12 @@ func (t AppTxReader) ReadTxFlags(data *AppFlags, app string, appData []byte) (in // craft the tx input := btypes.TxInput{ - Address: info.Address, + Address: pk.Address(), Coins: amountCoins, Sequence: data.Sequence, } if data.Sequence == 1 { - input.PubKey = info.PubKey + input.PubKey = pk } tx := btypes.AppTx{ Gas: data.Gas, diff --git a/cmd/basecli/apptx.go b/cmd/basecli/commands/apptx.go similarity index 98% rename from cmd/basecli/apptx.go rename to cmd/basecli/commands/apptx.go index 9c9523fc47..7cf9e3c6a2 100644 --- a/cmd/basecli/apptx.go +++ b/cmd/basecli/commands/apptx.go @@ -1,4 +1,4 @@ -package main +package commands import ( "github.com/pkg/errors" diff --git a/cmd/basecli/sendtx.go b/cmd/basecli/commands/sendtx.go similarity index 99% rename from cmd/basecli/sendtx.go rename to cmd/basecli/commands/sendtx.go index 5f0ae78882..0660ed22c3 100644 --- a/cmd/basecli/sendtx.go +++ b/cmd/basecli/commands/sendtx.go @@ -1,4 +1,4 @@ -package main +package commands import ( "github.com/pkg/errors" diff --git a/cmd/basecli/counter.go b/cmd/basecli/counter/counter.go similarity index 74% rename from cmd/basecli/counter.go rename to cmd/basecli/counter/counter.go index 7a6c9cc67a..3576e1629a 100644 --- a/cmd/basecli/counter.go +++ b/cmd/basecli/counter/counter.go @@ -1,14 +1,16 @@ -package main +package counter import ( flag "github.com/spf13/pflag" "github.com/spf13/viper" + crypto "github.com/tendermint/go-crypto" wire "github.com/tendermint/go-wire" lightclient "github.com/tendermint/light-client" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/commands/txs" + bcmd "github.com/tendermint/basecoin/cmd/basecli/commands" "github.com/tendermint/basecoin/plugins/counter" btypes "github.com/tendermint/basecoin/types" ) @@ -37,19 +39,19 @@ type CounterTxMaker struct{} func (m CounterTxMaker) MakeReader() (lightclient.TxReader, error) { chainID := viper.GetString(commands.ChainFlag) - return CounterTxReader{AppTxReader{ChainID: chainID}}, nil + return CounterTxReader{bcmd.AppTxReader{ChainID: chainID}}, nil } // define flags type CounterFlags struct { - AppFlags `mapstructure:",squash"` - Valid bool - CountFee string + bcmd.AppFlags `mapstructure:",squash"` + Valid bool + CountFee string } func (m CounterTxMaker) Flags() (*flag.FlagSet, interface{}) { - fs, app := AppFlagSet() + fs, app := bcmd.AppFlagSet() fs.String("countfee", "", "Coins to send in the format ,...") fs.Bool("valid", false, "Is count valid?") return fs, &CounterFlags{AppFlags: app} @@ -58,15 +60,15 @@ func (m CounterTxMaker) Flags() (*flag.FlagSet, interface{}) { // parse flags type CounterTxReader struct { - App AppTxReader + App bcmd.AppTxReader } -func (t CounterTxReader) ReadTxJSON(data []byte) (interface{}, error) { +func (t CounterTxReader) ReadTxJSON(data []byte, pk crypto.PubKey) (interface{}, error) { // TODO: something. maybe? - return t.App.ReadTxJSON(data) + return t.App.ReadTxJSON(data, pk) } -func (t CounterTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { +func (t CounterTxReader) ReadTxFlags(flags interface{}, pk crypto.PubKey) (interface{}, error) { data := flags.(*CounterFlags) countFee, err := btypes.ParseCoins(data.CountFee) if err != nil { @@ -79,5 +81,5 @@ func (t CounterTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { } txBytes := wire.BinaryBytes(ctx) - return t.App.ReadTxFlags(&data.AppFlags, counter.New().Name(), txBytes) + return t.App.ReadTxFlags(&data.AppFlags, counter.New().Name(), txBytes, pk) } diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 0652e96110..01dc646832 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -4,6 +4,7 @@ import ( "os" "github.com/spf13/cobra" + keycmd "github.com/tendermint/go-crypto/cmd" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/commands/proofs" @@ -11,6 +12,9 @@ import ( "github.com/tendermint/light-client/commands/seeds" "github.com/tendermint/light-client/commands/txs" "github.com/tendermint/tmlibs/cli" + + bcmd "github.com/tendermint/basecoin/cmd/basecli/commands" + bcount "github.com/tendermint/basecoin/cmd/basecli/counter" ) // BaseCli represents the base command when called without any subcommands @@ -29,12 +33,12 @@ func main() { commands.AddBasicFlags(BaseCli) //initialize proofs and txs - proofs.StatePresenters.Register("account", AccountPresenter{}) - proofs.StatePresenters.Register("counter", CounterPresenter{}) - proofs.TxPresenters.Register("base", BaseTxPresenter{}) + proofs.StatePresenters.Register("account", bcmd.AccountPresenter{}) + proofs.TxPresenters.Register("base", bcmd.BaseTxPresenter{}) + proofs.StatePresenters.Register("counter", bcount.CounterPresenter{}) - txs.Register("send", SendTxMaker{}) - txs.Register("counter", CounterTxMaker{}) + txs.Register("send", bcmd.SendTxMaker{}) + txs.Register("counter", bcount.CounterTxMaker{}) // set up the various commands to use BaseCli.AddCommand( diff --git a/glide.lock b/glide.lock index 5afaddaefb..2a9d7c4ccd 100644 --- a/glide.lock +++ b/glide.lock @@ -127,7 +127,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: c003b47d43fd79dcec14e5cdaf353cc461fa7cb7 + version: 61c7c5daa6b75e0fcb191319fc2c546b29eafff7 subpackages: - certifiers - certifiers/client From bd62b21d6e2f7faa6dfeed62d5ac4b9bb3553031 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 17 May 2017 12:46:08 +0200 Subject: [PATCH 43/67] Bump version to 0.5.0, update deps --- cmd/commands/start.go | 5 ++++- glide.lock | 16 ++++++++-------- version/version.go | 6 +++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 7db4bf14d4..053e6e400f 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -131,10 +131,13 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error { cfg.SetRoot(cfg.RootDir) config.EnsureRoot(cfg.RootDir) - tmLogger, err := log.NewFilterByLevel(logger, cfg.LogLevel) + // TODO: parse the log level from the config properly (multi modules) + // but some tm code must be refactored for better usability + lvl, err := log.AllowLevel(cfg.LogLevel) if err != nil { return err } + tmLogger := log.NewFilter(logger, lvl) // Create & start tendermint node privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile(), tmLogger) diff --git a/glide.lock b/glide.lock index 2a9d7c4ccd..675b418f6d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: 997e4cc3339141ee01aa2adf656425a49ebf117e6ca9e81ba72b8f94fee3e86e -updated: 2017-05-16T13:41:59.92225084Z +updated: 2017-05-17T12:25:00.580569867+02:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd @@ -39,7 +39,7 @@ imports: - name: github.com/gorilla/context version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 - name: github.com/gorilla/handlers - version: 13d73096a474cac93275c679c7b8a2dc17ddba82 + version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221 - name: github.com/gorilla/mux version: 392c28fe23e1c45ddba891b0320b3b5df220beea - name: github.com/gorilla/websocket @@ -68,7 +68,7 @@ imports: - name: github.com/pelletier/go-buffruneio version: c37440a7cf42ac63b919c752ca73a85067e05992 - name: github.com/pelletier/go-toml - version: 685a1f1cb7a66b9cadbe8f1ac49d9f8f567d6a9d + version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/spf13/afero @@ -113,7 +113,7 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: a42b10e0feb465eb56fbc6bb5b71d57ef646ec57 + version: 438b16f1f84ef002d7408ecd6fc3a3974cbc9559 subpackages: - cmd - keys @@ -122,12 +122,12 @@ imports: - keys/server/types - keys/storage/filestorage - name: github.com/tendermint/go-wire - version: 7f81de645283af7c62f17eafe3ef13b38cc0836b + version: 97beaedf0f4dbc035309157c92be3b30cc6e5d74 subpackages: - data - data/base58 - name: github.com/tendermint/light-client - version: 61c7c5daa6b75e0fcb191319fc2c546b29eafff7 + version: 478876ca34b360df62f941d5e20cdd608fa0a466 subpackages: - certifiers - certifiers/client @@ -145,7 +145,7 @@ imports: - client - iavl - name: github.com/tendermint/tendermint - version: e1792c1ea521ff6c10f79d7865a027024978b629 + version: 11b5d11e9eec170e1d3dce165f0270d5c0759d69 subpackages: - blockchain - config @@ -170,7 +170,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: 812d9f9b84d1dfe4cb46ce021b3a2d97b48d1292 + version: 8af1c70a8be17543eb33e9bfbbcdd8371e3201cc subpackages: - autofile - cli diff --git a/version/version.go b/version/version.go index 3822823050..07d89dbe9c 100644 --- a/version/version.go +++ b/version/version.go @@ -1,7 +1,7 @@ package version const Maj = "0" -const Min = "4" -const Fix = "1" +const Min = "5" +const Fix = "0" -const Version = "0.4.1" +const Version = "0.5.0" From 2983f5018b11476623b295b0001d33eccf784942 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 21 May 2017 19:51:28 -0700 Subject: [PATCH 44/67] Allow keyfile to be absolute path --- cmd/commands/key.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/commands/key.go b/cmd/commands/key.go index d0d2009d83..4f0b253818 100644 --- a/cmd/commands/key.go +++ b/cmd/commands/key.go @@ -89,8 +89,13 @@ func genKey() *Key { } func LoadKey(keyFile string) (*Key, error) { - rootDir := viper.GetString(cli.HomeFlag) - filePath := path.Join(rootDir, keyFile) + filePath := keyFile + + if !strings.HasPrefix(keyFile, "/") && !strings.HasPrefix(keyFile, ".") { + rootDir := viper.GetString(cli.HomeFlag) + filePath = path.Join(rootDir, keyFile) + } + keyJSONBytes, err := ioutil.ReadFile(filePath) if err != nil { return nil, err From be321373da2c9c856c7fb7c83bdb5d91fb999342 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 22 May 2017 11:22:41 +0200 Subject: [PATCH 45/67] 87: Sort coin order on ParseCoins to be less fragile --- types/coin.go | 19 +++++++++- types/coin_test.go | 92 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 24 deletions(-) diff --git a/types/coin.go b/types/coin.go index e34f7d1bdb..0499e58c0f 100644 --- a/types/coin.go +++ b/types/coin.go @@ -3,8 +3,11 @@ package types import ( "fmt" "regexp" + "sort" "strconv" "strings" + + "github.com/pkg/errors" ) type Coin struct { @@ -53,9 +56,8 @@ func (coins Coins) String() string { } func ParseCoins(str string) (Coins, error) { - split := strings.Split(str, ",") - var coins []Coin + var coins Coins for _, el := range split { if len(el) > 0 { @@ -67,6 +69,12 @@ func ParseCoins(str string) (Coins, error) { } } + // ensure they are in proper order, to avoid random failures later + coins.Sort() + if !coins.IsValid() { + return nil, errors.Errorf("ParseCoins invalid: %#v", coins) + } + return coins, nil } @@ -195,3 +203,10 @@ func (coins Coins) IsNonnegative() bool { } return true } + +/*** Implement Sort interface ***/ + +func (c Coins) Len() int { return len(c) } +func (c Coins) Less(i, j int) bool { return c[i].Denom < c[j].Denom } +func (c Coins) Swap(i, j int) { c[i], c[j] = c[j], c[i] } +func (c Coins) Sort() { sort.Sort(c) } diff --git a/types/coin_test.go b/types/coin_test.go index 8cbc708a49..bf99d0caab 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestCoins(t *testing.T) { @@ -56,30 +55,79 @@ func TestCoins(t *testing.T) { //Test the parse coin and parse coins functionality func TestParse(t *testing.T) { - assert, require := assert.New(t), require.New(t) + assert := assert.New(t) - makeCoin := func(str string) Coin { - coin, err := ParseCoin(str) - require.Nil(err) - return coin + cases := []struct { + input string + valid bool // if false, we expect an error on parse + expected Coins // if valid is true, make sure this is returned + }{ + {"", true, nil}, + {"1foo", true, Coins{{"foo", 1}}}, + {"10bar", true, Coins{{"bar", 10}}}, + {"99bar,1foo", true, Coins{{"bar", 99}, {"foo", 1}}}, + {"98 bar , 1 foo ", true, Coins{{"bar", 98}, {"foo", 1}}}, + {"2foo, 97 bar", true, Coins{{"bar", 97}, {"foo", 2}}}, } - makeCoins := func(str string) Coins { - coin, err := ParseCoins(str) - require.Nil(err) - return coin + for _, tc := range cases { + res, err := ParseCoins(tc.input) + if !tc.valid { + assert.NotNil(err, tc.input) + } else if assert.Nil(err, "%s: %+v", tc.input, err) { + assert.Equal(tc.expected, res) + } } - //testing ParseCoin Function - assert.Equal(Coin{}, makeCoin(""), "ParseCoin makes bad empty coin") - assert.Equal(Coin{"fooCoin", 1}, makeCoin("1fooCoin"), "ParseCoin makes bad coins") - assert.Equal(Coin{"barCoin", 10}, makeCoin("10 barCoin"), "ParseCoin makes bad coins") - - //testing ParseCoins Function - assert.True(Coins{{"fooCoin", 1}}.IsEqual(makeCoins("1fooCoin")), - "ParseCoins doesn't parse a single coin") - assert.True(Coins{{"barCoin", 99}, {"fooCoin", 1}}.IsEqual(makeCoins("99barCoin,1fooCoin")), - "ParseCoins doesn't properly parse two coins") - assert.True(Coins{{"barCoin", 99}, {"fooCoin", 1}}.IsEqual(makeCoins("99 barCoin, 1 fooCoin")), - "ParseCoins doesn't properly parse two coins which use spaces") +} + +func TestSortCoins(t *testing.T) { + assert := assert.New(t) + + good := Coins{ + Coin{"GAS", 1}, + Coin{"MINERAL", 1}, + Coin{"TREE", 1}, + } + empty := Coins{ + Coin{"GOLD", 0}, + } + badSort1 := Coins{ + Coin{"TREE", 1}, + Coin{"GAS", 1}, + Coin{"MINERAL", 1}, + } + badSort2 := Coins{ // both are after the first one, but the second and third are in the wrong order + Coin{"GAS", 1}, + Coin{"TREE", 1}, + Coin{"MINERAL", 1}, + } + badAmt := Coins{ + Coin{"GAS", 1}, + Coin{"TREE", 0}, + Coin{"MINERAL", 1}, + } + dup := Coins{ + Coin{"GAS", 1}, + Coin{"GAS", 1}, + Coin{"MINERAL", 1}, + } + + cases := []struct { + coins Coins + before, after bool // valid before/after sort + }{ + {good, true, true}, + {empty, false, false}, + {badSort1, false, true}, + {badSort2, false, true}, + {badAmt, false, false}, + {dup, false, false}, + } + + for _, tc := range cases { + assert.Equal(tc.before, tc.coins.IsValid()) + tc.coins.Sort() + assert.Equal(tc.after, tc.coins.IsValid()) + } } From b53d71c5cf6f5e2e5c84c992e9436d394e79e815 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 22 May 2017 11:59:34 +0200 Subject: [PATCH 46/67] 87: sort the coins from genesis.json/SetOptions to ensure they are valid --- app/app.go | 1 + app/app_test.go | 41 +++++++++++++++++++++++++++++++++++++---- app/genesis_test.go | 10 +++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/app.go b/app/app.go index 94d37c43db..7b903a5b99 100644 --- a/app/app.go +++ b/app/app.go @@ -82,6 +82,7 @@ func (app *Basecoin) SetOption(key string, value string) string { if err != nil { return "Error decoding acc message: " + err.Error() } + acc.Balance.Sort() app.state.SetAccount(acc.PubKey.Address(), &acc) app.logger.Info("SetAccount", "addr", acc.PubKey.Address(), "acc", acc) diff --git a/app/app_test.go b/app/app_test.go index c56708e2b3..d37a6ade8e 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -1,14 +1,15 @@ package app import ( + "encoding/hex" "encoding/json" - "fmt" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/abci/types" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" @@ -103,6 +104,7 @@ func TestSplitKey(t *testing.T) { func TestSetOption(t *testing.T) { assert := assert.New(t) + require := require.New(t) eyesCli := eyes.NewLocalClient("", 0) app := NewBasecoin(eyesCli) @@ -114,11 +116,43 @@ func TestSetOption(t *testing.T) { assert.EqualValues(app.GetState().GetChainID(), chainID) assert.EqualValues(res, "Success") + // make a nice account... accIn := types.MakeAcc("input0") accsInBytes, err := json.Marshal(accIn.Account) assert.Nil(err) res = app.SetOption("base/account", string(accsInBytes)) - assert.EqualValues(res, "Success") + require.EqualValues(res, "Success") + // make sure it is set correctly, with some balance + acct := state.GetAccount(app.GetState(), accIn.PubKey.Address()) + require.NotNil(acct) + assert.Equal(accIn.Balance, acct.Balance) + + // let's parse an account with badly sorted coins... + unsortAddr, err := hex.DecodeString("C471FB670E44D219EE6DF2FC284BE38793ACBCE1") + require.Nil(err) + unsortCoins := types.Coins{{"BTC", 789}, {"eth", 123}} + unsortAcc := `{ + "pub_key": { + "type": "ed25519", + "data": "AD084F0572C116D618B36F2EB08240D1BAB4B51716CCE0E7734B89C8936DCE9A" + }, + "coins": [ + { + "denom": "eth", + "amount": 123 + }, + { + "denom": "BTC", + "amount": 789 + } + ] +}` + res = app.SetOption("base/account", unsortAcc) + require.EqualValues(res, "Success") + acct = state.GetAccount(app.GetState(), unsortAddr) + require.NotNil(acct) + assert.True(acct.Balance.IsValid()) + assert.Equal(unsortCoins, acct.Balance) res = app.SetOption("base/dslfkgjdas", "") assert.NotEqual(res, "Success") @@ -128,6 +162,7 @@ func TestSetOption(t *testing.T) { res = app.SetOption("dslfkgjdas/szfdjzs", "") assert.NotEqual(res, "Success") + } // Test CheckTx and DeliverTx with insufficient and sufficient balance @@ -179,7 +214,5 @@ func TestQuery(t *testing.T) { Path: "/account", Data: at.accIn.Account.PubKey.Address(), }) - fmt.Println(resQueryPreCommit) - fmt.Println(resQueryPostCommit) assert.NotEqual(resQueryPreCommit, resQueryPostCommit, "Query should change before/after commit") } diff --git a/app/genesis_test.go b/app/genesis_test.go index df47827465..186bb231fa 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -7,9 +7,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/go-crypto" eyescli "github.com/tendermint/merkleeyes/client" + cmn "github.com/tendermint/tmlibs/common" ) const genesisFilepath = "./testdata/genesis.json" @@ -34,8 +34,12 @@ func TestLoadGenesis(t *testing.T) { // make sure balance is proper assert.Equal(2, len(acct.Balance)) - assert.EqualValues(12345, acct.Balance[0].Amount) - assert.EqualValues("blank", acct.Balance[0].Denom) + assert.True(acct.Balance.IsValid()) + // note, that we now sort them to be valid + assert.EqualValues(654321, acct.Balance[0].Amount) + assert.EqualValues("ETH", acct.Balance[0].Denom) + assert.EqualValues(12345, acct.Balance[1].Amount) + assert.EqualValues("blank", acct.Balance[1].Denom) // and public key is parsed properly apk := acct.PubKey.Unwrap() From ecaff359d27c15fb53800086efa477d7f466f09f Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 22 May 2017 13:10:25 +0200 Subject: [PATCH 47/67] 89: Add support for setting accounts by address (not just pub_key) in genesis.json --- app/app.go | 11 +++++--- app/genesis.go | 42 +++++++++++++++++++++++++++++- app/genesis_test.go | 47 ++++++++++++++++++++++++++++++++++ app/testdata/genesis2.json | 52 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 app/testdata/genesis2.json diff --git a/app/app.go b/app/app.go index 7b903a5b99..2107dc17e6 100644 --- a/app/app.go +++ b/app/app.go @@ -1,6 +1,7 @@ package app import ( + "encoding/hex" "encoding/json" "strings" @@ -77,14 +78,18 @@ func (app *Basecoin) SetOption(key string, value string) string { app.state.SetChainID(value) return "Success" case "account": - var acc types.Account + var acc GenesisAccount err := json.Unmarshal([]byte(value), &acc) if err != nil { return "Error decoding acc message: " + err.Error() } acc.Balance.Sort() - app.state.SetAccount(acc.PubKey.Address(), &acc) - app.logger.Info("SetAccount", "addr", acc.PubKey.Address(), "acc", acc) + addr, err := acc.GetAddr() + if err != nil { + return "Invalid address: " + err.Error() + } + app.state.SetAccount(addr, acc.ToAccount()) + app.logger.Info("SetAccount", "addr", hex.EncodeToString(addr), "acc", acc) return "Success" } diff --git a/app/genesis.go b/app/genesis.go index f1c36914f8..fa6a5ac305 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -1,11 +1,14 @@ package app import ( + "bytes" "encoding/json" "github.com/pkg/errors" "github.com/tendermint/basecoin/types" + crypto "github.com/tendermint/go-crypto" + "github.com/tendermint/go-wire/data" cmn "github.com/tendermint/tmlibs/common" ) @@ -49,7 +52,7 @@ type FullGenesisDoc struct { } type GenesisDoc struct { - Accounts []types.Account `json:"accounts"` + Accounts []GenesisAccount `json:"accounts"` PluginOptions []json.RawMessage `json:"plugin_options"` pluginOptions []keyValue // unmarshaled rawmessages @@ -98,3 +101,40 @@ func parseGenesisList(kvz_ []json.RawMessage) (kvz []keyValue, err error) { } return kvz, nil } + +/**** code to parse accounts from genesis docs ***/ + +type GenesisAccount struct { + Address data.Bytes `json:"address"` + // this from types.Account (don't know how to embed this properly) + PubKey crypto.PubKey `json:"pub_key"` // May be nil, if not known. + Sequence int `json:"sequence"` + Balance types.Coins `json:"coins"` +} + +func (g GenesisAccount) ToAccount() *types.Account { + return &types.Account{ + PubKey: g.PubKey, + Sequence: g.Sequence, + Balance: g.Balance, + } +} + +func (g GenesisAccount) GetAddr() ([]byte, error) { + noAddr, noPk := len(g.Address) == 0, g.PubKey.Empty() + + if noAddr { + if noPk { + return nil, errors.New("No address given") + } + return g.PubKey.Address(), nil + } + if noPk { // but is addr... + return g.Address, nil + } + // now, we have both, make sure they check out + if bytes.Equal(g.Address, g.PubKey.Address()) { + return g.Address, nil + } + return nil, errors.New("Address and pubkey don't match") +} diff --git a/app/genesis_test.go b/app/genesis_test.go index 186bb231fa..b2a590bcf3 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -7,12 +7,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tendermint/basecoin/types" "github.com/tendermint/go-crypto" eyescli "github.com/tendermint/merkleeyes/client" cmn "github.com/tendermint/tmlibs/common" ) const genesisFilepath = "./testdata/genesis.json" +const genesisAcctFilepath = "./testdata/genesis2.json" func TestLoadGenesis(t *testing.T) { assert, require := assert.New(t), require.New(t) @@ -50,6 +52,51 @@ func TestLoadGenesis(t *testing.T) { } } +// Fix for issue #89, change the parse format for accounts in genesis.json +func TestLoadGenesisAccountAddress(t *testing.T) { + assert, require := assert.New(t), require.New(t) + + eyesCli := eyescli.NewLocalClient("", 0) + app := NewBasecoin(eyesCli) + err := app.LoadGenesis(genesisAcctFilepath) + require.Nil(err, "%+v", err) + + // check the chain id + assert.Equal("addr_accounts_chain", app.GetState().GetChainID()) + + // make sure the accounts were set properly + cases := []struct { + addr string + exists bool + hasPubkey bool + coins types.Coins + }{ + // this comes from a public key, should be stored proper (alice) + {"62035D628DE7543332544AA60D90D3693B6AD51B", true, true, types.Coins{{"one", 111}}}, + // this comes from an address, should be stored proper (bob) + {"C471FB670E44D219EE6DF2FC284BE38793ACBCE1", true, false, types.Coins{{"two", 222}}}, + // this one had a mismatched address and pubkey, should not store under either (carl) + {"1234ABCDD18E8EFE3FFC4B0506BF9BF8E5B0D9E9", false, false, nil}, // this is given addr + {"700BEC5ED18E8EFE3FFC4B0506BF9BF8E5B0D9E9", false, false, nil}, // this is addr of the given pubkey + // this comes from a secp256k1 public key, should be stored proper (sam) + {"979F080B1DD046C452C2A8A250D18646C6B669D4", true, true, types.Coins{{"four", 444}}}, + } + + for _, tc := range cases { + addr, err := hex.DecodeString(tc.addr) + require.Nil(err, tc.addr) + acct := app.GetState().GetAccount(addr) + if !tc.exists { + assert.Nil(acct, tc.addr) + } else if assert.NotNil(acct, tc.addr) { + // it should and does exist... + assert.True(acct.Balance.IsValid()) + assert.Equal(tc.coins, acct.Balance) + assert.Equal(!tc.hasPubkey, acct.PubKey.Empty(), tc.addr) + } + } +} + func TestParseGenesisList(t *testing.T) { assert, require := assert.New(t), require.New(t) diff --git a/app/testdata/genesis2.json b/app/testdata/genesis2.json new file mode 100644 index 0000000000..a880b3c64c --- /dev/null +++ b/app/testdata/genesis2.json @@ -0,0 +1,52 @@ +{ + "chain_id": "addr_accounts_chain", + "app_options": { + "accounts": [{ + "name": "alice", + "pub_key": { + "type": "ed25519", + "data": "DBD9A46C45868F0A37C92B53113C09B048FBD87B5FBC2F8B199052973B8FAA36" + }, + "coins": [ + { + "denom": "one", + "amount": 111 + } + ] + }, { + "name": "bob", + "address": "C471FB670E44D219EE6DF2FC284BE38793ACBCE1", + "coins": [ + { + "denom": "two", + "amount": 222 + } + ] + }, { + "name": "carl", + "address": "1234ABCDD18E8EFE3FFC4B0506BF9BF8E5B0D9E9", + "pub_key": { + "type": "ed25519", + "data": "177C0AC45E86257F0708DC085D592AB22AAEECD1D26381B757F7C96135921858" + }, + "coins": [ + { + "denom": "three", + "amount": 333 + } + ] + }, { + "name": "sam", + "pub_key": { + "type": "secp256k1", + "data": "02AA8342F63CCCCE6DDB128525BA048CE0B2993DA3B4308746E1F216361A87651E" + }, + "coins": [ + { + "denom": "four", + "amount": 444 + } + ] + }] + } +} From 029c0e9c725b8a3d932b8e8c65be7ddf5ba04232 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 22 May 2017 13:16:08 +0200 Subject: [PATCH 48/67] 90: don't panic on missing pk in tx construction --- cmd/basecli/commands/adapters.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/basecli/commands/adapters.go b/cmd/basecli/commands/adapters.go index f475456741..a1899019c1 100644 --- a/cmd/basecli/commands/adapters.go +++ b/cmd/basecli/commands/adapters.go @@ -107,9 +107,15 @@ func (t SendTxReader) ReadTxFlags(flags interface{}, pk crypto.PubKey) (interfac return nil, err } + // get addr if available + var addr []byte + if !pk.Empty() { + addr = pk.Address() + } + // craft the tx input := btypes.TxInput{ - Address: pk.Address(), + Address: addr, Coins: amountCoins, Sequence: data.Sequence, } @@ -174,9 +180,15 @@ func (t AppTxReader) ReadTxFlags(data *AppFlags, app string, appData []byte, pk return nil, err } + // get addr if available + var addr []byte + if !pk.Empty() { + addr = pk.Address() + } + // craft the tx input := btypes.TxInput{ - Address: pk.Address(), + Address: addr, Coins: amountCoins, Sequence: data.Sequence, } From 8daa916729e9fddd46c3577561c2f3c8d263950a Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 22 May 2017 13:30:42 +0200 Subject: [PATCH 49/67] 88: Correct functioning of unsafe_reset_all to mirror tendermint --- cmd/commands/reset.go | 15 ++++++--------- cmd/commands/start.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/commands/reset.go b/cmd/commands/reset.go index 296e58ad12..4d38f94bfe 100644 --- a/cmd/commands/reset.go +++ b/cmd/commands/reset.go @@ -1,13 +1,9 @@ package commands import ( - "os" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "github.com/tendermint/tendermint/config" - "github.com/tendermint/tmlibs/cli" + tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) var UnsafeResetAllCmd = &cobra.Command{ @@ -17,9 +13,10 @@ var UnsafeResetAllCmd = &cobra.Command{ } func unsafeResetAllCmd(cmd *cobra.Command, args []string) error { - rootDir := viper.GetString(cli.HomeFlag) - // wipe out rootdir if it exists before recreating it - os.RemoveAll(rootDir) - config.EnsureRoot(rootDir) + cfg, err := getTendermintConfig() + if err != nil { + return err + } + tmcmd.ResetAll(cfg.DBDir(), cfg.PrivValidatorFile(), logger) return nil } diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 053e6e400f..7a15f59df5 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -122,14 +122,22 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error { return nil } -func startTendermint(dir string, basecoinApp *app.Basecoin) error { +func getTendermintConfig() (*config.Config, error) { cfg := config.DefaultConfig() err := viper.Unmarshal(cfg) if err != nil { - return err + return nil, err } cfg.SetRoot(cfg.RootDir) config.EnsureRoot(cfg.RootDir) + return cfg, nil +} + +func startTendermint(dir string, basecoinApp *app.Basecoin) error { + cfg, err := getTendermintConfig() + if err != nil { + return err + } // TODO: parse the log level from the config properly (multi modules) // but some tm code must be refactored for better usability From aeb36bd5312e8da7ba9d8f9cece46d2987ce4657 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 11:08:34 -0400 Subject: [PATCH 50/67] [ibc] CoinsPayload --- plugins/ibc/ibc.go | 71 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 7502792898..06fd25cbca 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "net/url" "strings" @@ -12,6 +13,7 @@ import ( merkle "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" + bcsm "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" tm "github.com/tendermint/tendermint/types" ) @@ -54,7 +56,44 @@ type Packet struct { DstChainID string Sequence uint64 Type string - Payload []byte + Payload Payload +} + +//-------------------------------------------------------------------------------- + +const ( + PayloadTypeBytes = byte(0x01) + PayloadTypeCoins = byte(0x02) +) + +var _ = wire.RegisterInterface( + struct{ Payload }{}, + wire.ConcreteType{BytesPayload{}, PayloadTypeBytes}, + wire.ConcreteType{CoinsPayload{}, PayloadTypeCoins}, +) + +type Payload interface { + AssertIsPayload() + ValidateBasic() abci.Result +} + +func (BytesPayload) AssertIsPayload() {} +func (CoinsPayload) AssertIsPayload() {} + +type BytesPayload []byte + +func (p BytesPayload) ValidateBasic() abci.Result { + return abci.OK +} + +type CoinsPayload struct { + Address []byte + Coins types.Coins +} + +func (p CoinsPayload) ValidateBasic() abci.Result { + // TODO: validate + return abci.OK } //-------------------------------------------------------------------------------- @@ -299,6 +338,23 @@ func (sm *IBCStateMachine) runPacketCreateTx(tx IBCPacketCreateTx) { sm.res.Log = "Already exists" return } + + // Execute the payload + switch payload := tx.Packet.Payload.(type) { + case BytesPayload: + // do nothing + case CoinsPayload: + // ensure enough coins were sent in tx to cover the payload coins + if !sm.ctx.Coins.IsGTE(payload.Coins) { + sm.res.Code = abci.CodeType_InsufficientFunds + sm.res.Log = fmt.Sprintf("Not enough funds sent in tx (%v) to send %v via IBC", sm.ctx.Coins, payload.Coins) + return + } + + // deduct coins from context + sm.ctx.Coins = sm.ctx.Coins.Minus(payload.Coins) + } + // Save new Packet save(sm.store, packetKey, packet) } @@ -327,7 +383,7 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { return } - // Save new Packet + // Save new Packet (just for fun) save(sm.store, packetKeyIngress, packet) // Load Header and make sure it exists @@ -360,6 +416,17 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { return } + // Execute payload + switch payload := packet.Payload.(type) { + case BytesPayload: + // do nothing + case CoinsPayload: + // Add coins to destination account + acc := bcsm.GetAccount(sm.store, payload.Address) + acc.Balance = acc.Balance.Plus(payload.Coins) + bcsm.SetAccount(sm.store, payload.Address, acc) + } + return } From ee0772396c7e4dbe31e20b27bfdb9625eddd8ce3 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 11:08:46 -0400 Subject: [PATCH 51/67] [ibc] cleanup tests --- plugins/ibc/ibc.go | 10 ++ plugins/ibc/ibc_test.go | 318 +++++++++++++++++----------------------- 2 files changed, 144 insertions(+), 184 deletions(-) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 06fd25cbca..7e38967957 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -59,6 +59,16 @@ type Packet struct { Payload Payload } +func NewPacket(src, dst string, seq uint64, ty string, payload Payload) Packet { + return Packet{ + SrcChainID: src, + DstChainID: dst, + Sequence: seq, + Type: ty, + Payload: payload, + } +} + //-------------------------------------------------------------------------------- const ( diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 1853a3a72d..4b2c6a945c 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -101,34 +101,19 @@ var testGenesisDoc = `{ }` func TestIBCGenesisFromString(t *testing.T) { - assert := assert.New(t) - eyesClient := eyes.NewLocalClient("", 0) store := types.NewKVCache(eyesClient) store.SetLogging() // Log all activity ibcPlugin := New() - ctx := types.CallContext{ - CallerAddress: nil, - CallerAccount: nil, - Coins: types.Coins{}, - } + ctx := types.NewCallContext(nil, nil, types.Coins{}) - res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ - BlockchainGenesis{ - ChainID: "test_chain", - Genesis: testGenesisDoc, - }, - }})) - assert.True(res.IsOK(), res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + registerChain(t, ibcPlugin, store, ctx, "test_chain", testGenesisDoc) } //-------------------------------------------------------------------------------- -func TestIBCPlugin(t *testing.T) { - assert := assert.New(t) +func TestIBCPluginRegister(t *testing.T) { require := require.New(t) eyesClient := eyes.NewLocalClient("", 0) @@ -136,14 +121,10 @@ func TestIBCPlugin(t *testing.T) { store.SetLogging() // Log all activity ibcPlugin := New() - ctx := types.CallContext{ - CallerAddress: nil, - CallerAccount: nil, - Coins: types.Coins{}, - } + ctx := types.NewCallContext(nil, nil, types.Coins{}) chainID_1 := "test_chain" - genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) + genDoc_1, _ := genGenesisDoc(chainID_1, 4) genDocJSON_1, err := json.Marshal(genDoc_1) require.Nil(err) @@ -154,20 +135,10 @@ func TestIBCPlugin(t *testing.T) { Genesis: "", }, }})) - assert.Equal(IBCCodeEncodingError, res.Code) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, IBCCodeEncodingError) // Successfully register a chain - res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ - BlockchainGenesis{ - ChainID: "test_chain", - Genesis: string(genDocJSON_1), - }, - }})) - assert.True(res.IsOK(), res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Duplicate request fails res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ @@ -176,74 +147,88 @@ func TestIBCPlugin(t *testing.T) { Genesis: string(genDocJSON_1), }, }})) - assert.Equal(IBCCodeChainAlreadyExists, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, IBCCodeChainAlreadyExists) +} + +func TestIBCPluginPost(t *testing.T) { + require := require.New(t) + + eyesClient := eyes.NewLocalClient("", 0) + store := types.NewKVCache(eyesClient) + store.SetLogging() // Log all activity + + ibcPlugin := New() + ctx := types.NewCallContext(nil, nil, types.Coins{}) + + chainID_1 := "test_chain" + genDoc_1, _ := genGenesisDoc(chainID_1, 4) + genDocJSON_1, err := json.Marshal(genDoc_1) + require.Nil(err) + + // Register a chain + registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Create a new packet (for testing) - packet := Packet{ - SrcChainID: "test_chain", - DstChainID: "dst_chain", - Sequence: 0, - Type: "data", - Payload: []byte("hello world"), - } - res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ + packet := NewPacket("test_chain", "dst_chain", 0, "data", BytesPayload([]byte("hello world"))) + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ Packet: packet, }})) - assert.Equal(abci.CodeType_OK, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, abci.CodeType_OK) // Post a duplicate packet res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ Packet: packet, }})) - assert.Equal(IBCCodePacketAlreadyExists, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, IBCCodePacketAlreadyExists) +} + +func TestIBCPlugin(t *testing.T) { + assert := assert.New(t) + require := require.New(t) + + eyesClient := eyes.NewLocalClient("", 0) + store := types.NewKVCache(eyesClient) + store.SetLogging() // Log all activity + + ibcPlugin := New() + ctx := types.NewCallContext(nil, nil, types.Coins{}) + + chainID_1 := "test_chain" + genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) + genDocJSON_1, err := json.Marshal(genDoc_1) + require.Nil(err) + + // Register a chain + registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) + + // Create a new packet (for testing) + packet := NewPacket("test_chain", "dst_chain", 0, "data", BytesPayload([]byte("hello world"))) + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ + Packet: packet, + }})) + assertAndLog(t, store, res, abci.CodeType_OK) + + // Post a duplicate packet + res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ + Packet: packet, + }})) + assertAndLog(t, store, res, IBCCodePacketAlreadyExists) // Construct a Header that includes the above packet. store.Sync() resCommit := eyesClient.CommitSync() appHash := resCommit.Data - header := tm.Header{ - ChainID: "test_chain", - Height: 999, - AppHash: appHash, - ValidatorsHash: []byte("must_exist"), // TODO make optional - } + header := newHeader("test_chain", 999, appHash, []byte("must_exist")) // Construct a Commit that signs above header - blockHash := header.Hash() - blockID := tm.BlockID{Hash: blockHash} - commit := tm.Commit{ - BlockID: blockID, - Precommits: make([]*tm.Vote, len(privAccs_1)), - } - for i, privAcc := range privAccs_1 { - vote := &tm.Vote{ - ValidatorAddress: privAcc.Account.PubKey.Address(), - ValidatorIndex: i, - Height: 999, - Round: 0, - Type: tm.VoteTypePrecommit, - BlockID: tm.BlockID{Hash: blockHash}, - } - vote.Signature = privAcc.PrivKey.Sign( - tm.SignBytes("test_chain", vote), - ) - commit.Precommits[i] = vote - } + commit := constructCommit(privAccs_1, header) // Update a chain res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ Header: header, Commit: commit, }})) - assert.Equal(abci.CodeType_OK, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, abci.CodeType_OK) // Get proof for the packet packetKey := toKey(_IBC, _EGRESS, @@ -268,13 +253,10 @@ func TestIBCPlugin(t *testing.T) { Packet: packet, Proof: proof, }})) - assert.Equal(abci.CodeType_OK, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, abci.CodeType_OK) } func TestIBCPluginBadCommit(t *testing.T) { - assert := assert.New(t) require := require.New(t) eyesClient := eyes.NewLocalClient("", 0) @@ -282,11 +264,7 @@ func TestIBCPluginBadCommit(t *testing.T) { store.SetLogging() // Log all activity ibcPlugin := New() - ctx := types.CallContext{ - CallerAddress: nil, - CallerAccount: nil, - Coins: types.Coins{}, - } + ctx := types.NewCallContext(nil, nil, types.Coins{}) chainID_1 := "test_chain" genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) @@ -294,57 +272,24 @@ func TestIBCPluginBadCommit(t *testing.T) { require.Nil(err) // Successfully register a chain - res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ - BlockchainGenesis{ - ChainID: "test_chain", - Genesis: string(genDocJSON_1), - }, - }})) - assert.True(res.IsOK(), res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Construct a Header - header := tm.Header{ - ChainID: "test_chain", - Height: 999, - ValidatorsHash: []byte("must_exist"), // TODO make optional - } + header := newHeader("test_chain", 999, nil, []byte("must_exist")) // Construct a Commit that signs above header - blockHash := header.Hash() - blockID := tm.BlockID{Hash: blockHash} - commit := tm.Commit{ - BlockID: blockID, - Precommits: make([]*tm.Vote, len(privAccs_1)), - } - for i, privAcc := range privAccs_1 { - vote := &tm.Vote{ - ValidatorAddress: privAcc.Account.PubKey.Address(), - ValidatorIndex: i, - Height: 999, - Round: 0, - Type: tm.VoteTypePrecommit, - BlockID: tm.BlockID{Hash: blockHash}, - } - vote.Signature = privAcc.PrivKey.Sign( - tm.SignBytes("test_chain", vote), - ) - commit.Precommits[i] = vote - } + commit := constructCommit(privAccs_1, header) // Update a chain with a broken commit // Modify the first byte of the first signature sig := commit.Precommits[0].Signature.Unwrap().(crypto.SignatureEd25519) sig[0] += 1 commit.Precommits[0].Signature = sig.Wrap() - res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ Header: header, Commit: commit, }})) - assert.Equal(IBCCodeInvalidCommit, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, IBCCodeInvalidCommit) } @@ -357,11 +302,7 @@ func TestIBCPluginBadProof(t *testing.T) { store.SetLogging() // Log all activity ibcPlugin := New() - ctx := types.CallContext{ - CallerAddress: nil, - CallerAccount: nil, - Coins: types.Coins{}, - } + ctx := types.NewCallContext(nil, nil, types.Coins{}) chainID_1 := "test_chain" genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) @@ -369,72 +310,30 @@ func TestIBCPluginBadProof(t *testing.T) { require.Nil(err) // Successfully register a chain - res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ - BlockchainGenesis{ - ChainID: "test_chain", - Genesis: string(genDocJSON_1), - }, - }})) - assert.True(res.IsOK(), res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Create a new packet (for testing) - packet := Packet{ - SrcChainID: "test_chain", - DstChainID: "dst_chain", - Sequence: 0, - Type: "data", - Payload: []byte("hello world"), - } - res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ + packet := NewPacket("test_chain", "dst_chain", 0, "data", BytesPayload([]byte("hello world"))) + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ Packet: packet, }})) - assert.Equal(abci.CodeType_OK, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, abci.CodeType_OK) // Construct a Header that includes the above packet. store.Sync() resCommit := eyesClient.CommitSync() appHash := resCommit.Data - header := tm.Header{ - ChainID: "test_chain", - Height: 999, - AppHash: appHash, - ValidatorsHash: []byte("must_exist"), // TODO make optional - } + header := newHeader("test_chain", 999, appHash, []byte("must_exist")) // Construct a Commit that signs above header - blockHash := header.Hash() - blockID := tm.BlockID{Hash: blockHash} - commit := tm.Commit{ - BlockID: blockID, - Precommits: make([]*tm.Vote, len(privAccs_1)), - } - for i, privAcc := range privAccs_1 { - vote := &tm.Vote{ - ValidatorAddress: privAcc.Account.PubKey.Address(), - ValidatorIndex: i, - Height: 999, - Round: 0, - Type: tm.VoteTypePrecommit, - BlockID: tm.BlockID{Hash: blockHash}, - } - vote.Signature = privAcc.PrivKey.Sign( - tm.SignBytes("test_chain", vote), - ) - commit.Precommits[i] = vote - } + commit := constructCommit(privAccs_1, header) // Update a chain res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ Header: header, Commit: commit, }})) - assert.Equal(abci.CodeType_OK, res.Code, res.Log) - t.Log(">>", strings.Join(store.GetLogLines(), "\n")) - store.ClearLogLines() + assertAndLog(t, store, res, abci.CodeType_OK) // Get proof for the packet packetKey := toKey(_IBC, _EGRESS, @@ -462,7 +361,58 @@ func TestIBCPluginBadProof(t *testing.T) { Packet: packet, Proof: proof, }})) - assert.Equal(IBCCodeInvalidProof, res.Code, res.Log) + assertAndLog(t, store, res, IBCCodeInvalidProof) +} + +//------------------------------------- +// utils + +func assertAndLog(t *testing.T, store *types.KVCache, res abci.Result, codeExpected abci.CodeType) { + assert := assert.New(t) + assert.Equal(codeExpected, res.Code, res.Log) t.Log(">>", strings.Join(store.GetLogLines(), "\n")) store.ClearLogLines() } + +func newHeader(chainID string, height int, appHash, valHash []byte) tm.Header { + return tm.Header{ + ChainID: chainID, + Height: height, + AppHash: appHash, + ValidatorsHash: valHash, + } +} + +func registerChain(t *testing.T, ibcPlugin *IBCPlugin, store *types.KVCache, ctx types.CallContext, chainID, genDoc string) { + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCRegisterChainTx{ + BlockchainGenesis{ + ChainID: chainID, + Genesis: genDoc, + }, + }})) + assertAndLog(t, store, res, abci.CodeType_OK) +} + +func constructCommit(privAccs []types.PrivAccount, header tm.Header) tm.Commit { + blockHash := header.Hash() + blockID := tm.BlockID{Hash: blockHash} + commit := tm.Commit{ + BlockID: blockID, + Precommits: make([]*tm.Vote, len(privAccs)), + } + for i, privAcc := range privAccs { + vote := &tm.Vote{ + ValidatorAddress: privAcc.Account.PubKey.Address(), + ValidatorIndex: i, + Height: 999, + Round: 0, + Type: tm.VoteTypePrecommit, + BlockID: tm.BlockID{Hash: blockHash}, + } + vote.Signature = privAcc.PrivKey.Sign( + tm.SignBytes("test_chain", vote), + ) + commit.Precommits[i] = vote + } + return commit +} From 38716d4815be17973047a49b4f8ee8327e05d5bb Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 14:30:41 -0400 Subject: [PATCH 52/67] [ibc] test CoinsPayload --- plugins/ibc/ibc.go | 3 ++ plugins/ibc/ibc_test.go | 109 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 7e38967957..bcf224d6be 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -433,6 +433,9 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { case CoinsPayload: // Add coins to destination account acc := bcsm.GetAccount(sm.store, payload.Address) + if acc == nil { + acc = &types.Account{} + } acc.Balance = acc.Balance.Plus(payload.Coins) bcsm.SetAccount(sm.store, payload.Address, acc) } diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 4b2c6a945c..40d49a8239 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -17,6 +17,7 @@ import ( "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" + sm "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" tm "github.com/tendermint/tendermint/types" ) @@ -182,7 +183,7 @@ func TestIBCPluginPost(t *testing.T) { assertAndLog(t, store, res, IBCCodePacketAlreadyExists) } -func TestIBCPlugin(t *testing.T) { +func TestIBCPluginPayloadBytes(t *testing.T) { assert := assert.New(t) require := require.New(t) @@ -208,12 +209,6 @@ func TestIBCPlugin(t *testing.T) { }})) assertAndLog(t, store, res, abci.CodeType_OK) - // Post a duplicate packet - res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ - Packet: packet, - }})) - assertAndLog(t, store, res, IBCCodePacketAlreadyExists) - // Construct a Header that includes the above packet. store.Sync() resCommit := eyesClient.CommitSync() @@ -256,6 +251,106 @@ func TestIBCPlugin(t *testing.T) { assertAndLog(t, store, res, abci.CodeType_OK) } +func TestIBCPluginPayloadCoins(t *testing.T) { + assert := assert.New(t) + require := require.New(t) + + eyesClient := eyes.NewLocalClient("", 0) + store := types.NewKVCache(eyesClient) + store.SetLogging() // Log all activity + + ibcPlugin := New() + coins := types.Coins{ + types.Coin{ + Denom: "mycoin", + Amount: 100, + }, + } + ctx := types.NewCallContext(nil, nil, coins) + + chainID_1 := "test_chain" + genDoc_1, privAccs_1 := genGenesisDoc(chainID_1, 4) + genDocJSON_1, err := json.Marshal(genDoc_1) + require.Nil(err) + + // Register a chain + registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) + + // send coins to this addr on the other chain + destinationAddr := []byte("some address") + coinsBad := types.Coins{types.Coin{"mycoin", 200}} + coinsGood := types.Coins{types.Coin{"mycoin", 1}} + + // Try to send too many coins + packet := NewPacket("test_chain", "dst_chain", 0, "data", CoinsPayload{ + Address: destinationAddr, + Coins: coinsBad, + }) + res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ + Packet: packet, + }})) + assertAndLog(t, store, res, abci.CodeType_InsufficientFunds) + + // Send a small enough number of coins + packet = NewPacket("test_chain", "dst_chain", 0, "data", CoinsPayload{ + Address: destinationAddr, + Coins: coinsGood, + }) + res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ + Packet: packet, + }})) + assertAndLog(t, store, res, abci.CodeType_OK) + + // Construct a Header that includes the above packet. + store.Sync() + resCommit := eyesClient.CommitSync() + appHash := resCommit.Data + header := newHeader("test_chain", 999, appHash, []byte("must_exist")) + + // Construct a Commit that signs above header + commit := constructCommit(privAccs_1, header) + + // Update a chain + res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{ + Header: header, + Commit: commit, + }})) + assertAndLog(t, store, res, abci.CodeType_OK) + + // Get proof for the packet + packetKey := toKey(_IBC, _EGRESS, + packet.SrcChainID, + packet.DstChainID, + cmn.Fmt("%v", packet.Sequence), + ) + resQuery, err := eyesClient.QuerySync(abci.RequestQuery{ + Path: "/store", + Data: packetKey, + Prove: true, + }) + assert.Nil(err) + var proof *iavl.IAVLProof + err = wire.ReadBinaryBytes(resQuery.Proof, &proof) + assert.Nil(err) + + // Account should be empty before the tx + acc := sm.GetAccount(store, destinationAddr) + assert.Nil(acc) + + // Post a packet + res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketPostTx{ + FromChainID: "test_chain", + FromChainHeight: 999, + Packet: packet, + Proof: proof, + }})) + assertAndLog(t, store, res, abci.CodeType_OK) + + // Account should now have some coins + acc = sm.GetAccount(store, destinationAddr) + assert.Equal(acc.Balance, coinsGood) +} + func TestIBCPluginBadCommit(t *testing.T) { require := require.New(t) From 412c2b5bb751edcc568ac63245114c4dec891044 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 15:36:46 -0400 Subject: [PATCH 53/67] support SendTx to other chains via IBC --- plugins/ibc/ibc.go | 66 +++++++++++++++++++++++++++++++++-------- plugins/ibc/ibc_test.go | 15 +++++----- state/execution.go | 29 +++++++++++++----- state/state.go | 31 ++----------------- types/account.go | 24 +++++++++++++++ types/tx.go | 29 ++++++++++++++++-- 6 files changed, 135 insertions(+), 59 deletions(-) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index bcf224d6be..f20442222d 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/url" + "strconv" "strings" abci "github.com/tendermint/abci/types" @@ -13,7 +14,6 @@ import ( merkle "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" - bcsm "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" tm "github.com/tendermint/tendermint/types" ) @@ -55,20 +55,53 @@ type Packet struct { SrcChainID string DstChainID string Sequence uint64 - Type string + Type string // redundant now that Type() is a method on Payload ? Payload Payload } -func NewPacket(src, dst string, seq uint64, ty string, payload Payload) Packet { +func NewPacket(src, dst string, seq uint64, payload Payload) Packet { return Packet{ SrcChainID: src, DstChainID: dst, Sequence: seq, - Type: ty, + Type: payload.Type(), Payload: payload, } } +// GetSequenceNumber gets the sequence number for packets being sent from the src chain to the dst chain +func GetSequenceNumber(store types.KVStore, src, dst string) uint64 { + sequenceKey := toKey(_IBC, _EGRESS, src, dst) + seqBytes := store.Get(sequenceKey) + if seqBytes == nil { + return 0 + } + seq, err := strconv.ParseUint(string(seqBytes), 10, 64) + if err != nil { + cmn.PanicSanity(err.Error()) + } + return seq +} + +// SetSequenceNumber sets the sequence number for packets being sent from the src chain to the dst chain +func SetSequenceNumber(store types.KVStore, src, dst string, seq uint64) { + sequenceKey := toKey(_IBC, _EGRESS, src, dst) + store.Set(sequenceKey, []byte(strconv.FormatUint(seq, 10))) +} + +// SaveNewIBCPacket creates an IBC packet with the given payload from the src chain to the dst chain +// using the correct sequence number. It also increments the sequence number by 1 +func SaveNewIBCPacket(state types.KVStore, src, dst string, payload Payload) { + // fetch sequence number and increment by 1 + seq := GetSequenceNumber(state, src, dst) + SetSequenceNumber(state, src, dst, seq+1) + + // save ibc packet + packetKey := toKey(_IBC, _EGRESS, src, dst, cmn.Fmt("%v", seq)) + packet := NewPacket(src, dst, uint64(seq), payload) + save(state, packetKey, packet) +} + //-------------------------------------------------------------------------------- const ( @@ -78,21 +111,26 @@ const ( var _ = wire.RegisterInterface( struct{ Payload }{}, - wire.ConcreteType{BytesPayload{}, PayloadTypeBytes}, + wire.ConcreteType{DataPayload{}, PayloadTypeBytes}, wire.ConcreteType{CoinsPayload{}, PayloadTypeCoins}, ) type Payload interface { AssertIsPayload() + Type() string ValidateBasic() abci.Result } -func (BytesPayload) AssertIsPayload() {} +func (DataPayload) AssertIsPayload() {} func (CoinsPayload) AssertIsPayload() {} -type BytesPayload []byte +type DataPayload []byte -func (p BytesPayload) ValidateBasic() abci.Result { +func (p DataPayload) Type() string { + return "data" +} + +func (p DataPayload) ValidateBasic() abci.Result { return abci.OK } @@ -101,6 +139,10 @@ type CoinsPayload struct { Coins types.Coins } +func (p CoinsPayload) Type() string { + return "coin" +} + func (p CoinsPayload) ValidateBasic() abci.Result { // TODO: validate return abci.OK @@ -351,7 +393,7 @@ func (sm *IBCStateMachine) runPacketCreateTx(tx IBCPacketCreateTx) { // Execute the payload switch payload := tx.Packet.Payload.(type) { - case BytesPayload: + case DataPayload: // do nothing case CoinsPayload: // ensure enough coins were sent in tx to cover the payload coins @@ -428,16 +470,16 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { // Execute payload switch payload := packet.Payload.(type) { - case BytesPayload: + case DataPayload: // do nothing case CoinsPayload: // Add coins to destination account - acc := bcsm.GetAccount(sm.store, payload.Address) + acc := types.GetAccount(sm.store, payload.Address) if acc == nil { acc = &types.Account{} } acc.Balance = acc.Balance.Plus(payload.Coins) - bcsm.SetAccount(sm.store, payload.Address, acc) + types.SetAccount(sm.store, payload.Address, acc) } return diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 40d49a8239..93a913dec0 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -17,7 +17,6 @@ import ( "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" - sm "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" tm "github.com/tendermint/tendermint/types" ) @@ -170,7 +169,7 @@ func TestIBCPluginPost(t *testing.T) { registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Create a new packet (for testing) - packet := NewPacket("test_chain", "dst_chain", 0, "data", BytesPayload([]byte("hello world"))) + packet := NewPacket("test_chain", "dst_chain", 0, DataPayload([]byte("hello world"))) res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ Packet: packet, }})) @@ -203,7 +202,7 @@ func TestIBCPluginPayloadBytes(t *testing.T) { registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Create a new packet (for testing) - packet := NewPacket("test_chain", "dst_chain", 0, "data", BytesPayload([]byte("hello world"))) + packet := NewPacket("test_chain", "dst_chain", 0, DataPayload([]byte("hello world"))) res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ Packet: packet, }})) @@ -282,7 +281,7 @@ func TestIBCPluginPayloadCoins(t *testing.T) { coinsGood := types.Coins{types.Coin{"mycoin", 1}} // Try to send too many coins - packet := NewPacket("test_chain", "dst_chain", 0, "data", CoinsPayload{ + packet := NewPacket("test_chain", "dst_chain", 0, CoinsPayload{ Address: destinationAddr, Coins: coinsBad, }) @@ -292,7 +291,7 @@ func TestIBCPluginPayloadCoins(t *testing.T) { assertAndLog(t, store, res, abci.CodeType_InsufficientFunds) // Send a small enough number of coins - packet = NewPacket("test_chain", "dst_chain", 0, "data", CoinsPayload{ + packet = NewPacket("test_chain", "dst_chain", 0, CoinsPayload{ Address: destinationAddr, Coins: coinsGood, }) @@ -334,7 +333,7 @@ func TestIBCPluginPayloadCoins(t *testing.T) { assert.Nil(err) // Account should be empty before the tx - acc := sm.GetAccount(store, destinationAddr) + acc := types.GetAccount(store, destinationAddr) assert.Nil(acc) // Post a packet @@ -347,7 +346,7 @@ func TestIBCPluginPayloadCoins(t *testing.T) { assertAndLog(t, store, res, abci.CodeType_OK) // Account should now have some coins - acc = sm.GetAccount(store, destinationAddr) + acc = types.GetAccount(store, destinationAddr) assert.Equal(acc.Balance, coinsGood) } @@ -408,7 +407,7 @@ func TestIBCPluginBadProof(t *testing.T) { registerChain(t, ibcPlugin, store, ctx, "test_chain", string(genDocJSON_1)) // Create a new packet (for testing) - packet := NewPacket("test_chain", "dst_chain", 0, "data", BytesPayload([]byte("hello world"))) + packet := NewPacket("test_chain", "dst_chain", 0, DataPayload([]byte("hello world"))) res := ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCPacketCreateTx{ Packet: packet, }})) diff --git a/state/execution.go b/state/execution.go index 246246846d..307c0d463c 100644 --- a/state/execution.go +++ b/state/execution.go @@ -2,9 +2,11 @@ package state import ( abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/events" + + "github.com/tendermint/basecoin/plugins/ibc" + "github.com/tendermint/basecoin/types" ) // If the tx is invalid, a TMSP error will be returned. @@ -189,17 +191,23 @@ func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Acco } for _, out := range outs { + chain, outAddress, _ := out.ChainAndAddress() // already validated + if chain != nil { + // we dont need an account for the other chain. + // we'll just create an outgoing ibc packet + continue + } // Account shouldn't be duplicated - if _, ok := accounts[string(out.Address)]; ok { + if _, ok := accounts[string(outAddress)]; ok { return nil, abci.ErrBaseDuplicateAddress } - acc := state.GetAccount(out.Address) + acc := state.GetAccount(outAddress) // output account may be nil (new) if acc == nil { // zero value is valid, empty account acc = &types.Account{} } - accounts[string(out.Address)] = acc + accounts[string(outAddress)] = acc } return accounts, abci.OK } @@ -281,15 +289,22 @@ func adjustByInputs(state types.AccountSetter, accounts map[string]*types.Accoun } } -func adjustByOutputs(state types.AccountSetter, accounts map[string]*types.Account, outs []types.TxOutput, isCheckTx bool) { +func adjustByOutputs(state *State, accounts map[string]*types.Account, outs []types.TxOutput, isCheckTx bool) { for _, out := range outs { - acc := accounts[string(out.Address)] + destChain, outAddress, _ := out.ChainAndAddress() // already validated + if destChain != nil { + payload := ibc.CoinsPayload{outAddress, out.Coins} + ibc.SaveNewIBCPacket(state, state.GetChainID(), string(destChain), payload) + continue + } + + acc := accounts[string(outAddress)] if acc == nil { cmn.PanicSanity("adjustByOutputs() expects account in accounts") } acc.Balance = acc.Balance.Plus(out.Coins) if !isCheckTx { - state.SetAccount(out.Address, acc) + state.SetAccount(outAddress, acc) } } } diff --git a/state/state.go b/state/state.go index fbec5ae8e0..e9daf73b12 100644 --- a/state/state.go +++ b/state/state.go @@ -3,9 +3,7 @@ package state import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/types" - wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" - . "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" ) @@ -64,11 +62,11 @@ func (s *State) Set(key []byte, value []byte) { } func (s *State) GetAccount(addr []byte) *types.Account { - return GetAccount(s, addr) + return types.GetAccount(s, addr) } func (s *State) SetAccount(addr []byte, acc *types.Account) { - SetAccount(s, addr, acc) + types.SetAccount(s, addr, acc) } func (s *State) CacheWrap() *State { @@ -97,28 +95,3 @@ func (s *State) Commit() abci.Result { } } - -//---------------------------------------- - -func AccountKey(addr []byte) []byte { - return append([]byte("base/a/"), addr...) -} - -func GetAccount(store types.KVStore, addr []byte) *types.Account { - data := store.Get(AccountKey(addr)) - if len(data) == 0 { - return nil - } - var acc *types.Account - err := wire.ReadBinaryBytes(data, &acc) - if err != nil { - panic(Fmt("Error reading account %X error: %v", - data, err.Error())) - } - return acc -} - -func SetAccount(store types.KVStore, addr []byte, acc *types.Account) { - accBytes := wire.BinaryBytes(acc) - store.Set(AccountKey(addr), accBytes) -} diff --git a/types/account.go b/types/account.go index d1e62d8321..ec4154fc42 100644 --- a/types/account.go +++ b/types/account.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/tendermint/go-crypto" + "github.com/tendermint/go-wire" ) type Account struct { @@ -49,3 +50,26 @@ type AccountGetterSetter interface { GetAccount(addr []byte) *Account SetAccount(addr []byte, acc *Account) } + +func AccountKey(addr []byte) []byte { + return append([]byte("base/a/"), addr...) +} + +func GetAccount(store KVStore, addr []byte) *Account { + data := store.Get(AccountKey(addr)) + if len(data) == 0 { + return nil + } + var acc *Account + err := wire.ReadBinaryBytes(data, &acc) + if err != nil { + panic(fmt.Sprintf("Error reading account %X error: %v", + data, err.Error())) + } + return acc +} + +func SetAccount(store KVStore, addr []byte, acc *Account) { + accBytes := wire.BinaryBytes(acc) + store.Set(AccountKey(addr), accBytes) +} diff --git a/types/tx.go b/types/tx.go index ed3e2ca0c9..a54d7caf0a 100644 --- a/types/tx.go +++ b/types/tx.go @@ -116,10 +116,33 @@ type TxOutput struct { Coins Coins `json:"coins"` // } -func (txOut TxOutput) ValidateBasic() abci.Result { - if len(txOut.Address) != 20 { - return abci.ErrBaseInvalidOutput.AppendLog("Invalid address length") +// An output destined for another chain may be formatted as `chainID/address`. +// ChainAndAddress returns the chainID prefix and the address. +// If there is no chainID prefix, the first returned value is nil. +func (txOut TxOutput) ChainAndAddress() ([]byte, []byte, abci.Result) { + var chainPrefix []byte + address := txOut.Address + if len(address) > 20 { + spl := bytes.Split(address, []byte("/")) + if len(spl) < 2 { + return nil, nil, abci.ErrBaseInvalidOutput.AppendLog("Invalid address format") + } + chainPrefix = spl[0] + address = bytes.Join(spl[1:], nil) } + + if len(address) != 20 { + return nil, nil, abci.ErrBaseInvalidOutput.AppendLog("Invalid address length") + } + return chainPrefix, address, abci.OK +} + +func (txOut TxOutput) ValidateBasic() abci.Result { + _, _, r := txOut.ChainAndAddress() + if r.IsErr() { + return r + } + if !txOut.Coins.IsValid() { return abci.ErrBaseInvalidOutput.AppendLog(Fmt("Invalid coins %v", txOut.Coins)) } From 4503bb61f290542418ac57c59555c5240e7c94fc Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 15:59:13 -0400 Subject: [PATCH 54/67] test SendTx to IBC packet --- plugins/ibc/ibc.go | 9 +++ state/execution_test.go | 151 +++++++++++++++++++++++++--------------- types/test_helpers.go | 6 +- 3 files changed, 107 insertions(+), 59 deletions(-) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index f20442222d..e4b4412895 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -102,6 +102,15 @@ func SaveNewIBCPacket(state types.KVStore, src, dst string, payload Payload) { save(state, packetKey, packet) } +func GetIBCPacket(state types.KVStore, src, dst string, seq uint64) (Packet, error) { + packetKey := toKey(_IBC, _EGRESS, src, dst, cmn.Fmt("%v", seq)) + packetBytes := state.Get(packetKey) + + var packet Packet + err := wire.ReadBinaryBytes(packetBytes, &packet) + return packet, err +} + //-------------------------------------------------------------------------------- const ( diff --git a/state/execution_test.go b/state/execution_test.go index b8e526ae48..b69e66c40a 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -6,8 +6,10 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/types" "github.com/tendermint/tmlibs/log" + + "github.com/tendermint/basecoin/plugins/ibc" + "github.com/tendermint/basecoin/types" ) //-------------------------------------------------------- @@ -33,11 +35,6 @@ func (et *execTest) signTx(tx *types.SendTx, accsIn ...types.PrivAccount) { types.SignTx(et.chainID, tx, accsIn...) } -// make tx from accsIn to et.accOut -func (et *execTest) getTx(seq int, accOut types.PrivAccount, accsIn ...types.PrivAccount) *types.SendTx { - return types.GetTx(seq, accOut, accsIn...) -} - // returns the final balance and expected balance for input and output accounts func (et *execTest) exec(tx *types.SendTx, checkTx bool) (res abci.Result, inGot, inExp, outGot, outExp types.Coins) { initBalIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance @@ -85,19 +82,19 @@ func TestGetInputs(t *testing.T) { //test getInputs for registered, non-registered account et.reset() - txs := types.Accs2TxInputs(1, et.accIn) - acc, res = getInputs(et.state, txs) + inputs := types.Accs2TxInputs(1, et.accIn) + acc, res = getInputs(et.state, inputs) assert.True(res.IsErr(), "getInputs: expected error when using getInput with non-registered Input") et.acc2State(et.accIn) - acc, res = getInputs(et.state, txs) + acc, res = getInputs(et.state, inputs) assert.True(res.IsOK(), "getInputs: expected to getInput from registered Input") //test sending duplicate accounts et.reset() et.acc2State(et.accIn, et.accIn, et.accIn) - txs = types.Accs2TxInputs(1, et.accIn, et.accIn, et.accIn) - acc, res = getInputs(et.state, txs) + inputs = types.Accs2TxInputs(1, et.accIn, et.accIn, et.accIn) + acc, res = getInputs(et.state, inputs) assert.True(res.IsErr(), "getInputs: expected error when sending duplicate accounts") } @@ -112,24 +109,24 @@ func TestGetOrMakeOutputs(t *testing.T) { //test sending duplicate accounts et.reset() - txs := types.Accs2TxOutputs(et.accIn, et.accIn, et.accIn) - _, res = getOrMakeOutputs(et.state, nil, txs) + outputs := types.Accs2TxOutputs(et.accIn, et.accIn, et.accIn) + _, res = getOrMakeOutputs(et.state, nil, outputs) assert.True(res.IsErr(), "getOrMakeOutputs: expected error when sending duplicate accounts") //test sending to existing/new account et.reset() - txs1 := types.Accs2TxOutputs(et.accIn) - txs2 := types.Accs2TxOutputs(et.accOut) + outputs1 := types.Accs2TxOutputs(et.accIn) + outputs2 := types.Accs2TxOutputs(et.accOut) et.acc2State(et.accIn) - _, res = getOrMakeOutputs(et.state, nil, txs1) + _, res = getOrMakeOutputs(et.state, nil, outputs1) assert.True(res.IsOK(), "getOrMakeOutputs: error when sending to existing account") - mapRes2, res := getOrMakeOutputs(et.state, nil, txs2) + mapRes2, res := getOrMakeOutputs(et.state, nil, outputs2) assert.True(res.IsOK(), "getOrMakeOutputs: error when sending to new account") //test the map results - _, map2ok := mapRes2[string(txs2[0].Address)] + _, map2ok := mapRes2[string(outputs2[0].Address)] assert.True(map2ok, "getOrMakeOutputs: account output does not contain new account map item") } @@ -139,12 +136,12 @@ func TestValidateInputsBasic(t *testing.T) { et := newExecTest() //validate input basic - txs := types.Accs2TxInputs(1, et.accIn) - res := validateInputsBasic(txs) + inputs := types.Accs2TxInputs(1, et.accIn) + res := validateInputsBasic(inputs) assert.True(res.IsOK(), "validateInputsBasic: expected no error on good tx input. Error: %v", res.Error()) - txs[0].Coins[0].Amount = 0 - res = validateInputsBasic(txs) + inputs[0].Coins[0].Amount = 0 + res = validateInputsBasic(inputs) assert.True(res.IsErr(), "validateInputsBasic: expected error on bad tx input") } @@ -159,28 +156,28 @@ func TestValidateInputsAdvanced(t *testing.T) { accIn3 := types.MakeAcc("fooz") //validate inputs advanced - txs := et.getTx(1, et.accOut, accIn1, accIn2, accIn3) + tx := types.MakeSendTx(1, et.accOut, accIn1, accIn2, accIn3) et.acc2State(accIn1, accIn2, accIn3, et.accOut) - accMap, res := getInputs(et.state, txs.Inputs) + accMap, res := getInputs(et.state, tx.Inputs) assert.True(res.IsOK(), "validateInputsAdvanced: error retrieving accMap. Error: %v", res.Error()) - signBytes := txs.SignBytes(et.chainID) + signBytes := tx.SignBytes(et.chainID) //test bad case, unsigned - totalCoins, res := validateInputsAdvanced(accMap, signBytes, txs.Inputs) + totalCoins, res := validateInputsAdvanced(accMap, signBytes, tx.Inputs) assert.True(res.IsErr(), "validateInputsAdvanced: expected an error on an unsigned tx input") //test good case sgined - et.signTx(txs, accIn1, accIn2, accIn3, et.accOut) - totalCoins, res = validateInputsAdvanced(accMap, signBytes, txs.Inputs) + et.signTx(tx, accIn1, accIn2, accIn3, et.accOut) + totalCoins, res = validateInputsAdvanced(accMap, signBytes, tx.Inputs) assert.True(res.IsOK(), "validateInputsAdvanced: expected no error on good tx input. Error: %v", res.Error()) - txsTotalCoins := txs.Inputs[0].Coins. - Plus(txs.Inputs[1].Coins). - Plus(txs.Inputs[2].Coins) + txTotalCoins := tx.Inputs[0].Coins. + Plus(tx.Inputs[1].Coins). + Plus(tx.Inputs[2].Coins) - assert.True(totalCoins.IsEqual(txsTotalCoins), - "ValidateInputsAdvanced: transaction total coins are not equal: got %v, expected %v", txsTotalCoins, totalCoins) + assert.True(totalCoins.IsEqual(txTotalCoins), + "ValidateInputsAdvanced: transaction total coins are not equal: got %v, expected %v", txTotalCoins, totalCoins) } func TestValidateInputAdvanced(t *testing.T) { @@ -188,31 +185,31 @@ func TestValidateInputAdvanced(t *testing.T) { et := newExecTest() //validate input advanced - txs := et.getTx(1, et.accOut, et.accIn) + tx := types.MakeSendTx(1, et.accOut, et.accIn) et.acc2State(et.accIn, et.accOut) - signBytes := txs.SignBytes(et.chainID) + signBytes := tx.SignBytes(et.chainID) //unsigned case - res := validateInputAdvanced(&et.accIn.Account, signBytes, txs.Inputs[0]) + res := validateInputAdvanced(&et.accIn.Account, signBytes, tx.Inputs[0]) assert.True(res.IsErr(), "validateInputAdvanced: expected error on tx input without signature") //good signed case - et.signTx(txs, et.accIn, et.accOut) - res = validateInputAdvanced(&et.accIn.Account, signBytes, txs.Inputs[0]) + et.signTx(tx, et.accIn, et.accOut) + res = validateInputAdvanced(&et.accIn.Account, signBytes, tx.Inputs[0]) assert.True(res.IsOK(), "validateInputAdvanced: expected no error on good tx input. Error: %v", res.Error()) //bad sequence case et.accIn.Sequence = 1 - et.signTx(txs, et.accIn, et.accOut) - res = validateInputAdvanced(&et.accIn.Account, signBytes, txs.Inputs[0]) + et.signTx(tx, et.accIn, et.accOut) + res = validateInputAdvanced(&et.accIn.Account, signBytes, tx.Inputs[0]) assert.Equal(abci.CodeType_BaseInvalidSequence, res.Code, "validateInputAdvanced: expected error on tx input with bad sequence") et.accIn.Sequence = 0 //restore sequence //bad balance case et.accIn.Balance = types.Coins{{"mycoin", 2}} - et.signTx(txs, et.accIn, et.accOut) - res = validateInputAdvanced(&et.accIn.Account, signBytes, txs.Inputs[0]) + et.signTx(tx, et.accIn, et.accOut) + res = validateInputAdvanced(&et.accIn.Account, signBytes, tx.Inputs[0]) assert.Equal(abci.CodeType_BaseInsufficientFunds, res.Code, "validateInputAdvanced: expected error on tx input with insufficient funds %v", et.accIn.Sequence) } @@ -222,12 +219,12 @@ func TestValidateOutputsAdvanced(t *testing.T) { et := newExecTest() //validateOutputsBasic - txs := types.Accs2TxOutputs(et.accIn) - res := validateOutputsBasic(txs) + tx := types.Accs2TxOutputs(et.accIn) + res := validateOutputsBasic(tx) assert.True(res.IsOK(), "validateOutputsBasic: expected no error on good tx output. Error: %v", res.Error()) - txs[0].Coins[0].Amount = 0 - res = validateOutputsBasic(txs) + tx[0].Coins[0].Amount = 0 + res = validateOutputsBasic(tx) assert.True(res.IsErr(), "validateInputBasic: expected error on bad tx output. Error: %v", res.Error()) } @@ -236,9 +233,9 @@ func TestSumOutput(t *testing.T) { et := newExecTest() //SumOutput - txs := types.Accs2TxOutputs(et.accIn, et.accOut) - total := sumOutputs(txs) - assert.True(total.IsEqual(txs[0].Coins.Plus(txs[1].Coins)), "sumOutputs: total coins are not equal") + tx := types.Accs2TxOutputs(et.accIn, et.accOut) + total := sumOutputs(tx) + assert.True(total.IsEqual(tx[0].Coins.Plus(tx[1].Coins)), "sumOutputs: total coins are not equal") } func TestAdjustBy(t *testing.T) { @@ -271,23 +268,23 @@ func TestAdjustBy(t *testing.T) { } -func TestExecTx(t *testing.T) { +func TestSendTx(t *testing.T) { assert := assert.New(t) et := newExecTest() //ExecTx - txs := et.getTx(1, et.accOut, et.accIn) + tx := types.MakeSendTx(1, et.accOut, et.accIn) et.acc2State(et.accIn) et.acc2State(et.accOut) - et.signTx(txs, et.accIn) + et.signTx(tx, et.accIn) //Bad Balance et.accIn.Balance = types.Coins{{"mycoin", 2}} et.acc2State(et.accIn) - res, _, _, _, _ := et.exec(txs, true) + res, _, _, _, _ := et.exec(tx, true) assert.True(res.IsErr(), "ExecTx/Bad CheckTx: Expected error return from ExecTx, returned: %v", res) - res, balIn, balInExp, balOut, balOutExp := et.exec(txs, false) + res, balIn, balInExp, balOut, balOutExp := et.exec(tx, false) assert.True(res.IsErr(), "ExecTx/Bad DeliverTx: Expected error return from ExecTx, returned: %v", res) assert.False(balIn.IsEqual(balInExp), "ExecTx/Bad DeliverTx: balance shouldn't be equal for accIn: got %v, expected: %v", balIn, balInExp) @@ -298,17 +295,59 @@ func TestExecTx(t *testing.T) { et.reset() et.acc2State(et.accIn) et.acc2State(et.accOut) - res, _, _, _, _ = et.exec(txs, true) + res, _, _, _, _ = et.exec(tx, true) assert.True(res.IsOK(), "ExecTx/Good CheckTx: Expected OK return from ExecTx, Error: %v", res) //Regular DeliverTx et.reset() et.acc2State(et.accIn) et.acc2State(et.accOut) - res, balIn, balInExp, balOut, balOutExp = et.exec(txs, false) + res, balIn, balInExp, balOut, balOutExp = et.exec(tx, false) assert.True(res.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", res) assert.True(balIn.IsEqual(balInExp), "ExecTx/good DeliverTx: unexpected change in input balance, got: %v, expected: %v", balIn, balInExp) assert.True(balOut.IsEqual(balOutExp), "ExecTx/good DeliverTx: unexpected change in output balance, got: %v, expected: %v", balOut, balOutExp) } + +func TestSendTxIBC(t *testing.T) { + assert := assert.New(t) + et := newExecTest() + + //ExecTx + chainID2 := "otherchain" + tx := types.MakeSendTx(1, et.accOut, et.accIn) + dstAddress := tx.Outputs[0].Address + tx.Outputs[0].Address = []byte(chainID2 + "/" + string(tx.Outputs[0].Address)) + et.acc2State(et.accIn) + et.signTx(tx, et.accIn) + + //Regular DeliverTx + et.reset() + et.acc2State(et.accIn) + + initBalIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance + + res := ExecTx(et.state, nil, tx, false, nil) + + balIn := et.state.GetAccount(et.accIn.Account.PubKey.Address()).Balance + decrBalInExp := tx.Outputs[0].Coins.Plus(types.Coins{tx.Fee}) //expected decrease in balance In + balInExp := initBalIn.Minus(decrBalInExp) + + assert.True(res.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", res) + assert.True(balIn.IsEqual(balInExp), + "ExecTx/good DeliverTx: unexpected change in input balance, got: %v, expected: %v", balIn, balInExp) + + packet, err := ibc.GetIBCPacket(et.state, et.chainID, chainID2, 0) + assert.Nil(err) + + assert.Equal(packet.SrcChainID, et.chainID) + assert.Equal(packet.DstChainID, chainID2) + assert.Equal(packet.Sequence, uint64(0)) + assert.Equal(packet.Type, "coin") + + coins, ok := packet.Payload.(ibc.CoinsPayload) + assert.True(ok) + assert.Equal(coins.Coins, tx.Outputs[0].Coins) + assert.EqualValues(coins.Address, dstAddress) +} diff --git a/types/test_helpers.go b/types/test_helpers.go index ffd3ce931f..2b7be27a9d 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -86,15 +86,15 @@ func Accs2TxOutputs(accs ...PrivAccount) []TxOutput { return txs } -func GetTx(seq int, accOut PrivAccount, accsIn ...PrivAccount) *SendTx { - txs := &SendTx{ +func MakeSendTx(seq int, accOut PrivAccount, accsIn ...PrivAccount) *SendTx { + tx := &SendTx{ Gas: 0, Fee: Coin{"mycoin", 1}, Inputs: Accs2TxInputs(seq, accsIn...), Outputs: Accs2TxOutputs(accOut), } - return txs + return tx } func SignTx(chainID string, tx *SendTx, accs ...PrivAccount) { From f4c5edaca3d4580334d83434d9f184f589ddb66e Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 18:23:58 -0400 Subject: [PATCH 55/67] fixes to compile --- app/app.go | 2 +- cmd/basecli/commands/adapters.go | 2 +- cmd/commands/ibc.go | 7 ++++++- cmd/commands/utils.go | 3 +-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index 2107dc17e6..27a3b9c98a 100644 --- a/app/app.go +++ b/app/app.go @@ -150,7 +150,7 @@ func (app *Basecoin) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQu // handle special path for account info if reqQuery.Path == "/account" { reqQuery.Path = "/key" - reqQuery.Data = sm.AccountKey(reqQuery.Data) + reqQuery.Data = types.AccountKey(reqQuery.Data) } resQuery, err := app.eyesCli.QuerySync(reqQuery) diff --git a/cmd/basecli/commands/adapters.go b/cmd/basecli/commands/adapters.go index a1899019c1..fa2cfec08e 100644 --- a/cmd/basecli/commands/adapters.go +++ b/cmd/basecli/commands/adapters.go @@ -23,7 +23,7 @@ type AccountPresenter struct{} func (_ AccountPresenter) MakeKey(str string) ([]byte, error) { res, err := hex.DecodeString(str) if err == nil { - res = state.AccountKey(res) + res = btypes.AccountKey(res) } return res, err } diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index fa6d4758cc..4297bba422 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -196,13 +196,18 @@ func ibcPacketCreateTxCmd(cmd *cobra.Command, args []string) error { return err } + var payload ibc.Payload + if err := wire.ReadBinaryBytes(payloadBytes, &payload); err != nil { + return err + } + ibcTx := ibc.IBCPacketCreateTx{ Packet: ibc.Packet{ SrcChainID: fromChain, DstChainID: toChain, Sequence: sequence, Type: packetType, - Payload: payloadBytes, + Payload: payload, }, } diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index ae1f49aaa4..ff14faf450 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -11,7 +11,6 @@ import ( abci "github.com/tendermint/abci/types" wire "github.com/tendermint/go-wire" - "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" client "github.com/tendermint/tendermint/rpc/client" @@ -114,7 +113,7 @@ func Query(tmAddr string, key []byte) (*abci.ResultQuery, error) { // fetch the account by querying the app func getAcc(tmAddr string, address []byte) (*types.Account, error) { - key := state.AccountKey(address) + key := types.AccountKey(address) response, err := Query(tmAddr, key) if err != nil { return nil, err From 7b83dea0d6257fce0446dc6d5e90ed9ed5e751ce Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 19:02:11 -0400 Subject: [PATCH 56/67] [cmd] new relay command for IBC relay --- cmd/basecoin/main.go | 1 + cmd/commands/relay.go | 211 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 cmd/commands/relay.go diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index 76ba6d5e93..5bc03e0fa6 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -18,6 +18,7 @@ func main() { RootCmd.AddCommand( commands.InitCmd, commands.StartCmd, + commands.RelayCmd, commands.TxCmd, commands.QueryCmd, commands.KeyCmd, diff --git a/cmd/commands/relay.go b/cmd/commands/relay.go new file mode 100644 index 0000000000..e4a4d56d31 --- /dev/null +++ b/cmd/commands/relay.go @@ -0,0 +1,211 @@ +package commands + +import ( + "fmt" + "strconv" + "time" + + "github.com/pkg/errors" + "github.com/spf13/cobra" + + // "github.com/spf13/viper" + // "github.com/tendermint/tmlibs/cli" + // "github.com/tendermint/tmlibs/log" + + "github.com/tendermint/go-wire" + "github.com/tendermint/merkleeyes/iavl" + cmn "github.com/tendermint/tmlibs/common" + + "github.com/tendermint/basecoin/plugins/ibc" + "github.com/tendermint/basecoin/types" + "github.com/tendermint/tendermint/rpc/client" + tmtypes "github.com/tendermint/tendermint/types" +) + +var RelayCmd = &cobra.Command{ + Use: "relay", + Short: "Start basecoin relayer to relay IBC packets between chains", + RunE: relayCmd, +} + +//flags +var ( + chain1AddrFlag string + chain2AddrFlag string + + chain1IDFlag string + chain2IDFlag string + + fromFileFlag string +) + +func init() { + + flags := []Flag2Register{ + {&chain1AddrFlag, "chain1-addr", "tcp://localhost:46657", "Node address for chain1"}, + {&chain2AddrFlag, "chain2-addr", "tcp://localhost:36657", "Node address for chain2"}, + {&chain1IDFlag, "chain1-id", "test_chain_1", "ChainID for chain1"}, + {&chain2IDFlag, "chain2-id", "test_chain_2", "ChainID for chain2"}, + {&fromFileFlag, "from", "key.json", "Path to a private key to sign the transaction"}, + } + RegisterFlags(RelayCmd, flags) +} + +func loop(addr1, addr2, id1, id2 string) { + latestSeq := -1 + + // load the priv key + privKey, err := LoadKey(fromFlag) + if err != nil { + logger.Error(err.Error()) + cmn.PanicCrisis(err.Error()) + } + + // relay from chain1 to chain2 + thisRelayer := relayer{privKey, id2, addr2} + +OUTER: + for { + + time.Sleep(time.Second) + + // get the latest ibc packet sequence number + key := fmt.Sprintf("ibc,egress,%v,%v", id1, id2) + query, err := Query(addr1, []byte(key)) + if err != nil { + logger.Error(err.Error()) + continue OUTER + } + seq, err := strconv.ParseUint(string(query.Value), 10, 64) + if err != nil { + logger.Error(err.Error()) + continue OUTER + } + + // if there's a new packet, relay the header and commit data + if latestSeq < int(seq) { + header, commit, err := getHeaderAndCommit(addr1, int(query.Height)) + if err != nil { + logger.Error(err.Error()) + continue OUTER + } + + // update the chain state on the other chain + ibcTx := ibc.IBCUpdateChainTx{ + Header: *header, + Commit: *commit, + } + if err := thisRelayer.appTx(ibcTx); err != nil { + logger.Error(err.Error()) + continue OUTER + } + } + + // get all packets since the last one we relayed + for ; latestSeq < int(seq); latestSeq++ { + key := fmt.Sprintf("ibc,egress,%v,%v,%d", id1, id2, latestSeq) + query, err := Query(addr1, []byte(key)) + if err != nil { + logger.Error(err.Error()) + continue OUTER + } + + var packet ibc.Packet + err = wire.ReadBinaryBytes(query.Value, &packet) + if err != nil { + logger.Error(err.Error()) + continue OUTER + } + + proof := new(iavl.IAVLProof) + err = wire.ReadBinaryBytes(query.Proof, proof) + if err != nil { + logger.Error(err.Error()) + continue OUTER + } + + // relay the packet and proof + ibcTx := ibc.IBCPacketPostTx{ + FromChainID: id1, + FromChainHeight: uint64(query.Height), + Packet: packet, + Proof: proof, + } + if err := thisRelayer.appTx(ibcTx); err != nil { + logger.Error(err.Error()) + continue OUTER + } + } + } +} + +type relayer struct { + privKey *Key + chainID string + nodeAddr string +} + +func (r *relayer) appTx(ibcTx ibc.IBCTx) error { + sequence, err := getSeq(r.privKey.Address[:]) + if err != nil { + return err + } + + data := []byte(wire.BinaryBytes(struct { + ibc.IBCTx `json:"unwrap"` + }{ibcTx})) + + input := types.NewTxInput(r.privKey.PubKey, types.Coins{}, sequence) + tx := &types.AppTx{ + Gas: 0, + Fee: types.Coin{"mycoin", 1}, + Name: "IBC", + Input: input, + Data: data, + } + + tx.Input.Signature = r.privKey.Sign(tx.SignBytes(r.chainID)) + txBytes := []byte(wire.BinaryBytes(struct { + types.Tx `json:"unwrap"` + }{tx})) + + data, log, err := broadcastTxToNode(r.nodeAddr, txBytes) + if err != nil { + return err + } + fmt.Printf("Response: %X ; %s\n", data, log) + return nil +} + +// broadcast the transaction to tendermint +func broadcastTxToNode(nodeAddr string, tx tmtypes.Tx) ([]byte, string, error) { + httpClient := client.NewHTTP(nodeAddr, "/websocket") + res, err := httpClient.BroadcastTxCommit(tx) + if err != nil { + return nil, "", errors.Errorf("Error on broadcast tx: %v", err) + } + + if !res.CheckTx.Code.IsOK() { + r := res.CheckTx + return nil, "", errors.Errorf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log) + } + + if !res.DeliverTx.Code.IsOK() { + r := res.DeliverTx + return nil, "", errors.Errorf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log) + } + + return res.DeliverTx.Data, res.DeliverTx.Log, nil +} + +func relayCmd(cmd *cobra.Command, args []string) error { + + go loop(chain1AddrFlag, chain2AddrFlag, chain1IDFlag, chain2IDFlag) + go loop(chain2AddrFlag, chain1AddrFlag, chain2IDFlag, chain1IDFlag) + + cmn.TrapSignal(func() { + // TODO: Cleanup + }) + return nil + +} From 444b96dfe7f93f291ca039e13c49872e305ebad1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 22:22:58 -0400 Subject: [PATCH 57/67] fixes for relay --- cmd/commands/query.go | 4 +- cmd/commands/relay.go | 117 ++++++++++++++++++++++++++---------------- cmd/commands/tx.go | 4 +- cmd/commands/utils.go | 28 +++++++++- demo/start.sh | 4 +- glide.lock | 16 +++--- glide.yaml | 5 -- plugins/ibc/ibc.go | 5 +- 8 files changed, 119 insertions(+), 64 deletions(-) diff --git a/cmd/commands/query.go b/cmd/commands/query.go index 1b46a6617a..330ba1514e 100644 --- a/cmd/commands/query.go +++ b/cmd/commands/query.go @@ -10,6 +10,7 @@ import ( "github.com/tendermint/go-wire" "github.com/tendermint/merkleeyes/iavl" + "github.com/tendermint/tendermint/rpc/client" tmtypes "github.com/tendermint/tendermint/types" ) @@ -120,7 +121,8 @@ func accountCmd(cmd *cobra.Command, args []string) error { return errors.Errorf("Account address (%v) is invalid hex: %v\n", addrHex, err) } - acc, err := getAcc(nodeFlag, addr) + httpClient := client.NewHTTP(nodeFlag, "/websocket") + acc, err := getAccWithClient(httpClient, addr) if err != nil { return err } diff --git a/cmd/commands/relay.go b/cmd/commands/relay.go index e4a4d56d31..2c7f812a03 100644 --- a/cmd/commands/relay.go +++ b/cmd/commands/relay.go @@ -52,7 +52,7 @@ func init() { } func loop(addr1, addr2, id1, id2 string) { - latestSeq := -1 + nextSeq := 0 // load the priv key privKey, err := LoadKey(fromFlag) @@ -62,7 +62,11 @@ func loop(addr1, addr2, id1, id2 string) { } // relay from chain1 to chain2 - thisRelayer := relayer{privKey, id2, addr2} + thisRelayer := newRelayer(privKey, id2, addr2) + + logger.Info(fmt.Sprintf("Relaying from chain %v on %v to chain %v on %v", id1, addr1, id2, addr2)) + + httpClient := client.NewHTTP(addr1, "/websocket") OUTER: for { @@ -71,69 +75,83 @@ OUTER: // get the latest ibc packet sequence number key := fmt.Sprintf("ibc,egress,%v,%v", id1, id2) - query, err := Query(addr1, []byte(key)) + query, err := queryWithClient(httpClient, []byte(key)) if err != nil { - logger.Error(err.Error()) + logger.Error("Error querying for latest sequence", "key", key, "error", err.Error()) continue OUTER } + if len(query.Value) == 0 { + // nothing yet + continue OUTER + } + seq, err := strconv.ParseUint(string(query.Value), 10, 64) if err != nil { - logger.Error(err.Error()) + logger.Error("Error parsing sequence number from query", "query.Value", query.Value, "error", err.Error()) continue OUTER } - // if there's a new packet, relay the header and commit data - if latestSeq < int(seq) { - header, commit, err := getHeaderAndCommit(addr1, int(query.Height)) - if err != nil { - logger.Error(err.Error()) - continue OUTER - } - - // update the chain state on the other chain - ibcTx := ibc.IBCUpdateChainTx{ - Header: *header, - Commit: *commit, - } - if err := thisRelayer.appTx(ibcTx); err != nil { - logger.Error(err.Error()) - continue OUTER - } - } - // get all packets since the last one we relayed - for ; latestSeq < int(seq); latestSeq++ { - key := fmt.Sprintf("ibc,egress,%v,%v,%d", id1, id2, latestSeq) - query, err := Query(addr1, []byte(key)) + for ; nextSeq <= int(seq); nextSeq++ { + key := fmt.Sprintf("ibc,egress,%v,%v,%d", id1, id2, nextSeq) + query, err := queryWithClient(httpClient, []byte(key)) if err != nil { - logger.Error(err.Error()) + logger.Error("Error querying for packet", "seqeuence", nextSeq, "key", key, "error", err.Error()) continue OUTER } var packet ibc.Packet err = wire.ReadBinaryBytes(query.Value, &packet) if err != nil { - logger.Error(err.Error()) + logger.Error("Error unmarshalling packet", "key", key, "query.Value", query.Value, "error", err.Error()) continue OUTER } proof := new(iavl.IAVLProof) - err = wire.ReadBinaryBytes(query.Proof, proof) + err = wire.ReadBinaryBytes(query.Proof, &proof) if err != nil { - logger.Error(err.Error()) + logger.Error("Error unmarshalling proof", "query.Proof", query.Proof, "error", err.Error()) + continue OUTER + } + + // query.Height is actually for the next block, + // so wait a block before we fetch the header & commit + if err := waitForBlock(httpClient); err != nil { + logger.Error("Error waiting for a block", "addr", addr1, "error", err.Error()) + continue OUTER + } + + // get the header and commit from the height the query was done at + res, err := httpClient.Commit(int(query.Height)) + if err != nil { + logger.Error("Error fetching header and commits", "height", query.Height, "error", err.Error()) + continue OUTER + } + + // update the chain state on the other chain + updateTx := ibc.IBCUpdateChainTx{ + Header: *res.Header, + Commit: *res.Commit, + } + logger.Info("Updating chain", "src-chain", id1, "height", res.Header.Height, "appHash", res.Header.AppHash) + if err := thisRelayer.appTx(updateTx); err != nil { + logger.Error("Error creating/sending IBCUpdateChainTx", "error", err.Error()) continue OUTER } // relay the packet and proof - ibcTx := ibc.IBCPacketPostTx{ + logger.Info("Relaying packet", "src-chain", id1, "height", query.Height, "sequence", nextSeq) + postTx := ibc.IBCPacketPostTx{ FromChainID: id1, - FromChainHeight: uint64(query.Height), + FromChainHeight: query.Height, Packet: packet, Proof: proof, } - if err := thisRelayer.appTx(ibcTx); err != nil { - logger.Error(err.Error()) - continue OUTER + + if err := thisRelayer.appTx(postTx); err != nil { + logger.Error("Error creating/sending IBCPacketPostTx", "error", err.Error()) + // dont `continue OUTER` here. the error might be eg. Already exists + // TODO: catch this programmatically ? } } } @@ -143,22 +161,36 @@ type relayer struct { privKey *Key chainID string nodeAddr string + client *client.HTTP +} + +func newRelayer(privKey *Key, chainID, nodeAddr string) *relayer { + httpClient := client.NewHTTP(nodeAddr, "/websocket") + return &relayer{ + privKey: privKey, + chainID: chainID, + nodeAddr: nodeAddr, + client: httpClient, + } } func (r *relayer) appTx(ibcTx ibc.IBCTx) error { - sequence, err := getSeq(r.privKey.Address[:]) + acc, err := getAccWithClient(r.client, r.privKey.Address[:]) if err != nil { return err } + sequence := acc.Sequence + 1 data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` }{ibcTx})) - input := types.NewTxInput(r.privKey.PubKey, types.Coins{}, sequence) + smallCoins := types.Coin{"mycoin", 1} + + input := types.NewTxInput(r.privKey.PubKey, types.Coins{smallCoins}, sequence) tx := &types.AppTx{ Gas: 0, - Fee: types.Coin{"mycoin", 1}, + Fee: smallCoins, Name: "IBC", Input: input, Data: data, @@ -169,17 +201,16 @@ func (r *relayer) appTx(ibcTx ibc.IBCTx) error { types.Tx `json:"unwrap"` }{tx})) - data, log, err := broadcastTxToNode(r.nodeAddr, txBytes) + data, log, err := broadcastTxWithClient(r.client, txBytes) if err != nil { return err } - fmt.Printf("Response: %X ; %s\n", data, log) + _, _ = data, log return nil } // broadcast the transaction to tendermint -func broadcastTxToNode(nodeAddr string, tx tmtypes.Tx) ([]byte, string, error) { - httpClient := client.NewHTTP(nodeAddr, "/websocket") +func broadcastTxWithClient(httpClient *client.HTTP, tx tmtypes.Tx) ([]byte, string, error) { res, err := httpClient.BroadcastTxCommit(tx) if err != nil { return nil, "", errors.Errorf("Error on broadcast tx: %v", err) diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index eae7f36a6f..946c290a17 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -220,12 +220,12 @@ func broadcastTx(tx types.Tx) ([]byte, string, error) { // if the sequence flag is set, return it; // else, fetch the account by querying the app and return the sequence number func getSeq(address []byte) (int, error) { - if seqFlag >= 0 { return seqFlag, nil } - acc, err := getAcc(txNodeFlag, address) + httpClient := client.NewHTTP(txNodeFlag, "/websocket") + acc, err := getAccWithClient(httpClient, address) if err != nil { return 0, err } diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index ff14faf450..dc0b5f1620 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -100,6 +100,10 @@ func StripHex(s string) string { func Query(tmAddr string, key []byte) (*abci.ResultQuery, error) { httpClient := client.NewHTTP(tmAddr, "/websocket") + return queryWithClient(httpClient, key) +} + +func queryWithClient(httpClient *client.HTTP, key []byte) (*abci.ResultQuery, error) { res, err := httpClient.ABCIQuery("/key", key, true) if err != nil { return nil, errors.Errorf("Error calling /abci_query: %v", err) @@ -111,10 +115,10 @@ func Query(tmAddr string, key []byte) (*abci.ResultQuery, error) { } // fetch the account by querying the app -func getAcc(tmAddr string, address []byte) (*types.Account, error) { +func getAccWithClient(httpClient *client.HTTP, address []byte) (*types.Account, error) { key := types.AccountKey(address) - response, err := Query(tmAddr, key) + response, err := queryWithClient(httpClient, key) if err != nil { return nil, err } @@ -146,3 +150,23 @@ func getHeaderAndCommit(tmAddr string, height int) (*tmtypes.Header, *tmtypes.Co return header, commit, nil } + +func waitForBlock(httpClient *client.HTTP) error { + res, err := httpClient.Status() + if err != nil { + return err + } + + lastHeight := res.LatestBlockHeight + for { + res, err := httpClient.Status() + if err != nil { + return err + } + if res.LatestBlockHeight > lastHeight { + break + } + + } + return nil +} diff --git a/demo/start.sh b/demo/start.sh index f15a5fd5bd..f56e407ec1 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -123,8 +123,8 @@ echo "" echo "... creating egress packet on chain1" echo "" # create a packet on chain1 destined for chain2 -PAYLOAD="DEADBEEF" #TODO -basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS1 packet create --ibc_from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --ibc_sequence 1 +PAYLOAD="010104DEADBEEF" #TODO +basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS1 packet create --ibc_from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --ibc_sequence 0 ifExit echo "" diff --git a/glide.lock b/glide.lock index 675b418f6d..f82aa4d990 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 997e4cc3339141ee01aa2adf656425a49ebf117e6ca9e81ba72b8f94fee3e86e -updated: 2017-05-17T12:25:00.580569867+02:00 +hash: 9d06ae13959cbb2835f5ae400a4b65e4bc329a567c949aec4aeab318c271da39 +updated: 2017-05-21T21:31:06.796806933-04:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd @@ -101,7 +101,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 5dabeffb35c027d7087a12149685daa68989168b + version: 864d1f80b36b440bde030a5c18d8ac3aa8c2949d subpackages: - client - example/dummy @@ -113,7 +113,7 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: 438b16f1f84ef002d7408ecd6fc3a3974cbc9559 + version: 7dff40942a64cdeefefa9446b2d104750b349f8a subpackages: - cmd - keys @@ -122,7 +122,7 @@ imports: - keys/server/types - keys/storage/filestorage - name: github.com/tendermint/go-wire - version: 97beaedf0f4dbc035309157c92be3b30cc6e5d74 + version: 5f88da3dbc1a72844e6dfaf274ce87f851d488eb subpackages: - data - data/base58 @@ -139,13 +139,13 @@ imports: - commands/txs - proofs - name: github.com/tendermint/merkleeyes - version: c722818b460381bc5b82e38c73ff6e22a9df624d + version: a0e73e1ac3e18e12a007520a4ea2c9822256e307 subpackages: - app - client - iavl - name: github.com/tendermint/tendermint - version: 11b5d11e9eec170e1d3dce165f0270d5c0759d69 + version: 267f134d44e76efb2adef5f0c993da8a5d5bd1b8 subpackages: - blockchain - config @@ -170,7 +170,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: 8af1c70a8be17543eb33e9bfbbcdd8371e3201cc + version: 306795ae1d8e4f4a10dcc8bdb32a00455843c9d5 subpackages: - autofile - cli diff --git a/glide.yaml b/glide.yaml index b050008553..abc395a69c 100644 --- a/glide.yaml +++ b/glide.yaml @@ -6,17 +6,14 @@ import: - package: github.com/spf13/pflag - package: github.com/spf13/viper - package: github.com/tendermint/abci - version: develop subpackages: - server - types - package: github.com/tendermint/go-crypto - version: develop subpackages: - cmd - keys - package: github.com/tendermint/go-wire - version: develop subpackages: - data - package: github.com/tendermint/light-client @@ -28,7 +25,6 @@ import: - commands/txs - proofs - package: github.com/tendermint/merkleeyes - version: develop subpackages: - client - iavl @@ -44,7 +40,6 @@ import: - rpc/lib/types - types - package: github.com/tendermint/tmlibs - version: develop subpackages: - cli - common diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index e4b4412895..bea7a43dfb 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -418,6 +418,9 @@ func (sm *IBCStateMachine) runPacketCreateTx(tx IBCPacketCreateTx) { // Save new Packet save(sm.store, packetKey, packet) + + // set the sequence number + SetSequenceNumber(sm.store, packet.SrcChainID, packet.DstChainID, packet.Sequence) } func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { @@ -473,7 +476,7 @@ func (sm *IBCStateMachine) runPacketPostTx(tx IBCPacketPostTx) { ok := proof.Verify(packetKeyEgress, packetBytes, header.AppHash) if !ok { sm.res.Code = IBCCodeInvalidProof - sm.res.Log = "Proof is invalid" + sm.res.Log = fmt.Sprintf("Proof is invalid. key: %s; packetByes %X; header %v; proof %v", packetKeyEgress, packetBytes, header, proof) return } From 7f2d25c593485b82802a6ef1c2f1c9646dd1cdfa Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 22:40:48 -0400 Subject: [PATCH 58/67] [cmd] support SendTx to other chains via IBC --- cmd/commands/relay.go | 5 +++++ cmd/commands/tx.go | 20 +++++++++++++++++++- plugins/ibc/ibc.go | 4 +++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/commands/relay.go b/cmd/commands/relay.go index 2c7f812a03..5a2cacfc96 100644 --- a/cmd/commands/relay.go +++ b/cmd/commands/relay.go @@ -90,6 +90,11 @@ OUTER: logger.Error("Error parsing sequence number from query", "query.Value", query.Value, "error", err.Error()) continue OUTER } + seq -= 1 // seq is the packet count. -1 because 0-indexed + + if nextSeq <= int(seq) { + logger.Info("Got new packets", "last-sequence", nextSeq-1, "new-sequence", seq) + } // get all packets since the last one we relayed for ; nextSeq <= int(seq); nextSeq++ { diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 946c290a17..2cde963b99 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -3,6 +3,7 @@ package commands import ( "encoding/hex" "fmt" + "strings" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -81,12 +82,29 @@ func init() { func sendTxCmd(cmd *cobra.Command, args []string) error { + var toHex string + var chainPrefix string + spl := strings.Split(toFlag, "/") + switch len(spl) { + case 1: + toHex = spl[0] + case 2: + chainPrefix = spl[0] + toHex = spl[1] + default: + return errors.Errorf("To address has too many slashes") + } + // convert destination address to bytes - to, err := hex.DecodeString(StripHex(toFlag)) + to, err := hex.DecodeString(StripHex(toHex)) if err != nil { return errors.Errorf("To address is invalid hex: %v\n", err) } + if chainPrefix != "" { + to = []byte(chainPrefix + "/" + string(to)) + } + // load the priv key privKey, err := LoadKey(fromFlag) if err != nil { diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index bea7a43dfb..eb8a27f1b0 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -69,7 +69,9 @@ func NewPacket(src, dst string, seq uint64, payload Payload) Packet { } } -// GetSequenceNumber gets the sequence number for packets being sent from the src chain to the dst chain +// GetSequenceNumber gets the sequence number for packets being sent from the src chain to the dst chain. +// The sequence number counts how many packets have been sent. +// The next packet must include the latest sequence number. func GetSequenceNumber(store types.KVStore, src, dst string) uint64 { sequenceKey := toKey(_IBC, _EGRESS, src, dst) seqBytes := store.Get(sequenceKey) From 4583f7b74824b36fe5c59a61882792fe953b98e2 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 21 May 2017 22:45:45 -0400 Subject: [PATCH 59/67] update demo for cross chain SendTx --- demo/start.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/demo/start.sh b/demo/start.sh index f56e407ec1..490806fd62 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -122,16 +122,20 @@ ifExit echo "" echo "... creating egress packet on chain1" echo "" -# create a packet on chain1 destined for chain2 -PAYLOAD="010104DEADBEEF" #TODO -basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS1 packet create --ibc_from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --ibc_sequence 0 +# send coins from chain1 to an address on chain2 +# TODO: dont hardcode the address +basecoin tx send --amount 10mycoin $CHAIN_FLAGS1 --to $CHAIN_ID2/053BA0F19616AFF975C8756A2CBFF04F408B4D47 ifExit +# alternative way to create packets (for testing) +# basecoin tx ibc --amount 10mycoin $CHAIN_FLAGS1 packet create --ibc_from $CHAIN_ID1 --to $CHAIN_ID2 --type coin --payload $PAYLOAD --ibc_sequence 0 + echo "" echo "... querying for packet data" echo "" # query for the packet data and proof -QUERY_RESULT=$(basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,1) +# since we only sent one packet, the sequence number is 0 +QUERY_RESULT=$(basecoin query ibc,egress,$CHAIN_ID1,$CHAIN_ID2,0) ifExit HEIGHT=$(echo $QUERY_RESULT | jq .height) PACKET=$(echo $QUERY_RESULT | jq .value) @@ -187,7 +191,7 @@ echo "" echo "... checking if the packet is present on chain2" echo "" # query for the packet on chain2 -basecoin query --node tcp://localhost:36657 ibc,ingress,test_chain_2,test_chain_1,1 +basecoin query --node tcp://localhost:36657 ibc,ingress,test_chain_2,test_chain_1,0 ifExit echo "" From 1f5a27896534ea63300388b484baac4e4de14cdc Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 22 May 2017 07:44:50 -0400 Subject: [PATCH 60/67] fix build/tests --- app/app_test.go | 7 +++---- cmd/basecli/commands/adapters.go | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/app_test.go b/app/app_test.go index d37a6ade8e..1f150e8c48 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" @@ -38,7 +37,7 @@ func newAppTest(t *testing.T) *appTest { // make a tx sending 5mycoin from each accIn to accOut func (at *appTest) getTx(seq int) *types.SendTx { - tx := types.GetTx(seq, at.accOut, at.accIn) + tx := types.MakeSendTx(seq, at.accOut, at.accIn) types.SignTx(at.chainID, tx, at.accIn) return tx } @@ -123,7 +122,7 @@ func TestSetOption(t *testing.T) { res = app.SetOption("base/account", string(accsInBytes)) require.EqualValues(res, "Success") // make sure it is set correctly, with some balance - acct := state.GetAccount(app.GetState(), accIn.PubKey.Address()) + acct := types.GetAccount(app.GetState(), accIn.PubKey.Address()) require.NotNil(acct) assert.Equal(accIn.Balance, acct.Balance) @@ -149,7 +148,7 @@ func TestSetOption(t *testing.T) { }` res = app.SetOption("base/account", unsortAcc) require.EqualValues(res, "Success") - acct = state.GetAccount(app.GetState(), unsortAddr) + acct = types.GetAccount(app.GetState(), unsortAddr) require.NotNil(acct) assert.True(acct.Balance.IsValid()) assert.Equal(unsortCoins, acct.Balance) diff --git a/cmd/basecli/commands/adapters.go b/cmd/basecli/commands/adapters.go index fa2cfec08e..516cb2f0df 100644 --- a/cmd/basecli/commands/adapters.go +++ b/cmd/basecli/commands/adapters.go @@ -14,7 +14,6 @@ import ( "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/proofs" - "github.com/tendermint/basecoin/state" btypes "github.com/tendermint/basecoin/types" ) From 9daea812c637553b4bc73fa7ab3d011798f9bb3d Mon Sep 17 00:00:00 2001 From: rhm Date: Tue, 23 May 2017 14:00:02 +0100 Subject: [PATCH 61/67] fixing dumb links --- docs/guide/basecoin-tool.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/guide/basecoin-tool.md b/docs/guide/basecoin-tool.md index 52f42d8320..53d8df0378 100644 --- a/docs/guide/basecoin-tool.md +++ b/docs/guide/basecoin-tool.md @@ -1,7 +1,7 @@ # The Basecoin Tool -In previous tutorials we learned the [basics of the `basecoin` CLI](/docs/guides/basecoin-basics) -and [how to implement a plugin](/docs/guides/example-plugin). +In previous tutorials we learned the [basics of the `basecoin` CLI](/docs/guide/basecoin-basics.md) +and [how to implement a plugin](/docs/guide/basecoin-plugins.md). In this tutorial, we provide more details on using the `basecoin` tool. # Data Directory @@ -14,7 +14,7 @@ basecoin init basecoin start ``` -or +or ``` BCHOME=~/.my_basecoin_data basecoin init @@ -33,7 +33,7 @@ basecoin init This will create a single `genesis.json` file in `~/.basecoin` with the information for both Basecoin and Tendermint. -Now, In one window, run +Now, In one window, run ``` basecoin start --without-tendermint @@ -147,7 +147,7 @@ basecoin unsafe_reset_all Any required plugin initialization should be constructed using `SetOption` on genesis. When starting a new chain for the first time, `SetOption` will be called for each item the genesis file. Within genesis.json file entries are made in the format: `"/", ""`, where `` is the plugin name, -and `` and `` are the strings passed into the plugin SetOption function. -This function is intended to be used to set plugin specific information such +and `` and `` are the strings passed into the plugin SetOption function. +This function is intended to be used to set plugin specific information such as the plugin state. From c059e99f56e4956c5a3644a77781664853998e65 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 24 May 2017 15:21:38 +0200 Subject: [PATCH 62/67] Update dependencies --- glide.lock | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/glide.lock b/glide.lock index f82aa4d990..059bdc1dc8 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,14 @@ hash: 9d06ae13959cbb2835f5ae400a4b65e4bc329a567c949aec4aeab318c271da39 -updated: 2017-05-21T21:31:06.796806933-04:00 +updated: 2017-05-24T15:11:32.643553723+02:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd - name: github.com/btcsuite/btcd - version: 1ae306021e323ae11c71ffb8546fbd9019e6cb6f + version: b8df516b4b267acf2de46be593a9d948d1d2c420 subpackages: - btcec +- name: github.com/btcsuite/fastsha256 + version: 637e656429416087660c84436a2a035d69d54e2e - name: github.com/BurntSushi/toml version: b26d9c308763d68093482582cea63d69be07a0f0 - name: github.com/ebuchman/fail-test @@ -28,9 +30,9 @@ imports: - name: github.com/go-playground/universal-translator version: 71201497bace774495daed26a3874fd339e0b538 - name: github.com/go-stack/stack - version: 7a2f19628aabfe68f0766b59e74d6315f8347d22 + version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf - version: b50ceb1fa9818fa4d78b016c2d4ae025593a7ce3 + version: 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8 subpackages: - proto - ptypes/any @@ -41,7 +43,7 @@ imports: - name: github.com/gorilla/handlers version: 3a5767ca75ece5f7f1440b1d16975247f8d8b221 - name: github.com/gorilla/mux - version: 392c28fe23e1c45ddba891b0320b3b5df220beea + version: bcd8bc72b08df0f70df986b97f95590779502d31 - name: github.com/gorilla/websocket version: a91eba7f97777409bc2c443f5534d41dd20c5720 - name: github.com/hashicorp/hcl @@ -70,7 +72,7 @@ imports: - name: github.com/pelletier/go-toml version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a - name: github.com/pkg/errors - version: 645ef00459ed84a119197bfb8d8205042c6df63d + version: ff09b135c25aae272398c51a07235b90a75aa4f0 - name: github.com/spf13/afero version: 9be650865eab0c12963d8753212f4f9c66cdcf12 subpackages: @@ -101,7 +103,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 864d1f80b36b440bde030a5c18d8ac3aa8c2949d + version: 5dabeffb35c027d7087a12149685daa68989168b subpackages: - client - example/dummy @@ -113,7 +115,7 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: 7dff40942a64cdeefefa9446b2d104750b349f8a + version: 438b16f1f84ef002d7408ecd6fc3a3974cbc9559 subpackages: - cmd - keys @@ -122,7 +124,7 @@ imports: - keys/server/types - keys/storage/filestorage - name: github.com/tendermint/go-wire - version: 5f88da3dbc1a72844e6dfaf274ce87f851d488eb + version: 97beaedf0f4dbc035309157c92be3b30cc6e5d74 subpackages: - data - data/base58 @@ -139,15 +141,17 @@ imports: - commands/txs - proofs - name: github.com/tendermint/merkleeyes - version: a0e73e1ac3e18e12a007520a4ea2c9822256e307 + version: c722818b460381bc5b82e38c73ff6e22a9df624d subpackages: - app - client - iavl - name: github.com/tendermint/tendermint - version: 267f134d44e76efb2adef5f0c993da8a5d5bd1b8 + version: 11b5d11e9eec170e1d3dce165f0270d5c0759d69 subpackages: - blockchain + - cmd/tendermint/commands + - cmd/tendermint/commands/flags - config - consensus - mempool @@ -170,7 +174,7 @@ imports: - types - version - name: github.com/tendermint/tmlibs - version: 306795ae1d8e4f4a10dcc8bdb32a00455843c9d5 + version: 8af1c70a8be17543eb33e9bfbbcdd8371e3201cc subpackages: - autofile - cli @@ -183,7 +187,7 @@ imports: - logger - merkle - name: golang.org/x/crypto - version: ab89591268e0c8b748cbe4047b00197516011af5 + version: c7af5bf2638a1164f2eb5467c39c6cffbd13a02e subpackages: - curve25519 - nacl/box @@ -194,7 +198,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: c9b681d35165f1995d6f3034e61f8761d4b90c99 + version: feeb485667d1fdabe727840fe00adc22431bc86e subpackages: - context - http2 @@ -219,7 +223,7 @@ imports: subpackages: - googleapis/rpc/status - name: google.golang.org/grpc - version: a0c3e72252b6fbf4826bb143e450eb05588a9d6d + version: 844f573616520565fdc6fb4db242321b5456fd6d subpackages: - codes - credentials @@ -240,7 +244,7 @@ imports: version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b testImports: - name: github.com/davecgh/go-spew - version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 + version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -248,7 +252,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 4d4bfba8f1d1027c4fdbe371823030df51419987 + version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require From da698bb7af0bdb6f4f3bd7b9bcf4ca9e3aa9623c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 24 May 2017 15:21:56 +0200 Subject: [PATCH 63/67] 94: init creates config, like tendermint init --- cmd/commands/init.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 3bcfd54266..2cfbbcd94a 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -6,10 +6,6 @@ import ( "path" "github.com/spf13/cobra" - "github.com/spf13/viper" - - "github.com/tendermint/tmlibs/cli" - cmn "github.com/tendermint/tmlibs/common" ) //commands @@ -35,14 +31,17 @@ func setupFile(path, data string, perm os.FileMode) (int, error) { } func initCmd(cmd *cobra.Command, args []string) error { - rootDir := viper.GetString(cli.HomeFlag) - cmn.EnsureDir(rootDir, 0777) + // this will ensure that config.toml is there if not yet created, and create dir + cfg, err := getTendermintConfig() + if err != nil { + return err + } // initalize basecoin - genesisFile := path.Join(rootDir, "genesis.json") - privValFile := path.Join(rootDir, "priv_validator.json") - key1File := path.Join(rootDir, "key.json") - key2File := path.Join(rootDir, "key2.json") + genesisFile := cfg.GenesisFile() + privValFile := cfg.PrivValidatorFile() + key1File := path.Join(cfg.RootDir, "key.json") + key2File := path.Join(cfg.RootDir, "key2.json") mod1, err := setupFile(genesisFile, GenesisJSON, 0644) if err != nil { From df5d65a891560be64a1572d3ce07c5d2a6b47957 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 24 May 2017 17:07:31 +0200 Subject: [PATCH 64/67] Update changelog for 0.5.0 release --- CHANGELOG.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 035d464cfd..98aaa04289 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 0.5.0 (May 27, 2017) + +BREAKING CHANGES: +- only those related to the tendermint 0.9 -> 0.10 upgrade + +ENHANCEMENTS: +- basecoin cli + - integrates tendermint 0.10.0 and unifies cli (init, unsafe_reset_all, ...) + - integrate viper, all command line flags can also be defined in environmental variables or config.toml +- genesis file + - you can define accounts with either address or pub_key + - sorts coins for you, so no silent errors if not in alphabetical order +- [light-client](https://github.com/tendermint/light-client) integration + - no longer must you trust the node you connect to, prove everything! + - new [basecli command](./cmd/basecli/README.md) + - integrated [key management](https://github.com/tendermint/go-crypto/blob/master/cmd/README.md), stored encrypted locally + - tracks validator set changes and proves everything from one initial validator seed + - `basecli proof state` gets complete proofs for any abci state + - `basecli proof tx` gets complete proof where a tx was stored in the chain + - `basecli proxy` exposes tendermint rpc, but only passes through results after doing complete verification + +BUG FIXES: +- no more silently ignored error with invalid coin names (eg. "17.22foo coin" used to parse as "17 foo", not warning/error) + + ## 0.4.1 (April 26, 2017) BUG FIXES: @@ -74,7 +99,7 @@ We also changed `chainID` to `chain_id` and consolidated to have just one of the FEATURES: -- Introduce `basecoin init` and `basecoin unsafe_reset_all` +- Introduce `basecoin init` and `basecoin unsafe_reset_all` ## 0.2.0 (March 6, 2017) @@ -86,8 +111,8 @@ BREAKING CHANGES: FEATURES: -- CLI for sending transactions and querying the state, -designed to be easily extensible as plugins are implemented +- CLI for sending transactions and querying the state, +designed to be easily extensible as plugins are implemented - Run Basecoin in-process with Tendermint - Add `/account` path in Query - IBC plugin for InterBlockchain Communication From 07fb680a01cb9dbf4b628922051c9abeca6be037 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 24 May 2017 17:15:42 +0200 Subject: [PATCH 65/67] 92: return error on empty coin in list --- types/coin.go | 31 +++++++++++++++++-------------- types/coin_test.go | 5 +++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/types/coin.go b/types/coin.go index 0499e58c0f..efc79b0b80 100644 --- a/types/coin.go +++ b/types/coin.go @@ -24,18 +24,18 @@ var reDenom = regexp.MustCompile("([^\\d\\W]+)") var reAmt = regexp.MustCompile("(\\d+)") func ParseCoin(str string) (Coin, error) { - var coin Coin - if len(str) > 0 { - amt, err := strconv.Atoi(reAmt.FindString(str)) - if err != nil { - return coin, err - } - denom := reDenom.FindString(str) - coin = Coin{denom, int64(amt)} + if len(str) == 0 { + return coin, errors.New("Empty string is invalid coin") } + amt, err := strconv.Atoi(reAmt.FindString(str)) + if err != nil { + return coin, err + } + denom := reDenom.FindString(str) + coin = Coin{denom, int64(amt)} return coin, nil } @@ -56,17 +56,20 @@ func (coins Coins) String() string { } func ParseCoins(str string) (Coins, error) { + // empty string is empty list... + if len(str) == 0 { + return nil, nil + } + split := strings.Split(str, ",") var coins Coins for _, el := range split { - if len(el) > 0 { - coin, err := ParseCoin(el) - if err != nil { - return coins, err - } - coins = append(coins, coin) + coin, err := ParseCoin(el) + if err != nil { + return coins, err } + coins = append(coins, coin) } // ensure they are in proper order, to avoid random failures later diff --git a/types/coin_test.go b/types/coin_test.go index bf99d0caab..39149d7e8d 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -68,6 +68,11 @@ func TestParse(t *testing.T) { {"99bar,1foo", true, Coins{{"bar", 99}, {"foo", 1}}}, {"98 bar , 1 foo ", true, Coins{{"bar", 98}, {"foo", 1}}}, {"2foo, 97 bar", true, Coins{{"bar", 97}, {"foo", 2}}}, + {"5 mycoin,", false, nil}, // no empty coins in a list + {"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name + {"11me coin, 12you coin", false, nil}, // no spaces in coin names + {"1.2btc", false, nil}, // amount must be integer + {"5foo-bar", false, nil}, // once more, only letters in coin name } for _, tc := range cases { From 6fec396fbd0216ec634fe73f6e83bbfabec960b0 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 24 May 2017 17:36:24 +0200 Subject: [PATCH 66/67] 92: Fix ParseCoins regexp in general --- cmd/commands/tx.go | 2 +- types/coin.go | 16 ++++++++++------ types/coin_test.go | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 2cde963b99..d13411bf04 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -59,7 +59,7 @@ func init() { {&fromFlag, "from", "key.json", "Path to a private key to sign the transaction"}, {&amountFlag, "amount", "", "Coins to send in transaction of the format ,,... (eg: 1btc,2gold,5silver)"}, {&gasFlag, "gas", 0, "The amount of gas for the transaction"}, - {&feeFlag, "fee", "", "Coins for the transaction fee of the format "}, + {&feeFlag, "fee", "0coin", "Coins for the transaction fee of the format "}, {&seqFlag, "sequence", -1, "Sequence number for the account (-1 to autocalculate)"}, } diff --git a/types/coin.go b/types/coin.go index efc79b0b80..7460a8e8a5 100644 --- a/types/coin.go +++ b/types/coin.go @@ -20,22 +20,26 @@ func (coin Coin) String() string { } //regex codes for extracting coins from string -var reDenom = regexp.MustCompile("([^\\d\\W]+)") +var reDenom = regexp.MustCompile("") var reAmt = regexp.MustCompile("(\\d+)") +var reCoin = regexp.MustCompile("^([[:digit:]]+)[[:space:]]*([[:alpha:]]+)$") + func ParseCoin(str string) (Coin, error) { var coin Coin - if len(str) == 0 { - return coin, errors.New("Empty string is invalid coin") + matches := reCoin.FindStringSubmatch(strings.TrimSpace(str)) + if matches == nil { + return coin, errors.Errorf("%s is invalid coin definition", str) } - amt, err := strconv.Atoi(reAmt.FindString(str)) + // parse the amount (should always parse properly) + amt, err := strconv.Atoi(matches[1]) if err != nil { return coin, err } - denom := reDenom.FindString(str) - coin = Coin{denom, int64(amt)} + + coin = Coin{matches[2], int64(amt)} return coin, nil } diff --git a/types/coin_test.go b/types/coin_test.go index 39149d7e8d..bf651c50de 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -67,6 +67,7 @@ func TestParse(t *testing.T) { {"10bar", true, Coins{{"bar", 10}}}, {"99bar,1foo", true, Coins{{"bar", 99}, {"foo", 1}}}, {"98 bar , 1 foo ", true, Coins{{"bar", 98}, {"foo", 1}}}, + {" 55\t \t bling\n", true, Coins{{"bling", 55}}}, {"2foo, 97 bar", true, Coins{{"bar", 97}, {"foo", 2}}}, {"5 mycoin,", false, nil}, // no empty coins in a list {"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name @@ -78,7 +79,7 @@ func TestParse(t *testing.T) { for _, tc := range cases { res, err := ParseCoins(tc.input) if !tc.valid { - assert.NotNil(err, tc.input) + assert.NotNil(err, "%s: %#v", tc.input, res) } else if assert.Nil(err, "%s: %+v", tc.input, err) { assert.Equal(tc.expected, res) } From ddf434276cb43eada304f100fc0c6d56b305464e Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 29 May 2017 15:39:17 +0200 Subject: [PATCH 67/67] Added brief docs on light-client proxy --- cmd/basecli/LIGHT_NODE.md | 58 +++++++++++++++++++++++++++++++++++++++ cmd/basecli/README.md | 10 ------- 2 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 cmd/basecli/LIGHT_NODE.md diff --git a/cmd/basecli/LIGHT_NODE.md b/cmd/basecli/LIGHT_NODE.md new file mode 100644 index 0000000000..bb58ebb19d --- /dev/null +++ b/cmd/basecli/LIGHT_NODE.md @@ -0,0 +1,58 @@ +# Run your own (super) lightweight node + +In addition to providing command-line tooling that goes cryptographic verification +on all the data your receive from the node, we have implemented a proxy mode, that +allows you to run a super lightweight node. It does not follow the chain on +every block or even every header, but only as needed. But still providing the +same security as running a full non-validator node on your local machine. + +Basically, it runs as a proxy that exposes the same rpc interface as the full node +and connects to a (potentially untrusted) full node. Every response is cryptographically +verified before being passed through, returning an error if it doesn't match. + +You can expect 2 rpc calls for every query plus <= 1 query for each validator set +change. Going offline for a while allows you to verify multiple validator set changes +with one call. Cuz at 1 block/sec and 1000 tx/block, it just doesn't make sense +to run a full node just to get security + +## Setup + +Just initialize your client with the proper validator set as in the [README](README.md) + +``` +$ export BCHOME=~/.lightnode +$ basecli init --node tcp://: --chainid +``` + +## Running + +``` +$ basecli proxy --serve tcp://localhost:7890 +... +curl localhost:7890/status +curl localhost:7890/block\?height=20 +``` + +You can even subscribe to events over websockets and they are all verified +before passing them though. Though if you want every block, you might as +well run a full (nonvalidating) node. + +## Seeds + +Every time the validator set changes, the light node verifies if it is legal, +and then creates a seed at that point. These "seeds" are verified checkpoints +that we can trace any proof back to, starting with one on `init`. + +To make sure you are based on the most recent header, you can run: + +``` +basecli seeds update +basecli seeds show +``` + +## Feedback + +This is the first release of basecli and the light-weight proxy. It is secure, but +may not be useful for your workflow. Please try it out and open github issues +for any enhancements or bugs you find. I am aiming to make this a very useful +tool by tendermint 0.11, for which I need community feedback. diff --git a/cmd/basecli/README.md b/cmd/basecli/README.md index 2d8fc23b3e..efa737512b 100644 --- a/cmd/basecli/README.md +++ b/cmd/basecli/README.md @@ -61,13 +61,3 @@ $ basecoin start % basecli proof state get --key $YOU --app account ``` -## Any questions??? - -``` -% basecli seeds show --height 1767 -% basecli proxy --serve tcp://localhost:7890 -... - -curl localhost:7890/status -curl localhost:7890/block\?height=20 -```