diff --git a/actions/rollup_register.go b/actions/rollup_register.go index 29b6f6c..9a575c8 100644 --- a/actions/rollup_register.go +++ b/actions/rollup_register.go @@ -70,16 +70,25 @@ func (r *RollupRegistration) Execute( switch r.OpCode { case CreateRollup: - if contains(namespaces, r.Namespace) { - return nil, ErrNameSpaceAlreadyRegistered + if !contains(namespaces, r.Namespace) { + namespaces = append(namespaces, r.Namespace) + } else { + // only allow modifing informations that are not related to ExitEpoch or StartEpoch + if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { + return nil, fmt.Errorf("authorization failed: %s", err.Error()) + } } if r.Info.StartEpoch < Epoch(hght, rules.GetEpochLength())+2 || r.Info.ExitEpoch != 0 { return nil, fmt.Errorf("epoch number is not valid, minimum: %d, actual: %d, exit: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.StartEpoch, r.Info.ExitEpoch) } - namespaces = append(namespaces, r.Namespace) + if r.Info.ExitEpoch != 0 { + return nil, fmt.Errorf("exit epoch not 0") + } + if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(CREATE): %w", err) } + // TODO: not useful as CreateRollup now handle both creation and update case UpdateRollup: // only allow modifing informations that are not related to ExitEpoch or StartEpoch if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil {