Skip to content

Commit c704f34

Browse files
committed
Use x-go-type to prevent java sdk from picking up changes
With x-go-type we can also explicitly make Rounds, Assets, and Apps use their types from `basics`. Having done so, a LOT of code can be cahnged to use those types properly instead of propagating uint64s throughout.
1 parent be34b8f commit c704f34

File tree

116 files changed

+3802
-5020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+3802
-5020
lines changed

agreement/msgp_gen.go

+21-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

catchup/service.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ func (s *Service) triggerSync() {
192192

193193
// SetDisableSyncRound attempts to set the first round we _do_not_ want to fetch from the network
194194
// Blocks from disableSyncRound or any round after disableSyncRound will not be fetched while this is set
195-
func (s *Service) SetDisableSyncRound(rnd uint64) error {
196-
if basics.Round(rnd) < s.ledger.LastRound() {
195+
func (s *Service) SetDisableSyncRound(rnd basics.Round) error {
196+
if rnd < s.ledger.LastRound() {
197197
return ErrSyncRoundInvalid
198198
}
199-
s.disableSyncRound.Store(rnd)
199+
s.disableSyncRound.Store(uint64(rnd))
200200
s.triggerSync()
201201
return nil
202202
}
@@ -208,8 +208,8 @@ func (s *Service) UnsetDisableSyncRound() {
208208
}
209209

210210
// GetDisableSyncRound returns the disabled sync round
211-
func (s *Service) GetDisableSyncRound() uint64 {
212-
return s.disableSyncRound.Load()
211+
func (s *Service) GetDisableSyncRound() basics.Round {
212+
return basics.Round(s.disableSyncRound.Load())
213213
}
214214

215215
// SynchronizingTime returns the time we've been performing a catchup operation (0 if not currently catching up)

cmd/algoh/blockWatcher.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"sync"
2121
"time"
2222

23+
"github.com/algorand/go-algorand/data/basics"
2324
"github.com/algorand/go-algorand/logging"
2425
"github.com/algorand/go-algorand/protocol"
2526
"github.com/algorand/go-algorand/rpcs"
@@ -28,7 +29,7 @@ import (
2829
var log = logging.Base()
2930

3031
type blockListener interface {
31-
init(uint64)
32+
init(basics.Round)
3233
onBlock(rpcs.EncodedBlockCert)
3334
}
3435

@@ -71,7 +72,7 @@ func runBlockWatcher(watchers []blockListener, client Client, abort <-chan struc
7172
}
7273
}
7374

74-
func (bw *blockWatcher) run(watchers []blockListener, stallDetect time.Duration, curBlock uint64) bool {
75+
func (bw *blockWatcher) run(watchers []blockListener, stallDetect time.Duration, curBlock basics.Round) bool {
7576
lastBlock := time.Now()
7677
for {
7778
// Inner loop needed during catchup.
@@ -112,7 +113,7 @@ func (bw *blockWatcher) run(watchers []blockListener, stallDetect time.Duration,
112113
}
113114

114115
// This keeps retrying forever, or until an abort signal is received.
115-
func (bw *blockWatcher) getLastRound() (uint64, bool) {
116+
func (bw *blockWatcher) getLastRound() (basics.Round, bool) {
116117
for {
117118
status, err := bw.client.Status()
118119
if err != nil {
@@ -125,7 +126,7 @@ func (bw *blockWatcher) getLastRound() (uint64, bool) {
125126
}
126127
}
127128

128-
func (bw *blockWatcher) blockUntilReady() (curBlock uint64, ok bool) {
129+
func (bw *blockWatcher) blockUntilReady() (curBlock basics.Round, ok bool) {
129130
curBlock, ok = bw.blockIfStalled()
130131
if !ok {
131132
return
@@ -135,7 +136,7 @@ func (bw *blockWatcher) blockUntilReady() (curBlock uint64, ok bool) {
135136
}
136137

137138
// blockIfStalled keeps checking status until the LastRound updates.
138-
func (bw *blockWatcher) blockIfStalled() (uint64, bool) {
139+
func (bw *blockWatcher) blockIfStalled() (basics.Round, bool) {
139140
curBlock, ok := bw.getLastRound()
140141
if !ok {
141142
return 0, false
@@ -160,7 +161,7 @@ func (bw *blockWatcher) blockIfStalled() (uint64, bool) {
160161
}
161162

162163
// blockIfCatchup blocks until the lastBlock stops quickly changing. An initial block is passed
163-
func (bw *blockWatcher) blockIfCatchup(start uint64) (uint64, bool) {
164+
func (bw *blockWatcher) blockIfCatchup(start basics.Round) (basics.Round, bool) {
164165
last := start
165166

166167
for {

cmd/algoh/blockWatcher_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323
"time"
2424

25+
"github.com/algorand/go-algorand/data/basics"
2526
"github.com/algorand/go-algorand/rpcs"
2627
"github.com/algorand/go-algorand/test/partitiontest"
2728
"github.com/stretchr/testify/require"
@@ -112,7 +113,7 @@ type testlistener struct {
112113
blockCount uint32
113114
}
114115

115-
func (l *testlistener) init(block uint64) {
116+
func (l *testlistener) init(block basics.Round) {
116117
atomic.AddUint32(&(l.initCount), 1)
117118
}
118119

cmd/algoh/blockstats.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"time"
2121

22+
"github.com/algorand/go-algorand/data/basics"
2223
"github.com/algorand/go-algorand/logging/telemetryspec"
2324
"github.com/algorand/go-algorand/rpcs"
2425
)
@@ -31,7 +32,7 @@ type blockstats struct {
3132
lastBlockTime time.Time
3233
}
3334

34-
func (stats *blockstats) init(block uint64) {
35+
func (stats *blockstats) init(block basics.Round) {
3536
}
3637

3738
func (stats *blockstats) onBlock(block rpcs.EncodedBlockCert) {

cmd/algoh/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import (
2020
"context"
2121

2222
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
23+
"github.com/algorand/go-algorand/data/basics"
2324
)
2425

2526
// Client is a minimal interface for the RestClient
2627
type Client interface {
2728
Status() (model.NodeStatusResponse, error)
28-
RawBlock(round uint64) ([]byte, error)
29+
RawBlock(round basics.Round) ([]byte, error)
2930
GetGoRoutines(ctx context.Context) (string, error)
3031
HealthCheck() error
3132
}

cmd/algoh/deadman.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ import (
2323
"time"
2424

2525
"github.com/algorand/go-algorand/config"
26+
"github.com/algorand/go-algorand/data/basics"
2627
"github.com/algorand/go-algorand/logging/telemetryspec"
2728
"github.com/algorand/go-algorand/rpcs"
2829
)
2930

3031
type deadManWatcher struct {
3132
timeout time.Duration
32-
newBlockChan chan uint64
33+
newBlockChan chan basics.Round
3334
uploadOnError bool
3435
client Client
3536
done <-chan struct{}
@@ -47,7 +48,7 @@ func makeDeadManWatcher(timeout int64, client Client, uploadOnError bool, done <
4748

4849
return deadManWatcher{
4950
timeout: deadManTime,
50-
newBlockChan: make(chan uint64),
51+
newBlockChan: make(chan basics.Round),
5152
client: client,
5253
uploadOnError: uploadOnError,
5354
done: done,
@@ -56,11 +57,11 @@ func makeDeadManWatcher(timeout int64, client Client, uploadOnError bool, done <
5657
}
5758
}
5859

59-
func (w deadManWatcher) init(initBlock uint64) {
60+
func (w deadManWatcher) init(initBlock basics.Round) {
6061
go w.run(initBlock)
6162
}
6263

63-
func (w deadManWatcher) run(initBlock uint64) {
64+
func (w deadManWatcher) run(initBlock basics.Round) {
6465
defer w.wg.Done()
6566
latestBlock := initBlock
6667

@@ -89,10 +90,10 @@ func (w deadManWatcher) run(initBlock uint64) {
8990
}
9091

9192
func (w deadManWatcher) onBlock(block rpcs.EncodedBlockCert) {
92-
w.newBlockChan <- uint64(block.Block.BlockHeader.Round)
93+
w.newBlockChan <- block.Block.BlockHeader.Round
9394
}
9495

95-
func (w deadManWatcher) reportDeadManTimeout(curBlock uint64) (err error) {
96+
func (w deadManWatcher) reportDeadManTimeout(curBlock basics.Round) (err error) {
9697
var details telemetryspec.DeadManTriggeredEventDetails
9798
if w.algodConfig.EnableProfiler {
9899
goRoutines, err := getGoRoutines(w.client)
@@ -101,7 +102,7 @@ func (w deadManWatcher) reportDeadManTimeout(curBlock uint64) (err error) {
101102
}
102103
details = telemetryspec.DeadManTriggeredEventDetails{
103104
Timeout: int64(w.timeout.Seconds()),
104-
CurrentBlock: curBlock,
105+
CurrentBlock: uint64(curBlock),
105106
GoRoutines: goRoutines,
106107
}
107108
} else {
@@ -111,7 +112,7 @@ func (w deadManWatcher) reportDeadManTimeout(curBlock uint64) (err error) {
111112
}
112113
details = telemetryspec.DeadManTriggeredEventDetails{
113114
Timeout: int64(w.timeout.Seconds()),
114-
CurrentBlock: curBlock,
115+
CurrentBlock: uint64(curBlock),
115116
GoRoutines: healthCheck,
116117
}
117118
}

cmd/algoh/mockClient.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ import (
3131
// Helpers to initialize mockClient //
3232
//////////////////////////////////////
3333

34-
func makeNodeStatuses(blocks ...uint64) (ret []model.NodeStatusResponse) {
34+
func makeNodeStatuses(blocks ...basics.Round) (ret []model.NodeStatusResponse) {
3535
ret = make([]model.NodeStatusResponse, 0, len(blocks))
3636
for _, block := range blocks {
3737
ret = append(ret, model.NodeStatusResponse{LastRound: block})
3838
}
3939
return ret
4040
}
4141

42-
func makeBlocks(blocks ...uint64) (ret map[uint64]rpcs.EncodedBlockCert) {
43-
ret = map[uint64]rpcs.EncodedBlockCert{}
42+
func makeBlocks(blocks ...basics.Round) (ret map[basics.Round]rpcs.EncodedBlockCert) {
43+
ret = map[basics.Round]rpcs.EncodedBlockCert{}
4444
for _, block := range blocks {
4545
ret[block] = rpcs.EncodedBlockCert{Block: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: basics.Round(block)}}}
4646
}
@@ -51,18 +51,18 @@ func makeBlocks(blocks ...uint64) (ret map[uint64]rpcs.EncodedBlockCert) {
5151

5252
type mockClient struct {
5353
StatusCalls int
54-
BlockCalls map[uint64]int
54+
BlockCalls map[basics.Round]int
5555
GetGoRoutinesCalls int
5656
HealthCheckCalls int
5757
error []error
5858
status []model.NodeStatusResponse
5959
routine []string
60-
block map[uint64]rpcs.EncodedBlockCert
60+
block map[basics.Round]rpcs.EncodedBlockCert
6161
}
6262

63-
func makeMockClient(error []error, status []model.NodeStatusResponse, block map[uint64]rpcs.EncodedBlockCert, routine []string) mockClient {
63+
func makeMockClient(error []error, status []model.NodeStatusResponse, block map[basics.Round]rpcs.EncodedBlockCert, routine []string) mockClient {
6464
return mockClient{
65-
BlockCalls: make(map[uint64]int),
65+
BlockCalls: make(map[basics.Round]int),
6666
error: error,
6767
status: status,
6868
block: block,
@@ -93,7 +93,7 @@ func (c *mockClient) Status() (s model.NodeStatusResponse, e error) {
9393
return
9494
}
9595

96-
func (c *mockClient) RawBlock(block uint64) (b []byte, e error) {
96+
func (c *mockClient) RawBlock(block basics.Round) (b []byte, e error) {
9797
c.BlockCalls[block]++
9898
e = c.nextError()
9999
bl, ok := c.block[block]

0 commit comments

Comments
 (0)