Skip to content

add feature flag for system action validation #4620

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
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type (
CheckStakingDurationUpperLimit bool
FixRevertSnapshot bool
TimestampedStakingContract bool
PreStateSystemAction bool
MakeUpBlockReward bool
}

Expand Down Expand Up @@ -316,6 +317,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
CheckStakingDurationUpperLimit: g.IsVanuatu(height),
FixRevertSnapshot: g.IsVanuatu(height),
TimestampedStakingContract: g.IsWake(height),
PreStateSystemAction: !g.IsWake(height),
MakeUpBlockReward: g.IsWake(height),
},
)
Expand Down
62 changes: 45 additions & 17 deletions state/factory/workingset.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ func (ws *workingSet) process(ctx context.Context, actions []*action.SealedEnvel
if err := ws.validate(ctx); err != nil {
return err
}
userActions, systemActions := ws.splitActions(actions)
if protocol.MustGetFeatureCtx(ctx).PreStateSystemAction {
if err := ws.validatePostSystemActions(ctx, systemActions); err != nil {
return err
}
}
reg := protocol.MustGetRegistry(ctx)
for _, p := range reg.All() {
if pp, ok := p.(protocol.PreStatesCreator); ok {
Expand All @@ -478,11 +484,10 @@ func (ws *workingSet) process(ctx context.Context, actions []*action.SealedEnvel
}
}
var (
receipts = make([]*action.Receipt, 0)
ctxWithBlockContext = ctx
blkCtx = protocol.MustGetBlockCtx(ctx)
fCtx = protocol.MustGetFeatureCtx(ctx)
userActions, systemActions = ws.splitActions(actions)
receipts = make([]*action.Receipt, 0)
ctxWithBlockContext = ctx
blkCtx = protocol.MustGetBlockCtx(ctx)
fCtx = protocol.MustGetFeatureCtx(ctx)
)
for _, act := range userActions {
if err := ws.txValidator.ValidateWithState(ctxWithBlockContext, act); err != nil {
Expand Down Expand Up @@ -513,8 +518,10 @@ func (ws *workingSet) process(ctx context.Context, actions []*action.SealedEnvel
}
}
// Handle post system actions
if err := ws.validatePostSystemActions(ctxWithBlockContext, systemActions); err != nil {
return err
if !protocol.MustGetFeatureCtx(ctx).PreStateSystemAction {
if err := ws.validatePostSystemActions(ctxWithBlockContext, systemActions); err != nil {
return err
}
}
for _, act := range systemActions {
actionCtx, err := withActionCtx(ctxWithBlockContext, act)
Expand Down Expand Up @@ -682,6 +689,16 @@ func (ws *workingSet) pickAndRunActions(
executedActions := make([]*action.SealedEnvelope, 0)
reg := protocol.MustGetRegistry(ctx)

var (
systemActions []*action.SealedEnvelope
)
if protocol.MustGetFeatureCtx(ctx).PreStateSystemAction {
systemActions, err = ws.generateSignedSystemActions(ctx, sign)
if err != nil {
return nil, err
}
}

for _, p := range reg.All() {
if pp, ok := p.(protocol.PreStatesCreator); ok {
if err := pp.CreatePreStates(ctx, ws); err != nil {
Expand Down Expand Up @@ -800,19 +817,14 @@ func (ws *workingSet) pickAndRunActions(
}
}

unsignedSystemActions, err := ws.generateSystemActions(ctxWithBlockContext)
if err != nil {
return nil, err
}
postSystemActions := make([]*action.SealedEnvelope, len(unsignedSystemActions))
for i, elp := range unsignedSystemActions {
selp, err := sign(elp)
if !fCtx.PreStateSystemAction {
systemActions, err = ws.generateSignedSystemActions(ctx, sign)
if err != nil {
return nil, errors.Wrapf(err, "failed to sign %+v", elp.Action())
return nil, err
}
postSystemActions[i] = selp
}
for _, selp := range postSystemActions {

for _, selp := range systemActions {
actionCtx, err := withActionCtx(ctxWithBlockContext, selp)
if err != nil {
return nil, err
Expand All @@ -832,6 +844,22 @@ func (ws *workingSet) pickAndRunActions(
return executedActions, ws.finalize()
}

func (ws *workingSet) generateSignedSystemActions(ctx context.Context, sign func(elp action.Envelope) (*action.SealedEnvelope, error)) ([]*action.SealedEnvelope, error) {
unsignedSystemActions, err := ws.generateSystemActions(ctx)
if err != nil {
return nil, err
}
postSystemActions := make([]*action.SealedEnvelope, len(unsignedSystemActions))
for i, elp := range unsignedSystemActions {
selp, err := sign(elp)
if err != nil {
return nil, errors.Wrapf(err, "failed to sign %+v", elp.Action())
}
postSystemActions[i] = selp
}
return postSystemActions, nil
}

func updateReceiptIndex(receipts []*action.Receipt) {
var txIndex, logIndex uint32
for _, r := range receipts {
Expand Down