Skip to content

Commit

Permalink
Merge branch 'develop' into add-index-for-first-in-epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 20, 2023
2 parents 95ad452 + f629581 commit 4dfae6b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 101 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI

env:
go-version: "1.21"
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }}
PROJECT_NAME: ${{ secrets.PROJECT_NAME }}
CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }}
Expand Down Expand Up @@ -65,7 +66,7 @@ jobs:
uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: "go.mod"
go-version: ${{ env.go-version }}
- name: fmt, tidy, generate
run: |
make install
Expand All @@ -88,7 +89,7 @@ jobs:
uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: "go.mod"
go-version: ${{ env.go-version }}
- name: setup env
run: make install
- name: staticcheck
Expand Down Expand Up @@ -126,7 +127,7 @@ jobs:
uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: "go.mod"
go-version: ${{ env.go-version }}
cache: ${{ runner.arch != 'arm64' }}
- name: setup env
run: make install
Expand Down Expand Up @@ -174,7 +175,7 @@ jobs:
uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: "go.mod"
go-version: ${{ env.go-version }}
cache: ${{ runner.arch != 'arm64' }}
- name: Add OpenCL support - Ubuntu
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down Expand Up @@ -242,7 +243,7 @@ jobs:
uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: "go.mod"
go-version: ${{ env.go-version }}
cache: ${{ runner.arch != 'arm64' }}
- name: Add OpenCL support - Ubuntu
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ Support for old certificate sync protocol is dropped. This update is incompatibl
### Features

### Improvements

