MCPcopy Create free account
hub / github.com/ethstorage/es-node / getShardList

Function getShardList

cmd/es-node/utils.go:124–157  ·  view source on GitHub ↗
(ctx context.Context, client *ethclient.Client, contract common.Address, shardLen int)

Source from the content-addressed store, hash-verified

122}
123
124func getShardList(ctx context.Context, client *ethclient.Client, contract common.Address, shardLen int) ([]uint64, error) {
125 var shardId uint64 = 0
126 var diffs []*big.Int
127 for {
128 diff, err := getDifficulty(ctx, client, contract, shardId)
129 if err != nil {
130 lg.Error("Query difficulty by shard", "error", err)
131 break
132 }
133 if diff != nil && diff.Cmp(big.NewInt(0)) == 0 {
134 // shardId not exist yet
135 break
136 }
137 lg.Info("Query difficulty by shard", "shard", shardId, "difficulty", diff)
138 diffs = append(diffs, diff)
139 shardId++
140 }
141 // get the shards with lowest difficulty
142 sortedShardIds := sortBigIntSlice(diffs)
143 var result []uint64
144 if len(sortedShardIds) == 0 {
145 // Will create at least one data file
146 result = []uint64{0}
147 } else {
148 if len(sortedShardIds) < shardLen {
149 shardLen = len(sortedShardIds)
150 }
151 for i := 0; i < shardLen; i++ {
152 result = append(result, uint64(sortedShardIds[i]))
153 }
154 }
155 lg.Info("Get shard list", "shards", result)
156 return result, nil
157}
158
159func getDifficulty(ctx context.Context, client *ethclient.Client, contract common.Address, shardIdx uint64) (*big.Int, error) {
160 res, err := getMiningInfo(ctx, client, contract, shardIdx)

Callers 2

TestCreateDataFileFunction · 0.85
EsNodeInitFunction · 0.85

Calls 3

getDifficultyFunction · 0.85
sortBigIntSliceFunction · 0.85
ErrorMethod · 0.45

Tested by 1

TestCreateDataFileFunction · 0.68