Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into malfeasance-v2-fou…
Browse files Browse the repository at this point in the history
…ndations
  • Loading branch information
fasmat committed Aug 7, 2024
2 parents 15c9a4e + 83b0499 commit 77ecaf3
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 236 deletions.
50 changes: 2 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- name: lint
run: make lint-github-action

build-tools:
build:
runs-on: ${{ matrix.os }}
needs: filter-changes
if: ${{ needs.filter-changes.outputs.nondocchanges == 'true' }}
Expand Down Expand Up @@ -160,6 +160,7 @@ jobs:
with:
check-latest: true
go-version: ${{ env.go-version }}
cache: ${{ runner.arch != 'arm64' }}
- name: setup env
run: make install
- name: build merge-nodes
Expand All @@ -168,52 +169,6 @@ jobs:
run: make gen-p2p-identity
- name: build bootstrapper
run: make bootstrapper

build:
runs-on: ${{ matrix.os }}
needs: filter-changes
if: ${{ needs.filter-changes.outputs.nondocchanges == 'true' }}
strategy:
fail-fast: true
matrix:
os:
- ubuntu-22.04
- ubuntu-latest-arm-8-cores
- macos-13
- [self-hosted, macOS, ARM64, go-spacemesh]
- windows-2022
steps:
- name: Add OpenCL support - Ubuntu
if: ${{ matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-latest-arm-8-cores' }}
run: sudo apt-get update -q && sudo apt-get install -qy ocl-icd-opencl-dev libpocl2
- name: disable Windows Defender - Windows
if: ${{ matrix.os == 'windows-2022' }}
run: |
Set-MpPreference -DisableRealtimeMonitoring $true
- name: Set new git config - Windows
if: ${{ matrix.os == 'windows-2022' }}
run: |
git config --global pack.window 1
git config --global core.compression 0
git config --global http.postBuffer 524288000
- name: checkout
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.GH_ACTION_PRIVATE_KEY }}
- uses: extractions/netrc@v2
with:
machine: github.com
username: ${{ secrets.GH_ACTION_TOKEN_USER }}
password: ${{ secrets.GH_ACTION_TOKEN }}
if: vars.GOPRIVATE
- name: set up go
uses: actions/setup-go@v5
with:
check-latest: true
go-version: ${{ env.go-version }}
cache: ${{ runner.arch != 'arm64' }}
- name: setup env
run: make install
- name: build
timeout-minutes: 5
run: make build
Expand Down Expand Up @@ -307,7 +262,6 @@ jobs:
- filter-changes
- quicktests
- lint
- build-tools
- build
- unittests
runs-on: ubuntu-22.04
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ and permanent ineligibility for rewards.

