Skip to content

Commit

Permalink
Simplify switch to different poet services (#6116)
Browse files Browse the repository at this point in the history
## Motivation

Fix of issue #5563



Co-authored-by: Matthias <5011972+fasmat@users.noreply.github.com>
  • Loading branch information
ConvallariaMaj and fasmat committed Aug 7, 2024
1 parent a79bdbb commit 5ac3af2
Show file tree
Hide file tree
Showing 20 changed files with 816 additions and 207 deletions.
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()
}
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
Loading

0 comments on commit 5ac3af2

Please sign in to comment.