Skip to content

Commit cacd3c9

Browse files
authored
refactor(block): simplify dual namespace (#2626)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview This PR simplifies the namespace migration. Currently, header and data namespaces after the migration must be different than the legacy namespace. Leading to 3 calls until the no data was published on the legacy namespaces. This requirement wasn't enforced leading to footgun. We decided to simplify the migration by requiring removing the header namespace and undeprecating the global namespace. This allows instead of always having 3 calls to have at most 2. <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> -->
1 parent 42f454b commit cacd3c9

File tree

14 files changed

+317
-696
lines changed

14 files changed

+317
-696
lines changed

apps/evm/single/cmd/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ var RunCmd = &cobra.Command{
4747
ec.SetLogger(logger.With().Str("module", "engine_client").Logger())
4848
}
4949

50-
headerNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.HeaderNamespace))
51-
dataNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.DataNamespace))
50+
headerNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.GetNamespace()))
51+
dataNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.GetDataNamespace()))
5252

5353
logger.Info().Str("headerNamespace", hex.EncodeToString(headerNamespace)).Str("dataNamespace", hex.EncodeToString(dataNamespace)).Msg("namespaces")
5454

apps/grpc/single/cmd/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ The execution client must implement the Evolve execution gRPC interface.`,
4747

4848
logger := rollcmd.SetupLogger(nodeConfig.Log)
4949

50-
headerNamespace := coreda.PrepareNamespace([]byte(nodeConfig.DA.HeaderNamespace))
51-
dataNamespace := coreda.PrepareNamespace([]byte(nodeConfig.DA.DataNamespace))
50+
headerNamespace := coreda.PrepareNamespace([]byte(nodeConfig.DA.GetNamespace()))
51+
dataNamespace := coreda.PrepareNamespace([]byte(nodeConfig.DA.GetDataNamespace()))
5252

5353
logger.Info().Str("headerNamespace", hex.EncodeToString(headerNamespace)).Str("dataNamespace", hex.EncodeToString(dataNamespace)).Msg("namespaces")
5454

apps/testapp/cmd/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ var RunCmd = &cobra.Command{
4747
ctx, cancel := context.WithCancel(context.Background())
4848
defer cancel()
4949

50-
headerNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.HeaderNamespace))
51-
dataNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.DataNamespace))
50+
headerNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.GetNamespace()))
51+
dataNamespace := da.PrepareNamespace([]byte(nodeConfig.DA.GetDataNamespace()))
5252

5353
logger.Info().Str("headerNamespace", hex.EncodeToString(headerNamespace)).Str("dataNamespace", hex.EncodeToString(dataNamespace)).Msg("namespaces")
5454

block/da_speed_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,21 @@ func setupManagerForTest(t *testing.T, initialDAHeight uint64) (*Manager, *rollm
119119
Node: config.NodeConfig{BlockTime: config.DurationWrapper{Duration: blockTime}},
120120
DA: config.DAConfig{BlockTime: config.DurationWrapper{Duration: blockTime}},
121121
},
122-
genesis: genesis.Genesis{ProposerAddress: addr},
123-
daHeight: new(atomic.Uint64),
124-
heightInCh: make(chan daHeightEvent),
125-
headerStore: headerStore,
126-
dataStore: dataStore,
127-
headerCache: cache.NewCache[types.SignedHeader](),
128-
dataCache: cache.NewCache[types.Data](),
129-
headerStoreCh: make(chan struct{}),
130-
dataStoreCh: make(chan struct{}),
131-
retrieveCh: make(chan struct{}),
132-
logger: logger,
133-
lastStateMtx: new(sync.RWMutex),
134-
da: mockDAClient,
135-
namespaceMigrationCompleted: &atomic.Bool{},
136-
signer: noopSigner,
137-
metrics: NopMetrics(),
122+
genesis: genesis.Genesis{ProposerAddress: addr},
123+
daHeight: new(atomic.Uint64),
124+
heightInCh: make(chan daHeightEvent),
125+
headerStore: headerStore,
126+
dataStore: dataStore,
127+
headerCache: cache.NewCache[types.SignedHeader](),
128+
dataCache: cache.NewCache[types.Data](),
129+
headerStoreCh: make(chan struct{}),
130+
dataStoreCh: make(chan struct{}),
131+
retrieveCh: make(chan struct{}),
132+
logger: logger,
133+
lastStateMtx: new(sync.RWMutex),
134+
da: mockDAClient,
135+
signer: noopSigner,
136+
metrics: NopMetrics(),
138137
}
139138
manager.daIncludedHeight.Store(0)
140139
manager.daHeight.Store(initialDAHeight)

block/manager.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ const (
4444
// defaultMempoolTTL is the number of blocks until transaction is dropped from mempool
4545
defaultMempoolTTL = 25
4646

47-
// Key for storing namespace migration state in the store
48-
namespaceMigrationKey = "namespace_migration_completed"
49-
5047
// Applies to the headerInCh and dataInCh, 10000 is a large enough number for headers per DA block.
5148
eventInChLength = 10000
5249
)
@@ -154,10 +151,6 @@ type Manager struct {
154151
// validatorHasherProvider is used to provide the validator hash for the header.
155152
// It is used to set the validator hash in the header.
156153
validatorHasherProvider types.ValidatorHasherProvider
157-
158-
// namespaceMigrationCompleted tracks whether we have completed the migration
159-
// from legacy namespace to separate header/data namespaces
160-
namespaceMigrationCompleted *atomic.Bool
161154
}
162155

163156
// getInitialState tries to load lastState from Store, and if it's not available it reads genesis.
@@ -394,19 +387,13 @@ func NewManager(
394387
aggregatorSignaturePayloadProvider: managerOpts.AggregatorNodeSignatureBytesProvider,
395388
syncNodeSignaturePayloadProvider: managerOpts.SyncNodeSignatureBytesProvider,
396389
validatorHasherProvider: managerOpts.ValidatorHasherProvider,
397-
namespaceMigrationCompleted: &atomic.Bool{},
398390
}
399391

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

405-
// initialize namespace migration state
406-
if migrationData, err := m.store.GetMetadata(ctx, namespaceMigrationKey); err == nil && len(migrationData) > 0 {
407-
m.namespaceMigrationCompleted.Store(migrationData[0] == 1)
408-
}
409-
410397
// Set the default publishBlock implementation
411398
m.publishBlock = m.publishBlockInternal
412399

@@ -428,24 +415,6 @@ func NewManager(
428415
return m, nil
429416
}
430417

431-
// setNamespaceMigrationCompleted marks the namespace migration as completed and persists it to disk
432-
func (m *Manager) setNamespaceMigrationCompleted(ctx context.Context) error {
433-
m.namespaceMigrationCompleted.Store(true)
434-
return m.store.SetMetadata(ctx, namespaceMigrationKey, []byte{1})
435-
}
436-
437-
// loadNamespaceMigrationState loads the namespace migration state from persistent storage
438-
func (m *Manager) loadNamespaceMigrationState(ctx context.Context) (bool, error) {
439-
migrationData, err := m.store.GetMetadata(ctx, namespaceMigrationKey)
440-
if err != nil {
441-
if errors.Is(err, ds.ErrNotFound) {
442-
return false, nil // Migration not completed
443-
}
444-
return false, fmt.Errorf("failed to load migration state: %w", err)
445-
}
446-
return len(migrationData) > 0 && migrationData[0] == 1, nil
447-
}
448-
449418
// PendingHeaders returns the pending headers.
450419
func (m *Manager) PendingHeaders() *PendingHeaders {
451420
return m.pendingHeaders

0 commit comments

Comments
 (0)