Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: checkpointing/implement cli #78

Merged
merged 5 commits into from
Jul 28, 2022
Merged

Conversation

gitferry
Copy link
Contributor

This PR fixes BM-40.

In particular, this PR implements tx and query cli for the checkpointing module.

I also added @vitsalis as a reviewer since this PR is mostly influenced by btclightclient's cli.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Some comments:

@@ -69,6 +70,14 @@ func (sig Signature) Equal(s Signature) bool {
return string(sig) == string(s)
}

func NewBLSSigFromHex(s string) (Signature, error) {
return hex.DecodeString(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way, you do not perform the checks that unmarshal does. Overall, in order to ensure consistency, you should try to use only one entry point. Something like this:

Suggested change
return hex.DecodeString(s)
bz, err := hex.DecodeString(s)
if err != nil {
return nil, err
}
var sig Signature
sig.Unmarshal(bz)
return sig, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

}

func (sig Signature) String() string {
return hex.EncodeToString(sig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return hex.EncodeToString(sig)
return hex.EncodeToString(sig.MustMarshal())

x/checkpointing/client/cli/query.go Show resolved Hide resolved
@@ -86,6 +87,10 @@ func (cm *RawCheckpointWithMeta) Accumulate(
return true, nil
}

func NewLastCommitHashFromHex(s string) (LastCommitHash, error) {
return hex.DecodeString(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decode first and then use unmarshall so checks are performed


var (
// Ensure that MsgInsertHeader implements all functions of the Msg interface
_ sdk.Msg = (*MsgAddBlsSig)(nil)
)

func NewMsgAddBlsSig(epochNum uint64, lch LastCommitHash, sig bls12381.Signature, addr sdk.ValAddress) (*MsgAddBlsSig, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for an error here, at least at this point.

sdkCtx := sdk.UnwrapSDKContext(ctx)

store := k.CheckpointsState(sdkCtx).checkpoints
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key parameter is not used, maybe replace with _?

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the following comments, LGTM!

}

func (sig Signature) String() (string, error) {
bz, err := sig.Marshal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use MustMarshal here? If something succeeded in becoming a Signature, then if we cannot marshal it, this means that something went super wrong.

// CmdRawCheckpointList defines the cobra command to query raw checkpoints by status
func CmdRawCheckpointList() *cobra.Command {
cmd := &cobra.Command{
Use: "raw-checkpoint-list [epoch_number]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says querying checkpoints by status, but the parameter is the epoch_number.


status, exists := types.CheckpointStatus_value[args[0]]
if !exists {
return errors.New("checkpoint not found")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message should denote that the status parameter does not correspond to a valid status.

}

func (lch *LastCommitHash) Unmarshal(bz []byte) error {
*lch = bz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to perform any checks here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need that because Cosmos is not aware of the content of the LastCommitHash, which comes from Tendermint. Thanks for pointing that out though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are not checking something like the length, because the canonic hash to be signed is in the checkpoint. If they send anything else, it will just be rejected.

@gitferry gitferry merged commit 2f29b18 into main Jul 28, 2022
@gitferry gitferry deleted the checkpointing/create-bls-sig-tx branch July 28, 2022 03:17

func CmdTxAddBlsSig() *cobra.Command {
cmd := &cobra.Command{
Use: "submit [epoch_number] [last_commit_hash] [bls_sig] [signer address]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it rather ask for the BLS private key file for example, or the name of the BLS key in the keyring, so that it can sign for you? Or maybe have a CLI command to sign, before you can call submit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this CLI is just for submission. Signing will be in a future CLI

return err
}

return clientCtx.PrintProto(res)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will print the raw checkpoint in JSON, which has a field that you should sign, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you meaning signing LastCommitHash and the epoch number using the querier's BLS private key? If so, yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants