Skip to content

Commit

Permalink
Merge branch 'develop' into no-poet-paralllel
Browse files Browse the repository at this point in the history
  • Loading branch information
acud authored Aug 8, 2024
2 parents 987a307 + 5ac3af2 commit 631e87b
Show file tree
Hide file tree
Showing 45 changed files with 1,705 additions and 444 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ the build folder you need to ensure that you have the gpu setup dynamic library
binary. The simplest way to do this is just copy the library file to be in the
same directory as the go-spacemesh binary. Alternatively you can modify your
system's library search paths (e.g. LD_LIBRARY_PATH) to ensure that the
library is found._
library is found.

go-spacemesh is p2p software which is designed to form a decentralized network by connecting to other instances of
go-spacemesh running on remote computers.
Expand Down
26 changes: 25 additions & 1 deletion activation/activation_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package activation
import (
"errors"
"fmt"
"strings"
)

var (
Expand All @@ -21,8 +22,31 @@ type PoetSvcUnstableError struct {
source error
}

func (e *PoetSvcUnstableError) Error() string {
func (e PoetSvcUnstableError) Error() string {
return fmt.Sprintf("poet service is unstable: %s (%v)", e.msg, e.source)
}

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

type PoetRegistrationMismatchError struct {
registrations []string
configuredPoets []string
}

func (e PoetRegistrationMismatchError) Error() string {
var sb strings.Builder
sb.WriteString("builder: none of configured poets matches the existing registrations.\n")
sb.WriteString("registrations:\n")
for _, r := range e.registrations {
sb.WriteString("\t")
sb.WriteString(r)
sb.WriteString("\n")
}
sb.WriteString("\nconfigured poets:\n")
for _, p := range e.configuredPoets {
sb.WriteString("\t")
sb.WriteString(p)
sb.WriteString("\n")
}
return sb.String()
}
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))
}
2 changes: 1 addition & 1 deletion activation/e2e/atx_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func Test_MarryAndMerge(t *testing.T) {
GracePeriod: epoch / 4,
}

client := ae2e.NewTestPoetClient(2)
client := ae2e.NewTestPoetClient(2, poetCfg)
poetSvc := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

clock, err := timesync.NewClock(
Expand Down
2 changes: 1 addition & 1 deletion activation/e2e/builds_atx_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestBuilder_SwitchesToBuildV2(t *testing.T) {
require.NoError(t, err)
t.Cleanup(clock.Close)

client := ae2e.NewTestPoetClient(1)
client := ae2e.NewTestPoetClient(1, poetCfg)
poetClient := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

localDB := localsql.InMemory()
Expand Down
2 changes: 1 addition & 1 deletion activation/e2e/checkpoint_merged_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Test_CheckpointAfterMerge(t *testing.T) {
GracePeriod: epoch / 4,
}

client := ae2e.NewTestPoetClient(2)
client := ae2e.NewTestPoetClient(2, poetCfg)
poetSvc := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

clock, err := timesync.NewClock(
Expand Down
2 changes: 1 addition & 1 deletion activation/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestCheckpoint_PublishingSoloATXs(t *testing.T) {
CycleGap: 3 * epoch / 4,
GracePeriod: epoch / 4,
}
client := ae2e.NewTestPoetClient(1)
client := ae2e.NewTestPoetClient(1, poetCfg)
poetService := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

// ensure that genesis aligns with layer timings
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestNIPostBuilderWithClients(t *testing.T) {
err = nipost.AddPost(localDb, sig.NodeID(), *fullPost(post, info, shared.ZeroChallenge))
require.NoError(t, err)

client := ae2e.NewTestPoetClient(1)
client := ae2e.NewTestPoetClient(1, poetCfg)
poetService := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

localDB := localsql.InMemory()
Expand Down Expand Up @@ -272,7 +272,7 @@ func Test_NIPostBuilderWithMultipleClients(t *testing.T) {
}

poetDb := activation.NewPoetDb(db, logger.Named("poetDb"))
client := ae2e.NewTestPoetClient(len(signers))
client := ae2e.NewTestPoetClient(len(signers), poetCfg)
poetService := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

mclock := activation.NewMocklayerClock(ctrl)
Expand Down
20 changes: 14 additions & 6 deletions activation/e2e/poet_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"net/url"
"strconv"
"sync"
"time"
Expand All @@ -20,15 +19,17 @@ import (
)

type TestPoet struct {
mu sync.Mutex
round int
mu sync.Mutex
round int
poetCfg activation.PoetConfig

expectedMembers int
registrations chan []byte
}

func NewTestPoetClient(expectedMembers int) *TestPoet {
func NewTestPoetClient(expectedMembers int, poetCfg activation.PoetConfig) *TestPoet {
return &TestPoet{
poetCfg: poetCfg,
expectedMembers: expectedMembers,
registrations: make(chan []byte, expectedMembers),
}
Expand Down Expand Up @@ -66,8 +67,15 @@ func (p *TestPoet) Submit(
return &types.PoetRound{ID: strconv.Itoa(round), End: time.Now()}, nil
}

func (p *TestPoet) CertifierInfo(ctx context.Context) (*url.URL, []byte, error) {
return nil, nil, errors.New("not supported")
func (p *TestPoet) CertifierInfo(ctx context.Context) (*types.CertifierInfo, error) {
return nil, errors.New("CertifierInfo: not supported")
}

func (p *TestPoet) Info(ctx context.Context) (*types.PoetInfo, error) {
return &types.PoetInfo{
PhaseShift: p.poetCfg.PhaseShift,
CycleGap: p.poetCfg.CycleGap,
}, nil
}

// Build a proof.
Expand Down
8 changes: 4 additions & 4 deletions activation/e2e/poet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ func TestCertifierInfo(t *testing.T) {
)
require.NoError(t, err)

url, pubkey, err := client.CertifierInfo(context.Background())
certInfo, err := client.CertifierInfo(context.Background())
r.NoError(err)
r.Equal("http://localhost:8080", url.String())
r.Equal([]byte("pubkey"), pubkey)
r.Equal("http://localhost:8080", certInfo.Url.String())
r.Equal([]byte("pubkey"), certInfo.Pubkey)
}

func TestNoCertifierInfo(t *testing.T) {
Expand Down Expand Up @@ -291,6 +291,6 @@ func TestNoCertifierInfo(t *testing.T) {
)
require.NoError(t, err)

_, _, err = client.CertifierInfo(context.Background())
_, err = client.CertifierInfo(context.Background())
r.ErrorContains(err, "poet doesn't support certificates")
}
2 changes: 1 addition & 1 deletion activation/e2e/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestValidator_Validate(t *testing.T) {
}

poetDb := activation.NewPoetDb(sql.InMemory(), logger.Named("poetDb"))
client := ae2e.NewTestPoetClient(1)
client := ae2e.NewTestPoetClient(1, poetCfg)
poetService := activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)

mclock := activation.NewMocklayerClock(ctrl)
Expand Down
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
Loading

0 comments on commit 631e87b

Please sign in to comment.