Fix slice out of bounds error in validator db migration (#8510)

* Fix slice out of bounds error in validator db migration #8509

* Add regression testing

* make it double just in case

* gofmt
This commit is contained in:
Preston Van Loon 2021-02-24 09:02:39 -06:00 committed by GitHub
parent eca8d85446
commit 6e831920bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -132,7 +132,7 @@ func batchPublicKeys(publicKeys [][]byte, batchSize int) [][][]byte {
}
batch := make([][][]byte, 0)
for i := 0; i < len(publicKeys); i += batchSize {
if i+batchSize == len(publicKeys)+1 {
if i+batchSize >= len(publicKeys)+1 {
batch = append(batch, publicKeys[i:])
} else {
batch = append(batch, publicKeys[i:i+batchSize])

View File

@ -14,7 +14,9 @@ import (
func TestStore_migrateSourceTargetEpochsBucketUp(t *testing.T) {
numEpochs := uint64(100)
numKeys := 50
// numKeys should be more than batch size for testing.
// See: https://github.com/prysmaticlabs/prysm/issues/8509
numKeys := 2*publicKeyMigrationBatchSize + 1
pubKeys := make([][48]byte, numKeys)
for i := 0; i < numKeys; i++ {
var pk [48]byte
@ -113,7 +115,9 @@ func TestStore_migrateSourceTargetEpochsBucketUp(t *testing.T) {
}
func TestStore_migrateSourceTargetEpochsBucketDown(t *testing.T) {
numKeys := 50
// numKeys should be more than batch size for testing.
// See: https://github.com/prysmaticlabs/prysm/issues/8509
numKeys := 2*publicKeyMigrationBatchSize + 1
pubKeys := make([][48]byte, numKeys)
for i := 0; i < numKeys; i++ {
var pk [48]byte