Skip to content

Commit 6712378

Browse files
authored
Merge pull request #6704 from spacemeshos/node-split-merge-develop
merge develop
2 parents 9b7d3e4 + 220bb0d commit 6712378

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3063
-1113
lines changed

activation/activation.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ type Builder struct {
9191
layerClock layerClock
9292
syncer Syncer
9393
logger *zap.Logger
94-
parentCtx context.Context
9594
poets []PoetService
9695
poetCfg PoetConfig
9796
poetRetryInterval time.Duration
@@ -135,14 +134,6 @@ func WithPoetRetryInterval(interval time.Duration) BuilderOption {
135134
}
136135
}
137136

138-
// WithContext modifies parent context for background job.
139-
func WithContext(ctx context.Context) BuilderOption {
140-
return func(b *Builder) {
141-
// TODO(mafa): fix this
142-
b.parentCtx = ctx // nolint:fatcontext
143-
}
144-
}
145-
146137
// WithPoetConfig sets the poet config.
147138
func WithPoetConfig(c PoetConfig) BuilderOption {
148139
return func(b *Builder) {
@@ -189,7 +180,6 @@ func NewBuilder(
189180
opts ...BuilderOption,
190181
) *Builder {
191182
b := &Builder{
192-
parentCtx: context.Background(),
193183
signers: make(map[types.NodeID]*signing.EdSigner),
194184
conf: conf,
195185
localDB: localDB,
@@ -229,7 +219,13 @@ func (b *Builder) Register(sig *signing.EdSigner) {
229219
b.postStates.Set(sig.NodeID(), types.PostStateIdle)
230220

231221
if b.stop != nil {
232-
b.startID(b.parentCtx, sig)
222+
ctx, stop := context.WithCancel(context.Background())
223+
prevStop := b.stop
224+
b.stop = func() {
225+
prevStop()
226+
stop()
227+
}
228+
b.startID(ctx, sig)
233229
}
234230
}
235231

@@ -269,9 +265,8 @@ func (b *Builder) StartSmeshing(coinbase types.Address) error {
269265
}
270266

271267
b.coinbaseAccount = coinbase
272-
ctx, stop := context.WithCancel(b.parentCtx)
268+
ctx, stop := context.WithCancel(context.Background())
273269
b.stop = stop
274-
275270
for _, sig := range b.signers {
276271
b.startID(ctx, sig)
277272
}

activation/handler_v1.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/spacemeshos/go-spacemesh/sql"
2828
"github.com/spacemeshos/go-spacemesh/sql/atxs"
2929
"github.com/spacemeshos/go-spacemesh/sql/identities"
30+
"github.com/spacemeshos/go-spacemesh/sql/malfeasance"
3031
"github.com/spacemeshos/go-spacemesh/system"
3132
)
3233

@@ -222,12 +223,12 @@ func (h *HandlerV1) syntacticallyValidateDeps(
222223
watx.NumUnits,
223224
PostSubset([]byte(h.local)), // use the local peer ID as seed for random subset
224225
)
225-
var invalidIdx *verifying.ErrInvalidIndex
226-
if errors.As(err, &invalidIdx) {
226+
var errInvalidIdx *verifying.ErrInvalidIndex
227+
if errors.As(err, &errInvalidIdx) {
227228
h.logger.Debug("ATX with invalid post index",
228229
log.ZContext(ctx),
229230
zap.Stringer("atx_id", watx.ID()),
230-
zap.Int("index", invalidIdx.Index),
231+
zap.Int("index", errInvalidIdx.Index),
231232
)
232233
malicious, err := identities.IsMalicious(h.cdb, watx.SmesherID)
233234
if err != nil {
@@ -236,13 +237,20 @@ func (h *HandlerV1) syntacticallyValidateDeps(
236237
if malicious {
237238
return nil, fmt.Errorf("smesher %s is known malfeasant", watx.SmesherID.ShortString())
238239
}
240+
malicious, err = malfeasance.IsMalicious(h.cdb, watx.SmesherID)
241+
if err != nil {
242+
return nil, fmt.Errorf("check if smesher is malicious: %w", err)
243+
}
244+
if malicious {
245+
return nil, fmt.Errorf("smesher %s is known malfeasant", watx.SmesherID.ShortString())
246+
}
239247
proof := &mwire.MalfeasanceProof{
240248
Layer: watx.PublishEpoch.FirstLayer(),
241249
Proof: mwire.Proof{
242250
Type: mwire.InvalidPostIndex,
243251
Data: &mwire.InvalidPostIndexProof{
244252
Atx: *watx,
245-
InvalidIdx: uint32(invalidIdx.Index),
253+
InvalidIdx: uint32(errInvalidIdx.Index),
246254
},
247255
},
248256
}
@@ -489,6 +497,11 @@ func (h *HandlerV1) storeAtx(ctx context.Context, atx *types.ActivationTx, watx
489497
if err != nil {
490498
return fmt.Errorf("check if node is malicious: %w", err)
491499
}
500+
malicious2, err := malfeasance.IsMalicious(tx, atx.SmesherID)
501+
if err != nil {
502+
return fmt.Errorf("check if node is malicious: %w", err)
503+
}
504+
malicious = malicious || malicious2
492505
if !malicious {
493506
malicious, err = h.checkMalicious(ctx, tx, watx)
494507
if err != nil {

0 commit comments

Comments
 (0)