Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5d982c4
add extension signing
mconcat Jul 10, 2021
08c4f89
modify state execution in progress
mconcat Jul 9, 2021
306296a
add extension signing
mconcat Jul 10, 2021
dbb2c71
verify in progress
mconcat Jul 15, 2021
059eafa
Merge branch 'mconcat/abci-vote-extension-2' of mconcat.github.com:si…
mconcat Jul 15, 2021
d01e50a
modify CommitSig
mconcat Jul 15, 2021
2dcf9af
fix test
mconcat Jul 16, 2021
1bb0326
Merge branch 'mconcat/abci-vote-extension' into mconcat/abci-vote-ext…
mconcat Jul 20, 2021
fc5767d
Apply suggestions from code review
mconcat Jul 20, 2021
d52863d
fix test
mconcat Jul 21, 2021
539eac2
Merge branch 'mconcat/abci-vote-extension-2' of github.com:sikkatech/…
mconcat Jul 21, 2021
a9708f0
VoteExtensionSigned => VoteExtensionToSigned
mconcat Aug 2, 2021
90a3ee4
Merge branch 'mconcat/abci-vote-extension' into mconcat/abci-vote-ext…
mconcat Aug 5, 2021
185fe06
add example VoteExtension
mconcat Aug 9, 2021
0e30b6a
Merge branch 'mconcat/abci-vote-extension' into mconcat/abci-vote-ext…
mconcat Aug 11, 2021
ae4a96c
fix vote
mconcat Aug 13, 2021
86035a3
Merge branch 'mconcat/abci-vote-extension' into mconcat/abci-vote-ext…
mconcat Aug 13, 2021
68dd6c6
abci: Vote Extension 1 (#6646)
mconcat Aug 23, 2021
27bc51b
Merge branch 'mconcat/abci-vote-extension' into mconcat/abci-vote-ext…
mconcat Aug 24, 2021
2279c7b
add abcipp_kvstore.go
mconcat Aug 27, 2021
ba4f88f
add extension test
mconcat Aug 30, 2021
d53c4ec
fix test
mconcat Sep 1, 2021
920518e
fix test
mconcat Sep 1, 2021
c87d7ca
Merge branch 'abci++' of github.com:tendermint/tendermint into mconca…
mconcat Sep 1, 2021
1f6aa38
fix test
mconcat Sep 1, 2021
ccdb40b
fit lint
mconcat Sep 1, 2021
094adfa
uncomment test
mconcat Sep 1, 2021
6d3dc26
refactor test in progress
mconcat Sep 7, 2021
020e6f9
gofmt
mconcat Sep 16, 2021
fc796fa
apply review
mconcat Sep 16, 2021
85e1808
fix lint
mconcat Sep 16, 2021
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
30 changes: 15 additions & 15 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,13 @@ func (cli *grpcClient) VerifyVoteExtensionAsync(
}
return cli.finishAsyncCall(
ctx,
req,
req,
&types.Response{
Value: &types.Response_VerifyVoteExtension{
VerifyVoteExtension: res,
},
},
)
Value: &types.Response_VerifyVoteExtension{
VerifyVoteExtension: res,
},
},
)
}

