Skip to content
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

Move memstore hydration initialized flag to memstore #2681

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
comments
jayy04 committed Jan 11, 2025
commit b4629a913d30982c7588b8a548815b3d5f82f12c
10 changes: 5 additions & 5 deletions protocol/mocks/ClobKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protocol/x/clob/ante/clob.go
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ func (cd ClobDecorator) AnteHandle(
}

// Disable order placement and cancelation processing if the clob keeper is not initialized.
if !cd.clobKeeper.IsInitialized() {
if !cd.clobKeeper.IsInMemStructuresInitialized() {
return ctx, errorsmod.Wrap(
types.ErrClobNotInitialized,
"clob keeper is not initialized. Please wait for the next block.",
2 changes: 1 addition & 1 deletion protocol/x/clob/ante/clob_test.go
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ func runTestCase(t *testing.T, tc TestCase) {
// Setup AnteHandler.
mockClobKeeper := &mocks.ClobKeeper{}
mockClobKeeper.On("Logger", mock.Anything).Return(log.NewNopLogger()).Maybe()
mockClobKeeper.On("IsInitialized").Return(true).Maybe()
mockClobKeeper.On("IsInMemStructuresInitialized").Return(true).Maybe()
cd := ante.NewClobDecorator(mockClobKeeper)
antehandler := sdk.ChainAnteDecorators(cd)
if tc.setupMocks != nil {
54 changes: 27 additions & 27 deletions protocol/x/clob/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ type (
streamingManager streamingtypes.FullNodeStreamingManager
finalizeBlockEventStager finalizeblock.EventStager[*types.ClobStagedFinalizeBlockEvent]

initialized *atomic.Bool
inMemStructuresInitialized *atomic.Bool

Flags flags.ClobFlags

@@ -102,28 +102,28 @@ func NewKeeper(
revshareKeeper types.RevShareKeeper,
) *Keeper {
keeper := &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
transientStoreKey: transientStoreKey,
authorities: lib.UniqueSliceToSet(authorities),
MemClob: memClob,
PerpetualIdToClobPairId: make(map[uint32][]types.ClobPairId),
subaccountsKeeper: subaccountsKeeper,
assetsKeeper: assetsKeeper,
blockTimeKeeper: blockTimeKeeper,
bankKeeper: bankKeeper,
feeTiersKeeper: feeTiersKeeper,
perpetualsKeeper: perpetualsKeeper,
pricesKeeper: pricesKeeper,
statsKeeper: statsKeeper,
rewardsKeeper: rewardsKeeper,
affiliatesKeeper: affiliatesKeeper,
accountPlusKeeper: accountPlusKeeper,
indexerEventManager: indexerEventManager,
streamingManager: streamingManager,
initialized: &atomic.Bool{}, // False by default.
txDecoder: txDecoder,
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
transientStoreKey: transientStoreKey,
authorities: lib.UniqueSliceToSet(authorities),
MemClob: memClob,
PerpetualIdToClobPairId: make(map[uint32][]types.ClobPairId),
subaccountsKeeper: subaccountsKeeper,
assetsKeeper: assetsKeeper,
blockTimeKeeper: blockTimeKeeper,
bankKeeper: bankKeeper,
feeTiersKeeper: feeTiersKeeper,
perpetualsKeeper: perpetualsKeeper,
pricesKeeper: pricesKeeper,
statsKeeper: statsKeeper,
rewardsKeeper: rewardsKeeper,
affiliatesKeeper: affiliatesKeeper,
accountPlusKeeper: accountPlusKeeper,
indexerEventManager: indexerEventManager,
streamingManager: streamingManager,
inMemStructuresInitialized: &atomic.Bool{}, // False by default.
txDecoder: txDecoder,
mevTelemetryConfig: MevTelemetryConfig{
Enabled: clobFlags.MevTelemetryEnabled,
Hosts: clobFlags.MevTelemetryHosts,
@@ -177,9 +177,9 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
func (k Keeper) InitializeForGenesis(ctx sdk.Context) {
}

// IsInitialized returns whether the clob keeper has been hydrated.
func (k Keeper) IsInitialized() bool {
return k.initialized.Load()
// IsInMemStructuresInitialized returns whether the clob keeper has been hydrated.
func (k Keeper) IsInMemStructuresInitialized() bool {
return k.inMemStructuresInitialized.Load()
}

// Initialize hydrates the clob keeper with the necessary in memory data structures.
@@ -189,7 +189,7 @@ func (k Keeper) Initialize(ctx sdk.Context) {

// Code below hydrates the in memory data structures and is not rolled back even if
// the block execution is discarded by OE. Therefore, they are only called once.
alreadyInitialized := k.initialized.Swap(true)
alreadyInitialized := k.inMemStructuresInitialized.Swap(true)
if alreadyInitialized {
return
}
2 changes: 1 addition & 1 deletion protocol/x/clob/types/clob_keeper.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ type ClobKeeper interface {
LiquidationsKeeper
LiquidationsConfigKeeper

IsInitialized() bool
IsInMemStructuresInitialized() bool
Initialize(ctx sdk.Context)

AddOrderToOrderbookSubaccountUpdatesCheck(