108 lines
3.2 KiB
Go
108 lines
3.2 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/gob"
|
|
|
|
"cosmossdk.io/core/store"
|
|
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
|
|
|
"git.vdb.to/cerc-io/laconicd/server/distsig"
|
|
"git.vdb.to/cerc-io/laconicd/x/onboarding"
|
|
)
|
|
|
|
func (app *LaconicApp[T]) ExtendVote(
|
|
ctx context.Context, _ store.ReaderMap, req *abci.ExtendVoteRequest,
|
|
) (*abci.ExtendVoteResponse, error) {
|
|
dsm := app.DistSigManager()
|
|
ourEthAddress := dsm.LongtermEthAddress()
|
|
us, err := app.OnboardingKeeper.GetParticipantByNitroAddress(ctx, ourEthAddress.String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if us == nil { // if we are not a participant, we don't need to do anything
|
|
return nil, nil
|
|
}
|
|
|
|
// // If any OnboardParticipant tx (or any tx that changes validator set) has been processed,
|
|
// // begin DKG for the new participants. The extension will contain our DKG deals.
|
|
// newParticipants := false
|
|
// for _, tx := range req.Txs {
|
|
// var opMsg onboarding.MsgOnboardParticipant
|
|
// if err := opMsg.Unmarshal(tx); err != nil {
|
|
// // we've already processed the tx, so we don't need to look at the message; we know the
|
|
// // participant set has changed and we need to run DKG.
|
|
// newParticipants = true
|
|
// }
|
|
// }
|
|
// // TODO: check if responses are processed, generate commits
|
|
// if !newParticipants {
|
|
// return nil, nil
|
|
// }
|
|
|
|
// Get public keys of participants
|
|
var pubkeys []distsig.Point
|
|
if err := app.OnboardingKeeper.Participants.Walk(ctx, nil, func(_ string, p onboarding.Participant) (bool, error) {
|
|
var pubkey distsig.Point
|
|
if err := pubkey.UnmarshalBinary(p.PublicKey); err != nil {
|
|
return false, err
|
|
}
|
|
pubkeys = append(pubkeys, pubkey)
|
|
return false, nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
if !dsm.NeedDKG(pubkeys) {
|
|
app.Logger().Debug("No change in DSS participants")
|
|
return nil, nil
|
|
}
|
|
|
|
if err = dsm.StartDKG(req.Height, pubkeys); err != nil {
|
|
return nil, err
|
|
}
|
|
buf := new(bytes.Buffer)
|
|
enc := gob.NewEncoder(buf)
|
|
if err := enc.Encode(dsm.FlushDKGMessages()); err != nil {
|
|
return nil, err
|
|
}
|
|
var extension []byte
|
|
if len(buf.Bytes()) != 0 {
|
|
extension = buf.Bytes()
|
|
}
|
|
return &abci.ExtendVoteResponse{
|
|
VoteExtension: extension,
|
|
}, nil
|
|
}
|
|
|
|
func (app *LaconicApp[T]) VerifyVoteExtension(
|
|
ctx context.Context, _ store.ReaderMap, req *abci.VerifyVoteExtensionRequest,
|
|
) (*abci.VerifyVoteExtensionResponse, error) {
|
|
dec := gob.NewDecoder(bytes.NewReader(req.VoteExtension))
|
|
var messages distsig.DkgMessages
|
|
if err := dec.Decode(&messages); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// // This method must be deterministic, so just check that there is a deal for each participant
|
|
// numParticipants := 0
|
|
// app.OnboardingKeeper.Participants.Walk(ctx, nil, func(string, onboarding.Participant) (bool, error) {
|
|
// numParticipants++
|
|
// return false, nil
|
|
// })
|
|
// if len(deals) != numParticipants {
|
|
// return &abci.VerifyVoteExtensionResponse{
|
|
// Status: abci.VERIFY_VOTE_EXTENSION_STATUS_REJECT,
|
|
// }, nil
|
|
// }
|
|
|
|
err := app.DistSigManager().ProcessDKGMessages(&messages)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// This method must be deterministic, so just accept whatever for now (TODO: actually verify)
|
|
return &abci.VerifyVoteExtensionResponse{
|
|
Status: abci.VERIFY_VOTE_EXTENSION_STATUS_ACCEPT,
|
|
}, nil
|
|
}
|