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

Dang/query spot price #84

Merged
merged 3 commits into from
Mar 10, 2025
Merged

Dang/query spot price #84

merged 3 commits into from
Mar 10, 2025

Conversation

GNaD13
Copy link
Collaborator

@GNaD13 GNaD13 commented Mar 10, 2025

No description provided.

@GNaD13 GNaD13 merged commit 1b6860c into feat/txfees Mar 10, 2025
@GNaD13 GNaD13 deleted the dang/query-spot-price branch March 10, 2025 04:11
Comment on lines +14 to +58
k.IterateEpochInfo(ctx, func(index int64, epochInfo types.EpochInfo) (stop bool) {
logger := k.Logger(ctx)

// If blocktime < initial epoch start time, return
if ctx.BlockTime().Before(epochInfo.StartTime) {
return false
}
// if epoch counting hasn't started, signal we need to start.
shouldInitialEpochStart := !epochInfo.EpochCountingStarted

epochEndTime := epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
shouldEpochStart := (ctx.BlockTime().After(epochEndTime)) || shouldInitialEpochStart

if !shouldEpochStart {
logger.Info(fmt.Sprintf("Epoch with identifier %s has not ended yet", epochInfo.Identifier))
return false
}
epochInfo.CurrentEpochStartHeight = ctx.BlockHeight()

if shouldInitialEpochStart {
epochInfo.EpochCountingStarted = true
epochInfo.CurrentEpoch = 1
epochInfo.CurrentEpochStartTime = epochInfo.StartTime
logger.Info(fmt.Sprintf("Starting new epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
} else {
k.AfterEpochEnd(ctx, epochInfo.Identifier)
epochInfo.CurrentEpoch++
epochInfo.CurrentEpochStartTime = epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
logger.Info(fmt.Sprintf("Starting epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
}

// emit new epoch start event, set epoch info, and run BeforeEpochStart hook
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeEpochStart,
sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochInfo.CurrentEpoch)),
sdk.NewAttribute(types.AttributeEpochStartTime, fmt.Sprintf("%d", epochInfo.CurrentEpochStartTime.Unix())),
),
)
if err := k.SetEpochInfo(ctx, epochInfo); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("error setting epoch info: %s", err.Error()))
return true
}
return false
})

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
epoch := types.EpochInfo{}
err := k.cdc.Unmarshal(iterator.Value(), &epoch)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant