diff --git a/client/client.go b/client/client.go index c39357ba1..c3c1e151d 100644 --- a/client/client.go +++ b/client/client.go @@ -38,7 +38,7 @@ type Client interface { InitChainSync(validators []*types.Validator) (err error) BeginBlockSync(hash []byte, header *types.Header) (err error) - EndBlockSync(height uint64) (changedValidators []*types.Validator, err error) + EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) } //---------------------------------------- diff --git a/client/grpc_client.go b/client/grpc_client.go index e72f31fb5..15cda522e 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -329,10 +329,14 @@ func (cli *grpcClient) BeginBlockSync(hash []byte, header *types.Header) (err er return cli.Error() } -func (cli *grpcClient) EndBlockSync(height uint64) (validators []*types.Validator, err error) { +func (cli *grpcClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) { reqres := cli.EndBlockAsync(height) if err := cli.Error(); err != nil { - return nil, err + return resEndBlock, err + } + if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil { + return *resEndBlock_, nil + } else { + return resEndBlock, nil } - return reqres.Response.GetEndBlock().Diffs, nil } diff --git a/client/local_client.go b/client/local_client.go index 0c363d0c2..ee5d6f281 100644 --- a/client/local_client.go +++ b/client/local_client.go @@ -136,14 +136,14 @@ func (app *localClient) BeginBlockAsync(hash []byte, header *types.Header) *ReqR func (app *localClient) EndBlockAsync(height uint64) *ReqRes { app.mtx.Lock() - var validators []*types.Validator + var resEndBlock types.ResponseEndBlock if bcApp, ok := app.Application.(types.BlockchainAware); ok { - validators = bcApp.EndBlock(height) + resEndBlock = bcApp.EndBlock(height) } app.mtx.Unlock() return app.callback( types.ToRequestEndBlock(height), - types.ToResponseEndBlock(validators), + types.ToResponseEndBlock(resEndBlock), ) } @@ -217,13 +217,13 @@ func (app *localClient) BeginBlockSync(hash []byte, header *types.Header) (err e return nil } -func (app *localClient) EndBlockSync(height uint64) (changedValidators []*types.Validator, err error) { +func (app *localClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) { app.mtx.Lock() if bcApp, ok := app.Application.(types.BlockchainAware); ok { - changedValidators = bcApp.EndBlock(height) + resEndBlock = bcApp.EndBlock(height) } app.mtx.Unlock() - return changedValidators, nil + return resEndBlock, nil } //------------------------------------------------------- diff --git a/client/socket_client.go b/client/socket_client.go index 8c5c84287..aecaeea52 100644 --- a/client/socket_client.go +++ b/client/socket_client.go @@ -373,13 +373,17 @@ func (cli *socketClient) BeginBlockSync(hash []byte, header *types.Header) (err return nil } -func (cli *socketClient) EndBlockSync(height uint64) (validators []*types.Validator, err error) { +func (cli *socketClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) { reqres := cli.queueRequest(types.ToRequestEndBlock(height)) cli.FlushSync() if err := cli.Error(); err != nil { - return nil, err + return resEndBlock, err + } + if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil { + return *resEndBlock_, nil + } else { + return resEndBlock, nil } - return reqres.Response.GetEndBlock().Diffs, nil } //---------------------------------------- diff --git a/cmd/counter/main.go b/cmd/counter/main.go index c04a40e0f..0f284af9e 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -17,7 +17,7 @@ func main() { app := counter.NewCounterApplication(*serialPtr) // Start the listener - _, err := server.NewServer(*addrPtr, *tmspPtr, app) + srv, err := server.NewServer(*addrPtr, *tmspPtr, app) if err != nil { Exit(err.Error()) } @@ -25,6 +25,7 @@ func main() { // Wait forever TrapSignal(func() { // Cleanup + srv.Stop() }) } diff --git a/cmd/dummy/main.go b/cmd/dummy/main.go index 8a1465c49..fe7ae750b 100644 --- a/cmd/dummy/main.go +++ b/cmd/dummy/main.go @@ -25,7 +25,7 @@ func main() { } // Start the listener - _, err := server.NewServer(*addrPtr, *tmspPtr, app) + srv, err := server.NewServer(*addrPtr, *tmspPtr, app) if err != nil { Exit(err.Error()) } @@ -33,6 +33,7 @@ func main() { // Wait forever TrapSignal(func() { // Cleanup + srv.Stop() }) } diff --git a/example/chain_aware/chain_aware_app.go b/example/chain_aware/chain_aware_app.go index 15d8f8761..cd91c6825 100644 --- a/example/chain_aware/chain_aware_app.go +++ b/example/chain_aware/chain_aware_app.go @@ -15,7 +15,7 @@ func main() { flag.Parse() // Start the listener - _, err := server.NewServer(*addrPtr, *tmspPtr, NewChainAwareApplication()) + srv, err := server.NewServer(*addrPtr, *tmspPtr, NewChainAwareApplication()) if err != nil { Exit(err.Error()) } @@ -23,6 +23,7 @@ func main() { // Wait forever TrapSignal(func() { // Cleanup + srv.Stop() }) } @@ -65,9 +66,9 @@ func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) return } -func (app *ChainAwareApplication) EndBlock(height uint64) []*types.Validator { +func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) { app.endCount += 1 - return nil + return } func (app *ChainAwareApplication) InitChain(vals []*types.Validator) { diff --git a/example/chain_aware/chain_aware_test.go b/example/chain_aware/chain_aware_test.go index bad7c8120..fd3754704 100644 --- a/example/chain_aware/chain_aware_test.go +++ b/example/chain_aware/chain_aware_test.go @@ -16,10 +16,11 @@ func TestChainAware(t *testing.T) { app := NewChainAwareApplication() // Start the listener - _, err := server.NewServer("unix://test.sock", "socket", app) + srv, err := server.NewServer("unix://test.sock", "socket", app) if err != nil { t.Fatal(err) } + defer srv.Stop() // Connect to the socket client, err := tmspcli.NewSocketClient("unix://test.sock", false) diff --git a/example/dummy/dummy_test.go b/example/dummy/dummy_test.go index eea7f4a85..f1287c9d3 100644 --- a/example/dummy/dummy_test.go +++ b/example/dummy/dummy_test.go @@ -179,10 +179,10 @@ func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff [ t.Fatal(r) } } - diff2 := dummyChain.EndBlock(height) + resEndBlock := dummyChain.EndBlock(height) dummy.Commit() - valsEqual(t, diff, diff2) + valsEqual(t, diff, resEndBlock.Diffs) } diff --git a/example/dummy/persistent_dummy.go b/example/dummy/persistent_dummy.go index fc2b38cd5..dc774ca36 100644 --- a/example/dummy/persistent_dummy.go +++ b/example/dummy/persistent_dummy.go @@ -113,8 +113,8 @@ func (app *PersistentDummyApplication) BeginBlock(hash []byte, header *types.Hea } // Update the validator set -func (app *PersistentDummyApplication) EndBlock(height uint64) (diffs []*types.Validator) { - return app.changes +func (app *PersistentDummyApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) { + return types.ResponseEndBlock{Diffs: app.changes} } //----------------------------------------- diff --git a/server/socket_server.go b/server/socket_server.go index 43b4ed638..5a916ef4e 100644 --- a/server/socket_server.go +++ b/server/socket_server.go @@ -168,7 +168,8 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types case *types.Request_Flush: responses <- types.ToResponseFlush() case *types.Request_Info: - responses <- types.ToResponseInfo(s.app.Info()) + resInfo := s.app.Info() + responses <- types.ToResponseInfo(resInfo) case *types.Request_SetOption: so := r.SetOption logStr := s.app.SetOption(so.Key, so.Value) @@ -197,10 +198,10 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types responses <- types.ToResponseBeginBlock() case *types.Request_EndBlock: if app, ok := s.app.(types.BlockchainAware); ok { - validators := app.EndBlock(r.EndBlock.Height) - responses <- types.ToResponseEndBlock(validators) + resEndBlock := app.EndBlock(r.EndBlock.Height) + responses <- types.ToResponseEndBlock(resEndBlock) } else { - responses <- types.ToResponseEndBlock(nil) + responses <- types.ToResponseEndBlock(types.ResponseEndBlock{}) } default: responses <- types.ToResponseException("Unknown request") diff --git a/types/application.go b/types/application.go index d124afd50..59b619e88 100644 --- a/types/application.go +++ b/types/application.go @@ -38,7 +38,7 @@ type BlockchainAware interface { // Signals the end of a block // diffs: changed validators from app to TendermintCore - EndBlock(height uint64) (diffs []*Validator) + EndBlock(height uint64) ResponseEndBlock } //------------------------------------ @@ -103,8 +103,8 @@ func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlo func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) { if chainAware, ok := app.app.(BlockchainAware); ok { - diffs := chainAware.EndBlock(req.Height) - return &ResponseEndBlock{diffs}, nil + resEndBlock := chainAware.EndBlock(req.Height) + return &resEndBlock, nil } return &ResponseEndBlock{}, nil } diff --git a/types/messages.go b/types/messages.go index afd4548e0..428b05dc6 100644 --- a/types/messages.go +++ b/types/messages.go @@ -142,9 +142,10 @@ func ToResponseBeginBlock() *Response { } } -func ToResponseEndBlock(validators []*Validator) *Response { +func ToResponseEndBlock(resEndBlock ResponseEndBlock) *Response { + resEndBlockCopy := resEndBlock return &Response{ - Value: &Response_EndBlock{&ResponseEndBlock{validators}}, + Value: &Response_EndBlock{&resEndBlockCopy}, } }