drop BlockchainAware
This commit is contained in:
parent
8df0bc3a40
commit
b025c13f67
|
@ -111,9 +111,7 @@ func (app *localClient) CommitAsync() *ReqRes {
|
|||
|
||||
func (app *localClient) InitChainAsync(validators []*types.Validator) *ReqRes {
|
||||
app.mtx.Lock()
|
||||
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
|
||||
bcApp.InitChain(validators)
|
||||
}
|
||||
app.Application.InitChain(validators)
|
||||
reqRes := app.callback(
|
||||
types.ToRequestInitChain(validators),
|
||||
types.ToResponseInitChain(),
|
||||
|
@ -124,9 +122,7 @@ func (app *localClient) InitChainAsync(validators []*types.Validator) *ReqRes {
|
|||
|
||||
func (app *localClient) BeginBlockAsync(hash []byte, header *types.Header) *ReqRes {
|
||||
app.mtx.Lock()
|
||||
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
|
||||
bcApp.BeginBlock(hash, header)
|
||||
}
|
||||
app.Application.BeginBlock(hash, header)
|
||||
app.mtx.Unlock()
|
||||
return app.callback(
|
||||
types.ToRequestBeginBlock(hash, header),
|
||||
|
@ -136,10 +132,7 @@ func (app *localClient) BeginBlockAsync(hash []byte, header *types.Header) *ReqR
|
|||
|
||||
func (app *localClient) EndBlockAsync(height uint64) *ReqRes {
|
||||
app.mtx.Lock()
|
||||
var resEndBlock types.ResponseEndBlock
|
||||
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
|
||||
resEndBlock = bcApp.EndBlock(height)
|
||||
}
|
||||
resEndBlock := app.Application.EndBlock(height)
|
||||
app.mtx.Unlock()
|
||||
return app.callback(
|
||||
types.ToRequestEndBlock(height),
|
||||
|
@ -201,27 +194,21 @@ func (app *localClient) CommitSync() (res types.Result) {
|
|||
|
||||
func (app *localClient) InitChainSync(validators []*types.Validator) (err error) {
|
||||
app.mtx.Lock()
|
||||
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
|
||||
bcApp.InitChain(validators)
|
||||
}
|
||||
app.Application.InitChain(validators)
|
||||
app.mtx.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *localClient) BeginBlockSync(hash []byte, header *types.Header) (err error) {
|
||||
app.mtx.Lock()
|
||||
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
|
||||
bcApp.BeginBlock(hash, header)
|
||||
}
|
||||
app.Application.BeginBlock(hash, header)
|
||||
app.mtx.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *localClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEndBlock, err error) {
|
||||
app.mtx.Lock()
|
||||
if bcApp, ok := app.Application.(types.BlockchainAware); ok {
|
||||
resEndBlock = bcApp.EndBlock(height)
|
||||
}
|
||||
resEndBlock = app.Application.EndBlock(height)
|
||||
app.mtx.Unlock()
|
||||
return resEndBlock, nil
|
||||
}
|
||||
|
|
|
@ -80,3 +80,13 @@ func (app *CounterApplication) Query(reqQuery types.RequestQuery) types.Response
|
|||
return types.ResponseQuery{Log: Fmt("Invalid query path. Expected hash or tx, got %v", reqQuery.Path)}
|
||||
}
|
||||
}
|
||||
|
||||
func (app *CounterApplication) InitChain(validators []*types.Validator) {
|
||||
}
|
||||
|
||||
func (app *CounterApplication) BeginBlock(hash []byte, header *types.Header) {
|
||||
}
|
||||
|
||||
func (app *CounterApplication) EndBlock(height uint64) types.ResponseEndBlock {
|
||||
return types.ResponseEndBlock{}
|
||||
}
|
||||
|
|
|
@ -70,3 +70,13 @@ func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (app *DummyApplication) InitChain(validators []*types.Validator) {
|
||||
}
|
||||
|
||||
func (app *DummyApplication) BeginBlock(hash []byte, header *types.Header) {
|
||||
}
|
||||
|
||||
func (app *DummyApplication) EndBlock(height uint64) types.ResponseEndBlock {
|
||||
return types.ResponseEndBlock{}
|
||||
}
|
||||
|
|
|
@ -180,14 +180,13 @@ func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff [
|
|||
Height: height,
|
||||
}
|
||||
|
||||
dummyChain := dummy.(types.BlockchainAware) // hmm...
|
||||
dummyChain.BeginBlock(hash, header)
|
||||
dummy.BeginBlock(hash, header)
|
||||
for _, tx := range txs {
|
||||
if r := dummy.DeliverTx(tx); r.IsErr() {
|
||||
t.Fatal(r)
|
||||
}
|
||||
}
|
||||
resEndBlock := dummyChain.EndBlock(height)
|
||||
resEndBlock := dummy.EndBlock(height)
|
||||
dummy.Commit()
|
||||
|
||||
valsEqual(t, diff, resEndBlock.Diffs)
|
||||
|
|
|
@ -34,3 +34,13 @@ func (app *NilApplication) Commit() types.Result {
|
|||
func (app *NilApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
|
||||
return resQuery
|
||||
}
|
||||
|
||||
func (app *NilApplication) InitChain(validators []*types.Validator) {
|
||||
}
|
||||
|
||||
func (app *NilApplication) BeginBlock(hash []byte, header *types.Header) {
|
||||
}
|
||||
|
||||
func (app *NilApplication) EndBlock(height uint64) types.ResponseEndBlock {
|
||||
return types.ResponseEndBlock{}
|
||||
}
|
||||
|
|
|
@ -187,22 +187,14 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types
|
|||
resQuery := s.app.Query(*r.Query)
|
||||
responses <- types.ToResponseQuery(resQuery)
|
||||
case *types.Request_InitChain:
|
||||
if app, ok := s.app.(types.BlockchainAware); ok {
|
||||
app.InitChain(r.InitChain.Validators)
|
||||
}
|
||||
s.app.InitChain(r.InitChain.Validators)
|
||||
responses <- types.ToResponseInitChain()
|
||||
case *types.Request_BeginBlock:
|
||||
if app, ok := s.app.(types.BlockchainAware); ok {
|
||||
app.BeginBlock(r.BeginBlock.Hash, r.BeginBlock.Header)
|
||||
}
|
||||
s.app.BeginBlock(r.BeginBlock.Hash, r.BeginBlock.Header)
|
||||
responses <- types.ToResponseBeginBlock()
|
||||
case *types.Request_EndBlock:
|
||||
if app, ok := s.app.(types.BlockchainAware); ok {
|
||||
resEndBlock := app.EndBlock(r.EndBlock.Height)
|
||||
resEndBlock := s.app.EndBlock(r.EndBlock.Height)
|
||||
responses <- types.ToResponseEndBlock(resEndBlock)
|
||||
} else {
|
||||
responses <- types.ToResponseEndBlock(types.ResponseEndBlock{})
|
||||
}
|
||||
default:
|
||||
responses <- types.ToResponseException("Unknown request")
|
||||
}
|
||||
|
|
|
@ -6,42 +6,25 @@ import (
|
|||
|
||||
// Applications
|
||||
type Application interface {
|
||||
// Info/Query Connection
|
||||
Info() ResponseInfo // Return application info
|
||||
SetOption(key string, value string) (log string) // Set application option
|
||||
Query(reqQuery RequestQuery) ResponseQuery // Query for state
|
||||
|
||||
// Return application info
|
||||
Info() ResponseInfo
|
||||
// Mempool Connection
|
||||
CheckTx(tx []byte) Result // Validate a tx for the mempool
|
||||
|
||||
// Set application option (e.g. mode=mempool, mode=consensus)
|
||||
SetOption(key string, value string) (log string)
|
||||
|
||||
// Deliver a tx
|
||||
DeliverTx(tx []byte) Result
|
||||
|
||||
// Validate a tx for the mempool
|
||||
CheckTx(tx []byte) Result
|
||||
|
||||
// Query for state
|
||||
Query(reqQuery RequestQuery) ResponseQuery
|
||||
|
||||
// Return the application Merkle root hash
|
||||
Commit() Result
|
||||
}
|
||||
|
||||
// Some applications can choose to implement BlockchainAware
|
||||
type BlockchainAware interface {
|
||||
|
||||
// Initialize blockchain
|
||||
// validators: genesis validators from TendermintCore
|
||||
InitChain(validators []*Validator)
|
||||
|
||||
// Signals the beginning of a block
|
||||
BeginBlock(hash []byte, header *Header)
|
||||
|
||||
// Signals the end of a block
|
||||
// diffs: changed validators from app to TendermintCore
|
||||
EndBlock(height uint64) ResponseEndBlock
|
||||
// Consensus Connection
|
||||
InitChain(validators []*Validator) // Initialize blockchain with validators from TendermintCore
|
||||
BeginBlock(hash []byte, header *Header) // Signals the beginning of a block
|
||||
DeliverTx(tx []byte) Result // Deliver a tx for full processing
|
||||
EndBlock(height uint64) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
|
||||
Commit() Result // Commit the state and return the application Merkle root hash
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
// GRPC wrapper for application
|
||||
type GRPCApplication struct {
|
||||
app Application
|
||||
}
|
||||
|
@ -88,23 +71,16 @@ func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*Re
|
|||
}
|
||||
|
||||
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
|
||||
if chainAware, ok := app.app.(BlockchainAware); ok {
|
||||
chainAware.InitChain(req.Validators)
|
||||
}
|
||||
return &ResponseInitChain{}, nil
|
||||
app.app.InitChain(req.Validators)
|
||||
return &ResponseInitChain{}, nil // NOTE: empty return
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
|
||||
if chainAware, ok := app.app.(BlockchainAware); ok {
|
||||
chainAware.BeginBlock(req.Hash, req.Header)
|
||||
}
|
||||
return &ResponseBeginBlock{}, nil
|
||||
app.app.BeginBlock(req.Hash, req.Header)
|
||||
return &ResponseBeginBlock{}, nil // NOTE: empty return
|
||||
}
|
||||
|
||||
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
|
||||
if chainAware, ok := app.app.(BlockchainAware); ok {
|
||||
resEndBlock := chainAware.EndBlock(req.Height)
|
||||
resEndBlock := app.app.EndBlock(req.Height)
|
||||
return &resEndBlock, nil
|
||||
}
|
||||
return &ResponseEndBlock{}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue