From 9f581dd850183ead2e16711339087f4d20cc6e47 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Tue, 6 Sep 2022 20:02:27 +0800 Subject: [PATCH 1/4] fixed sending bls-sig tx --- app/utils.go | 26 +++++++++++----- cmd/babylond/cmd/testnet.go | 2 +- go.mod | 4 +-- go.sum | 8 ++--- privval/file.go | 12 +++++++- testutil/datagen/init_val.go | 8 +++-- x/btccheckpoint/types/query.pb.gw.go | 9 ++++-- x/btclightclient/types/query.pb.gw.go | 29 ++++++++++++++---- x/checkpointing/abci.go | 2 ++ x/checkpointing/keeper/bls_signer.go | 12 +++++++- x/checkpointing/keeper/keeper.go | 2 +- x/checkpointing/keeper/msg_server.go | 2 ++ x/checkpointing/types/query.pb.gw.go | 44 +++++++++++++++++++++------ x/checkpointing/types/types.go | 37 ++++++++++++---------- x/epoching/types/query.pb.gw.go | 24 ++++++++++++--- 15 files changed, 163 insertions(+), 58 deletions(-) diff --git a/app/utils.go b/app/utils.go index 5f60da75b..c456bee95 100644 --- a/app/utils.go +++ b/app/utils.go @@ -3,8 +3,8 @@ package app import ( "github.com/babylonchain/babylon/privval" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" tmconfig "github.com/tendermint/tendermint/config" @@ -21,12 +21,12 @@ type PrivSigner struct { func InitClientContext(clientCtx client.Context, backend string) (*PrivSigner, error) { // setup private validator nodeCfg := tmconfig.DefaultConfig() - pvKeyFile := nodeCfg.PrivValidatorKeyFile() + pvKeyFile := filepath.Join(".testnet/node0/babylond", nodeCfg.PrivValidatorKeyFile()) err := tmos.EnsureDir(filepath.Dir(pvKeyFile), 0777) if err != nil { return nil, err } - pvStateFile := nodeCfg.PrivValidatorStateFile() + pvStateFile := filepath.Join(".testnet/node0/babylond", nodeCfg.PrivValidatorStateFile()) err = tmos.EnsureDir(filepath.Dir(pvStateFile), 0777) if err != nil { return nil, err @@ -43,14 +43,26 @@ func InitClientContext(clientCtx client.Context, backend string) (*PrivSigner, e WithTxConfig(encodingCfg.TxConfig). WithAccountRetriever(types.AccountRetriever{}). WithInput(os.Stdin). - WithBroadcastMode(flags.BroadcastAsync). - WithFromAddress(sdk.AccAddress(wrappedPV.GetAddress())) + WithBroadcastMode(flags.BroadcastBlock). + WithFromAddress(sdk.AccAddress(wrappedPV.GetAddress())). + WithFeeGranterAddress(sdk.AccAddress(wrappedPV.GetAddress())). + WithViper(""). + WithFromName("node0"). + WithChainID("chain-test"). + WithSkipConfirmation(true) + clientCtx, err = config.ReadFromClientConfig(clientCtx) + if err != nil { + return nil, err + } + clientCtx.KeyringDir = "/Users/lanpo/Worksapce/babylon/.testnet/node0/babylond" + kb, err := client.NewKeyringFromBackend(clientCtx, backend) - kb, err := keyring.New(sdk.KeyringServiceName(), backend, DefaultNodeHome, clientCtx.Input) + //kb, err := keyring.New(sdk.KeyringServiceName(), backend, DefaultNodeHome, clientCtx.Input) + //kb, err := keyring.New(sdk.KeyringServiceName(), backend, keyringPath, clientCtx.Input) if err != nil { return nil, err } - clientCtx.WithKeyring(kb) + clientCtx = clientCtx.WithKeyring(kb).WithChainID("chain-test").WithBroadcastMode(flags.BroadcastBlock) return &PrivSigner{ WrappedPV: wrappedPV, diff --git a/cmd/babylond/cmd/testnet.go b/cmd/babylond/cmd/testnet.go index b8c6c7640..6504ea32d 100644 --- a/cmd/babylond/cmd/testnet.go +++ b/cmd/babylond/cmd/testnet.go @@ -185,7 +185,7 @@ func InitTestnet( } // generate validator keys - nodeIDs[i], valKeys[i], err = datagen.InitializeNodeValidatorFiles(nodeConfig) + nodeIDs[i], valKeys[i], err = datagen.InitializeNodeValidatorFiles(nodeConfig, addr) if err != nil { _ = os.RemoveAll(outputDir) return err diff --git a/go.mod b/go.mod index c6e4cf5c9..bb364261c 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/supranational/blst v0.3.8 github.com/tendermint/tendermint v0.34.19 github.com/tendermint/tm-db v0.6.6 - google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f + google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc google.golang.org/grpc v1.48.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -28,7 +28,7 @@ require ( github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d github.com/golang/mock v1.6.0 github.com/regen-network/cosmos-proto v0.3.1 - google.golang.org/protobuf v1.28.0 + google.golang.org/protobuf v1.28.1 ) require ( diff --git a/go.sum b/go.sum index 117150e22..d2b40da04 100644 --- a/go.sum +++ b/go.sum @@ -1462,8 +1462,8 @@ google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f h1:P8EiVSxZwC6xH2niv2N66aqwMtYFg+D54gbjpcqKJtM= -google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= +google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI= +google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= @@ -1480,8 +1480,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/privval/file.go b/privval/file.go index 680223e15..fc82cc6ea 100644 --- a/privval/file.go +++ b/privval/file.go @@ -40,6 +40,7 @@ func voteToStep(vote *tmproto.Vote) int8 { // WrappedFilePVKey wraps FilePVKey with BLS keys. type WrappedFilePVKey struct { + AccAddress string `json:"acc_address"` Address types.Address `json:"address"` PubKey tmcrypto.PubKey `json:"pub_key"` PrivKey tmcrypto.PrivKey `json:"priv_key"` @@ -165,7 +166,16 @@ func LoadOrGenWrappedFilePV(keyFilePath, stateFilePath string) *WrappedFilePV { // GetAddress returns the address of the validator. // Implements PrivValidator. func (pv *WrappedFilePV) GetAddress() sdk.ValAddress { - return sdk.ValAddress(pv.Key.Address) + addr, err := sdk.AccAddressFromBech32(pv.Key.AccAddress) + if err != nil { + panic(err) + } + return sdk.ValAddress(addr) +} + +func (pv *WrappedFilePV) SetAccAddress(addr sdk.AccAddress) { + pv.Key.AccAddress = addr.String() + pv.Key.Save() } // GetPubKey returns the public key of the validator. diff --git a/testutil/datagen/init_val.go b/testutil/datagen/init_val.go index 4354eee62..8d59ad425 100644 --- a/testutil/datagen/init_val.go +++ b/testutil/datagen/init_val.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/babylonchain/babylon/crypto/bls12381" "github.com/babylonchain/babylon/privval" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" cfg "github.com/tendermint/tendermint/config" tmed25519 "github.com/tendermint/tendermint/crypto/ed25519" @@ -13,11 +14,11 @@ import ( ) // InitializeNodeValidatorFiles creates private validator and p2p configuration files. -func InitializeNodeValidatorFiles(config *cfg.Config) (string, *privval.ValidatorKeys, error) { - return InitializeNodeValidatorFilesFromMnemonic(config, "") +func InitializeNodeValidatorFiles(config *cfg.Config, addr sdk.AccAddress) (string, *privval.ValidatorKeys, error) { + return InitializeNodeValidatorFilesFromMnemonic(config, "", addr) } -func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic string) (nodeID string, valKeys *privval.ValidatorKeys, err error) { +func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic string, addr sdk.AccAddress) (nodeID string, valKeys *privval.ValidatorKeys, err error) { if len(mnemonic) > 0 && !bip39.IsMnemonicValid(mnemonic) { return "", nil, fmt.Errorf("invalid mnemonic") } @@ -47,6 +48,7 @@ func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic strin blsPrivKey := bls12381.GenPrivKeyFromSecret([]byte(mnemonic)) filePV = privval.NewWrappedFilePV(privKey, blsPrivKey, pvKeyFile, pvStateFile) } + filePV.SetAccAddress(addr) valPrivkey := filePV.GetValPrivKey() blsPrivkey := filePV.GetBlsPrivKey() diff --git a/x/btccheckpoint/types/query.pb.gw.go b/x/btccheckpoint/types/query.pb.gw.go index 508b2bd79..1182a8bb4 100644 --- a/x/btccheckpoint/types/query.pb.gw.go +++ b/x/btccheckpoint/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -52,12 +54,14 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -65,6 +69,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -140,7 +145,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylonchain", "babylon", "btccheckpoint", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylonchain", "babylon", "btccheckpoint", "params"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/x/btclightclient/types/query.pb.gw.go b/x/btclightclient/types/query.pb.gw.go index 7811e6661..08aa8777a 100644 --- a/x/btclightclient/types/query.pb.gw.go +++ b/x/btclightclient/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -178,12 +180,14 @@ func local_request_Query_Tip_0(ctx context.Context, marshaler runtime.Marshaler, // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -191,6 +195,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -204,6 +209,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Hashes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -211,6 +218,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Hashes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -224,6 +232,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Contains_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -231,6 +241,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Contains_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -244,6 +255,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_MainChain_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -251,6 +264,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_MainChain_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -264,6 +278,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Tip_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -271,6 +287,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Tip_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -426,15 +443,15 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "params"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Hashes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "hashes"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Hashes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "hashes"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Contains_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "contains"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Contains_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "contains"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_MainChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "mainchain"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_MainChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "mainchain"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Tip_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "tip"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Tip_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "tip"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/x/checkpointing/abci.go b/x/checkpointing/abci.go index de9f7bfaf..4d25c03a4 100644 --- a/x/checkpointing/abci.go +++ b/x/checkpointing/abci.go @@ -1,6 +1,7 @@ package checkpointing import ( + "fmt" "time" "github.com/babylonchain/babylon/x/checkpointing/types" @@ -43,6 +44,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, req abci.RequestBeginBlock) } go func() { + ctx.Logger().Info("sending bls sig", "bls sig message for epoch", fmt.Sprintf("%v", epoch.EpochNumber-1)) err = k.SendBlsSig(ctx, epoch.EpochNumber-1, lch) if err != nil { panic(err) diff --git a/x/checkpointing/keeper/bls_signer.go b/x/checkpointing/keeper/bls_signer.go index d599b060c..b43b5d428 100644 --- a/x/checkpointing/keeper/bls_signer.go +++ b/x/checkpointing/keeper/bls_signer.go @@ -1,8 +1,10 @@ package keeper import ( + "fmt" "github.com/babylonchain/babylon/crypto/bls12381" "github.com/babylonchain/babylon/x/checkpointing/types" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/pflag" @@ -24,7 +26,8 @@ func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommi _, _, err := curValSet.FindValidatorWithIndex(addr) if err != nil { // only send the BLS sig when the node itself is a validator - return nil + ctx.Logger().Info("node itself is not validator", "validator set", fmt.Sprintf("%v, itself addr: %v", curValSet, addr)) + return err } // get BLS signature by signing @@ -36,10 +39,17 @@ func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommi // create MsgAddBlsSig message msg := types.NewMsgAddBlsSig(epochNum, lch, blsSig, addr) + ctx.Logger().Info("sending bls sig", "keyring", fmt.Sprintf("%v", k.clientCtx.Keyring)) + ctx.Logger().Info("sending bls sig", "keyring dir", fmt.Sprintf("%v", k.clientCtx.KeyringDir)) // insert the message into the transaction fs := pflag.NewFlagSet("", pflag.ContinueOnError) + fs.String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10uatom") + + err = fs.Set(flags.FlagFees, "100stake") + //err = fs.Set(flags.FlagGasPrices, "1stake") err = tx.GenerateOrBroadcastTxCLI(k.clientCtx, fs, msg) + ctx.Logger().Info("bls sig sent", "bls sig message", fmt.Sprintf("%v", msg)) if err != nil { return err } diff --git a/x/checkpointing/keeper/keeper.go b/x/checkpointing/keeper/keeper.go index c70731ac8..b85dd1bd9 100644 --- a/x/checkpointing/keeper/keeper.go +++ b/x/checkpointing/keeper/keeper.go @@ -97,7 +97,7 @@ func (k Keeper) addBlsSig(ctx sdk.Context, sig *types.BlsSig) error { } // accumulate BLS signatures - updated, err := ckptWithMeta.Accumulate( + updated, err := ckptWithMeta.Accumulate(ctx, vals, signerAddr, signerBlsKey, *sig.BlsSig, k.GetTotalVotingPower(ctx, sig.GetEpochNum())) if err != nil { return err diff --git a/x/checkpointing/keeper/msg_server.go b/x/checkpointing/keeper/msg_server.go index a8f73cb0d..ca507c2d2 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -3,6 +3,7 @@ package keeper import ( "context" "errors" + "fmt" epochingtypes "github.com/babylonchain/babylon/x/epoching/types" ed255192 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -26,6 +27,7 @@ var _ types.MsgServer = msgServer{} // AddBlsSig adds BLS sig messages and changes a raw checkpoint status to SEALED if sufficient voting power is accumulated func (m msgServer) AddBlsSig(goCtx context.Context, msg *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + m.k.Logger(ctx).Info("Checkpointing", "BLS sig", fmt.Sprintf("%v", msg.BlsSig)) err := m.k.addBlsSig(ctx, msg.BlsSig) if err != nil { diff --git a/x/checkpointing/types/query.pb.gw.go b/x/checkpointing/types/query.pb.gw.go index d578b387c..84408500b 100644 --- a/x/checkpointing/types/query.pb.gw.go +++ b/x/checkpointing/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join var ( filter_Query_RawCheckpointList_0 = &utilities.DoubleArray{Encoding: map[string]int{"status": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} @@ -436,12 +438,14 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_RawCheckpointList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -449,6 +453,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_RawCheckpointList_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -462,6 +467,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_RecentRawCheckpointList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -469,6 +476,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_RecentRawCheckpointList_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -482,6 +490,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_RawCheckpoint_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -489,6 +499,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_RawCheckpoint_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -502,6 +513,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_LatestCheckpoint_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -509,6 +522,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_LatestCheckpoint_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -522,6 +536,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_BlsPublicKeyList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -529,6 +545,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_BlsPublicKeyList_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -542,6 +559,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_EpochStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -549,6 +568,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_EpochStatus_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -562,6 +582,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_RecentEpochStatusCount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -569,6 +591,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_RecentEpochStatusCount_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -582,6 +605,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -589,6 +614,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -804,21 +830,21 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_RawCheckpointList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "raw_checkpoints", "status"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RawCheckpointList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "raw_checkpoints", "status"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_RecentRawCheckpointList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "recent_raw_checkpoints", "from_epoch_num"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RecentRawCheckpointList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "recent_raw_checkpoints", "from_epoch_num"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_RawCheckpoint_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "raw_checkpoint", "epoch_num"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RawCheckpoint_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "raw_checkpoint", "epoch_num"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_LatestCheckpoint_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "checkpointing", "v1", "latest_checkpoint"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_LatestCheckpoint_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "checkpointing", "v1", "latest_checkpoint"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_BlsPublicKeyList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "bls_public_keys", "epoch_num"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_BlsPublicKeyList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "checkpointing", "v1", "bls_public_keys", "epoch_num"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_EpochStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"babylon", "checkpointing", "v1", "epoch", "epoch_num", "status"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_EpochStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"babylon", "checkpointing", "v1", "epoch", "epoch_num", "status"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_RecentEpochStatusCount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "checkpointing", "v1", "epochs"}, "status_count", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RecentEpochStatusCount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "checkpointing", "v1", "epochs"}, "status_count", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "checkpointing", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "checkpointing", "v1", "params"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index 4b1d4b271..707a1b365 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -5,9 +5,9 @@ import ( "crypto/sha256" "encoding/hex" "errors" + "fmt" "github.com/babylonchain/babylon/crypto/bls12381" epochingtypes "github.com/babylonchain/babylon/x/epoching/types" - "github.com/boljen/go-bitmap" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -46,6 +46,7 @@ func NewCheckpointWithMeta(ckpt *RawCheckpoint, status CheckpointStatus) *RawChe // 4. accumulates voting power // it returns True if the checkpoint is updated func (cm *RawCheckpointWithMeta) Accumulate( + ctx sdk.Context, vals epochingtypes.ValidatorSet, signerAddr sdk.ValAddress, signerBlsKey bls12381.PublicKey, @@ -58,38 +59,42 @@ func (cm *RawCheckpointWithMeta) Accumulate( } // get validator and its index - val, index, err := vals.FindValidatorWithIndex(signerAddr) + val, _, err := vals.FindValidatorWithIndex(signerAddr) if err != nil { return false, err } // return an error if the validator has already voted - if bitmap.Get(cm.Ckpt.Bitmap, index) { - return false, ErrCkptAlreadyVoted - } + //if bitmap.Get(cm.Ckpt.Bitmap, index) { + // return false, ErrCkptAlreadyVoted + //} // aggregate BLS sig - aggSig, err := bls12381.AggrSig(*cm.Ckpt.BlsMultiSig, sig) - if err != nil { - return false, err - } - cm.Ckpt.BlsMultiSig = &aggSig + //aggSig, err := bls12381.AggrSig(*cm.Ckpt.BlsMultiSig, sig) + //if err != nil { + // return false, err + //} + cm.Ckpt.BlsMultiSig = &sig + ctx.Logger().Info("accumulating bls sig", "aggregate sig", fmt.Sprintf("%x", sig.Bytes())) // aggregate BLS public key - aggPK, err := bls12381.AggrPK(*cm.BlsAggrPk, signerBlsKey) - if err != nil { - return false, err - } - cm.BlsAggrPk = &aggPK + //aggPK, err := bls12381.AggrPK(*cm.BlsAggrPk, signerBlsKey) + //if err != nil { + // return false, err + //} + cm.BlsAggrPk = &signerBlsKey + ctx.Logger().Info("accumulating bls sig", "aggregate pk", fmt.Sprintf("%x", signerBlsKey.Bytes())) // update bitmap - bitmap.Set(cm.Ckpt.Bitmap, index, true) + //bitmap.Set(cm.Ckpt.Bitmap, index, true) + ctx.Logger().Info("accumulating bls sig", "bitmap", fmt.Sprintf("%x", cm.Ckpt.Bitmap)) // accumulate voting power and update status when the threshold is reached cm.PowerSum += uint64(val.Power) if int64(cm.PowerSum) > totalPower/3 { cm.Status = Sealed } + ctx.Logger().Info("accumulating bls sig", "status", fmt.Sprintf("%v", cm.Status)) return true, nil } diff --git a/x/epoching/types/query.pb.gw.go b/x/epoching/types/query.pb.gw.go index fd1b27985..aad446a78 100644 --- a/x/epoching/types/query.pb.gw.go +++ b/x/epoching/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -196,12 +198,14 @@ func local_request_Query_ValidatorLifecycle_0(ctx context.Context, marshaler run // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -209,6 +213,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -222,6 +227,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_CurrentEpoch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -229,6 +236,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_CurrentEpoch_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -242,6 +250,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_EpochMsgs_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -249,6 +259,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_EpochMsgs_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -262,6 +273,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_ValidatorLifecycle_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -269,6 +282,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_ValidatorLifecycle_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -404,13 +418,13 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "epoching", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "epoching", "v1", "params"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_CurrentEpoch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "epoching", "v1", "current_epoch"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_CurrentEpoch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "epoching", "v1", "current_epoch"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_EpochMsgs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "epoching", "v1", "epoch_msgs", "epoch_num"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_EpochMsgs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "epoching", "v1", "epoch_msgs", "epoch_num"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_ValidatorLifecycle_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "epoching", "v1", "validator_lifecycle", "val_addr"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_ValidatorLifecycle_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"babylon", "epoching", "v1", "validator_lifecycle", "val_addr"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( From 87be66c36d084f6afaaa64c343c4bdeccb37714d Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Wed, 7 Sep 2022 15:40:09 +0800 Subject: [PATCH 2/4] add flags to startCmd --- README.md | 5 +++- app/test_helpers.go | 2 +- app/utils.go | 37 ++++++++-------------------- cmd/babylond/cmd/root.go | 33 ++++++++++++++++--------- go.mod | 4 +-- go.sum | 8 +++--- privval/file.go | 3 +++ x/checkpointing/abci.go | 2 -- x/checkpointing/keeper/bls_signer.go | 11 +++------ x/checkpointing/keeper/keeper.go | 2 +- x/checkpointing/keeper/msg_server.go | 3 --- x/checkpointing/types/types.go | 4 --- 12 files changed, 49 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index b538ff622..542e7b50b 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,10 @@ A brief description of the contents: ### Running the node ```console -babylond start --home ./.testnet/node0/babylond +babylond start --home ./.testnet/node0/babylond \ + --keyring-backend test \ + --chain-id chain-test \ + --from node0 ``` ### Logs diff --git a/app/test_helpers.go b/app/test_helpers.go index 11446bab0..9d6aa1a19 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -94,7 +94,7 @@ func Setup(isCheckTx bool) *BabylonApp { // SetupPrivSigner sets up a PrivSigner for testing func SetupPrivSigner() (*PrivSigner, error) { nodeCfg := tmconfig.DefaultConfig() - privSigner, _ := InitClientContext(client.Context{}, keyring.BackendMemory) + privSigner, _ := InitPrivSigner(client.Context{}, ".", keyring.BackendMemory) privSigner.WrappedPV.Clean(nodeCfg.PrivValidatorKeyFile(), nodeCfg.PrivValidatorStateFile()) return privSigner, nil } diff --git a/app/utils.go b/app/utils.go index c456bee95..9d1a52165 100644 --- a/app/utils.go +++ b/app/utils.go @@ -3,13 +3,10 @@ package app import ( "github.com/babylonchain/babylon/privval" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/config" - "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" tmconfig "github.com/tendermint/tendermint/config" tmos "github.com/tendermint/tendermint/libs/os" - "os" "path/filepath" ) @@ -18,15 +15,15 @@ type PrivSigner struct { ClientCtx client.Context } -func InitClientContext(clientCtx client.Context, backend string) (*PrivSigner, error) { +func InitPrivSigner(clientCtx client.Context, nodeDir string, backEnd string) (*PrivSigner, error) { // setup private validator nodeCfg := tmconfig.DefaultConfig() - pvKeyFile := filepath.Join(".testnet/node0/babylond", nodeCfg.PrivValidatorKeyFile()) + pvKeyFile := filepath.Join(nodeDir, nodeCfg.PrivValidatorKeyFile()) err := tmos.EnsureDir(filepath.Dir(pvKeyFile), 0777) if err != nil { return nil, err } - pvStateFile := filepath.Join(".testnet/node0/babylond", nodeCfg.PrivValidatorStateFile()) + pvStateFile := filepath.Join(nodeDir, nodeCfg.PrivValidatorStateFile()) err = tmos.EnsureDir(filepath.Dir(pvStateFile), 0777) if err != nil { return nil, err @@ -35,34 +32,20 @@ func InitClientContext(clientCtx client.Context, backend string) (*PrivSigner, e // setup client context encodingCfg := MakeTestEncodingConfig() - clientCtx = client.Context{}. - WithHomeDir(DefaultNodeHome). + kb, err := client.NewKeyringFromBackend(clientCtx, backEnd) + if err != nil { + return nil, err + } + clientCtx = clientCtx. WithInterfaceRegistry(encodingCfg.InterfaceRegistry). WithCodec(encodingCfg.Marshaler). WithLegacyAmino(encodingCfg.Amino). WithTxConfig(encodingCfg.TxConfig). WithAccountRetriever(types.AccountRetriever{}). - WithInput(os.Stdin). - WithBroadcastMode(flags.BroadcastBlock). WithFromAddress(sdk.AccAddress(wrappedPV.GetAddress())). WithFeeGranterAddress(sdk.AccAddress(wrappedPV.GetAddress())). - WithViper(""). - WithFromName("node0"). - WithChainID("chain-test"). - WithSkipConfirmation(true) - clientCtx, err = config.ReadFromClientConfig(clientCtx) - if err != nil { - return nil, err - } - clientCtx.KeyringDir = "/Users/lanpo/Worksapce/babylon/.testnet/node0/babylond" - kb, err := client.NewKeyringFromBackend(clientCtx, backend) - - //kb, err := keyring.New(sdk.KeyringServiceName(), backend, DefaultNodeHome, clientCtx.Input) - //kb, err := keyring.New(sdk.KeyringServiceName(), backend, keyringPath, clientCtx.Input) - if err != nil { - return nil, err - } - clientCtx = clientCtx.WithKeyring(kb).WithChainID("chain-test").WithBroadcastMode(flags.BroadcastBlock) + WithSkipConfirmation(true). + WithKeyring(kb) return &PrivSigner{ WrappedPV: wrappedPV, diff --git a/cmd/babylond/cmd/root.go b/cmd/babylond/cmd/root.go index 82193ab91..eb8f24193 100644 --- a/cmd/babylond/cmd/root.go +++ b/cmd/babylond/cmd/root.go @@ -2,7 +2,6 @@ package cmd import ( "errors" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "io" "os" "path/filepath" @@ -141,6 +140,10 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) + + startCmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") + startCmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") + startCmd.Flags().String(flags.FlagFrom, "", "Name or address of private key with which to sign") } func queryCommand() *cobra.Command { @@ -215,7 +218,8 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a panic(err) } - snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") + homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) + snapshotDir := filepath.Join(homeDir, "data", "snapshots") snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir) if err != nil { panic(err) @@ -225,14 +229,20 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a panic(err) } - // TODO: add a new flag to check whether the node is validator - //backend := appOpts.Get(flags.FlagKeyringBackend).(string) - clientCtx := client.Context{} - // TODO: comment the options below because those flags are not passed in integration test - //WithChainID(appOpts.Get(flags.FlagChainID).(string)). - //WithFromName(appOpts.Get(flags.FlagFrom).(string)) - // TODO: use BackendTest of keyring for now because the current integration test does not pass FlagKeryingBackend - privSigner, err := app.InitClientContext(clientCtx, keyring.BackendTest) + backend := cast.ToString(appOpts.Get(flags.FlagKeyringBackend)) + chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) + fromName := cast.ToString(appOpts.Get(flags.FlagFrom)) + + clientCtx, err := config.ReadFromClientConfig(client.Context{}.WithHomeDir(app.DefaultNodeHome).WithViper("")) + if err != nil { + panic(err) + } + clientCtx = clientCtx. + WithKeyringDir(homeDir). + WithChainID(chainID). + WithFromName(fromName). + WithInput(os.Stdin) + privSigner, err := app.InitPrivSigner(clientCtx, homeDir, backend) if err != nil { panic(err) } @@ -270,11 +280,10 @@ func (a appCreator) appExport( return servertypes.ExportedApp{}, errors.New("application home not set") } - backend := appOpts.Get(flags.FlagKeyringBackend).(string) clientCtx := client.Context{}. WithChainID(appOpts.Get(flags.FlagChainID).(string)). WithFromName(appOpts.Get(flags.FlagFrom).(string)) - privSigner, err := app.InitClientContext(clientCtx, backend) + privSigner, err := app.InitPrivSigner(clientCtx, "", "") if err != nil { panic(err) } diff --git a/go.mod b/go.mod index bb364261c..c6e4cf5c9 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/supranational/blst v0.3.8 github.com/tendermint/tendermint v0.34.19 github.com/tendermint/tm-db v0.6.6 - google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc + google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f google.golang.org/grpc v1.48.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -28,7 +28,7 @@ require ( github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d github.com/golang/mock v1.6.0 github.com/regen-network/cosmos-proto v0.3.1 - google.golang.org/protobuf v1.28.1 + google.golang.org/protobuf v1.28.0 ) require ( diff --git a/go.sum b/go.sum index d2b40da04..117150e22 100644 --- a/go.sum +++ b/go.sum @@ -1462,8 +1462,8 @@ google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI= -google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f h1:P8EiVSxZwC6xH2niv2N66aqwMtYFg+D54gbjpcqKJtM= +google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= @@ -1480,8 +1480,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/privval/file.go b/privval/file.go index fc82cc6ea..7db9aa277 100644 --- a/privval/file.go +++ b/privval/file.go @@ -166,6 +166,9 @@ func LoadOrGenWrappedFilePV(keyFilePath, stateFilePath string) *WrappedFilePV { // GetAddress returns the address of the validator. // Implements PrivValidator. func (pv *WrappedFilePV) GetAddress() sdk.ValAddress { + if pv.Key.AccAddress == "" { + return sdk.ValAddress{} + } addr, err := sdk.AccAddressFromBech32(pv.Key.AccAddress) if err != nil { panic(err) diff --git a/x/checkpointing/abci.go b/x/checkpointing/abci.go index 4d25c03a4..de9f7bfaf 100644 --- a/x/checkpointing/abci.go +++ b/x/checkpointing/abci.go @@ -1,7 +1,6 @@ package checkpointing import ( - "fmt" "time" "github.com/babylonchain/babylon/x/checkpointing/types" @@ -44,7 +43,6 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, req abci.RequestBeginBlock) } go func() { - ctx.Logger().Info("sending bls sig", "bls sig message for epoch", fmt.Sprintf("%v", epoch.EpochNumber-1)) err = k.SendBlsSig(ctx, epoch.EpochNumber-1, lch) if err != nil { panic(err) diff --git a/x/checkpointing/keeper/bls_signer.go b/x/checkpointing/keeper/bls_signer.go index b43b5d428..76e22e968 100644 --- a/x/checkpointing/keeper/bls_signer.go +++ b/x/checkpointing/keeper/bls_signer.go @@ -1,7 +1,6 @@ package keeper import ( - "fmt" "github.com/babylonchain/babylon/crypto/bls12381" "github.com/babylonchain/babylon/x/checkpointing/types" "github.com/cosmos/cosmos-sdk/client/flags" @@ -25,9 +24,8 @@ func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommi // check if itself is the validator _, _, err := curValSet.FindValidatorWithIndex(addr) if err != nil { - // only send the BLS sig when the node itself is a validator - ctx.Logger().Info("node itself is not validator", "validator set", fmt.Sprintf("%v, itself addr: %v", curValSet, addr)) - return err + // only send the BLS sig when the node itself is a validator, not being a validator is not an error + return nil } // get BLS signature by signing @@ -39,17 +37,14 @@ func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommi // create MsgAddBlsSig message msg := types.NewMsgAddBlsSig(epochNum, lch, blsSig, addr) - ctx.Logger().Info("sending bls sig", "keyring", fmt.Sprintf("%v", k.clientCtx.Keyring)) - ctx.Logger().Info("sending bls sig", "keyring dir", fmt.Sprintf("%v", k.clientCtx.KeyringDir)) // insert the message into the transaction fs := pflag.NewFlagSet("", pflag.ContinueOnError) + // TODO: hardcoded for now, will set fees as a parameter for the checkpointing module fs.String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10uatom") - err = fs.Set(flags.FlagFees, "100stake") //err = fs.Set(flags.FlagGasPrices, "1stake") err = tx.GenerateOrBroadcastTxCLI(k.clientCtx, fs, msg) - ctx.Logger().Info("bls sig sent", "bls sig message", fmt.Sprintf("%v", msg)) if err != nil { return err } diff --git a/x/checkpointing/keeper/keeper.go b/x/checkpointing/keeper/keeper.go index b85dd1bd9..c70731ac8 100644 --- a/x/checkpointing/keeper/keeper.go +++ b/x/checkpointing/keeper/keeper.go @@ -97,7 +97,7 @@ func (k Keeper) addBlsSig(ctx sdk.Context, sig *types.BlsSig) error { } // accumulate BLS signatures - updated, err := ckptWithMeta.Accumulate(ctx, + updated, err := ckptWithMeta.Accumulate( vals, signerAddr, signerBlsKey, *sig.BlsSig, k.GetTotalVotingPower(ctx, sig.GetEpochNum())) if err != nil { return err diff --git a/x/checkpointing/keeper/msg_server.go b/x/checkpointing/keeper/msg_server.go index ca507c2d2..5d4aca517 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -3,8 +3,6 @@ package keeper import ( "context" "errors" - "fmt" - epochingtypes "github.com/babylonchain/babylon/x/epoching/types" ed255192 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,7 +25,6 @@ var _ types.MsgServer = msgServer{} // AddBlsSig adds BLS sig messages and changes a raw checkpoint status to SEALED if sufficient voting power is accumulated func (m msgServer) AddBlsSig(goCtx context.Context, msg *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - m.k.Logger(ctx).Info("Checkpointing", "BLS sig", fmt.Sprintf("%v", msg.BlsSig)) err := m.k.addBlsSig(ctx, msg.BlsSig) if err != nil { diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index 244aef53b..455988f0c 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "encoding/hex" "errors" - "fmt" "github.com/babylonchain/babylon/crypto/bls12381" epochingtypes "github.com/babylonchain/babylon/x/epoching/types" "github.com/boljen/go-bitmap" @@ -47,7 +46,6 @@ func NewCheckpointWithMeta(ckpt *RawCheckpoint, status CheckpointStatus) *RawChe // 4. accumulates voting power // it returns True if the checkpoint is updated func (cm *RawCheckpointWithMeta) Accumulate( - ctx sdk.Context, vals epochingtypes.ValidatorSet, signerAddr sdk.ValAddress, signerBlsKey bls12381.PublicKey, @@ -94,14 +92,12 @@ func (cm *RawCheckpointWithMeta) Accumulate( // update bitmap bitmap.Set(cm.Ckpt.Bitmap, index, true) - ctx.Logger().Info("accumulating bls sig", "bitmap", fmt.Sprintf("%x", cm.Ckpt.Bitmap)) // accumulate voting power and update status when the threshold is reached cm.PowerSum += uint64(val.Power) if int64(cm.PowerSum) > totalPower/3 { cm.Status = Sealed } - ctx.Logger().Info("accumulating bls sig", "status", fmt.Sprintf("%v", cm.Status)) return true, nil } From 074efedcea78c42f1b3697258f357dbd4f4277af Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Thu, 8 Sep 2022 10:55:46 +0800 Subject: [PATCH 3/4] minor --- cmd/babylond/cmd/root.go | 4 +++- testutil/datagen/val_set.go | 4 ++-- x/checkpointing/keeper/bls_signer.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/babylond/cmd/root.go b/cmd/babylond/cmd/root.go index eb8f24193..4cf2b01ba 100644 --- a/cmd/babylond/cmd/root.go +++ b/cmd/babylond/cmd/root.go @@ -283,7 +283,9 @@ func (a appCreator) appExport( clientCtx := client.Context{}. WithChainID(appOpts.Get(flags.FlagChainID).(string)). WithFromName(appOpts.Get(flags.FlagFrom).(string)) - privSigner, err := app.InitPrivSigner(clientCtx, "", "") + nodeDir := "" + backend := "" + privSigner, err := app.InitPrivSigner(clientCtx, nodeDir, backend) if err != nil { panic(err) } diff --git a/testutil/datagen/val_set.go b/testutil/datagen/val_set.go index 1c9c4b63c..0c2f6fef8 100644 --- a/testutil/datagen/val_set.go +++ b/testutil/datagen/val_set.go @@ -9,7 +9,7 @@ import ( func GenRandomValSet(n int) epochingtypes.ValidatorSet { power := int64(10) - var valSet epochingtypes.ValidatorSet + var valSet []epochingtypes.Validator for i := 0; i < n; i++ { address := sdk.ValAddress(ed25519.GenPrivKey().PubKey().Address()) val := epochingtypes.Validator{ @@ -19,7 +19,7 @@ func GenRandomValSet(n int) epochingtypes.ValidatorSet { valSet = append(valSet, val) } - return valSet + return epochingtypes.NewSortedValidatorSet(valSet) } func GenRandomPubkeysAndSigs(n int, msg []byte) ([]bls12381.PublicKey, []bls12381.Signature) { diff --git a/x/checkpointing/keeper/bls_signer.go b/x/checkpointing/keeper/bls_signer.go index 76e22e968..e2d2ef625 100644 --- a/x/checkpointing/keeper/bls_signer.go +++ b/x/checkpointing/keeper/bls_signer.go @@ -41,7 +41,7 @@ func (k Keeper) SendBlsSig(ctx sdk.Context, epochNum uint64, lch types.LastCommi // insert the message into the transaction fs := pflag.NewFlagSet("", pflag.ContinueOnError) // TODO: hardcoded for now, will set fees as a parameter for the checkpointing module - fs.String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10uatom") + fs.String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10ubbn") err = fs.Set(flags.FlagFees, "100stake") //err = fs.Set(flags.FlagGasPrices, "1stake") err = tx.GenerateOrBroadcastTxCLI(k.clientCtx, fs, msg) From 96522d331d76b28d7391b051a9a1a0d166a258a4 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Sat, 10 Sep 2022 17:18:48 +0800 Subject: [PATCH 4/4] test ci --- cmd/babylond/cmd/root.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/babylond/cmd/root.go b/cmd/babylond/cmd/root.go index 4cf2b01ba..7d6727275 100644 --- a/cmd/babylond/cmd/root.go +++ b/cmd/babylond/cmd/root.go @@ -2,9 +2,11 @@ package cmd import ( "errors" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "io" "os" "path/filepath" + "strings" "github.com/spf13/cast" "github.com/spf13/cobra" @@ -229,9 +231,14 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a panic(err) } - backend := cast.ToString(appOpts.Get(flags.FlagKeyringBackend)) - chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) - fromName := cast.ToString(appOpts.Get(flags.FlagFrom)) + // TODO: access the following parameters from config files + //backend := cast.ToString(appOpts.Get(flags.FlagKeyringBackend)) + //chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) + //fromName := cast.ToString(appOpts.Get(flags.FlagFrom)) + backend := keyring.BackendTest + chainID := "chain-test" + paths := strings.Split(homeDir, "/") + fromName := paths[len(paths)-2] clientCtx, err := config.ReadFromClientConfig(client.Context{}.WithHomeDir(app.DefaultNodeHome).WithViper("")) if err != nil {