Skip to content

Commit 7356306

Browse files
evan-forbestac0turtlemconcatliamsiadlerjohn
authored
Add Prepare and Process Proposal ABCI++ methods (tendermint#631)
* abci: PrepareProposal (tendermint#6544) * regenerate mocks, proto, mod/sum, and clean up remaining preprocesstxs * fix tests and revert to old go.mod * mockery * add processproposal proto/boilerplate/logic * gofmt * fix test * move UNKNOWN response behaviour to reject * fix test and add testing util code * pass full block data when proposing or processing proposals * linter * add the process proposal method to the e2e app * add missing kvstore abci method * pass block data and results for bass app * use correct kvstore process logic for kvstore app * remove linting comment Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com> * formatting Co-authored-by: John Adler <adlerjohn@users.noreply.github.com> * use go generate instead of make mockery * add link Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: mconcat <monoidconcat@gmail.com> Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com> Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
1 parent 721562a commit 7356306

41 files changed

Lines changed: 2752 additions & 984 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

abci/client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ type Client interface {
5858
OfferSnapshotSync(types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error)
5959
LoadSnapshotChunkSync(types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error)
6060
ApplySnapshotChunkSync(types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error)
61-
PreprocessTxsSync(types.RequestPreprocessTxs) (*types.ResponsePreprocessTxs, error)
61+
PrepareProposalSync(types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error)
62+
ProcessProposalSync(types.RequestProcessProposal) (*types.ResponseProcessProposal, error)
6263
}
6364

6465
//----------------------------------------

abci/client/grpc_client.go

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"sync"
77
"time"
88

9-
"golang.org/x/net/context"
9+
"context"
10+
1011
"google.golang.org/grpc"
1112

1213
"github.com/tendermint/tendermint/abci/types"
@@ -302,13 +303,43 @@ func (cli *grpcClient) ApplySnapshotChunkAsync(params types.RequestApplySnapshot
302303
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_ApplySnapshotChunk{ApplySnapshotChunk: res}})
303304
}
304305

305-
func (cli *grpcClient) PreprocessTxsAsync(params types.RequestPreprocessTxs) *ReqRes {
306-
req := types.ToRequestPreprocessTxs(params)
307-
res, err := cli.client.PreprocessTxs(context.Background(), req.GetPreprocessTxs(), grpc.WaitForReady(true))
306+
func (cli *grpcClient) PrepareProposalAsync(
307+
params types.RequestPrepareProposal,
308+
) *ReqRes {
309+
310+
req := types.ToRequestPrepareProposal(params)
311+
res, err := cli.client.PrepareProposal(context.Background(), req.GetPrepareProposal(), grpc.WaitForReady(true))
308312
if err != nil {
309-
cli.StopForError(err)
313+
return nil
310314
}
311-
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_PreprocessTxs{PreprocessTxs: res}})
315+
return cli.finishAsyncCall(
316+
req,
317+
&types.Response{
318+
Value: &types.Response_PrepareProposal{
319+
PrepareProposal: res,
320+
},
321+
},
322+
)
323+
}
324+
325+
func (cli *grpcClient) ProcessProposalAsync(
326+
params types.RequestProcessProposal,
327+
) *ReqRes {
328+
329+
req := types.ToRequestProcessProposal(params)
330+
res, err := cli.client.ProcessProposal(context.Background(), req.GetProcessProposal(), grpc.WaitForReady(true))
331+
if err != nil {
332+
return nil
333+
}
334+
335+
return cli.finishAsyncCall(
336+
req,
337+
&types.Response{
338+
Value: &types.Response_ProcessProposal{
339+
ProcessProposal: res,
340+
},
341+
},
342+
)
312343
}
313344

314345
// finishAsyncCall creates a ReqRes for an async call, and immediately populates it
@@ -427,9 +458,17 @@ func (cli *grpcClient) ApplySnapshotChunkSync(
427458
return cli.finishSyncCall(reqres).GetApplySnapshotChunk(), cli.Error()
428459
}
429460

430-
func (cli *grpcClient) PreprocessTxsSync(
431-
params types.RequestPreprocessTxs,
432-
) (*types.ResponsePreprocessTxs, error) {
433-
reqres := cli.PreprocessTxsAsync(params)
434-
return reqres.Response.GetPreprocessTxs(), cli.Error()
461+
func (cli *grpcClient) PrepareProposalSync(
462+
params types.RequestPrepareProposal,
463+
) (*types.ResponsePrepareProposal, error) {
464+
465+
reqres := cli.PrepareProposalAsync(params)
466+
return cli.finishSyncCall(reqres).GetPrepareProposal(), cli.Error()
467+
}
468+
469+
func (cli *grpcClient) ProcessProposalSync(
470+
params types.RequestProcessProposal,
471+
) (*types.ResponseProcessProposal, error) {
472+
reqres := cli.ProcessProposalAsync(params)
473+
return cli.finishSyncCall(reqres).GetProcessProposal(), cli.Error()
435474
}

abci/client/local_client.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,30 @@ func (app *localClient) ApplySnapshotChunkAsync(req types.RequestApplySnapshotCh
207207
)
208208
}
209209

