Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Add ABCI method needed for Fraud Proof Verification #67

Merged
merged 10 commits into from
Oct 13, 2022
1 change: 1 addition & 0 deletions abci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Client interface {
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
15 changes: 15 additions & 0 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ func (cli *grpcClient) GenerateFraudProofAsync(params types.RequestGenerateFraud
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 @@ -447,3 +456,9 @@ func (cli *grpcClient) GenerateFraudProofSync(
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()
}
20 changes: 20 additions & 0 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ func (app *localClient) GenerateFraudProofAsync(req types.RequestGenerateFraudPr
)
}

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 @@ -363,6 +374,15 @@ func (app *localClient) GenerateFraudProofSync(
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
23 changes: 23 additions & 0 deletions abci/client/mocks/client.go

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

9 changes: 9 additions & 0 deletions abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ func (cli *socketClient) GenerateFraudProofSync(
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
5 changes: 5 additions & 0 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ func (app *PersistentKVStoreApplication) GenerateFraudProof(
return types.ResponseGenerateFraudProof{}
}

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

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

Expand Down
3 changes: 3 additions & 0 deletions abci/server/socket_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types
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
47 changes: 36 additions & 11 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,34 @@ type Application interface {
CheckTx(RequestCheckTx) ResponseCheckTx // Validate a tx for the mempool

// Consensus Connection
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain w validators/other info from TendermintCore
BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
DeliverTx(RequestDeliverTx) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
GetAppHash(RequestGetAppHash) ResponseGetAppHash // Get appHash
GenerateFraudProof(RequestGenerateFraudProof) ResponseGenerateFraudProof // Generate FraudProof

// Initialize blockchain w validators/other info from TendermintCore
InitChain(RequestInitChain) ResponseInitChain
// Signals the beginning of a block
BeginBlock(RequestBeginBlock) ResponseBeginBlock
// Deliver a tx for full processing
DeliverTx(RequestDeliverTx) ResponseDeliverTx
// Signals the end of a block, returns changes to the validator set
EndBlock(RequestEndBlock) ResponseEndBlock
// Commit the state and return the application Merkle root hash
Commit() ResponseCommit
// Get appHash
GetAppHash(RequestGetAppHash) ResponseGetAppHash
// Generate Fraud Proof
GenerateFraudProof(RequestGenerateFraudProof) ResponseGenerateFraudProof
// Verifies a Fraud Proof
VerifyFraudProof(RequestVerifyFraudProof) ResponseVerifyFraudProof

// State Sync Connection
ListSnapshots(RequestListSnapshots) ResponseListSnapshots // List available snapshots
OfferSnapshot(RequestOfferSnapshot) ResponseOfferSnapshot // Offer a snapshot to the application
LoadSnapshotChunk(RequestLoadSnapshotChunk) ResponseLoadSnapshotChunk // Load a snapshot chunk
ApplySnapshotChunk(RequestApplySnapshotChunk) ResponseApplySnapshotChunk // Apply a shapshot chunk

// List available snapshots
ListSnapshots(RequestListSnapshots) ResponseListSnapshots
// Offer a snapshot to the application
OfferSnapshot(RequestOfferSnapshot) ResponseOfferSnapshot
// Load a snapshot chunk
LoadSnapshotChunk(RequestLoadSnapshotChunk) ResponseLoadSnapshotChunk
// Apply a shapshot chunk
ApplySnapshotChunk(RequestApplySnapshotChunk) ResponseApplySnapshotChunk
}

//-------------------------------------------------------
Expand Down Expand Up @@ -105,6 +120,10 @@ func (BaseApplication) GenerateFraudProof(req RequestGenerateFraudProof) Respons
return ResponseGenerateFraudProof{}
}

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

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

// GRPCApplication is a GRPC wrapper for Application
Expand Down Expand Up @@ -204,3 +223,9 @@ func (app *GRPCApplication) GenerateFraudProof(
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
}
12 changes: 12 additions & 0 deletions abci/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ func ToRequestGenerateFraudProof(req RequestGenerateFraudProof) *Request {
}
}

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

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

func ToResponseException(errStr string) *Response {
Expand Down Expand Up @@ -280,3 +286,9 @@ func ToResponseGenerateFraudProof(res ResponseGenerateFraudProof) *Response {
Value: &Response_GenerateFraudProof{&res},
}
}

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