Browse Source

EndBlock also returns ResponseEndBlock

pull/1780/head
Jae Kwon 8 years ago
committed by Ethan Buchman
parent
commit
f8167872d8
13 changed files with 46 additions and 32 deletions
  1. +1
    -1
      client/client.go
  2. +7
    -3
      client/grpc_client.go
  3. +6
    -6
      client/local_client.go
  4. +7
    -3
      client/socket_client.go
  5. +2
    -1
      cmd/counter/main.go
  6. +2
    -1
      cmd/dummy/main.go
  7. +4
    -3
      example/chain_aware/chain_aware_app.go
  8. +2
    -1
      example/chain_aware/chain_aware_test.go
  9. +2
    -2
      example/dummy/dummy_test.go
  10. +2
    -2
      example/dummy/persistent_dummy.go
  11. +5
    -4
      server/socket_server.go
  12. +3
    -3
      types/application.go
  13. +3
    -2
      types/messages.go

+ 1
- 1
client/client.go View File

@ -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)
}
//----------------------------------------


+ 7
- 3
client/grpc_client.go View File

@ -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
}

+ 6
- 6
client/local_client.go View File

@ -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
}
//-------------------------------------------------------


+ 7
- 3
client/socket_client.go View File

@ -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
}
//----------------------------------------


+ 2
- 1
cmd/counter/main.go View File

@ -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()
})
}

+ 2
- 1
cmd/dummy/main.go View File

@ -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()
})
}

+ 4
- 3
example/chain_aware/chain_aware_app.go View File

@ -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) {


+ 2
- 1
example/chain_aware/chain_aware_test.go View File

@ -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)


+ 2
- 2
example/dummy/dummy_test.go View File

@ -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)
}


+ 2
- 2
example/dummy/persistent_dummy.go View File

@ -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}
}
//-----------------------------------------


+ 5
- 4
server/socket_server.go View File

@ -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")


+ 3
- 3
types/application.go View File

@ -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
}

+ 3
- 2
types/messages.go View File

@ -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},
}
}


Loading…
Cancel
Save