* [#4998](https://github.com/spacemeshos/go-spacemesh/pull/4998) First phase of state size reduction.
Ephemeral data are deleted and state compacted at the time of upgrade. In steady-state, data is pruned periodically.
* [#5021](https://github.com/spacemeshos/go-spacemesh/pull/5021) Drop support for old certificate sync protocol.
* [#5024](https://github.com/spacemeshos/go-spacemesh/pull/5024) Active set will be saved in state separately from ballots.
* [#5035](https://github.com/spacemeshos/go-spacemesh/pull/5035) Fix possible nil pointer panic when node fails to persist nipost builder state.

## v1.1.5

Expand Down
24 changes: 11 additions & 13 deletions activation/nipost_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ const (
)

func write(path string, data []byte) error {
tmp, err := os.Create(fmt.Sprintf("%s.tmp", path))
tmpName := fmt.Sprintf("%s.tmp", path)
tmp, err := os.Create(tmpName)
if err != nil {
return fmt.Errorf("create temporary file %s: %w", tmp.Name(), err)
return fmt.Errorf("create temporary file %s: %w", tmpName, err)
}
defer tmp.Close()

checksum := crc64.New(crc64.MakeTable(crc64.ISO))
w := io.MultiWriter(tmp, checksum)
if _, err = w.Write(data); err != nil {
_ = tmp.Close()
if _, err := w.Write(data); err != nil {
return fmt.Errorf("write data %v: %w", tmp.Name(), err)
}

crc := make([]byte, crc64.Size)
binary.BigEndian.PutUint64(crc, checksum.Sum64())
if _, err = tmp.Write(crc); err != nil {
_ = tmp.Close()
if _, err := tmp.Write(crc); err != nil {
return fmt.Errorf("write checksum %s: %w", tmp.Name(), err)
}

if err = tmp.Close(); err != nil {
if err := tmp.Close(); err != nil {
return fmt.Errorf("failed to close tmp file %s: %w", tmp.Name(), err)
}

if err = atomic.ReplaceFile(tmp.Name(), path); err != nil {
if err := atomic.ReplaceFile(tmp.Name(), path); err != nil {
return fmt.Errorf("save file from %s, %s: %w", tmp.Name(), path, err)
}

Expand All @@ -57,7 +57,6 @@ func read(path string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("open file %s: %w", path, err)
}

defer file.Close()

fInfo, err := file.Stat()
Expand All @@ -70,20 +69,19 @@ func read(path string) ([]byte, error) {

data := make([]byte, fInfo.Size()-crc64.Size)
checksum := crc64.New(crc64.MakeTable(crc64.ISO))
if _, err = io.TeeReader(file, checksum).Read(data); err != nil {
if _, err := io.TeeReader(file, checksum).Read(data); err != nil {
return nil, fmt.Errorf("read file %s: %w", path, err)
}

saved := make([]byte, crc64.Size)
if _, err = file.Read(saved); err != nil {
if _, err := file.Read(saved); err != nil {
return nil, fmt.Errorf("read checksum %s: %w", path, err)
}

savedChecksum := binary.BigEndian.Uint64(saved)

if savedChecksum != checksum.Sum64() {
return nil, fmt.Errorf(
"wrong checksum 0x%X, computed 0x%X", savedChecksum, checksum.Sum64())
return nil, fmt.Errorf("wrong checksum 0x%X, computed 0x%X", savedChecksum, checksum.Sum64())
}

return data, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/spacemeshos/go-spacemesh

go 1.21
go 1.21.1

require (
cloud.google.com/go/storage v1.33.0
Expand Down
37 changes: 15 additions & 22 deletions hare3/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,24 @@ func (h *Hare) run(layer types.LayerID, beacon types.Beacon, proto *protocol) er
if err := h.onOutput(layer, current, proto.Next(vrf != nil), vrf); err != nil {
return err
}
walltime = walltime.Add(h.config.RoundDuration)
result := false
for {
walltime = walltime.Add(h.config.RoundDuration)
current := proto.IterRound
var vrf *types.HareEligibility
if current.IsMessageRound() {
start := time.Now()
vrf = h.oracle.active(h.signer.NodeID(), layer, current)
activeLatency.Observe(time.Since(start).Seconds())
}
h.tracer.OnActive(vrf)
select {
case <-h.wallclock.After(walltime.Sub(h.wallclock.Now())):
h.log.Debug("execute round",
zap.Uint32("lid", layer.Uint32()),
zap.Uint8("iter", proto.Iter), zap.Stringer("round", proto.Round),
zap.Bool("active", vrf != nil),
)
current := proto.IterRound
var vrf *types.HareEligibility
if current.IsMessageRound() {
start := time.Now()
vrf = h.oracle.active(h.signer.NodeID(), layer, current)
activeLatency.Observe(time.Since(start).Seconds())
}
h.tracer.OnActive(vrf)

out := proto.Next(vrf != nil)
if out.result != nil {
result = true
Expand All @@ -416,7 +416,6 @@ func (h *Hare) run(layer types.LayerID, beacon types.Beacon, proto *protocol) er
return fmt.Errorf("hare failed to reach consensus in %d iterations",
h.config.IterationsLimit)
}
walltime = walltime.Add(h.config.RoundDuration)
case <-h.ctx.Done():
return nil
}
Expand All @@ -428,23 +427,17 @@ func (h *Hare) onOutput(layer types.LayerID, ir IterRound, out output, vrf *type
out.message.Layer = layer
out.message.Eligibility = *vrf
out.message.Sender = h.signer.NodeID()
out.message.Signature = h.signer.Sign(signing.HARE, out.message.ToMetadata().ToBytes())
if err := h.pubsub.Publish(h.ctx, h.config.ProtocolName, out.message.ToBytes()); err != nil {
h.log.Error("failed to publish", zap.Inline(out.message), zap.Error(err))
}
}
h.log.Debug("round output",
zap.Uint32("lid", layer.Uint32()),
zap.Uint8("iter", ir.Iter), zap.Stringer("round", ir.Round),
zap.Inline(&out),
zap.Bool("active", vrf != nil),
)
if out.message != nil {
h.eg.Go(func() error {
out.message.Signature = h.signer.Sign(signing.HARE, out.message.ToMetadata().ToBytes())
if err := h.pubsub.Publish(h.ctx, h.config.ProtocolName, out.message.ToBytes()); err != nil {
h.log.Error("failed to publish", zap.Inline(out.message), zap.Error(err))
}
h.tracer.OnMessageSent(out.message)
return nil
})
}
h.tracer.OnMessageSent(out.message)
if out.coin != nil {
select {
case <-h.ctx.Done():
Expand Down

0 comments on commit 4dfae6b

Please sign in to comment.