func (cli *grpcClient) PrepareProposalAsync(
Expand All @@ -359,14 +359,14 @@ func (cli *grpcClient) PrepareProposalAsync(

req := types.ToRequestPrepareProposal(params)
res, err := cli.client.PrepareProposal(ctx, req.GetPrepareProposal(), grpc.WaitForReady(true))
if err != nil {
return nil, err
}

return cli.finishAsyncCall(
ctx,
req,
&types.Response{
if err != nil {
return nil, err
}

return cli.finishAsyncCall(
ctx,
req,
&types.Response{
Value: &types.Response_PrepareProposal{
PrepareProposal: res,
},
Expand Down Expand Up @@ -584,7 +584,7 @@ func (cli *grpcClient) VerifyVoteExtensionSync(
if err != nil {
return nil, err
}
return cli.finishSyncCall(reqres).GetVerifyVoteExtension(), cli.Error()
return cli.finishSyncCall(reqres).GetVerifyVoteExtension(), cli.Error()
}

func (cli *grpcClient) PrepareProposalSync(
Expand Down
14 changes: 7 additions & 7 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ func (app *localClient) PrepareProposalAsync(
ctx context.Context,
req types.RequestPrepareProposal,
) (*ReqRes, error) {
app.mtx.Lock()
defer app.mtx.Unlock()
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.PrepareProposal(req)
res := app.Application.PrepareProposal(req)
return app.callback(
types.ToRequestPrepareProposal(req),
types.ToResponsePrepareProposal(res),
), nil
), nil
}

//-------------------------------------------------------
Expand Down Expand Up @@ -407,15 +407,15 @@ func (app *localClient) VerifyVoteExtensionSync(
defer app.mtx.Unlock()

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

func (app *localClient) PrepareProposalSync(
ctx context.Context,
req types.RequestPrepareProposal,
) (*types.ResponsePrepareProposal, error) {
app.mtx.Lock()
defer app.mtx.Unlock()
app.mtx.Lock()
defer app.mtx.Unlock()

res := app.Application.PrepareProposal(req)
return &res, nil
Expand Down
92 changes: 92 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.

66 changes: 59 additions & 7 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/libs/log"
pc "github.com/tendermint/tendermint/proto/tendermint/crypto"
ptypes "github.com/tendermint/tendermint/proto/tendermint/types"
)

const (
Expand Down Expand Up @@ -76,6 +77,10 @@ func (app *PersistentKVStoreApplication) DeliverTx(req types.RequestDeliverTx) t
return app.execValidatorTx(req.Tx)
}

if isPrepareTx(req.Tx) {
return app.execPrepareTx(req.Tx)
}

// otherwise, update the key-value store
return app.app.DeliverTx(req)
}
Expand Down Expand Up @@ -172,21 +177,20 @@ func (app *PersistentKVStoreApplication) ApplySnapshotChunk(

func (app *PersistentKVStoreApplication) ExtendVote(
req types.RequestExtendVote) types.ResponseExtendVote {
return types.ResponseExtendVote{}
return types.ResponseExtendVote{
VoteExtension: ConstructVoteExtension(req.Vote.ValidatorAddress),
}
}

func (app *PersistentKVStoreApplication) VerifyVoteExtension(
req types.RequestVerifyVoteExtension) types.ResponseVerifyVoteExtension {
return types.ResponseVerifyVoteExtension{}
return types.RespondVerifyVoteExtension(
app.verifyExtension(req.Vote.ValidatorAddress, req.Vote.VoteExtension))
}

func (app *PersistentKVStoreApplication) PrepareProposal(
req types.RequestPrepareProposal) types.ResponsePrepareProposal {
if len(req.BlockData) >= 1 {
req.BlockData[1] = []byte("modified tx")
}

return types.ResponsePrepareProposal{BlockData: req.BlockData}
return types.ResponsePrepareProposal{BlockData: app.substPrepareTx(req.BlockData)}
}

//---------------------------------------------
Expand Down Expand Up @@ -303,3 +307,51 @@ func (app *PersistentKVStoreApplication) updateValidator(v types.ValidatorUpdate

return types.ResponseDeliverTx{Code: code.CodeTypeOK}
}

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

const PreparePrefix = "prepare"

func isPrepareTx(tx []byte) bool {
return strings.HasPrefix(string(tx), PreparePrefix)
}

// execPrepareTx is noop. tx data is considered as placeholder
// and is substitute at the PrepareProposal.
func (app *PersistentKVStoreApplication) execPrepareTx(tx []byte) types.ResponseDeliverTx {
// noop
return types.ResponseDeliverTx{}
}

// substPrepareTx subst all the preparetx in the blockdata
// to null string(could be any arbitrary string).
func (app *PersistentKVStoreApplication) substPrepareTx(blockData [][]byte) [][]byte {
for i, tx := range blockData {
if isPrepareTx(tx) {
blockData[i] = make([]byte, len(tx))
}
}

return blockData
}

func ConstructVoteExtension(valAddr []byte) *ptypes.VoteExtension {
return &ptypes.VoteExtension{
AppDataToSign: valAddr,
AppDataSelfAuthenticating: valAddr,
}
}

func (app *PersistentKVStoreApplication) verifyExtension(valAddr []byte, ext *ptypes.VoteExtension) bool {
if ext == nil {
return false
}
canonical := ConstructVoteExtension(valAddr)
if !bytes.Equal(canonical.AppDataToSign, ext.AppDataToSign) {
return false
}
if !bytes.Equal(canonical.AppDataSelfAuthenticating, ext.AppDataSelfAuthenticating) {
return false
}
return true
}
20 changes: 13 additions & 7 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ type Application interface {
// Consensus Connection
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain w validators/other info from TendermintCore
PrepareProposal(RequestPrepareProposal) ResponsePrepareProposal
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
ExtendVote(RequestExtendVote) ResponseExtendVote // Create application specific vote extension
VerifyVoteExtension(RequestVerifyVoteExtension) ResponseVerifyVoteExtension // Verify application's vote extension data
// 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
// Create application specific vote extension
ExtendVote(RequestExtendVote) ResponseExtendVote
// Verify application's vote extension data
VerifyVoteExtension(RequestVerifyVoteExtension) ResponseVerifyVoteExtension

// State Sync Connection
ListSnapshots(RequestListSnapshots) ResponseListSnapshots // List available snapshots
Expand Down Expand Up @@ -197,7 +203,7 @@ func (app *GRPCApplication) ExtendVote(
func (app *GRPCApplication) VerifyVoteExtension(
ctx context.Context, req *RequestVerifyVoteExtension) (*ResponseVerifyVoteExtension, error) {
res := app.app.VerifyVoteExtension(*req)
return &res, nil
return &res, nil
}

func (app *GRPCApplication) PrepareProposal(
Expand Down
4 changes: 2 additions & 2 deletions abci/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func ToRequestExtendVote(req RequestExtendVote) *Request {
func ToRequestVerifyVoteExtension(req RequestVerifyVoteExtension) *Request {
return &Request{
Value: &Request_VerifyVoteExtension{&req},
}
}
}

func ToRequestPrepareProposal(req RequestPrepareProposal) *Request {
Expand Down Expand Up @@ -228,7 +228,7 @@ func ToResponseExtendVote(res ResponseExtendVote) *Response {
func ToResponseVerifyVoteExtension(res ResponseVerifyVoteExtension) *Response {
return &Response{
Value: &Response_VerifyVoteExtension{&res},
}
}
}

func ToResponsePrepareProposal(res ResponsePrepareProposal) *Response {
Expand Down
34 changes: 34 additions & 0 deletions abci/types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"

"github.com/gogo/protobuf/jsonpb"

types "github.com/tendermint/tendermint/proto/tendermint/types"
)

const (
Expand Down Expand Up @@ -41,6 +43,16 @@ func (r ResponseQuery) IsErr() bool {
return r.Code != CodeTypeOK
}

// IsOK returns true if Code is OK
func (r ResponseVerifyVoteExtension) IsOK() bool {
return r.Result <= ResponseVerifyVoteExtension_ACCEPT
}

// IsErr returns true if Code is something other than OK.
func (r ResponseVerifyVoteExtension) IsErr() bool {
return r.Result > ResponseVerifyVoteExtension_ACCEPT
}

//---------------------------------------------------------------------------
// override JSON marshaling so we emit defaults (ie. disable omitempty)

Expand Down Expand Up @@ -118,3 +130,25 @@ var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
var _ jsonRoundTripper = (*ResponseCheckTx)(nil)

var _ jsonRoundTripper = (*EventAttribute)(nil)

// -----------------------------------------------
// construct Result data

func RespondExtendVote(appDataToSign, appDataSelfAuthenticating []byte) ResponseExtendVote {
return ResponseExtendVote{
VoteExtension: &types.VoteExtension{
AppDataToSign: appDataToSign,
AppDataSelfAuthenticating: appDataSelfAuthenticating,
},
}
}

func RespondVerifyVoteExtension(ok bool) ResponseVerifyVoteExtension {
result := ResponseVerifyVoteExtension_REJECT
if ok {
result = ResponseVerifyVoteExtension_ACCEPT
}
return ResponseVerifyVoteExtension{
Result: result,
}
}
Loading