210-
func (app *localClient) PreprocessTxsAsync(req types.RequestPreprocessTxs) (*ReqRes, error) {
210+
func (app *localClient) PrepareProposalAsync(
211+
req types.RequestPrepareProposal,
212+
) *ReqRes {
211213
app.mtx.Lock()
212214
defer app.mtx.Unlock()
213215

214-
res := app.Application.PreprocessTxs(req)
216+
res := app.Application.PrepareProposal(req)
215217
return app.callback(
216-
types.ToRequestPreprocessTxs(req),
217-
types.ToResponsePreprocessTx(res),
218-
), nil
218+
types.ToRequestPrepareProposal(req),
219+
types.ToResponsePrepareProposal(res),
220+
)
221+
}
222+
223+
func (app *localClient) ProcessProposalAsync(
224+
req types.RequestProcessProposal,
225+
) *ReqRes {
226+
app.mtx.Lock()
227+
defer app.mtx.Unlock()
228+
229+
res := app.Application.ProcessProposal(req)
230+
return app.callback(
231+
types.ToRequestProcessProposal(req),
232+
types.ToResponseProcessProposal(res),
233+
)
219234
}
220235

221236
//-------------------------------------------------------
@@ -334,13 +349,24 @@ func (app *localClient) ApplySnapshotChunkSync(
334349
return &res, nil
335350
}
336351

337-
func (app *localClient) PreprocessTxsSync(
338-
req types.RequestPreprocessTxs,
339-
) (*types.ResponsePreprocessTxs, error) {
352+
func (app *localClient) PrepareProposalSync(
353+
req types.RequestPrepareProposal,
354+
) (*types.ResponsePrepareProposal, error) {
355+
356+
app.mtx.Lock()
357+
defer app.mtx.Unlock()
358+
359+
res := app.Application.PrepareProposal(req)
360+
return &res, nil
361+
}
362+
363+
func (app *localClient) ProcessProposalSync(
364+
req types.RequestProcessProposal,
365+
) (*types.ResponseProcessProposal, error) {
340366
app.mtx.Lock()
341367
defer app.mtx.Unlock()
342368

343-
res := app.Application.PreprocessTxs(req)
369+
res := app.Application.ProcessProposal(req)
344370
return &res, nil
345371
}
346372

abci/client/mocks/client.go

Lines changed: 29 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

abci/client/socket_client.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/tendermint/tendermint/libs/service"
1616
tmsync "github.com/tendermint/tendermint/libs/sync"
1717
"github.com/tendermint/tendermint/libs/timer"
18-
"golang.org/x/net/context"
1918
)
2019

