mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-04 11:02:06 +00:00
[cherry-picked] ABCI Vote Extension 2 (#6885)
* add proto, add boilerplates * add canonical * fix tests * add vote signing test * Update internal/consensus/msgs_test.go * modify state execution in progress * add extension signing * add extension signing * VoteExtension -> ExtendVote * modify state execution in progress * add extension signing * verify in progress * modify CommitSig * fix test * apply review * update data structures * Apply suggestions from code review * Add comments * fix test * VoteExtensionSigned => VoteExtensionToSigned * Apply suggestions from code review Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> * *Signed -> *ToSign * add Vote to RequestExtendVote * add example VoteExtension * apply reviews * fix vote * Apply suggestions from code review Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> * fix typo, modify proto * add abcipp_kvstore.go * add extension test * fix test * fix test * fix test * fit lint * uncomment test * refactor test in progress * gofmt * apply review * fix lint Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
This commit is contained in:
@@ -720,6 +720,7 @@ func (cs *CommitSig) ToProto() *tmproto.CommitSig {
|
||||
ValidatorAddress: cs.ValidatorAddress,
|
||||
Timestamp: cs.Timestamp,
|
||||
Signature: cs.Signature,
|
||||
VoteExtension: cs.VoteExtension.ToProto(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,6 +732,7 @@ func (cs *CommitSig) FromProto(csp tmproto.CommitSig) error {
|
||||
cs.ValidatorAddress = csp.ValidatorAddress
|
||||
cs.Timestamp = csp.Timestamp
|
||||
cs.Signature = csp.Signature
|
||||
cs.VoteExtension = VoteExtensionToSignFromProto(csp.VoteExtension)
|
||||
|
||||
return cs.ValidateBasic()
|
||||
}
|
||||
|
||||
@@ -52,12 +52,34 @@ type VoteExtensionToSign struct {
|
||||
AppDataToSign []byte `json:"app_data_to_sign"`
|
||||
}
|
||||
|
||||
func (ext VoteExtensionToSign) ToProto() *tmproto.VoteExtensionToSign {
|
||||
if ext.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
return &tmproto.VoteExtensionToSign{
|
||||
AppDataToSign: ext.AppDataToSign,
|
||||
}
|
||||
}
|
||||
|
||||
func VoteExtensionToSignFromProto(pext *tmproto.VoteExtensionToSign) VoteExtensionToSign {
|
||||
if pext == nil {
|
||||
return VoteExtensionToSign{}
|
||||
}
|
||||
return VoteExtensionToSign{
|
||||
AppDataToSign: pext.AppDataToSign,
|
||||
}
|
||||
}
|
||||
|
||||
func (ext VoteExtensionToSign) IsEmpty() bool {
|
||||
return len(ext.AppDataToSign) == 0
|
||||
}
|
||||
|
||||
// BytesPacked returns a bytes-packed representation for
|
||||
// debugging and human identification. This function should
|
||||
// not be used for any logical operations.
|
||||
func (ext VoteExtensionToSign) BytesPacked() []byte {
|
||||
res := make([]byte, len(ext.AppDataToSign))
|
||||
copy(res, ext.AppDataToSign)
|
||||
res := []byte{}
|
||||
res = append(res, ext.AppDataToSign...)
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -86,9 +108,9 @@ func (ext VoteExtension) ToSign() VoteExtensionToSign {
|
||||
// debugging and human identification. This function should
|
||||
// not be used for any logical operations.
|
||||
func (ext VoteExtension) BytesPacked() []byte {
|
||||
res := make([]byte, len(ext.AppDataToSign)+len(ext.AppDataSelfAuthenticating))
|
||||
copy(res[:len(ext.AppDataToSign)], ext.AppDataToSign)
|
||||
copy(res[len(ext.AppDataToSign):], ext.AppDataSelfAuthenticating)
|
||||
res := []byte{}
|
||||
res = append(res, ext.AppDataToSign...)
|
||||
res = append(res, ext.AppDataSelfAuthenticating...)
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -257,11 +279,9 @@ func (vote *Vote) ValidateBasic() error {
|
||||
|
||||
func (ext VoteExtension) Copy() VoteExtension {
|
||||
res := VoteExtension{
|
||||
AppDataToSign: make([]byte, len(ext.AppDataToSign)),
|
||||
AppDataSelfAuthenticating: make([]byte, len(ext.AppDataSelfAuthenticating)),
|
||||
AppDataToSign: ext.AppDataToSign,
|
||||
AppDataSelfAuthenticating: ext.AppDataSelfAuthenticating,
|
||||
}
|
||||
copy(res.AppDataToSign, ext.AppDataToSign)
|
||||
copy(res.AppDataSelfAuthenticating, ext.AppDataSelfAuthenticating)
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user