Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Distributed POST verification #5390

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
74d1639
Distributed verification - WIP - publishing malf proofs
poszu Dec 22, 2023
ff5dce8
Verify only selected index in post malf proof
poszu Dec 28, 2023
9525a1f
Allow filtering out ATXs when quering for ATX with max height
poszu Dec 29, 2023
33b6781
Verify POST of a candidate for a positioning ATX
poszu Dec 29, 2023
f3486a6
Verify positioning ATX candidate chain
poszu Jan 3, 2024
f640fd4
Verify commitment ATX candidate chain
poszu Jan 5, 2024
4b4a6b9
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 5, 2024
8e1c9e9
Move SQL migration to 0010
poszu Jan 5, 2024
1246894
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 8, 2024
ea7aff6
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 10, 2024
6e80ec1
Fix tests
poszu Jan 11, 2024
ce86414
Configurable delay after which POST is assumed valid
poszu Jan 11, 2024
ff9224a
Merge branch 'develop' into distributed-post-verification
poszu Jan 11, 2024
4552066
[wip] systest for distributed post verification
poszu Jan 11, 2024
9f14f0c
Working systest for post malf proofs
poszu Jan 12, 2024
3a0b249
Bump api
poszu Jan 12, 2024
e8b1878
Revert sql DB changes in post setup mgr and lint
poszu Jan 12, 2024
04bdc36
Use K3=1 in distributed post systest
poszu Jan 12, 2024
5c282b3
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 12, 2024
f12f0ae
Fix waiting for layer end condition
poszu Jan 12, 2024
24479d7
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 26, 2024
2e63575
Bump post and api deps
poszu Jan 26, 2024
252ee44
Review feedback
poszu Jan 26, 2024
a5ddcc5
Fix TestMigrationsAppliedOnce
poszu Jan 26, 2024
1386d47
Refactor ErrInvalidChain as per review
poszu Jan 29, 2024
981396b
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 31, 2024
b164fb0
Mark stored ATXs 'valid' if k3=k2
poszu Jan 31, 2024
2e8ee52
Improve documentation & help of post-k3 config parameter
poszu Jan 31, 2024
0c1edc8
Verify if corrupted post is invalid
poszu Jan 31, 2024
b1a61fd
Fixes in distributed post systest
poszu Jan 31, 2024
75de259
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Jan 31, 2024
afa1cd8
Bump post to v0.11.0 and api to v1.27.0
poszu Jan 31, 2024
303620e
Don't pass --k3 to post-service
poszu Jan 31, 2024
b46f240
Reuse code to load node config in distributed post systest
poszu Feb 1, 2024
de7eba4
Review feedback
poszu Feb 1, 2024
9f55e78
Update CHANGELOG.md
poszu Feb 1, 2024
dae2039
Set the duration after which POST in ATXs is considered valid on main…
poszu Feb 1, 2024
791a357
Merge branch 'develop' into distributed-post-verification
poszu Feb 1, 2024
82de391
Merge remote-tracking branch 'origin/develop' into distributed-post-v…
poszu Feb 2, 2024
02b69cf
Merge branch 'develop' into distributed-post-verification
poszu Feb 2, 2024
73fec9e
Improve poet request timeouts in post malfeasance systest"
poszu Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile-libs.Inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ else
endif
endif

POSTRS_SETUP_REV = 0.6.6
POSTRS_SETUP_REV = 0.7.0
POSTRS_SETUP_ZIP = libpost-$(platform)-v$(POSTRS_SETUP_REV).zip
POSTRS_SETUP_URL_ZIP ?= https://github.com/spacemeshos/post-rs/releases/download/v$(POSTRS_SETUP_REV)/$(POSTRS_SETUP_ZIP)
POSTRS_PROFILER_ZIP = profiler-$(platform)-v$(POSTRS_SETUP_REV).zip
Expand Down
75 changes: 62 additions & 13 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
// Config defines configuration for Builder.
type Config struct {
GoldenATXID types.ATXID
LayersPerEpoch uint32
RegossipInterval time.Duration
}

