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

Commit

Permalink
Add ABCI methods needed to generate fraudproof
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav-Aggarwal committed Aug 24, 2022
1 parent a41c5ee commit eacacf0
Show file tree
Hide file tree
Showing 11 changed files with 3,308 additions and 523 deletions.
3 changes: 3 additions & 0 deletions abci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ 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)
TriggerFraudProofGenerationModeSync(types.RequestTriggerFraudProofGenerationMode) (*types.ResponseTriggerFraudProofGenerationMode, 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) TriggerFraudProofGenerationModeAsync(params types.RequestTriggerFraudProofGenerationMode) *ReqRes {
req := types.ToRequestTriggerFraudProofGenerationMode(params)
res, err := cli.client.TriggerFraudProofGenerationMode(context.Background(), req.GetTriggerFraudProofGenerationMode(), grpc.WaitForReady(true))
if err != nil {
cli.StopForError(err)
}
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_TriggerFraudProofGenerationMode{TriggerFraudProofGenerationMode: 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) TriggerFraudProofGenerationModeSync(
params types.RequestTriggerFraudProofGenerationMode) (*types.ResponseTriggerFraudProofGenerationMode, error) {
reqres := cli.TriggerFraudProofGenerationModeAsync(params)
return cli.finishSyncCall(reqres).GetTriggerFraudProofGenerationMode(), 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) TriggerFraudProofGenerationModeAsync(req types.RequestTriggerFraudProofGenerationMode) *ReqRes {
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.TriggerFraudProofGenerationMode(req)
return app.callback(
types.ToRequestTriggerFraudProofGenerationMode(req),
types.ToResponseTriggerFraudProofGenerationMode(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) TriggerFraudProofGenerationModeSync(
req types.RequestTriggerFraudProofGenerationMode) (*types.ResponseTriggerFraudProofGenerationMode, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

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

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

func (app *localClient) callback(req *types.Request, res *types.Response) *ReqRes {
Expand Down
39 changes: 39 additions & 0 deletions abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ 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) TriggerFraudProofGenerationModeAsync(req types.RequestTriggerFraudProofGenerationMode) *ReqRes {
return cli.queueRequest(types.ToRequestTriggerFraudProofGenerationMode(req))
}

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

func (cli *socketClient) FlushSync() error {
Expand Down Expand Up @@ -417,6 +429,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) TriggerFraudProofGenerationModeSync(
req types.RequestTriggerFraudProofGenerationMode) (*types.ResponseTriggerFraudProofGenerationMode, error) {
reqres := cli.queueRequest(types.ToRequestTriggerFraudProofGenerationMode(req))
if err := cli.FlushSync(); err != nil {
return nil, err
}
return reqres.Response.GetTriggerFraudProofGenerationMode(), 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 @@ -170,6 +170,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) TriggerFraudProofGenerationMode(
req types.RequestTriggerFraudProofGenerationMode) types.ResponseTriggerFraudProofGenerationMode {
return types.ResponseTriggerFraudProofGenerationMode{}
}

//---------------------------------------------
// 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_TriggerFraudProofGenerationMode:
res := s.app.TriggerFraudProofGenerationMode(*r.TriggerFraudProofGenerationMode)
responses <- types.ToResponseGenerateFraudProof(res)
default:
responses <- types.ToResponseException("Unknown request")
}
Expand Down
43 changes: 38 additions & 5 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ 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
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
TriggerFraudProofGenerationMode(RequestTriggerFraudProofGenerationMode) ResponseTriggerFraudProofGenerationMode // Trigger Fraud Proof Generation Mode

// State Sync Connection
ListSnapshots(RequestListSnapshots) ResponseListSnapshots // List available snapshots
Expand Down Expand Up @@ -95,6 +98,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) TriggerFraudProofGenerationMode(req RequestTriggerFraudProofGenerationMode) ResponseTriggerFraudProofGenerationMode {
return ResponseTriggerFraudProofGenerationMode{}
}

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

// GRPCApplication is a GRPC wrapper for Application
Expand Down Expand Up @@ -182,3 +197,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) TriggerFraudProofGenerationMode(
ctx context.Context, req *RequestTriggerFraudProofGenerationMode) (*ResponseTriggerFraudProofGenerationMode, error) {
res := app.app.TriggerFraudProofGenerationMode(*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 ToRequestTriggerFraudProofGenerationMode(req RequestTriggerFraudProofGenerationMode) *Request {
return &Request{
Value: &Request_TriggerFraudProofGenerationMode{&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 ToResponseTriggerFraudProofGenerationMode(res ResponseTriggerFraudProofGenerationMode) *Response {
return &Response{
Value: &Response_TriggerFraudProofGenerationMode{&res},
}
}
Loading

0 comments on commit eacacf0

Please sign in to comment.