Skip to content

Commit

Permalink
Bump poet to v0.9.3 (#5003)
Browse files Browse the repository at this point in the history
## Motivation
Bump to the latest version
## Changes
- bumped poet to v0.9.3
- adjusted the code to match the changed poet module structure
- fixed poet client UT (missing PoW)

## Test Plan
existing tests pass
  • Loading branch information
poszu committed Sep 14, 2023
1 parent e9994ca commit e0f2f27
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 54 deletions.
4 changes: 2 additions & 2 deletions activation/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func buildNIPost(tb testing.TB, postProvider *testPostManager, nipostChallenge t
PhaseShift: epoch / 5,
CycleGap: epoch / 10,
GracePeriod: epoch / 10,
RequestTimeout: epoch / 20,
RequestTimeout: epoch / 10,
RequestRetryDelay: epoch / 100,
MaxRequestRetries: 10,
}
Expand All @@ -213,7 +213,7 @@ func buildNIPost(tb testing.TB, postProvider *testPostManager, nipostChallenge t
poetDb,
[]string{poetProver.RestURL().String()},
tb.TempDir(),
logtest.New(tb),
logtest.New(tb, zapcore.DebugLevel),
signer,
poetCfg,
mclock,
Expand Down
42 changes: 21 additions & 21 deletions activation/poet_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import (
"net/http/httptest"
"testing"

"github.com/spacemeshos/poet/config"
rpcapi "github.com/spacemeshos/poet/release/proto/go/rpc/api/v1"
"github.com/spacemeshos/poet/server"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"

"github.com/spacemeshos/go-spacemesh/common/types"
)

func Test_HTTPPoetClient_ParsesURL(t *testing.T) {
cfg := config.DefaultConfig()
cfg := server.DefaultRoundConfig()

t.Run("add http if missing", func(t *testing.T) {
client, err := NewHTTPPoetClient("bla", PoetConfig{
PhaseShift: cfg.Service.PhaseShift,
CycleGap: cfg.Service.CycleGap,
PhaseShift: cfg.PhaseShift,
CycleGap: cfg.CycleGap,
})
require.NoError(t, err)
require.Equal(t, "http://bla", client.baseURL.String())
})

t.Run("do not change scheme if present", func(t *testing.T) {
client, err := NewHTTPPoetClient("https://bla", PoetConfig{
PhaseShift: cfg.Service.PhaseShift,
CycleGap: cfg.Service.CycleGap,
PhaseShift: cfg.PhaseShift,
CycleGap: cfg.CycleGap,
})
require.NoError(t, err)
require.Equal(t, "https://bla", client.baseURL.String())
Expand All @@ -49,10 +49,10 @@ func Test_HTTPPoetClient_Submit(t *testing.T) {
}))
defer ts.Close()

cfg := config.DefaultConfig()
cfg := server.DefaultRoundConfig()
client, err := NewHTTPPoetClient(ts.URL, PoetConfig{
PhaseShift: cfg.Service.PhaseShift,
CycleGap: cfg.Service.CycleGap,
PhaseShift: cfg.PhaseShift,
CycleGap: cfg.CycleGap,
}, withCustomHttpClient(ts.Client()))
require.NoError(t, err)

Expand All @@ -73,18 +73,18 @@ func Test_HTTPPoetClient_Address(t *testing.T) {
}))
defer ts.Close()

cfg := config.DefaultConfig()
cfg := server.DefaultRoundConfig()
client, err := NewHTTPPoetClient(ts.URL, PoetConfig{
PhaseShift: cfg.Service.PhaseShift,
CycleGap: cfg.Service.CycleGap,
PhaseShift: cfg.PhaseShift,
CycleGap: cfg.CycleGap,
}, withCustomHttpClient(ts.Client()))
require.NoError(t, err)

require.Equal(t, ts.URL, client.Address())
}

