Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fraud proof #1

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions abci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type Client interface {
OfferSnapshotSync(types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error)
LoadSnapshotChunkSync(types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error)
ApplySnapshotChunkSync(types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error)

GetAppHashSync(types.RequestGetAppHash) (*types.ResponseGetAppHash, error)
GenerateFraudProofSync(types.RequestGenerateFraudProof) (*types.ResponseGenerateFraudProof, error)
VerifyFraudProofSync(types.RequestVerifyFraudProof) (*types.ResponseVerifyFraudProof, error)
}

//----------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,33 @@ func (cli *grpcClient) ApplySnapshotChunkAsync(params types.RequestApplySnapshot
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_ApplySnapshotChunk{ApplySnapshotChunk: res}})
}

func (cli *grpcClient) GetAppHashAsync(params types.RequestGetAppHash) *ReqRes {
req := types.ToRequestGetAppHash(params)
res, err := cli.client.GetAppHash(context.Background(), req.GetGetAppHash(), grpc.WaitForReady(true))
if err != nil {
cli.StopForError(err)
}
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_GetAppHash{GetAppHash: res}})
}

func (cli *grpcClient) GenerateFraudProofAsync(params types.RequestGenerateFraudProof) *ReqRes {
req := types.ToRequestGenerateFraudProof(params)
res, err := cli.client.GenerateFraudProof(context.Background(), req.GetGenerateFraudProof(), grpc.WaitForReady(true))
if err != nil {
cli.StopForError(err)
}
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_GenerateFraudProof{GenerateFraudProof: res}})
}

func (cli *grpcClient) VerifyFraudProofAsync(params types.RequestVerifyFraudProof) *ReqRes {
req := types.ToRequestVerifyFraudProof(params)
res, err := cli.client.VerifyFraudProof(context.Background(), req.GetVerifyFraudProof(), grpc.WaitForReady(true))
if err != nil {
cli.StopForError(err)
}
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_VerifyFraudProof{VerifyFraudProof: res}})
}

// finishAsyncCall creates a ReqRes for an async call, and immediately populates it
// with the response. We don't complete it until it's been ordered via the channel.
func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response) *ReqRes {
Expand Down Expand Up @@ -417,3 +444,21 @@ func (cli *grpcClient) ApplySnapshotChunkSync(
reqres := cli.ApplySnapshotChunkAsync(params)
return cli.finishSyncCall(reqres).GetApplySnapshotChunk(), cli.Error()
}

func (cli *grpcClient) GetAppHashSync(
params types.RequestGetAppHash) (*types.ResponseGetAppHash, error) {
reqres := cli.GetAppHashAsync(params)
return cli.finishSyncCall(reqres).GetGetAppHash(), cli.Error()
}

func (cli *grpcClient) GenerateFraudProofSync(
params types.RequestGenerateFraudProof) (*types.ResponseGenerateFraudProof, error) {
reqres := cli.GenerateFraudProofAsync(params)
return cli.finishSyncCall(reqres).GetGenerateFraudProof(), cli.Error()
}

func (cli *grpcClient) VerifyFraudProofSync(
params types.RequestVerifyFraudProof) (*types.ResponseVerifyFraudProof, error) {
reqres := cli.VerifyFraudProofAsync(params)
return cli.finishSyncCall(reqres).GetVerifyFraudProof(), cli.Error()
}
60 changes: 60 additions & 0 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,39 @@ func (app *localClient) ApplySnapshotChunkAsync(req types.RequestApplySnapshotCh
)
}

func (app *localClient) GetAppHashAsync(req types.RequestGetAppHash) *ReqRes {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.GetAppHash(req)
return app.callback(
types.ToRequestGetAppHash(req),
types.ToResponseGetAppHash(res),
)
}

func (app *localClient) GenerateFraudProofAsync(req types.RequestGenerateFraudProof) *ReqRes {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.GenerateFraudProof(req)
return app.callback(
types.ToRequestGenerateFraudProof(req),
types.ToResponseGenerateFraudProof(res),
)
}

func (app *localClient) VerifyFraudProofAsync(req types.RequestVerifyFraudProof) *ReqRes {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.VerifyFraudProof(req)
return app.callback(
types.ToRequestVerifyFraudProof(req),
types.ToResponseVerifyFraudProof(res),
)
}

