Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor-publisher…
Browse files Browse the repository at this point in the history
…-wip
  • Loading branch information
fasmat committed Aug 7, 2024
2 parents ee6ce3b + 83b0499 commit 0175bc9
Show file tree
Hide file tree
Showing 27 changed files with 909 additions and 250 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
4 changes: 2 additions & 2 deletions activation/builder_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestBuilder_BuildsInitialAtxV2(t *testing.T) {
require.Empty(t, atx.Marriages)
require.Equal(t, posEpoch+1, atx.PublishEpoch)
require.Equal(t, sig.NodeID(), atx.SmesherID)
require.True(t, signing.NewEdVerifier().Verify(signing.ATX, atx.SmesherID, atx.SignedBytes(), atx.Signature))
require.True(t, signing.NewEdVerifier().Verify(signing.ATX, atx.SmesherID, atx.ID().Bytes(), atx.Signature))
}

func TestBuilder_SwitchesToBuildV2(t *testing.T) {
Expand Down Expand Up @@ -106,5 +106,5 @@ func TestBuilder_SwitchesToBuildV2(t *testing.T) {
require.Empty(t, atx2.Marriages)
require.Equal(t, atx1.PublishEpoch+1, atx2.PublishEpoch)
require.Equal(t, sig.NodeID(), atx2.SmesherID)
require.True(t, signing.NewEdVerifier().Verify(signing.ATX, atx2.SmesherID, atx2.SignedBytes(), atx2.Signature))
require.True(t, signing.NewEdVerifier().Verify(signing.ATX, atx2.SmesherID, atx2.ID().Bytes(), atx2.Signature))
}
39 changes: 23 additions & 16 deletions activation/handler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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/events"
Expand Down Expand Up @@ -626,9 +627,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 @@ -669,7 +668,7 @@ func (h *HandlerV2) checkMalicious(
return nil
}

malicious, err = h.checkDoubleMarry(ctx, tx, watx.ID(), marrying)
malicious, err = h.checkDoubleMarry(ctx, tx, watx, marrying)
if err != nil {
return fmt.Errorf("checking double marry: %w", err)
}
Expand Down Expand Up @@ -704,18 +703,31 @@ func (h *HandlerV2) checkMalicious(
func (h *HandlerV2) checkDoubleMarry(
ctx context.Context,
tx *sql.Tx,
atxID types.ATXID,
atx *wire.ActivationTxV2,
marrying []marriage,
) (bool, error) {
for _, m := range marrying {
mATX, err := identities.MarriageATX(tx, m.id)
if err != nil {
return false, fmt.Errorf("checking if ID is married: %w", err)
}
if mATX != atxID {
// TODO(mafa): finish proof
proof := &wire.ATXProof{
ProofType: wire.DoubleMarry,
if mATX != atx.ID() {
var blob sql.Blob
v, err := atxs.LoadBlob(ctx, tx, mATX.Bytes(), &blob)
if err != nil {
return true, fmt.Errorf("creating double marry proof: %w", err)
}
if v != types.AtxV2 {
h.logger.Fatal("Failed to create double marry malfeasance proof: ATX is not v2",
zap.Stringer("atx_id", mATX),
)
}
var otherAtx wire.ActivationTxV2
codec.MustDecode(blob.Bytes, &otherAtx)

proof, err := wire.NewDoubleMarryProof(tx, atx, &otherAtx, m.id)
if err != nil {
return true, fmt.Errorf("creating double marry proof: %w", err)
}
return true, h.malPublisher.Publish(ctx, m.id, proof)
}
Expand Down Expand Up @@ -747,9 +759,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 @@ -776,10 +786,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
30 changes: 13 additions & 17 deletions activation/handler_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 @@ -1561,17 +1562,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 @@ -1719,13 +1710,18 @@ func Test_Marriages(t *testing.T) {
gomock.Any(),
sig.NodeID(),
gomock.Cond(func(data any) bool {
proof, ok := data.(*wire.ATXProof)
if !ok {
return false
}
return proof.ProofType == wire.DoubleMarry
_, 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)
b := codec.MustEncode(malProof)
_ = b
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 malfeasancePublisher interface {
Publish(ctx context.Context, id types.NodeID, proof *wire.ATXProof) error
Publish(ctx context.Context, id types.NodeID, proof wire.Proof) error
}

type atxProvider interface {
Expand Down
2 changes: 1 addition & 1 deletion activation/malfeasance2.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// MalfeasancePublisher is the publisher for ATX proofs.
type MalfeasancePublisher struct{}

func (p *MalfeasancePublisher) Publish(ctx context.Context, id types.NodeID, proof *wire.ATXProof) error {
func (p *MalfeasancePublisher) 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 0175bc9

Please sign in to comment.