* [#5470](https://github.com/spacemeshos/go-spacemesh/pull/5470)
Fixed a bug in event reporting where the node reports a disconnection from the PoST service as a "PoST failed" event.
Disconnections cannot be avoided completely and do not interrupt the PoST proofing process. As long as the PoST
Disconnections cannot be avoided completely and do not interrupt the PoST proving process. As long as the PoST
service reconnects within a reasonable time, the node will continue to operate normally without reporting any errors
via the event API.

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ clear-test-cache:
.PHONY: clear-test-cache

test: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" gotestsum -- -race -timeout 8m -p 1 $(UNIT_TESTS)
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" gotestsum -- -race -timeout 8m $(UNIT_TESTS)
.PHONY: test

generate: get-libs
Expand Down Expand Up @@ -145,7 +145,7 @@ lint-github-action: get-libs
.PHONY: lint-github-action

cover: get-libs
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -coverprofile=cover.out -timeout 0 -p 1 -coverpkg=./... $(UNIT_TESTS)
@$(ULIMIT) CGO_LDFLAGS="$(CGO_TEST_LDFLAGS)" go test -coverprofile=cover.out -timeout 30m -coverpkg=./... $(UNIT_TESTS)
.PHONY: cover

list-versions:
Expand Down
8 changes: 6 additions & 2 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func (b *Builder) run(ctx context.Context, sig *signing.EdSigner) {

b.logger.Warn("failed to publish atx", zap.Error(err))

poetErr := &PoetSvcUnstableError{}
switch {
case errors.Is(err, ErrATXChallengeExpired):
b.logger.Debug("retrying with new challenge after waiting for a layer")
Expand All @@ -459,8 +460,11 @@ func (b *Builder) run(ctx context.Context, sig *signing.EdSigner) {
return
case <-b.layerClock.AwaitLayer(currentLayer.Add(1)):
}
case errors.Is(err, ErrPoetServiceUnstable):
b.logger.Warn("retrying after poet retry interval", zap.Duration("interval", b.poetRetryInterval))
case errors.As(err, &poetErr):
b.logger.Warn("retrying after poet retry interval",
zap.Duration("interval", b.poetRetryInterval),
zap.Error(poetErr.source),
)
select {
case <-ctx.Done():
return
Expand Down
7 changes: 0 additions & 7 deletions activation/activation_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
var (
// ErrATXChallengeExpired is returned when atx missed its publication window and needs to be regenerated.
ErrATXChallengeExpired = errors.New("builder: atx expired")
// ErrPoetServiceUnstable is returned when poet quality of service is low.
ErrPoetServiceUnstable = &PoetSvcUnstableError{}
// ErrPoetProofNotReceived is returned when no poet proof was received.
ErrPoetProofNotReceived = errors.New("builder: didn't receive any poet proof")
)
Expand All @@ -28,8 +26,3 @@ func (e *PoetSvcUnstableError) Error() string {
}

func (e *PoetSvcUnstableError) Unwrap() error { return e.source }

func (e *PoetSvcUnstableError) Is(target error) bool {
_, ok := target.(*PoetSvcUnstableError)
return ok
}
2 changes: 1 addition & 1 deletion activation/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ func TestBuilder_RetryPublishActivationTx(t *testing.T) {
tries++
t.Logf("try %d: %s", tries, now)
if tries < expectedTries {
return nil, ErrPoetServiceUnstable
return nil, &PoetSvcUnstableError{}
}
close(builderConfirmation)
return newNIPostWithPoet(t, []byte("66666")), nil
Expand Down
22 changes: 5 additions & 17 deletions activation/handler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,7 @@ func (h *HandlerV2) syntacticallyValidateDeps(
zap.Int("index", invalidIdx.Index),
)
// TODO(mafa): finish proof
proof := &wire.ATXProof{
ProofType: wire.InvalidPost,
}
var proof wire.Proof
if err := h.malPublisher.Publish(ctx, id, proof); err != nil {
return nil, fmt.Errorf("publishing malfeasance proof for invalid post: %w", err)
}
Expand Down Expand Up @@ -721,7 +719,7 @@ func (h *HandlerV2) checkDoubleMarry(

// found an identity that is already married
var blob sql.Blob
if _, err := atxs.LoadBlob(ctx, tx, mAtxID[:], &blob); err != nil {
if _, err := atxs.LoadBlob(ctx, tx, mAtxID.Bytes(), &blob); err != nil {
return true, fmt.Errorf("get atx blob %s: %w", mAtxID.ShortString(), err)
}
mAtx := &wire.ActivationTxV2{}
Expand All @@ -730,12 +728,7 @@ func (h *HandlerV2) checkDoubleMarry(
if err != nil {
return true, fmt.Errorf("creating double marry proof: %w", err)
}
atxProof := &wire.ATXProof{
Version: 0,
ProofType: wire.DoubleMarry,
Proof: codec.MustEncode(proof),
}
return true, h.malPublisher.Publish(ctx, m.id, atxProof)
return true, h.malPublisher.Publish(ctx, m.id, proof)
}
return false, nil
}
Expand Down Expand Up @@ -764,9 +757,7 @@ func (h *HandlerV2) checkDoublePost(
zap.Uint32("epoch", atx.PublishEpoch.Uint32()),
)
// TODO(mafa): finish proof
proof := &wire.ATXProof{
ProofType: wire.DoublePublish,
}
var proof wire.Proof
return true, h.malPublisher.Publish(ctx, id, proof)
}
return false, nil
Expand All @@ -793,10 +784,7 @@ func (h *HandlerV2) checkDoubleMerge(ctx context.Context, tx *sql.Tx, watx *wire
zap.Stringer("smesher_id", watx.SmesherID),
)

// TODO(mafa): finish proof
proof := &wire.ATXProof{
ProofType: wire.DoubleMerge,
}
var proof wire.Proof
return true, h.malPublisher.Publish(ctx, watx.SmesherID, proof)
}

Expand Down
39 changes: 15 additions & 24 deletions activation/handler_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/fetch"
Expand Down Expand Up @@ -1562,17 +1561,7 @@ func TestHandlerV2_SyntacticallyValidateDeps(t *testing.T) {
gomock.Any(),
).
Return(verifying.ErrInvalidIndex{Index: 7})
atxHandler.mMalPublish.EXPECT().Publish(
gomock.Any(),
sig.NodeID(),
gomock.Cond(func(data any) bool {
proof, ok := data.(*wire.ATXProof)
if !ok {
return false
}
return proof.ProofType == wire.InvalidPost
}),
)
atxHandler.mMalPublish.EXPECT().Publish(gomock.Any(), sig.NodeID(), gomock.Any())
_, err := atxHandler.syntacticallyValidateDeps(context.Background(), atx)
vErr := &verifying.ErrInvalidIndex{}
require.ErrorAs(t, err, vErr)
Expand Down Expand Up @@ -1716,18 +1705,20 @@ func Test_Marriages(t *testing.T) {
}
atx2.Sign(sig)
atxHandler.expectAtxV2(atx2)
atxHandler.mMalPublish.EXPECT().Publish(gomock.Any(), sig.NodeID(), gomock.Any()).
DoAndReturn(func(ctx context.Context, id types.NodeID, proof *wire.ATXProof) error {
require.Equal(t, wire.ProofVersion(0), proof.Version)
require.Equal(t, wire.DoubleMarry, proof.ProofType)
doubleMarryProof := &wire.ProofDoubleMarry{}
codec.MustDecode(proof.Proof, doubleMarryProof)

nodeID, err := doubleMarryProof.Valid(atxHandler.edVerifier)
require.NoError(t, err)
require.Equal(t, sig.NodeID(), nodeID)
return nil
})
atxHandler.mMalPublish.EXPECT().Publish(
gomock.Any(),
sig.NodeID(),
gomock.Cond(func(data any) bool {
_, ok := data.(*wire.ProofDoubleMarry)
return ok
}),
).DoAndReturn(func(ctx context.Context, id types.NodeID, proof wire.Proof) error {
malProof := proof.(*wire.ProofDoubleMarry)
nId, err := malProof.Valid(atxHandler.edVerifier)
require.NoError(t, err)
require.Equal(t, sig.NodeID(), nId)
return nil
})
err = atxHandler.processATX(context.Background(), "", atx2, time.Now())
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion activation/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type syncer interface {
// Additionally the publisher will only gossip proofs when the node is in sync, otherwise it will only store them.
// and mark the associated identity as malfeasant.
type atxMalfeasancePublisher interface {
Publish(ctx context.Context, id types.NodeID, proof *wire.ATXProof) error
Publish(ctx context.Context, id types.NodeID, proof wire.Proof) error
}

type malfeasancePublisher interface {
Expand Down
12 changes: 6 additions & 6 deletions activation/malfeasance2_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ func (mh *MalfeasanceHandlerV2) Validate(ctx context.Context, data []byte) ([]ty
var proof wire.Proof
switch decoded.ProofType {
case wire.DoublePublish:
var p wire.ProofDoublePublish
if err := codec.Decode(decoded.Proof, &p); err != nil {
p := &wire.ProofDoublePublish{}
if err := codec.Decode(decoded.Proof, p); err != nil {
return nil, fmt.Errorf("decoding ATX double publish proof: %w", err)
}
proof = p
case wire.DoubleMarry:
var p wire.ProofDoubleMarry
if err := codec.Decode(decoded.Proof, &p); err != nil {
p := &wire.ProofDoubleMarry{}
if err := codec.Decode(decoded.Proof, p); err != nil {
return nil, fmt.Errorf("decoding ATX double marry proof: %w", err)
}
proof = p
case wire.InvalidPost:
var p wire.ProofInvalidPost
if err := codec.Decode(decoded.Proof, &p); err != nil {
p := &wire.ProofInvalidPost{}
if err := codec.Decode(decoded.Proof, p); err != nil {
return nil, fmt.Errorf("decoding ATX invalid post proof: %w", err)
}
default:
Expand Down
2 changes: 1 addition & 1 deletion activation/malfeasance2_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// ATXMalfeasancePublisher is the publisher for ATX proofs.
type ATXMalfeasancePublisher struct{}

func (p *ATXMalfeasancePublisher) Publish(ctx context.Context, id types.NodeID, proof *wire.ATXProof) error {
func (p *ATXMalfeasancePublisher) Publish(ctx context.Context, id types.NodeID, proof wire.Proof) error {
// TODO(mafa): implement me
return nil
}
6 changes: 3 additions & 3 deletions activation/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions activation/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func Test_NIPost_PostClientHandling(t *testing.T) {
})

t.Run("connect, disconnect, then cancel before reconnect", func(t *testing.T) {
// post client connects, starts post, disconnects in between and proofing is canceled before reconnection
// post client connects, starts post, disconnects in between and proving is canceled before reconnection
sig, err := signing.NewEdSigner()
require.NoError(t, err)

Expand Down Expand Up @@ -713,9 +713,14 @@ func TestNIPSTBuilder_PoetUnstable(t *testing.T) {
)
require.NoError(t, err)

nipst, err := nb.BuildNIPost(context.Background(), sig, challenge,
&types.NIPostChallenge{PublishEpoch: postGenesisEpoch + 2})
require.ErrorIs(t, err, ErrPoetServiceUnstable)
nipst, err := nb.BuildNIPost(
context.Background(),
sig,
challenge,
&types.NIPostChallenge{PublishEpoch: postGenesisEpoch + 2},
)
poetErr := &PoetSvcUnstableError{}
require.ErrorAs(t, err, &poetErr)
require.Nil(t, nipst)
})
t.Run("Submit hangs", func(t *testing.T) {
Expand Down Expand Up @@ -750,9 +755,14 @@ func TestNIPSTBuilder_PoetUnstable(t *testing.T) {
)
require.NoError(t, err)

nipst, err := nb.BuildNIPost(context.Background(), sig, challenge,
&types.NIPostChallenge{PublishEpoch: postGenesisEpoch + 2})
require.ErrorIs(t, err, ErrPoetServiceUnstable)
nipst, err := nb.BuildNIPost(
context.Background(),
sig,
challenge,
&types.NIPostChallenge{PublishEpoch: postGenesisEpoch + 2},
)
poetErr := &PoetSvcUnstableError{}
require.ErrorAs(t, err, &poetErr)
require.Nil(t, nipst)
})
t.Run("GetProof fails", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 77ecaf3

Please sign in to comment.