Skip to content

Commit 332e0b5

Browse files
authored
feature flag for system action validation (#4620)
1 parent 2f568fe commit 332e0b5

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

action/protocol/context.go

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ type (
155155
CheckStakingDurationUpperLimit bool
156156
FixRevertSnapshot bool
157157
TimestampedStakingContract bool
158+
PreStateSystemAction bool
158159
MakeUpBlockReward bool
159160
}
160161

@@ -316,6 +317,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
316317
CheckStakingDurationUpperLimit: g.IsVanuatu(height),
317318
FixRevertSnapshot: g.IsVanuatu(height),
318319
TimestampedStakingContract: g.IsWake(height),
320+
PreStateSystemAction: !g.IsWake(height),
319321
MakeUpBlockReward: g.IsWake(height),
320322
},
321323
)

state/factory/workingset.go

+45-17
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ func (ws *workingSet) process(ctx context.Context, actions []*action.SealedEnvel
469469
if err := ws.validate(ctx); err != nil {
470470
return err
471471
}
472+
userActions, systemActions := ws.splitActions(actions)
473+
if protocol.MustGetFeatureCtx(ctx).PreStateSystemAction {
474+
if err := ws.validatePostSystemActions(ctx, systemActions); err != nil {
475+
return err
476+
}
477+
}
472478
reg := protocol.MustGetRegistry(ctx)
473479
for _, p := range reg.All() {
474480
if pp, ok := p.(protocol.PreStatesCreator); ok {
@@ -478,11 +484,10 @@ func (ws *workingSet) process(ctx context.Context, actions []*action.SealedEnvel
478484
}
479485
}
480486
var (
481-
receipts = make([]*action.Receipt, 0)
482-
ctxWithBlockContext = ctx
483-
blkCtx = protocol.MustGetBlockCtx(ctx)
484-
fCtx = protocol.MustGetFeatureCtx(ctx)
485-
userActions, systemActions = ws.splitActions(actions)
487+
receipts = make([]*action.Receipt, 0)
488+
ctxWithBlockContext = ctx
489+
blkCtx = protocol.MustGetBlockCtx(ctx)
490+
fCtx = protocol.MustGetFeatureCtx(ctx)
486491
)
487492
for _, act := range userActions {
488493
if err := ws.txValidator.ValidateWithState(ctxWithBlockContext, act); err != nil {
@@ -513,8 +518,10 @@ func (ws *workingSet) process(ctx context.Context, actions []*action.SealedEnvel
513518
}
514519
}
515520
// Handle post system actions
516-
if err := ws.validatePostSystemActions(ctxWithBlockContext, systemActions); err != nil {
517-
return err
521+
if !protocol.MustGetFeatureCtx(ctx).PreStateSystemAction {
522+
if err := ws.validatePostSystemActions(ctxWithBlockContext, systemActions); err != nil {
523+
return err
524+
}
518525
}
519526
for _, act := range systemActions {
520527
actionCtx, err := withActionCtx(ctxWithBlockContext, act)
@@ -682,6 +689,16 @@ func (ws *workingSet) pickAndRunActions(
682689
executedActions := make([]*action.SealedEnvelope, 0)
683690
reg := protocol.MustGetRegistry(ctx)
684691

692+
var (
693+
systemActions []*action.SealedEnvelope
694+
)
695+
if protocol.MustGetFeatureCtx(ctx).PreStateSystemAction {
696+
systemActions, err = ws.generateSignedSystemActions(ctx, sign)
697+
if err != nil {
698+
return nil, err
699+
}
700+
}
701+
685702
for _, p := range reg.All() {
686703
if pp, ok := p.(protocol.PreStatesCreator); ok {
687704
if err := pp.CreatePreStates(ctx, ws); err != nil {
@@ -800,19 +817,14 @@ func (ws *workingSet) pickAndRunActions(
800817
}
801818
}
802819

803-
unsignedSystemActions, err := ws.generateSystemActions(ctxWithBlockContext)
804-
if err != nil {
805-
return nil, err
806-
}
807-
postSystemActions := make([]*action.SealedEnvelope, len(unsignedSystemActions))
808-
for i, elp := range unsignedSystemActions {
809-
selp, err := sign(elp)
820+
if !fCtx.PreStateSystemAction {
821+
systemActions, err = ws.generateSignedSystemActions(ctx, sign)
810822
if err != nil {
811-
return nil, errors.Wrapf(err, "failed to sign %+v", elp.Action())
823+
return nil, err
812824
}
813-
postSystemActions[i] = selp
814825
}
815-
for _, selp := range postSystemActions {
826+
827+
for _, selp := range systemActions {
816828
actionCtx, err := withActionCtx(ctxWithBlockContext, selp)
817829
if err != nil {
818830
return nil, err
@@ -832,6 +844,22 @@ func (ws *workingSet) pickAndRunActions(
832844
return executedActions, ws.finalize()
833845
}
834846

847+
func (ws *workingSet) generateSignedSystemActions(ctx context.Context, sign func(elp action.Envelope) (*action.SealedEnvelope, error)) ([]*action.SealedEnvelope, error) {
848+
unsignedSystemActions, err := ws.generateSystemActions(ctx)
849+
if err != nil {
850+
return nil, err
851+
}
852+
postSystemActions := make([]*action.SealedEnvelope, len(unsignedSystemActions))
853+
for i, elp := range unsignedSystemActions {
854+
selp, err := sign(elp)
855+
if err != nil {
856+
return nil, errors.Wrapf(err, "failed to sign %+v", elp.Action())
857+
}
858+
postSystemActions[i] = selp
859+
}
860+
return postSystemActions, nil
861+
}
862+
835863
func updateReceiptIndex(receipts []*action.Receipt) {
836864
var txIndex, logIndex uint32
837865
for _, r := range receipts {

0 commit comments

Comments
 (0)