func Test_HTTPPoetClient_Address_Mainnet(t *testing.T) {
poetCfg := config.DefaultConfig()
poetCfg := server.DefaultRoundConfig()

poETServers := []string{
"https://mainnet-poet-0.spacemesh.network",
Expand All @@ -97,8 +97,8 @@ func Test_HTTPPoetClient_Address_Mainnet(t *testing.T) {
for _, url := range poETServers {
t.Run(url, func(t *testing.T) {
client, err := NewHTTPPoetClient(url, PoetConfig{
PhaseShift: poetCfg.Service.PhaseShift,
CycleGap: poetCfg.Service.CycleGap,
PhaseShift: poetCfg.PhaseShift,
CycleGap: poetCfg.CycleGap,
})
require.NoError(t, err)
require.Equal(t, url, client.Address())
Expand All @@ -119,10 +119,10 @@ func Test_HTTPPoetClient_Proof(t *testing.T) {
}))
defer ts.Close()

cfg := config.DefaultConfig()
cfg := server.DefaultRoundConfig()
client, err := NewHTTPPoetClient(ts.URL, PoetConfig{
PhaseShift: cfg.Service.PhaseShift,
CycleGap: cfg.Service.CycleGap,
PhaseShift: cfg.PhaseShift,
CycleGap: cfg.CycleGap,
}, withCustomHttpClient(ts.Client()))
require.NoError(t, err)

Expand All @@ -143,10 +143,10 @@ func Test_HTTPPoetClient_PoetServiceID(t *testing.T) {
}))
defer ts.Close()

cfg := config.DefaultConfig()
cfg := server.DefaultRoundConfig()
client, err := NewHTTPPoetClient(ts.URL, PoetConfig{
PhaseShift: cfg.Service.PhaseShift,
CycleGap: cfg.Service.CycleGap,
PhaseShift: cfg.PhaseShift,
CycleGap: cfg.CycleGap,
}, withCustomHttpClient(ts.Client()))
require.NoError(t, err)

Expand Down
18 changes: 17 additions & 1 deletion activation/poet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"testing"

"github.com/spacemeshos/poet/shared"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -41,14 +42,29 @@ func TestHTTPPoet(t *testing.T) {
client, err := NewHTTPPoetClient(c.RestURL().String(), DefaultPoetConfig(), WithLogger(zaptest.NewLogger(t)))
require.NoError(t, err)

resp, err := client.PowParams(context.Background())
r.NoError(err)

signer, err := signing.NewEdSigner(signing.WithPrefix([]byte("prefix")))
require.NoError(t, err)
ch := types.RandomHash()

nonce, err := shared.FindSubmitPowNonce(
context.Background(),
resp.Challenge,
ch.Bytes(),
signer.NodeID().Bytes(),
uint(resp.Difficulty),
)
r.NoError(err)

signature := signer.Sign(signing.POET, ch.Bytes())
prefix := bytes.Join([][]byte{signer.Prefix(), {byte(signing.POET)}}, nil)

poetRound, err := client.Submit(context.Background(), prefix, ch.Bytes(), signature, signer.NodeID(), PoetPoW{})
poetRound, err := client.Submit(context.Background(), prefix, ch.Bytes(), signature, signer.NodeID(), PoetPoW{
Nonce: nonce,
Params: *resp,
})
r.NoError(err)
r.NotNil(poetRound)
}
Expand Down
24 changes: 11 additions & 13 deletions activation/poet_test_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"net/url"
"time"

"github.com/spacemeshos/poet/config"
"github.com/spacemeshos/poet/server"
"github.com/spacemeshos/poet/service"
)

// HTTPPoetTestHarness utilizes a local self-contained poet server instance
Expand All @@ -23,35 +21,35 @@ func (h *HTTPPoetTestHarness) RestURL() *url.URL {
}
}

type HTTPPoetOpt func(*config.Config)
type HTTPPoetOpt func(*server.Config)

