Skip to content

Commit

Permalink
change to store historical info for all non-empty blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 22, 2023
1 parent b0b1ebe commit 4d08d10
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
66 changes: 66 additions & 0 deletions x/opchild/keeper/abci_listener.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package keeper

import (
"context"
"sync"

abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/baseapp"
store "github.com/cosmos/cosmos-sdk/store/types"
)

var _ baseapp.StreamingService = &ABCIListener{}

// ABCIListener is the abci listener to check whether current block is empty or not.
type ABCIListener struct {
emptyBlock bool
*Keeper
}

func newABCIListener(k *Keeper) ABCIListener {
return ABCIListener{emptyBlock: true, Keeper: k}
}

// ListenDeliverTx updates the steaming service with the latest DeliverTx messages
func (listener *ABCIListener) ListenDeliverTx(ctx context.Context, _ abci.RequestDeliverTx, _ abci.ResponseDeliverTx) error {
listener.emptyBlock = false

return nil
}

// Stream is the streaming service loop, awaits kv pairs and writes them to some destination stream or file
func (listener *ABCIListener) Stream(wg *sync.WaitGroup) error { return nil }

// Listeners returns the streaming service's listeners for the BaseApp to register
func (listener *ABCIListener) Listeners() map[store.StoreKey][]store.WriteListener { return nil }

// ListenBeginBlock updates the streaming service with the latest BeginBlock messages
func (listener *ABCIListener) ListenBeginBlock(ctx context.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error {
listener.emptyBlock = true

return nil
}

// ListenEndBlock updates the steaming service with the latest EndBlock messages
func (listener *ABCIListener) ListenEndBlock(ctx context.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error {

// if a block is empty, then remove historical info.
sdkCtx := sdk.UnwrapSDKContext(ctx)
if listener.emptyBlock && sdkCtx.BlockHeight() != 1 {
listener.DeleteHistoricalInfo(sdkCtx, sdkCtx.BlockHeight())
}

return nil
}

// ListenCommit updates the steaming service with the latest Commit event
func (listener *ABCIListener) ListenCommit(ctx context.Context, res abci.ResponseCommit) error {
return nil
}

// Closer is the interface that wraps the basic Close method.
func (listener *ABCIListener) Close() error {
return nil
}
6 changes: 0 additions & 6 deletions x/opchild/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context) []abci.ValidatorUpdate {
panic(err)
}

// if there is no validator updates,
// delete tracking info to prevent empty block creation.
if len(updates) == 0 {
k.DeleteHistoricalInfo(ctx, ctx.BlockHeight())
}

return updates
}

Expand Down

0 comments on commit 4d08d10

Please sign in to comment.