Skip to content

Commit 3ba0aea

Browse files
committed
refactor ticker
1 parent ed4ce7a commit 3ba0aea

File tree

13 files changed

+31
-338
lines changed

13 files changed

+31
-338
lines changed

cmd/network/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func main() {
5454
return
5555
}
5656
fmt.Println("\n🕐 Waiting for POS to become active... expected at block ", config.ForkBlock+config.TransitionPeriod)
57-
if err := utils.WaitForPOS(t.Context(), staker, config.ForkBlock+config.TransitionPeriod); err != nil {
57+
if err := utils.WaitForPOS(context.Background(), staker, config.ForkBlock+config.TransitionPeriod); err != nil {
5858
fmt.Println(" - Error waiting for PoS:", err)
5959
return
6060
}

cmd/txsimulation/contract/contract_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func (s *Service) poll() {
8484
time.Sleep(5 * time.Second) // Retry after a short delay
8585
continue
8686
}
87-
validators, err := s.FetchAll(block.(*api.JSONExpandedBlock).ID)
87+
validators, err := s.FetchAll(block.ID)
8888
if err != nil {
89-
slog.Error("Failed to fetch validatorInfo", "error", err, "block", block.(*api.JSONExpandedBlock).ID)
89+
slog.Error("Failed to fetch validatorInfo", "error", err, "block", block.ID)
9090
continue
9191
}
9292

cmd/txsimulation/devnet.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/xnodes"
2929
"github.com/vechain/hayabusa-e2e/hayabusa"
3030
utils2 "github.com/vechain/hayabusa-e2e/utils"
31+
"github.com/vechain/networkhub/utils/common"
3132
protocolbuiltin "github.com/vechain/thor/v2/builtin"
3233
genesisthor "github.com/vechain/thor/v2/genesis"
3334
"github.com/vechain/thor/v2/thor"
@@ -211,7 +212,7 @@ func setStargate(ctx context.Context, client *thorclient.Client, executors []*bi
211212
}
212213

213214
// wait for the receipts
214-
ticker := utils2.NewTicker(client)
215+
ticker := common.NewTicker(client)
215216
approved := make(map[thor.Address]bool)
216217
for range 6 {
217218
if len(approved) >= len(executors) {

cmd/txsimulation/devnetcleanup/delegations.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/contract"
99
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/stack"
10-
"github.com/vechain/hayabusa-e2e/utils"
10+
"github.com/vechain/networkhub/utils/common"
1111
"github.com/vechain/thor/v2/api"
1212
"github.com/vechain/thor/v2/thorclient/bind"
1313
)
@@ -87,14 +87,11 @@ func (c *Cleanup) exitDelegations(delegations []*big.Int, method exitMethod) {
8787
var groups [][]*big.Int
8888
groupSize := 100
8989
for i := 0; i < len(delegations); i += groupSize {
90-
end := i + groupSize
91-
if end > len(delegations) {
92-
end = len(delegations)
93-
}
90+
end := min(i+groupSize, len(delegations))
9491
groups = append(groups, delegations[i:end])
9592
}
9693

97-
ticker := utils.NewTicker(c.stack.Client())
94+
ticker := common.NewTicker(c.stack.Client())
9895

9996
for _, ids := range groups {
10097
slog.Info("processing cleanup", "first", ids[0], "last", ids[len(ids)-1], "count", len(ids))

cmd/txsimulation/lifecycle/engine.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func (e *Engine) Run() {
7171
}
7272
_, id, _ := e.stack.Staker().FirstActive()
7373
if !id.IsZero() {
74-
e.generateValidatorCycles(best.(*api.JSONExpandedBlock))
75-
e.generateDelegatorCycles(best.(*api.JSONExpandedBlock))
74+
e.generateValidatorCycles(best)
75+
e.generateDelegatorCycles(best)
7676
}
7777
delegationStatus := make(map[Status]int)
7878
validationStatus := make(map[Status]int)
@@ -87,7 +87,7 @@ func (e *Engine) Run() {
8787
}
8888
if lifecycle.Status() != StatusWithdrawn {
8989
e.workerPool.Run(func() {
90-
if err := lifecycle.Process(best.(*api.JSONExpandedBlock).Number); err != nil {
90+
if err := lifecycle.Process(best.Number); err != nil {
9191
slog.Error("failed to process lifecycle", "type", lifecycle.Type(), "id", lifecycle.ID(), "error", err)
9292
}
9393
})
@@ -139,11 +139,11 @@ func (e *Engine) Flush(status Status) error {
139139
for _, lifecycle := range e.lifecycles {
140140
e.workerPool.Run(func(l Lifecycle, current *api.JSONExpandedBlock) Worker {
141141
return func() {
142-
if err := lifecycle.Process(best.(*api.JSONExpandedBlock).Number); err != nil {
142+
if err := lifecycle.Process(best.Number); err != nil {
143143
slog.Error("failed to process lifecycle", "type", lifecycle.Type(), "id", lifecycle.ID(), "error", err)
144144
}
145145
}
146-
}(lifecycle, best.(*api.JSONExpandedBlock)))
146+
}(lifecycle, best))
147147
}
148148

149149
processed = true

0 commit comments

Comments
 (0)