Skip to content

Commit a369727

Browse files
committed
feat: shift starting node base on iteration
1 parent 9f269cb commit a369727

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

cmd/filecoin-chain-archiver/cmds/create.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"io/ioutil"
10+
"math/rand"
1011
"net/url"
1112
"strings"
1213
"syscall"
@@ -241,11 +242,23 @@ var cmdCreate = &cli.Command{
241242
return err
242243
}
243244

245+
var iteration int
246+
if cctx.IsSet("interval") {
247+
iteration = int(uint64(height)/uint64(flagInterval)) % len(nodes)
248+
} else {
249+
iteration = rand.Int() % len(nodes)
250+
}
251+
252+
logger.Infow("iteration", "value", iteration)
253+
cm.ShiftStartNode(iteration)
254+
244255
node, peerID, err := cm.GetNodeWithTipSet(ctx, tsk, filterList)
245256
if err != nil {
246257
return err
247258
}
248259

260+
logger.Infow("node", "peer_id", peerID)
261+
249262
lock, locked, err := nl.Lock(ctx, peerID)
250263
if err != nil {
251264
return err

pkg/consensus/consensus.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ func (cm *ConsensusManager) GetTipset(ctx context.Context, height abi.ChainEpoch
8585
return pick, nil
8686
}
8787

88+
func (cm *ConsensusManager) ShiftStartNode(iteration int) {
89+
nodes := make([]api.FullNode, len(cm.nodes))
90+
91+
for i := 0; i < len(cm.nodes); i++ {
92+
source := (i + iteration) % len(cm.nodes)
93+
logger.Debugw("shift start node", "assignment", i, "source")
94+
nodes[i] = cm.nodes[source]
95+
}
96+
97+
cm.nodes = nodes
98+
}
99+
88100
func (cm *ConsensusManager) GetNodeWithTipSet(ctx context.Context, tsk types.TipSetKey, filterList []string) (api.FullNode, string, error) {
89101
peerFilter := make(map[string]struct{})
90102
for _, peer := range filterList {

0 commit comments

Comments
 (0)