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

ShardIDFromKey still return 4 shards when starting from 0 #4564

Open
sophoah opened this issue Nov 16, 2023 · 0 comments
Open

ShardIDFromKey still return 4 shards when starting from 0 #4564

sophoah opened this issue Nov 16, 2023 · 0 comments

Comments

@sophoah
Copy link
Contributor

sophoah commented Nov 16, 2023

Describe the bug

When the node start from 0, HIP30 epoch hasn't been reached yet and the function below will still return shard 2 or 3 instead of 0 or 1

// ShardIDFromKey returns the shard ID statically determined from the input key
func (conf *ConfigType) ShardIDFromKey(key *bls_core.PublicKey) (uint32, error) {
	var pubKey bls.SerializedPublicKey
	if err := pubKey.FromLibBLSPublicKey(key); err != nil {
		return 0, errors.Wrapf(err,
			"cannot convert libbls public key %s to internal form",
			key.SerializeToHexStr())
	}
	epoch := conf.networkType.ChainConfig().StakingEpoch
	numShards := conf.shardingSchedule.InstanceForEpoch(epoch).NumShards()
	shardID := new(big.Int).Mod(pubKey.Big(), big.NewInt(int64(numShards)))
	return uint32(shardID.Uint64()), nil
}

What to expect
The shard belonging should be dependent on the latest epoch activation despite where the node has synced so far

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

1 participant