2120
const (
@@ -280,11 +279,17 @@ func (cli *socketClient) ApplySnapshotChunkAsync(req types.RequestApplySnapshotC
280279
return cli.queueRequest(types.ToRequestApplySnapshotChunk(req))
281280
}
282281

283-
func (cli *socketClient) PreprocessTxsAsync(ctx context.Context, req types.RequestPreprocessTxs) *ReqRes {
284-
return cli.queueRequest(types.ToRequestPreprocessTxs(req))
282+
func (cli *socketClient) PrepareProposalAsync(
283+
req types.RequestPrepareProposal,
284+
) *ReqRes {
285+
return cli.queueRequest(types.ToRequestPrepareProposal(req))
285286
}
286287

287-
//----------------------------------------
288+
func (cli *socketClient) ProcessProposalAsync(
289+
req types.RequestProcessProposal,
290+
) *ReqRes {
291+
return cli.queueRequest(types.ToRequestProcessProposal(req))
292+
}
288293

289294
func (cli *socketClient) FlushSync() error {
290295
reqRes := cli.queueRequest(types.ToRequestFlush())
@@ -422,14 +427,21 @@ func (cli *socketClient) ApplySnapshotChunkSync(
422427
return reqres.Response.GetApplySnapshotChunk(), cli.Error()
423428
}
424429

425-
func (cli *socketClient) PreprocessTxsSync(
426-
req types.RequestPreprocessTxs,
427-
) (*types.ResponsePreprocessTxs, error) {
428-
reqres := cli.queueRequest(types.ToRequestPreprocessTxs(req))
429-
if err := cli.FlushSync(); err != nil {
430-
return nil, err
431-
}
432-
return reqres.Response.GetPreprocessTxs(), nil
430+
func (cli *socketClient) PrepareProposalSync(
431+
req types.RequestPrepareProposal,
432+
) (*types.ResponsePrepareProposal, error) {
433+
434+
reqres := cli.queueRequest(types.ToRequestPrepareProposal(req))
435+
return reqres.Response.GetPrepareProposal(), nil
436+
}
437+
438+
func (cli *socketClient) ProcessProposalSync(
439+
req types.RequestProcessProposal,
440+
) (*types.ResponseProcessProposal, error) {
441+
442+
reqres := cli.queueRequest(types.ToRequestProcessProposal(req))
443+
444+
return reqres.Response.GetProcessProposal(), nil
433445
}
434446

435447
//----------------------------------------
@@ -507,8 +519,8 @@ func resMatchesReq(req *types.Request, res *types.Response) (ok bool) {
507519
_, ok = res.Value.(*types.Response_ListSnapshots)
508520
case *types.Request_OfferSnapshot:
509521
_, ok = res.Value.(*types.Response_OfferSnapshot)
510-
case *types.Request_PreprocessTxs:
511-
_, ok = res.Value.(*types.Response_PreprocessTxs)
522+
case *types.Request_PrepareProposal:
523+
_, ok = res.Value.(*types.Response_PrepareProposal)
512524
}
513525
return ok
514526
}

abci/example/kvstore/kvstore.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,17 @@ func (app *Application) Query(reqQuery types.RequestQuery) (resQuery types.Respo
171171
return resQuery
172172
}
173173

174-
func (app *Application) PreprocessTxs(
175-
req types.RequestPreprocessTxs) types.ResponsePreprocessTxs {
176-
return types.ResponsePreprocessTxs{Txs: req.Txs}
174+
func (app *Application) PrepareProposal(req types.RequestPrepareProposal) types.ResponsePrepareProposal {
175+
return types.ResponsePrepareProposal{
176+
BlockData: req.BlockData,
177+
}
178+
}
179+
180+
func (app *Application) ProcessProposal(req types.RequestProcessProposal) types.ResponseProcessProposal {
181+
for _, tx := range req.BlockData.Txs {
182+
if len(tx) == 0 {
183+
return types.ResponseProcessProposal{Result: types.ResponseProcessProposal_REJECT}
184+
}
185+
}
186+
return types.ResponseProcessProposal{Result: types.ResponseProcessProposal_ACCEPT}
177187
}

abci/example/kvstore/persistent_kvstore.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,19 @@ func (app *PersistentKVStoreApplication) ApplySnapshotChunk(
170170
return types.ResponseApplySnapshotChunk{Result: types.ResponseApplySnapshotChunk_ABORT}
171171
}
172172

173-
func (app *PersistentKVStoreApplication) PreprocessTxs(
174-
req types.RequestPreprocessTxs) types.ResponsePreprocessTxs {
175-
return types.ResponsePreprocessTxs{Txs: req.Txs}
173+
func (app *PersistentKVStoreApplication) PrepareProposal(
174+
req types.RequestPrepareProposal) types.ResponsePrepareProposal {
175+
return types.ResponsePrepareProposal{BlockData: req.BlockData}
176+
}
177+
178+
func (app *PersistentKVStoreApplication) ProcessProposal(
179+
req types.RequestProcessProposal) types.ResponseProcessProposal {
180+
for _, tx := range req.BlockData.Txs {
181+
if len(tx) == 0 {
182+
return types.ResponseProcessProposal{Result: types.ResponseProcessProposal_REJECT}
183+
}
184+
}
185+
return types.ResponseProcessProposal{Result: types.ResponseProcessProposal_ACCEPT}
176186
}
177187

178188
//---------------------------------------------

abci/server/socket_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types
230230
case *types.Request_OfferSnapshot:
231231
res := s.app.OfferSnapshot(*r.OfferSnapshot)
232232
responses <- types.ToResponseOfferSnapshot(res)
233+
case *types.Request_PrepareProposal:
234+
res := s.app.PrepareProposal(*r.PrepareProposal)
235+
responses <- types.ToResponsePrepareProposal(res)
233236
case *types.Request_LoadSnapshotChunk:
234237
res := s.app.LoadSnapshotChunk(*r.LoadSnapshotChunk)
235238
responses <- types.ToResponseLoadSnapshotChunk(res)
236239
case *types.Request_ApplySnapshotChunk:
237240
res := s.app.ApplySnapshotChunk(*r.ApplySnapshotChunk)
238241
responses <- types.ToResponseApplySnapshotChunk(res)
239-
case *types.Request_PreprocessTxs:
240-
res := s.app.PreprocessTxs(*r.PreprocessTxs)
241-
responses <- types.ToResponsePreprocessTx(res)
242242
default:
243243
responses <- types.ToResponseException("Unknown request")
244244
}

0 commit comments

Comments
 (0)