//-------------------------------------------------------

func (app *localClient) FlushSync() error {
Expand Down Expand Up @@ -323,6 +356,33 @@ func (app *localClient) ApplySnapshotChunkSync(
return &res, nil
}

func (app *localClient) GetAppHashSync(
req types.RequestGetAppHash) (*types.ResponseGetAppHash, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.GetAppHash(req)
return &res, nil
}

func (app *localClient) GenerateFraudProofSync(
req types.RequestGenerateFraudProof) (*types.ResponseGenerateFraudProof, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.GenerateFraudProof(req)
return &res, nil
}

func (app *localClient) VerifyFraudProofSync(
req types.RequestVerifyFraudProof) (*types.ResponseVerifyFraudProof, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.VerifyFraudProof(req)
return &res, nil
}

//-------------------------------------------------------

func (app *localClient) callback(req *types.Request, res *types.Response) *ReqRes {
Expand Down
1 change: 1 addition & 0 deletions abci/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ func (cli *socketClient) ApplySnapshotChunkAsync(req types.RequestApplySnapshotC
return cli.queueRequest(types.ToRequestApplySnapshotChunk(req))
}

func (cli *socketClient) GetAppHashAsync(req types.RequestGetAppHash) *ReqRes {
return cli.queueRequest(types.ToRequestGetAppHash(req))
}

func (cli *socketClient) GenerateFraudProofAsync(
req types.RequestGenerateFraudProof,
) *ReqRes {
return cli.queueRequest(types.ToRequestGenerateFraudProof(req))
}

//----------------------------------------

func (cli *socketClient) FlushSync() error {
Expand Down Expand Up @@ -417,6 +427,33 @@ func (cli *socketClient) ApplySnapshotChunkSync(
return reqres.Response.GetApplySnapshotChunk(), cli.Error()
}

func (cli *socketClient) GetAppHashSync(
req types.RequestGetAppHash) (*types.ResponseGetAppHash, error) {
reqres := cli.queueRequest(types.ToRequestGetAppHash(req))
if err := cli.FlushSync(); err != nil {
return nil, err
}
return reqres.Response.GetGetAppHash(), cli.Error()
}

func (cli *socketClient) GenerateFraudProofSync(
req types.RequestGenerateFraudProof) (*types.ResponseGenerateFraudProof, error) {
reqres := cli.queueRequest(types.ToRequestGenerateFraudProof(req))
if err := cli.FlushSync(); err != nil {
return nil, err
}
return reqres.Response.GetGenerateFraudProof(), cli.Error()
}

func (cli *socketClient) VerifyFraudProofSync(
req types.RequestVerifyFraudProof) (*types.ResponseVerifyFraudProof, error) {
reqres := cli.queueRequest(types.ToRequestVerifyFraudProof(req))
if err := cli.FlushSync(); err != nil {
return nil, err
}
return reqres.Response.GetVerifyFraudProof(), cli.Error()
}

//----------------------------------------

func (cli *socketClient) queueRequest(req *types.Request) *ReqRes {
Expand Down
15 changes: 15 additions & 0 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ func (app *PersistentKVStoreApplication) ApplySnapshotChunk(
return types.ResponseApplySnapshotChunk{Result: types.ResponseApplySnapshotChunk_ABORT}
}

func (app *PersistentKVStoreApplication) GetAppHash(
req types.RequestGetAppHash) types.ResponseGetAppHash {
return types.ResponseGetAppHash{}
}

func (app *PersistentKVStoreApplication) GenerateFraudProof(
req types.RequestGenerateFraudProof) types.ResponseGenerateFraudProof {
return types.ResponseGenerateFraudProof{}
}

func (app *PersistentKVStoreApplication) VerifyFraudProof(
req types.RequestVerifyFraudProof) types.ResponseVerifyFraudProof {
return types.ResponseVerifyFraudProof{}
}

//---------------------------------------------
// update validators

Expand Down
9 changes: 9 additions & 0 deletions abci/server/socket_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types
case *types.Request_ApplySnapshotChunk:
res := s.app.ApplySnapshotChunk(*r.ApplySnapshotChunk)
responses <- types.ToResponseApplySnapshotChunk(res)
case *types.Request_GetAppHash:
res := s.app.GetAppHash(*r.GetAppHash)
responses <- types.ToResponseGetAppHash(res)
case *types.Request_GenerateFraudProof:
res := s.app.GenerateFraudProof(*r.GenerateFraudProof)
responses <- types.ToResponseGenerateFraudProof(res)
case *types.Request_VerifyFraudProof:
res := s.app.VerifyFraudProof(*r.VerifyFraudProof)
responses <- types.ToResponseVerifyFraudProof(res)
default:
responses <- types.ToResponseException("Unknown request")
}
Expand Down
37 changes: 37 additions & 0 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ type Application interface {
OfferSnapshot(RequestOfferSnapshot) ResponseOfferSnapshot // Offer a snapshot to the application
LoadSnapshotChunk(RequestLoadSnapshotChunk) ResponseLoadSnapshotChunk // Load a snapshot chunk
ApplySnapshotChunk(RequestApplySnapshotChunk) ResponseApplySnapshotChunk // Apply a shapshot chunk

// Fraud Proof Connection
GetAppHash(RequestGetAppHash) ResponseGetAppHash
// Generate Fraud Proof
GenerateFraudProof(RequestGenerateFraudProof) ResponseGenerateFraudProof
// Verifies a Fraud Proof
VerifyFraudProof(RequestVerifyFraudProof) ResponseVerifyFraudProof
}

//-------------------------------------------------------
Expand Down Expand Up @@ -95,6 +102,18 @@ func (BaseApplication) ApplySnapshotChunk(req RequestApplySnapshotChunk) Respons
return ResponseApplySnapshotChunk{}
}

func (BaseApplication) GetAppHash(req RequestGetAppHash) ResponseGetAppHash {
return ResponseGetAppHash{}
}

func (BaseApplication) GenerateFraudProof(req RequestGenerateFraudProof) ResponseGenerateFraudProof {
return ResponseGenerateFraudProof{}
}

func (BaseApplication) VerifyFraudProof(req RequestVerifyFraudProof) ResponseVerifyFraudProof {
return ResponseVerifyFraudProof{}
}

//-------------------------------------------------------

// GRPCApplication is a GRPC wrapper for Application
Expand Down Expand Up @@ -182,3 +201,21 @@ func (app *GRPCApplication) ApplySnapshotChunk(
res := app.app.ApplySnapshotChunk(*req)
return &res, nil
}

func (app *GRPCApplication) GetAppHash(
ctx context.Context, req *RequestGetAppHash) (*ResponseGetAppHash, error) {
res := app.app.GetAppHash(*req)
return &res, nil
}

func (app *GRPCApplication) GenerateFraudProof(
ctx context.Context, req *RequestGenerateFraudProof) (*ResponseGenerateFraudProof, error) {
res := app.app.GenerateFraudProof(*req)
return &res, nil
}

func (app *GRPCApplication) VerifyFraudProof(
ctx context.Context, req *RequestVerifyFraudProof) (*ResponseVerifyFraudProof, error) {
res := app.app.VerifyFraudProof(*req)
return &res, nil
}
36 changes: 36 additions & 0 deletions abci/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request {
}
}

func ToRequestGetAppHash(req RequestGetAppHash) *Request {
return &Request{
Value: &Request_GetAppHash{&req},
}
}

func ToRequestGenerateFraudProof(req RequestGenerateFraudProof) *Request {
return &Request{
Value: &Request_GenerateFraudProof{&req},
}
}

func ToRequestVerifyFraudProof(req RequestVerifyFraudProof) *Request {
return &Request{
Value: &Request_VerifyFraudProof{&req},
}
}

//----------------------------------------

func ToResponseException(errStr string) *Response {
Expand Down Expand Up @@ -256,3 +274,21 @@ func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response {
Value: &Response_ApplySnapshotChunk{&res},
}
}

func ToResponseGetAppHash(res ResponseGetAppHash) *Response {
return &Response{
Value: &Response_GetAppHash{&res},
}
}

func ToResponseGenerateFraudProof(res ResponseGenerateFraudProof) *Response {
return &Response{
Value: &Response_GenerateFraudProof{&res},
}
}

func ToResponseVerifyFraudProof(res ResponseVerifyFraudProof) *Response {
return &Response{
Value: &Response_VerifyFraudProof{&res},
}
}
Loading