func WithGenesis(genesis time.Time) HTTPPoetOpt {
return func(cfg *config.Config) {
cfg.Service.Genesis = service.Genesis(genesis)
return func(cfg *server.Config) {
cfg.Genesis = server.Genesis(genesis)
}
}

func WithEpochDuration(epoch time.Duration) HTTPPoetOpt {
return func(cfg *config.Config) {
cfg.Service.EpochDuration = epoch
return func(cfg *server.Config) {
cfg.Round.EpochDuration = epoch
}
}

func WithPhaseShift(phase time.Duration) HTTPPoetOpt {
return func(cfg *config.Config) {
cfg.Service.PhaseShift = phase
return func(cfg *server.Config) {
cfg.Round.PhaseShift = phase
}
}

func WithCycleGap(gap time.Duration) HTTPPoetOpt {
return func(cfg *config.Config) {
cfg.Service.CycleGap = gap
return func(cfg *server.Config) {
cfg.Round.CycleGap = gap
}
}

// NewHTTPPoetTestHarness returns a new instance of HTTPPoetHarness.
func NewHTTPPoetTestHarness(ctx context.Context, poetdir string, opts ...HTTPPoetOpt) (*HTTPPoetTestHarness, error) {
cfg := config.DefaultConfig()
cfg := server.DefaultConfig()
cfg.PoetDir = poetdir
cfg.RawRESTListener = "localhost:0"
cfg.RawRPCListener = "localhost:0"
Expand All @@ -60,7 +58,7 @@ func NewHTTPPoetTestHarness(ctx context.Context, poetdir string, opts ...HTTPPoe
opt(cfg)
}

cfg, err := config.SetupConfig(cfg)
cfg, err := server.SetupConfig(cfg)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/google/uuid v1.3.1
github.com/grafana/pyroscope-go v1.0.2
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/hashicorp/golang-lru/v2 v2.0.6
github.com/ipfs/go-ds-leveldb v0.5.0
Expand All @@ -39,7 +39,7 @@ require (
github.com/spacemeshos/fixed v0.1.1
github.com/spacemeshos/go-scale v1.1.11
github.com/spacemeshos/merkle-tree v0.2.3
github.com/spacemeshos/poet v0.9.1
github.com/spacemeshos/poet v0.9.3
github.com/spacemeshos/post v0.9.4
github.com/spf13/afero v1.9.5
github.com/spf13/cobra v1.7.0
Expand Down Expand Up @@ -193,7 +193,7 @@ require (
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3 h1:o95KDiV/b1xdkumY5
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3/go.mod h1:hTxjzRcX49ogbTGVJ1sM5mz5s+SSgiGIyL3jjPxl32E=
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 h1:LSsiG61v9IzzxMkqEr6nrix4miJI62xlRjwT7BYD2SM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1/go.mod h1:Hbb13e3/WtqQ8U5hLGkek9gJvBLasHuPFI0UEGfnQ10=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -620,8 +620,8 @@ github.com/spacemeshos/go-scale v1.1.11 h1:esFyFSwSvZe+uian2oMUk0cmKWT8IxVt7jjGW
github.com/spacemeshos/go-scale v1.1.11/go.mod h1:loK9wrj9IHxATTrVqIyR2o9SB+E9/SAsiDDXuUfvbA8=
github.com/spacemeshos/merkle-tree v0.2.3 h1:zGEgOR9nxAzJr0EWjD39QFngwFEOxfxMloEJZtAysas=
github.com/spacemeshos/merkle-tree v0.2.3/go.mod h1:VomOcQ5pCBXz7goiWMP5hReyqOfDXGSKbrH2GB9Htww=
github.com/spacemeshos/poet v0.9.1 h1:10wiGjuuGCZq9mAuQjRvNCpE5Uv0KU6yW5eynUCIECU=
github.com/spacemeshos/poet v0.9.1/go.mod h1:ccxzHl5IRSenCSqonPI8M+5vPNwN+o3QU2X41bhbcao=
github.com/spacemeshos/poet v0.9.3 h1:l6nkmKzrMkdSfugh262xXFe0x2UfgfZVm7DSOvi39M8=
github.com/spacemeshos/poet v0.9.3/go.mod h1:PqGMBuUgTQbCEwzYyCoCjFy075dfCS3Ybpy4evqWQqo=
github.com/spacemeshos/post v0.9.4 h1:l/KGneUnLH5imy2Uml7G9kBnJuzl4ag0ku3U0OWaTxc=
github.com/spacemeshos/post v0.9.4/go.mod h1:YjYLMcFFSpxrI86TW2rhyWCWRRFG+8LPiONgARNuaP4=
github.com/spacemeshos/sha256-simd v0.1.0 h1:G7Mfu5RYdQiuE+wu4ZyJ7I0TI74uqLhFnKblEnSpjYI=
Expand Down Expand Up @@ -837,8 +837,8 @@ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4=
golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4=
golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
13 changes: 6 additions & 7 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
grpctags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
"github.com/mitchellh/mapstructure"
poetconfig "github.com/spacemeshos/poet/config"
"github.com/spacemeshos/poet/server"
"github.com/spacemeshos/post/verifying"
"github.com/spf13/afero"
Expand Down Expand Up @@ -964,20 +963,20 @@ func (app *App) launchStandalone(ctx context.Context) error {
if err := app.beaconProtocol.UpdateBeacon(epoch, value); err != nil {
return fmt.Errorf("update standalone beacon: %w", err)
}
cfg := poetconfig.DefaultConfig()
cfg := server.DefaultConfig()
cfg.PoetDir = filepath.Join(app.Config.DataDir(), "poet")

parsed, err := url.Parse(app.Config.PoETServers[0])
if err != nil {
return err
}
cfg.RawRESTListener = parsed.Host
cfg.Service.Genesis.UnmarshalFlag(app.Config.Genesis.GenesisTime)
cfg.Service.EpochDuration = app.Config.LayerDuration * time.Duration(app.Config.LayersPerEpoch)
cfg.Service.CycleGap = app.Config.POET.CycleGap
cfg.Service.PhaseShift = app.Config.POET.PhaseShift
cfg.Genesis.UnmarshalFlag(app.Config.Genesis.GenesisTime)
cfg.Round.EpochDuration = app.Config.LayerDuration * time.Duration(app.Config.LayersPerEpoch)
cfg.Round.CycleGap = app.Config.POET.CycleGap
cfg.Round.PhaseShift = app.Config.POET.PhaseShift

cfg, err = poetconfig.SetupConfig(cfg)
cfg, err = server.SetupConfig(cfg)
if err != nil {
return fmt.Errorf("setup poet config: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion systest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tmpfile := $(shell mktemp /tmp/systest-XXX)
test_name ?= TestSmeshing
org ?= spacemeshos
image_name ?= $(org)/systest:$(version_info)
poet_image ?= spacemeshos/poet:v0.9.1
poet_image ?= spacemeshos/poet:v0.9.3
smesher_image ?= $(org)/go-spacemesh-dev:$(version_info)
bs_image ?= $(org)/go-spacemesh-dev-bs:$(version_info)
test_id ?= systest-$(version_info)
Expand Down

0 comments on commit e0f2f27

Please sign in to comment.