Skip to content

Commit

Permalink
Fix failing tests and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Sep 7, 2023
1 parent bf208cb commit 94d01f0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ all: install build
install:
git lfs install
go mod download
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.53.3
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2
go install github.com/spacemeshos/go-scale/scalegen@v1.1.10
go install go.uber.org/mock/mockgen@v0.2.0
go install gotest.tools/gotestsum@v1.10.0
go install honnef.co/go/tools/cmd/staticcheck@v0.4.3
go install gotest.tools/gotestsum@v1.10.1
go install honnef.co/go/tools/cmd/staticcheck@v0.4.5
.PHONY: install

build: go-spacemesh get-profiler
Expand Down
12 changes: 0 additions & 12 deletions common/types/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,3 @@ func NewLayer(layerIndex LayerID) *Layer {
blocks: make([]*Block, 0, 3),
}
}

// MinLayer returns minimal nonzero layer.
func MinLayer(i, j LayerID) LayerID {
switch {
case i == 0:
return j
case j == 0:
return i
default:
return min(i, j)
}
}
12 changes: 8 additions & 4 deletions mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func NewMesh(cdb *datastore.CachedDB, c layerClock, trtl system.Tortoise, exec *
conState: state,
nextProcessedLayers: make(map[types.LayerID]struct{}),
missingBlocks: make(chan []types.BlockID, 32),

pendingUpdates: struct {
min, max types.LayerID
}{min: math.MaxUint32},
}
msh.latestLayer.Store(types.LayerID(0))
msh.latestLayerInState.Store(types.LayerID(0))
Expand Down Expand Up @@ -289,13 +293,13 @@ func (msh *Mesh) ProcessLayer(ctx context.Context, lid types.LayerID) error {
return err
}
results := msh.trtl.Updates()
pending := msh.pendingUpdates.min != 0
pending := msh.pendingUpdates.min != math.MaxUint32
if len(results) > 0 {
msh.pendingUpdates.min = types.MinLayer(msh.pendingUpdates.min, results[0].Layer)
msh.pendingUpdates.min = min(msh.pendingUpdates.min, results[0].Layer)
msh.pendingUpdates.max = max(msh.pendingUpdates.max, results[len(results)-1].Layer)
}
next := msh.LatestLayerInState() + 1
if next < msh.pendingUpdates.min {
if msh.pendingUpdates.min != math.MaxUint32 && next < msh.pendingUpdates.min {
msh.pendingUpdates.min = next
pending = true
}
Expand Down Expand Up @@ -340,7 +344,7 @@ func (msh *Mesh) ProcessLayer(ctx context.Context, lid types.LayerID) error {
msh.pendingUpdates.min = applicable[len(applicable)-1].Layer
msh.pendingUpdates.max = max(msh.pendingUpdates.min, msh.pendingUpdates.max)
} else {
msh.pendingUpdates.min = 0
msh.pendingUpdates.min = math.MaxUint32
msh.pendingUpdates.max = 0
}
return nil
Expand Down
35 changes: 23 additions & 12 deletions tortoise/tortoise.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ func (t *turtle) onLayer(ctx context.Context, last types.LayerID) {
opinion := layer.opinion
layer.computeOpinion(t.Hdist, t.last)
if opinion != layer.opinion {
t.pending = types.MinLayer(t.pending, t.last)
if t.pending == 0 {
t.pending = t.last
}
t.pending = min(t.pending, t.last)
}

t.logger.Debug("initial local opinion",
Expand Down Expand Up @@ -423,25 +426,25 @@ func (t *turtle) verifyLayers() {
vverified, vchanged := t.runVerifying()
if nverified == t.processed-1 && nverified == vverified {
t.switchModes()
changed = types.MinLayer(changed, vchanged)
changed = min(changed, vchanged)
}
} else {
nverified, changed = t.runVerifying()
// count all votes if next layer after verified is outside hdist
if !withinDistance(t.Hdist, nverified+1, t.last) {
fverified, fchanged := t.runFull()
nverified = fverified
changed = types.MinLayer(changed, fchanged)
changed = min(changed, fchanged)
}
}
for target := t.evicted.Add(1); target.Before(t.processed); target = target.Add(1) {
if nverified < target {
if target < t.verified {
changed = types.MinLayer(changed, target)
changed = min(changed, target)
}
break
} else if target > t.verified {
changed = types.MinLayer(changed, target)
changed = min(changed, target)
}
verified = target
}
Expand All @@ -451,8 +454,11 @@ func (t *turtle) verifyLayers() {
zap.Uint32("verified", verified.Uint32()),
zap.Uint32("changed", changed.Uint32()),
)
if changed != 0 {
t.pending = types.MinLayer(t.pending, changed)
if changed != math.MaxUint32 {
if t.pending == 0 {
t.pending = changed
}
t.pending = min(t.pending, changed)
t.onOpinionChange(changed, false)
}
t.verified = verified
Expand All @@ -461,13 +467,14 @@ func (t *turtle) verifyLayers() {

func (t *turtle) runVerifying() (verified, changed types.LayerID) {
verified = t.evicted
changed = math.MaxUint32
for target := t.evicted.Add(1); target.Before(t.processed); target = target.Add(1) {
v, c := t.verifying.verify(t.logger, target)
if !v {
return verified, changed
}
if c {
changed = types.MinLayer(changed, target)
changed = min(changed, target)
}
verified = target
}
Expand All @@ -486,13 +493,14 @@ func (t *turtle) runFull() (verified, changed types.LayerID) {
}
}
verified = t.evicted
changed = math.MaxUint32
for target := t.evicted.Add(1); target.Before(t.processed); target = target.Add(1) {
v, c := t.full.verify(t.logger, target)
if !v {
return verified, changed
}
if c {
changed = types.MinLayer(changed, target)
changed = min(changed, target)
}
verified = target
}
Expand Down Expand Up @@ -598,13 +606,16 @@ func (t *turtle) onOpinionChange(lid types.LayerID, early bool) {
zapBlocks(layer.blocks),
)
if opinion != layer.opinion {
changed = types.MinLayer(changed, recompute)
changed = min(changed, recompute)
} else if early {
break
}
}
if changed != 0 {
t.pending = types.MinLayer(t.pending, changed)
if changed != math.MaxUint32 {
if t.pending == 0 {
t.pending = changed
}
t.pending = min(t.pending, changed)
t.verifying.resetWeights(lid)
for target := lid.Add(1); !target.After(t.processed); target = target.Add(1) {
t.verifying.countVotes(t.logger, t.ballots[target])
Expand Down

0 comments on commit 94d01f0

Please sign in to comment.