From eee19e42db5004df1238d57f6875cc65626cd686 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Fri, 29 Apr 2022 10:29:26 -0400 Subject: [PATCH 1/2] consensus: reduce size of validator set changes test (#8442) --- internal/consensus/reactor_test.go | 76 +++++++++--------------------- 1 file changed, 22 insertions(+), 54 deletions(-) diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index 8a9abdf43..c6a8869db 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/rand" "os" "sync" "testing" @@ -776,8 +777,8 @@ func TestReactorValidatorSetChanges(t *testing.T) { cfg := configSetup(t) - nPeers := 7 - nVals := 4 + nPeers := 4 + nVals := 2 states, _, _, cleanup := randConsensusNetWithPeers( ctx, t, @@ -870,60 +871,27 @@ func TestReactorValidatorSetChanges(t *testing.T) { // it includes the commit for block 4, which should have the updated validator set waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states) - updateValidatorPubKey1, err := states[nVals].privValidator.GetPubKey(ctx) - require.NoError(t, err) + for i := 2; i <= 32; i *= 2 { + useState := rand.Intn(nVals) + t.Log(useState) + updateValidatorPubKey1, err := states[useState].privValidator.GetPubKey(ctx) + require.NoError(t, err) - updatePubKey1ABCI, err := encoding.PubKeyToProto(updateValidatorPubKey1) - require.NoError(t, err) + updatePubKey1ABCI, err := encoding.PubKeyToProto(updateValidatorPubKey1) + require.NoError(t, err) - updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25) - previousTotalVotingPower := states[nVals].GetRoundState().LastValidators.TotalVotingPower() + previousTotalVotingPower := states[useState].GetRoundState().LastValidators.TotalVotingPower() + updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, int64(i)) - waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, updateValidatorTx1) - waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, updateValidatorTx1) - waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states) - waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states) + waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, updateValidatorTx1) + waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, updateValidatorTx1) + waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states) + waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states) - require.NotEqualf( - t, states[nVals].GetRoundState().LastValidators.TotalVotingPower(), previousTotalVotingPower, - "expected voting power to change (before: %d, after: %d)", - previousTotalVotingPower, states[nVals].GetRoundState().LastValidators.TotalVotingPower(), - ) - - newValidatorPubKey2, err := states[nVals+1].privValidator.GetPubKey(ctx) - require.NoError(t, err) - - newVal2ABCI, err := encoding.PubKeyToProto(newValidatorPubKey2) - require.NoError(t, err) - - newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower) - - newValidatorPubKey3, err := states[nVals+2].privValidator.GetPubKey(ctx) - require.NoError(t, err) - - newVal3ABCI, err := encoding.PubKeyToProto(newValidatorPubKey3) - require.NoError(t, err) - - newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower) - - waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, newValidatorTx2, newValidatorTx3) - waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, newValidatorTx2, newValidatorTx3) - waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states) - - activeVals[string(newValidatorPubKey2.Address())] = struct{}{} - activeVals[string(newValidatorPubKey3.Address())] = struct{}{} - - waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states) - - removeValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, 0) - removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0) - - waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, removeValidatorTx2, removeValidatorTx3) - waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, removeValidatorTx2, removeValidatorTx3) - waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states) - - delete(activeVals, string(newValidatorPubKey2.Address())) - delete(activeVals, string(newValidatorPubKey3.Address())) - - waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states) + require.NotEqualf( + t, states[useState].GetRoundState().LastValidators.TotalVotingPower(), previousTotalVotingPower, + "expected voting power to change (before: %d, after: %d)", + previousTotalVotingPower, states[useState].GetRoundState().LastValidators.TotalVotingPower(), + ) + } } From 89196596f7ca12e8d397e674e73907c5d7ad96da Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Fri, 29 Apr 2022 10:56:10 -0400 Subject: [PATCH 2/2] privval/grpc: normalize signature (#8441) --- cmd/priv_val_server/main.go | 2 +- privval/grpc/client_test.go | 2 +- privval/grpc/server.go | 12 ++++-------- privval/grpc/server_test.go | 6 +++--- test/e2e/node/main.go | 2 +- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/priv_val_server/main.go b/cmd/priv_val_server/main.go index e34236acc..901422145 100644 --- a/cmd/priv_val_server/main.go +++ b/cmd/priv_val_server/main.go @@ -113,7 +113,7 @@ func main() { // add prometheus metrics for unary RPC calls opts = append(opts, grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor)) - ss := grpcprivval.NewSignerServer(*chainID, pv, logger) + ss := grpcprivval.NewSignerServer(logger, *chainID, pv) protocol, address := tmnet.ProtocolAndAddress(*addr) diff --git a/privval/grpc/client_test.go b/privval/grpc/client_test.go index 0b1056d03..a81f6ce07 100644 --- a/privval/grpc/client_test.go +++ b/privval/grpc/client_test.go @@ -29,7 +29,7 @@ func dialer(t *testing.T, pv types.PrivValidator, logger log.Logger) (*grpc.Serv server := grpc.NewServer() - s := tmgrpc.NewSignerServer(chainID, pv, logger) + s := tmgrpc.NewSignerServer(logger, chainID, pv) privvalproto.RegisterPrivValidatorAPIServer(server, s) diff --git a/privval/grpc/server.go b/privval/grpc/server.go index 13e0c9073..40af82479 100644 --- a/privval/grpc/server.go +++ b/privval/grpc/server.go @@ -21,11 +21,9 @@ type SignerServer struct { privVal types.PrivValidator } -func NewSignerServer(chainID string, - privVal types.PrivValidator, log log.Logger) *SignerServer { - +func NewSignerServer(logger log.Logger, chainID string, privVal types.PrivValidator) *SignerServer { return &SignerServer{ - logger: log, + logger: logger, chainID: chainID, privVal: privVal, } @@ -56,8 +54,7 @@ func (ss *SignerServer) GetPubKey(ctx context.Context, req *privvalproto.PubKeyR // SignVote receives a vote sign requests, attempts to sign it // returns SignedVoteResponse on success and error on failure -func (ss *SignerServer) SignVote(ctx context.Context, req *privvalproto.SignVoteRequest) ( - *privvalproto.SignedVoteResponse, error) { +func (ss *SignerServer) SignVote(ctx context.Context, req *privvalproto.SignVoteRequest) (*privvalproto.SignedVoteResponse, error) { vote := req.Vote err := ss.privVal.SignVote(ctx, req.ChainId, vote) @@ -72,8 +69,7 @@ func (ss *SignerServer) SignVote(ctx context.Context, req *privvalproto.SignVote // SignProposal receives a proposal sign requests, attempts to sign it // returns SignedProposalResponse on success and error on failure -func (ss *SignerServer) SignProposal(ctx context.Context, req *privvalproto.SignProposalRequest) ( - *privvalproto.SignedProposalResponse, error) { +func (ss *SignerServer) SignProposal(ctx context.Context, req *privvalproto.SignProposalRequest) (*privvalproto.SignedProposalResponse, error) { proposal := req.Proposal err := ss.privVal.SignProposal(ctx, req.ChainId, proposal) diff --git a/privval/grpc/server_test.go b/privval/grpc/server_test.go index db85a42b7..ad63b87a6 100644 --- a/privval/grpc/server_test.go +++ b/privval/grpc/server_test.go @@ -37,7 +37,7 @@ func TestGetPubKey(t *testing.T) { defer cancel() logger := log.NewTestingLogger(t) - s := tmgrpc.NewSignerServer(ChainID, tc.pv, logger) + s := tmgrpc.NewSignerServer(logger, ChainID, tc.pv) req := &privvalproto.PubKeyRequest{ChainId: ChainID} resp, err := s.GetPubKey(ctx, req) @@ -112,7 +112,7 @@ func TestSignVote(t *testing.T) { defer cancel() logger := log.NewTestingLogger(t) - s := tmgrpc.NewSignerServer(ChainID, tc.pv, logger) + s := tmgrpc.NewSignerServer(logger, ChainID, tc.pv) req := &privvalproto.SignVoteRequest{ChainId: ChainID, Vote: tc.have.ToProto()} resp, err := s.SignVote(ctx, req) @@ -183,7 +183,7 @@ func TestSignProposal(t *testing.T) { defer cancel() logger := log.NewTestingLogger(t) - s := tmgrpc.NewSignerServer(ChainID, tc.pv, logger) + s := tmgrpc.NewSignerServer(logger, ChainID, tc.pv) req := &privvalproto.SignProposalRequest{ChainId: ChainID, Proposal: tc.have.ToProto()} resp, err := s.SignProposal(ctx, req) diff --git a/test/e2e/node/main.go b/test/e2e/node/main.go index 54b9ef533..2cbb9e4b0 100644 --- a/test/e2e/node/main.go +++ b/test/e2e/node/main.go @@ -248,7 +248,7 @@ func startSigner(ctx context.Context, logger log.Logger, cfg *Config) error { if err != nil { return err } - ss := grpcprivval.NewSignerServer(cfg.ChainID, filePV, logger) + ss := grpcprivval.NewSignerServer(logger, cfg.ChainID, filePV) s := grpc.NewServer()