From 3b54ec04203e38ad606e4a0ef707cea7a472dee4 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 10 Jul 2019 15:58:57 -0700 Subject: [PATCH] [sharding] set shardID within FindAccount Signed-off-by: Leo Chen --- internal/configs/sharding/instance.go | 13 ++++++++----- internal/configs/sharding/shardingconfig.go | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/configs/sharding/instance.go b/internal/configs/sharding/instance.go index 5e97d52ef..dcd896d64 100644 --- a/internal/configs/sharding/instance.go +++ b/internal/configs/sharding/instance.go @@ -90,17 +90,20 @@ func (sc instance) FnAccounts() []genesis.DeployAccount { return sc.fnAccounts } -// FindAccount returns the deploy account based on the blskey -func (sc instance) FindAccount(blsPubKey string) (int, *genesis.DeployAccount) { +// FindAccount returns the deploy account based on the blskey, and if the account is a leader +// or not in the bootstrapping process. +func (sc instance) FindAccount(blsPubKey string) (bool, *genesis.DeployAccount) { for i, item := range sc.hmyAccounts { if item.BlsPublicKey == blsPubKey { - return i, &item + item.ShardID = uint32(i) % sc.numShards + return uint32(i) < sc.numShards, &item } } for i, item := range sc.fnAccounts { if item.BlsPublicKey == blsPubKey { - return i + int(sc.numShards), &item + item.ShardID = uint32(i) % sc.numShards + return false, &item } } - return -1, nil + return false, nil } diff --git a/internal/configs/sharding/shardingconfig.go b/internal/configs/sharding/shardingconfig.go index 52298cf33..b0cb73ecf 100644 --- a/internal/configs/sharding/shardingconfig.go +++ b/internal/configs/sharding/shardingconfig.go @@ -33,5 +33,5 @@ type Instance interface { FnAccounts() []genesis.DeployAccount // FindAccount returns the deploy account based on the blskey - FindAccount(blsPubKey string) (int, *genesis.DeployAccount) + FindAccount(blsPubKey string) (bool, *genesis.DeployAccount) }