From 8ba79252c8b1569c6d0c471488c118b0ff120589 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 2 Mar 2017 20:47:07 -0500 Subject: [PATCH] types: use mtx on PartSet.String() --- consensus/state.go | 2 ++ proxy/multi_app_conn.go | 8 ++++---- rpc/client/rpc_test.go | 22 +++++++++++----------- rpc/core/abci.go | 1 + types/part_set.go | 2 ++ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 882d5c87..f3fb7d16 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -122,6 +122,8 @@ func (rs RoundStepType) String() string { //----------------------------------------------------------------------------- // Immutable when returned from ConsensusState.GetRoundState() +// TODO: Actually, only the top pointer is copied, +// so access to field pointers is still racey type RoundState struct { Height int // Height we are working on Round int diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index 2c93152b..353ade35 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -1,7 +1,7 @@ package proxy import ( - . "github.com/tendermint/go-common" + cmn "github.com/tendermint/go-common" cfg "github.com/tendermint/go-config" ) @@ -9,7 +9,7 @@ import ( // Tendermint's interface to the application consists of multiple connections type AppConns interface { - Service + cmn.Service Mempool() AppConnMempool Consensus() AppConnConsensus @@ -32,7 +32,7 @@ type Handshaker interface { // which ensures the app and tendermint are synced. // TODO: on app restart, clients must reboot together type multiAppConn struct { - BaseService + cmn.BaseService config cfg.Config @@ -52,7 +52,7 @@ func NewMultiAppConn(config cfg.Config, clientCreator ClientCreator, handshaker handshaker: handshaker, clientCreator: clientCreator, } - multiAppConn.BaseService = *NewBaseService(log, "multiAppConn", multiAppConn) + multiAppConn.BaseService = *cmn.NewBaseService(log, "multiAppConn", multiAppConn) return multiAppConn } diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 11c7f726..68148593 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -66,17 +66,17 @@ func TestNetInfo(t *testing.T) { // FIXME: This seems to trigger a race condition with client.Local // go test -v -race . -run=DumpCons -// func TestDumpConsensusState(t *testing.T) { -// for i, c := range GetClients() { -// // FIXME: fix server so it doesn't panic on invalid input -// nc, ok := c.(client.NetworkClient) -// require.True(t, ok, "%d", i) -// cons, err := nc.DumpConsensusState() -// require.Nil(t, err, "%d: %+v", i, err) -// assert.NotEmpty(t, cons.RoundState) -// assert.Empty(t, cons.PeerRoundStates) -// } -// } +func TestDumpConsensusState(t *testing.T) { + for i, c := range GetClients() { + // FIXME: fix server so it doesn't panic on invalid input + nc, ok := c.(client.NetworkClient) + require.True(t, ok, "%d", i) + cons, err := nc.DumpConsensusState() + require.Nil(t, err, "%d: %+v", i, err) + assert.NotEmpty(t, cons.RoundState) + assert.Empty(t, cons.PeerRoundStates) + } +} func TestGenesisAndValidators(t *testing.T) { for i, c := range GetClients() { diff --git a/rpc/core/abci.go b/rpc/core/abci.go index cb748fe0..95772726 100644 --- a/rpc/core/abci.go +++ b/rpc/core/abci.go @@ -16,6 +16,7 @@ func ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, e if err != nil { return nil, err } + log.Info("ABCIQuery", "path", path, "data", data, "result", resQuery) return &ctypes.ResultABCIQuery{resQuery}, nil } diff --git a/types/part_set.go b/types/part_set.go index c2152440..3a5ee26a 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -268,6 +268,8 @@ func (ps *PartSet) StringShort() string { if ps == nil { return "nil-PartSet" } else { + ps.mtx.Lock() + defer ps.mtx.Unlock() return fmt.Sprintf("(%v of %v)", ps.Count(), ps.Total()) } }