From b906c141bd47f555abe3a57d2ae8e27291c24cd1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 4 Mar 2018 02:36:10 -0500 Subject: [PATCH] x/bank: remove Sequence from Input --- types/tx_msg.go | 13 ++++++++++++- x/bank/tx.go | 19 ++----------------- x/bank/tx_test.go | 40 +++++++++++++++------------------------- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/types/tx_msg.go b/types/tx_msg.go index c6c96c364c..e97fc331fe 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -66,7 +66,18 @@ func (tx StdTx) GetMsg() Msg { return tx.Msg } func (tx StdTx) GetFeePayer() Address { return tx.Signatures[0].PubKey.Address() } // XXX but PubKey is optional! func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures } -//__________________________________________________________ +// StdSignDoc is replay-prevention structure. +// It includes the result of msg.GetSignBytes(), +// as well as the ChainID (prevent cross chain replay) +// and the Sequence (prevent inchain replay). +type StdSignDoc struct { + ChainID string `json:"chain_id"` + Sequence int64 `json:"sequence"` + MsgBytes []byte `json:"msg_bytes"` + AltBytes []byte `json:"alt_bytes"` // TODO: do we really want this ? +} + +//------------------------------------- // Application function variable used to unmarshal transaction bytes type TxDecoder func(txBytes []byte) (Tx, Error) diff --git a/x/bank/tx.go b/x/bank/tx.go index eef2a087d0..58af937210 100644 --- a/x/bank/tx.go +++ b/x/bank/tx.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" - crypto "github.com/tendermint/go-crypto" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -142,11 +140,8 @@ func (msg IssueMsg) GetSigners() []sdk.Address { // Transaction Output type Input struct { - Address sdk.Address `json:"address"` - Coins sdk.Coins `json:"coins"` - Sequence int64 `json:"sequence"` - - signature crypto.Signature + Address sdk.Address `json:"address"` + Coins sdk.Coins `json:"coins"` } // ValidateBasic - validate transaction input @@ -154,9 +149,6 @@ func (in Input) ValidateBasic() sdk.Error { if len(in.Address) == 0 { return ErrInvalidAddress(in.Address.String()) } - if in.Sequence < 0 { - return ErrInvalidSequence("negative sequence") - } if !in.Coins.IsValid() { return ErrInvalidCoins(in.Coins.String()) } @@ -179,13 +171,6 @@ func NewInput(addr sdk.Address, coins sdk.Coins) Input { return input } -// NewInputWithSequence - create a transaction input, used with SendMsg -func NewInputWithSequence(addr sdk.Address, coins sdk.Coins, seq int64) Input { - input := NewInput(addr, coins) - input.Sequence = seq - return input -} - //---------------------------------------- // Output diff --git a/x/bank/tx_test.go b/x/bank/tx_test.go index 099e81dbf4..6d544626ae 100644 --- a/x/bank/tx_test.go +++ b/x/bank/tx_test.go @@ -13,20 +13,12 @@ func TestNewSendMsg(t *testing.T) {} func TestSendMsgType(t *testing.T) { // Construct a SendMsg + addr1 := sdk.Address([]byte("input")) + addr2 := sdk.Address([]byte("output")) + coins := sdk.Coins{{"atom", 10}} var msg = SendMsg{ - Inputs: []Input{ - { - Address: sdk.Address([]byte("input")), - Coins: sdk.Coins{{"atom", 10}}, - Sequence: 1, - }, - }, - Outputs: []Output{ - { - Address: sdk.Address([]byte("output")), - Coins: sdk.Coins{{"atom", 10}}, - }, - }, + Inputs: []Input{NewInput(addr1, coins)}, + Outputs: []Output{NewOutput(addr2, coins)}, } // TODO some failures for bad result @@ -53,18 +45,16 @@ func TestInputValidation(t *testing.T) { }{ // auth works with different apps {true, NewInput(addr1, someCoins)}, - {true, NewInputWithSequence(addr1, someCoins, 100)}, - {true, NewInputWithSequence(addr2, someCoins, 100)}, - {true, NewInputWithSequence(addr2, multiCoins, 100)}, + {true, NewInput(addr2, someCoins)}, + {true, NewInput(addr2, multiCoins)}, - {false, NewInput(emptyAddr, someCoins)}, // empty address - {false, NewInputWithSequence(addr1, someCoins, -1)}, // negative sequence - {false, NewInput(addr1, emptyCoins)}, // invalid coins - {false, NewInput(addr1, emptyCoins2)}, // invalid coins - {false, NewInput(addr1, someEmptyCoins)}, // invalid coins - {false, NewInput(addr1, minusCoins)}, // negative coins - {false, NewInput(addr1, someMinusCoins)}, // negative coins - {false, NewInput(addr1, unsortedCoins)}, // unsorted coins + {false, NewInput(emptyAddr, someCoins)}, // empty address + {false, NewInput(addr1, emptyCoins)}, // invalid coins + {false, NewInput(addr1, emptyCoins2)}, // invalid coins + {false, NewInput(addr1, someEmptyCoins)}, // invalid coins + {false, NewInput(addr1, minusCoins)}, // negative coins + {false, NewInput(addr1, someMinusCoins)}, // negative coins + {false, NewInput(addr1, unsortedCoins)}, // unsorted coins } for i, tc := range cases { @@ -144,7 +134,7 @@ func TestSendMsgValidation(t *testing.T) { {false, SendMsg{Inputs: []Input{input1}}}, // just input {false, SendMsg{Outputs: []Output{output1}}}, // just ouput {false, SendMsg{ - Inputs: []Input{NewInputWithSequence(emptyAddr, atom123, 1)}, // invalid input + Inputs: []Input{NewInput(emptyAddr, atom123)}, // invalid input Outputs: []Output{output1}}}, {false, SendMsg{ Inputs: []Input{input1},