Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
11 changes: 11 additions & 0 deletions apps/evm/based/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ func NewExtendedRunNodeCmd(ctx context.Context) *cobra.Command {
return fmt.Errorf("failed to create datastore: %w", err)
}

// Determine namespace for based sequencer (transactions should go to data namespace)
var sequencerNamespace []byte
if nodeConfig.DA.DataNamespace != "" {
sequencerNamespace = []byte(nodeConfig.DA.DataNamespace)
} else if basedNamespace != "" {
sequencerNamespace = []byte(basedNamespace)
} else {
sequencerNamespace = []byte("rollkit-data") // Default data namespace
}

// Pass raw DA implementation and namespace to NewSequencer
sequencer, err := based.NewSequencer(
logger,
Expand All @@ -146,6 +156,7 @@ func NewExtendedRunNodeCmd(ctx context.Context) *cobra.Command {
basedStartHeight,
basedMaxHeightDrift,
datastore,
sequencerNamespace,
)
if err != nil {
return fmt.Errorf("failed to create based sequencer: %w", err)
Expand Down
31 changes: 31 additions & 0 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const (
// This is temporary solution. It will be removed in future versions.
maxSubmitAttempts = 30

// Key for storing namespace migration state in the store
namespaceMigrationKey = "namespace_migration_completed"

// Applies to the headerInCh and dataInCh, 10000 is a large enough number for headers per DA block.
eventInChLength = 10000
)
Expand Down Expand Up @@ -168,6 +171,10 @@ type Manager struct {
// validatorHasherProvider is used to provide the validator hash for the header.
// It is used to set the validator hash in the header.
validatorHasherProvider types.ValidatorHasherProvider

// namespaceMigrationCompleted tracks whether we have completed the migration
// from legacy namespace to separate header/data namespaces
namespaceMigrationCompleted *atomic.Bool
}

// getInitialState tries to load lastState from Store, and if it's not available it reads genesis.
Expand Down Expand Up @@ -400,13 +407,19 @@ func NewManager(
txNotifyCh: make(chan struct{}, 1), // Non-blocking channel
signaturePayloadProvider: managerOpts.SignaturePayloadProvider,
validatorHasherProvider: managerOpts.ValidatorHasherProvider,
namespaceMigrationCompleted: &atomic.Bool{},
}

// initialize da included height
if height, err := m.store.GetMetadata(ctx, storepkg.DAIncludedHeightKey); err == nil && len(height) == 8 {
m.daIncludedHeight.Store(binary.LittleEndian.Uint64(height))
}

// initialize namespace migration state
if migrationData, err := m.store.GetMetadata(ctx, namespaceMigrationKey); err == nil && len(migrationData) > 0 {
m.namespaceMigrationCompleted.Store(migrationData[0] == 1)
}

// Set the default publishBlock implementation
m.publishBlock = m.publishBlockInternal

Expand All @@ -418,6 +431,24 @@ func NewManager(
return m, nil
}

// setNamespaceMigrationCompleted marks the namespace migration as completed and persists it to disk
func (m *Manager) setNamespaceMigrationCompleted(ctx context.Context) error {
m.namespaceMigrationCompleted.Store(true)
return m.store.SetMetadata(ctx, namespaceMigrationKey, []byte{1})
}

// loadNamespaceMigrationState loads the namespace migration state from persistent storage
func (m *Manager) loadNamespaceMigrationState(ctx context.Context) (bool, error) {
migrationData, err := m.store.GetMetadata(ctx, namespaceMigrationKey)
if err != nil {
if errors.Is(err, ds.ErrNotFound) {
return false, nil // Migration not completed
}
return false, fmt.Errorf("failed to load migration state: %w", err)
}
return len(migrationData) > 0 && migrationData[0] == 1, nil
}

// PendingHeaders returns the pending headers.
func (m *Manager) PendingHeaders() *PendingHeaders {
return m.pendingHeaders
Expand Down
Loading
Loading