Expand Down Expand Up @@ -90,11 +89,18 @@
stop context.CancelFunc
poetCfg PoetConfig
poetRetryInterval time.Duration
// delay before PoST in ATX is considered valid (counting from the time it was received)
postValidityDelay time.Duration
}

// BuilderOption ...
type BuilderOption func(*Builder)

func WithPostValidityDelay(delay time.Duration) BuilderOption {
return func(b *Builder) {
b.postValidityDelay = delay
}
}

// WithPoetRetryInterval modifies time that builder will have to wait before retrying ATX build process
// if it failed due to issues with PoET server.
func WithPoetRetryInterval(interval time.Duration) BuilderOption {
Expand Down Expand Up @@ -149,6 +155,7 @@
syncer: syncer,
log: log,
poetRetryInterval: defaultPoetRetryInterval,
postValidityDelay: 12 * time.Hour,
}
for _, opt := range opts {
opt(b)
Expand Down Expand Up @@ -403,7 +410,7 @@
}
}

posAtx, err := b.GetPositioningAtx()
posAtx, err := b.getPositioningAtx(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get positioning ATX: %w", err)
}
Expand Down Expand Up @@ -584,17 +591,24 @@
return len(buf), nil
}

// GetPositioningAtx returns atx id with the highest tick height.
func (b *Builder) GetPositioningAtx() (types.ATXID, error) {
id, err := atxs.GetIDWithMaxHeight(b.cdb, b.signer.NodeID())
if err != nil {
if errors.Is(err, sql.ErrNotFound) {
b.log.Info("using golden atx as positioning atx")
return b.goldenATXID, nil
}
return types.ATXID{}, fmt.Errorf("cannot find pos atx: %w", err)
// getPositioningAtx returns atx id with the highest tick height.
func (b *Builder) getPositioningAtx(ctx context.Context) (types.ATXID, error) {
id, err := findFullyValidHighTickAtx(
ctx,
b.cdb,
b.signer.NodeID(),
b.goldenATXID,
b.validator,
b.log,
VerifyChainOpts.AssumeValidBefore(time.Now().Add(-b.postValidityDelay)),
VerifyChainOpts.WithTrustedID(b.signer.NodeID()),
VerifyChainOpts.WithLogger(b.log),
)
if errors.Is(err, sql.ErrNotFound) {
b.log.Info("using golden atx as positioning atx")
return b.goldenATXID, nil
}
return id, nil
return id, err
}

func (b *Builder) Regossip(ctx context.Context) error {
Expand Down Expand Up @@ -630,3 +644,38 @@
jitter := randomDurationInRange(time.Duration(0), gracePeriod*maxNipostChallengeBuildJitter/100.0)
return roundStart.Add(jitter).Add(-gracePeriod)
}

func findFullyValidHighTickAtx(
poszu marked this conversation as resolved.
Show resolved Hide resolved
ctx context.Context,
db sql.Executor,
prefNodeID types.NodeID,
goldenATXID types.ATXID,
validator nipostValidator,
log *zap.Logger,
opts ...VerifyChainOption,
) (types.ATXID, error) {
rejectedAtxs := make(map[types.ATXID]struct{})
filter := func(id types.ATXID) bool {
_, ok := rejectedAtxs[id]
return !ok
}

for {
select {
case <-ctx.Done():
return types.ATXID{}, ctx.Err()

Check warning on line 666 in activation/activation.go

View check run for this annotation

Codecov / codecov/patch

activation/activation.go#L665-L666

Added lines #L665 - L666 were not covered by tests
default:
}
id, err := atxs.GetIDWithMaxHeight(db, prefNodeID, filter)
if err != nil {
return types.ATXID{}, err
}

if err := validator.VerifyChain(ctx, id, goldenATXID, opts...); err != nil {
log.Info("rejecting candidate for high-tick atx", zap.Error(err), zap.Stringer("atx_id", id))
rejectedAtxs[id] = struct{}{}
} else {
return id, nil
}
}
}
Loading
Loading