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

MakeGenesisState() populates State's ValidatorSets with empty slices unconditionally #2616

Closed
alessio opened this issue Oct 11, 2018 · 1 comment

Comments

@alessio
Copy link
Contributor

alessio commented Oct 11, 2018

When genesis's Validators is a nil slice, State's Validators and NextValidators fields should be populated accordingly.
A patch follows:

--- vendor/github.com/tendermint/tendermint/state/state.go.orig	2018-10-11 15:22:42.556215269 -0700
+++ vendor/github.com/tendermint/tendermint/state/state.go	2018-10-11 15:34:07.668015560 -0700
@@ -198,17 +198,25 @@ func MakeGenesisState(genDoc *types.Gene
 	}
 
 	// Make validators slice
-	validators := make([]*types.Validator, len(genDoc.Validators))
-	for i, val := range genDoc.Validators {
-		pubKey := val.PubKey
-		address := pubKey.Address()
-
-		// Make validator
-		validators[i] = &types.Validator{
-			Address:     address,
-			PubKey:      pubKey,
-			VotingPower: val.Power,
+	var validatorSet, nextValidatorSet *types.ValidatorSet
+	if genDoc.Validators == nil {
+		validatorSet = types.NewValidatorSet(nil)
+		nextValidatorSet = types.NewValidatorSet(nil)
+	} else {
+		validators := make([]*types.Validator, len(genDoc.Validators))
+		for i, val := range genDoc.Validators {
+			pubKey := val.PubKey
+			address := pubKey.Address()
+
+			// Make validator
+			validators[i] = &types.Validator{
+				Address:     address,
+				PubKey:      pubKey,
+				VotingPower: val.Power,
+			}
 		}
+		validatorSet = types.NewValidatorSet(validators)
+		nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementAccum(1)
 	}
 
 	return State{
@@ -219,8 +227,8 @@ func MakeGenesisState(genDoc *types.Gene
 		LastBlockID:     types.BlockID{},
 		LastBlockTime:   genDoc.GenesisTime,
 
-		NextValidators:              types.NewValidatorSet(validators).CopyIncrementAccum(1),
-		Validators:                  types.NewValidatorSet(validators),
+		NextValidators:              nextValidatorSet,
+		Validators:                  validatorSet,
 		LastValidators:              types.NewValidatorSet(nil),
 		LastHeightValidatorsChanged: 1,
 
ebuchman pushed a commit that referenced this issue Oct 12, 2018
…eld is nil (#2617)

* Pass nil to NewValidatorSet() when genesis file's Validators field is nil

Closes: #2616

* Update CHANGELOG_PENDING.md
@ebuchman
Copy link
Contributor

Thanks for the quick report and fix!

rickyyangz pushed a commit to rickyyangz/tendermint that referenced this issue Mar 11, 2019
commit 15ee704d9ffafa586be3ac1c889ee74dea7f3192
Author: Cong Zhao <zhaocong89@gmail.com>
Date:   Wed Jan 30 20:54:34 2019 +0800

    tendermint#121 second iteration

commit cd8a777a9659627feffabd61552535aaf2af8bb1
Author: Cong Zhao <zhaocong89@gmail.com>
Date:   Thu Dec 13 15:24:08 2018 +0800

    tendermint#121 state sync mode

commit 53e8710
Merge: 3f17d89 551d864
Author: cong <ackratos@users.noreply.github.com>
Date:   Mon Dec 24 10:19:23 2018 +0800

    Merge pull request tendermint#19 from BiJie/sentry

    [R4R]fix sentry node replay faild

commit 551d864
Author: fudongbai <296179868@qq.com>
Date:   Mon Dec 24 10:06:49 2018 +0800

    fix sentry node replay faild

commit 3f17d89
Merge: 93d3b62 ddeee6c
Author: zjubfd <baifudong@lancai.cn>
Date:   Mon Dec 17 15:16:46 2018 +0800

    Merge pull request tendermint#18 from BiJie/nostate

    [R4R]validator do not verify hash when with no state

commit 93d3b62
Merge: a1ad253 dbeddbc
Author: zjubfd <baifudong@lancai.cn>
Date:   Mon Dec 17 15:16:32 2018 +0800

    Merge pull request tendermint#17 from BiJie/idmissing

    [R4R]fix reconnect id missing  ,resolve tendermint#16

commit ddeee6c
Author: fudongbai <296179868@qq.com>
Date:   Mon Dec 17 15:00:46 2018 +0800

    validator do not verify hash when with no state

commit dbeddbc
Author: fudongbai <296179868@qq.com>
Date:   Fri Dec 14 16:19:12 2018 +0800

    fix reconnect id missing

commit a1ad253
Merge: 451a393 a561225
Author: cong <ackratos@users.noreply.github.com>
Date:   Fri Nov 30 15:07:50 2018 +0800

    Merge pull request tendermint#13 from BiJie/issue_262_pagination_testfix

    [R4R] tendermint#262 Fix tx search pagination test case

commit a561225
Author: Cong Zhao <zhaocong89@gmail.com>
Date:   Fri Nov 30 15:05:03 2018 +0800

    tendermint#262 Fix tx search pagination test case

commit 451a393
Merge: d345772 44fcecc
Author: zjubfd <baifudong@lancai.cn>
Date:   Fri Nov 30 14:04:58 2018 +0800

    Merge pull request tendermint#8 from BiJie/sentrynode

    [R4R]support Sentry Node, add simple blockexecutor and  restrictPeers config param#7

commit 44fcecc
Author: fudongbai <296179868@qq.com>
Date:   Wed Nov 28 16:58:20 2018 +0800

    add withAppStat param

commit d345772
Merge: 4f6dfec 0f8d95e
Author: cong <ackratos@users.noreply.github.com>
Date:   Tue Nov 27 13:41:23 2018 +0800

    Merge pull request tendermint#12 from BiJie/issue262_pagination

    [R4R] tendermint#262 Fix tx search pagination

commit 0f8d95e
Author: Cong Zhao <zhaocong89@gmail.com>
Date:   Mon Nov 26 10:48:39 2018 +0800

    tendermint#262 Fix tx search pagination

commit 4f6dfec
Merge: 6fad36f 2367603
Author: cong <ackratos@users.noreply.github.com>
Date:   Fri Nov 23 10:15:15 2018 +0800

    Merge pull request tendermint#11 from BiJie/BlockTimeIota_config_fix

    disable BlockTimeIota

commit 2367603
Author: Cong Zhao <zhaocong89@gmail.com>
Date:   Wed Nov 21 21:27:35 2018 +0800

    disable BlockTimeIota

commit 6fad36f
Merge: 759be18 74ced3b
Author: danliu <savyen@hotmail.com>
Date:   Wed Nov 21 15:19:51 2018 +0800

    Merge pull request tendermint#10 from BiJie/feature/fix_test

    fix mempool test

commit 74ced3b
Author: yutianwu <wzxingbupt@gmail.com>
Date:   Wed Nov 21 15:15:38 2018 +0800

    fix mempool test

commit 759be18
Merge: cf1745a ed87b99
Author: danliu <savyen@hotmail.com>
Date:   Wed Nov 21 15:01:36 2018 +0800

    Merge pull request tendermint#9 from BiJie/feature/change_default_params

    R4R: Change default params

commit ed87b99
Author: yutianwu <wzxingbupt@gmail.com>
Date:   Wed Nov 21 11:11:47 2018 +0800

    update comments

commit 15475b4
Author: yutianwu <wzxingbupt@gmail.com>
Date:   Wed Nov 21 11:08:37 2018 +0800

    change default params

commit cf1745a
Merge: 038d87b d5b5ea8
Author: danliu <savyen@hotmail.com>
Date:   Thu Nov 15 19:05:38 2018 +0800

    Merge pull request tendermint#6 from BiJie/issue_bc280

    Make mempool reactor handles received msg asynchronously

commit d5b5ea8
Author: danliu <danliu@localhost.localdomain>
Date:   Thu Nov 15 16:27:24 2018 +0800

    Make mempool reactor handles received msg asynchronously

commit 038d87b
Merge: 3821815 2363a81
Author: danliu <savyen@hotmail.com>
Date:   Wed Nov 14 16:05:35 2018 +0800

    Merge pull request tendermint#5 from BiJie/dependency-fix

    fix client_golang and go-metrics dependency

commit 2363a81
Author: Cong Zhao <zhaocong89@gmail.com>
Date:   Sat Nov 10 17:24:02 2018 +0800

    fix client_golang and go-metrics dependency

commit 3821815
Merge: 90eda9b 1701b9c
Author: danliu <savyen@hotmail.com>
Date:   Thu Nov 8 19:17:01 2018 +0800

    Merge pull request tendermint#3 from BiJie/issue_bc218

    Add priority lock for CheckTx in mempool and ReCheck ABCI interface

commit 1701b9c
Author: danliu <danliu@localhost.localdomain>
Date:   Thu Nov 8 16:11:17 2018 +0800

    Add priority lock for CheckTx in mempool and ReCheck ABCI interface

commit 90eda9b
Author: Ethan Buchman <ethan@coinculture.info>
Date:   Wed Oct 17 22:09:48 2018 -0400

    changelog and version

commit 1ad379a
Author: Alessio Treglia <quadrispro@ubuntu.com>
Date:   Wed Oct 17 18:55:23 2018 -0700

    Update CHANGELOG_PENDING.md

commit 7220167
Author: Anton Kaliaev <anton.kalyaev@gmail.com>
Date:   Mon Oct 15 06:28:41 2018 +0400

    set next validators along with validators while replay (tendermint#2637)

    Closes tendermint#2634

commit adf8cea
Author: Alessio Treglia <quadrispro@ubuntu.com>
Date:   Thu Oct 11 20:37:21 2018 -0700

    Pass nil to NewValidatorSet() when genesis file's Validators field is nil (tendermint#2617)

    Closes: tendermint#2616
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

No branches or pull requests

2 participants