diff --git a/bridge/setu/util/common.go b/bridge/setu/util/common.go index 01266f0ce..7da8fcf46 100644 --- a/bridge/setu/util/common.go +++ b/bridge/setu/util/common.go @@ -331,7 +331,7 @@ func GetCheckpointParams(cliCtx cliContext.CLIContext) (*checkpointTypes.Params, } // GetBufferedCheckpoint return checkpoint from bueffer -func GetBufferedCheckpoint(cliCtx cliContext.CLIContext) (*hmtypes.CheckpointBlockHeader, error) { +func GetBufferedCheckpoint(cliCtx cliContext.CLIContext) (*hmtypes.Checkpoint, error) { response, err := helper.FetchFromAPI( cliCtx, helper.GetHeimdallServerEndpoint(BufferedCheckpointURL), @@ -342,7 +342,7 @@ func GetBufferedCheckpoint(cliCtx cliContext.CLIContext) (*hmtypes.CheckpointBlo return nil, err } - var blockHeader hmtypes.CheckpointBlockHeader + var blockHeader hmtypes.Checkpoint if err := json.Unmarshal(response.Result, &blockHeader); err != nil { logger.Error("Error unmarshalling buffered checkpoint", "url", BufferedCheckpointURL, "err", err) return nil, err diff --git a/checkpoint/client/rest/query.go b/checkpoint/client/rest/query.go index 6cf2757b6..0e5353225 100644 --- a/checkpoint/client/rest/query.go +++ b/checkpoint/client/rest/query.go @@ -250,11 +250,11 @@ func noackHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } type stateDump struct { - ACKCount uint64 `json:"ack_count"` - CheckpointBuffer *hmTypes.CheckpointBlockHeader `json:"checkpoint_buffer"` - ValidatorCount int `json:"validator_count"` - ValidatorSet hmTypes.ValidatorSet `json:"validator_set"` - LastNoACK time.Time `json:"last_noack_time"` + ACKCount uint64 `json:"ack_count"` + CheckpointBuffer *hmTypes.Checkpoint `json:"checkpoint_buffer"` + ValidatorCount int `json:"validator_count"` + ValidatorSet hmTypes.ValidatorSet `json:"validator_set"` + LastNoACK time.Time `json:"last_noack_time"` } // get all state-dump of heimdall @@ -286,11 +286,11 @@ func overviewHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { // Checkpoint buffer // - var _checkpoint *hmTypes.CheckpointBlockHeader + var _checkpoint *hmTypes.Checkpoint checkpointBufferBytes, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCheckpointBuffer), nil) if err == nil { if len(checkpointBufferBytes) != 0 { - _checkpoint = new(hmTypes.CheckpointBlockHeader) + _checkpoint = new(hmTypes.Checkpoint) if err = json.Unmarshal(checkpointBufferBytes, _checkpoint); err != nil { // log and ignore RestLogger.Error("Error while unmarshing checkpoint header", "error", err) diff --git a/checkpoint/genesis_test.go b/checkpoint/genesis_test.go index ab901c0d7..6b693adcf 100644 --- a/checkpoint/genesis_test.go +++ b/checkpoint/genesis_test.go @@ -58,10 +58,10 @@ func (suite *GenesisTestSuite) TestInitExportGenesis() { timestamp, ) - checkpointBlockHeaders := make([]hmTypes.CheckpointBlockHeader, ackCount) + Checkpoints := make([]hmTypes.Checkpoint, ackCount) - for i := range checkpointBlockHeaders { - checkpointBlockHeaders[i] = bufferedCheckpoint + for i := range Checkpoints { + Checkpoints[i] = bufferedCheckpoint } params := types.DefaultParams() @@ -70,7 +70,7 @@ func (suite *GenesisTestSuite) TestInitExportGenesis() { &bufferedCheckpoint, uint64(lastNoACK), uint64(ackCount), - checkpointBlockHeaders, + Checkpoints, ) checkpoint.InitGenesis(ctx, app.CheckpointKeeper, genesisState) diff --git a/checkpoint/handler_test.go b/checkpoint/handler_test.go index 7d43a387e..438989f99 100644 --- a/checkpoint/handler_test.go +++ b/checkpoint/handler_test.go @@ -364,7 +364,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpointNoAckBeforeBufferTimeout() require.True(t, !result.IsOK(), errs.CodeToDefaultMsg(result.Code)) } -func (suite *HandlerTestSuite) SendCheckpoint(header hmTypes.CheckpointBlockHeader) (res sdk.Result) { +func (suite *HandlerTestSuite) SendCheckpoint(header hmTypes.Checkpoint) (res sdk.Result) { t, app, ctx := suite.T(), suite.app, suite.ctx // keeper := app.CheckpointKeeper topupKeeper := app.TopupKeeper diff --git a/checkpoint/integration_test.go b/checkpoint/integration_test.go index 9b9a988ea..20d03d52f 100644 --- a/checkpoint/integration_test.go +++ b/checkpoint/integration_test.go @@ -26,10 +26,10 @@ func createTestApp(isCheckTx bool) (*app.HeimdallApp, sdk.Context, context.CLICo params := types.NewParams(5*time.Second, 256, 1024) - checkpointBlockHeaders := make([]hmTypes.CheckpointBlockHeader, 0) + Checkpoints := make([]hmTypes.Checkpoint, 0) - for i := range checkpointBlockHeaders { - checkpointBlockHeaders[i] = hmTypes.CheckpointBlockHeader{} + for i := range Checkpoints { + Checkpoints[i] = hmTypes.Checkpoint{} } checkpointGenesis := types.NewGenesisState( diff --git a/checkpoint/keeper.go b/checkpoint/keeper.go index c6e905db8..7a81dc076 100644 --- a/checkpoint/keeper.go +++ b/checkpoint/keeper.go @@ -81,7 +81,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // AddCheckpoint adds checkpoint into final blocks -func (k *Keeper) AddCheckpoint(ctx sdk.Context, headerBlockNumber uint64, headerBlock hmTypes.CheckpointBlockHeader) error { +func (k *Keeper) AddCheckpoint(ctx sdk.Context, headerBlockNumber uint64, headerBlock hmTypes.Checkpoint) error { key := GetHeaderKey(headerBlockNumber) err := k.addCheckpoint(ctx, key, headerBlock) if err != nil { @@ -92,7 +92,7 @@ func (k *Keeper) AddCheckpoint(ctx sdk.Context, headerBlockNumber uint64, header } // SetCheckpointBuffer flushes Checkpoint Buffer -func (k *Keeper) SetCheckpointBuffer(ctx sdk.Context, headerBlock hmTypes.CheckpointBlockHeader) error { +func (k *Keeper) SetCheckpointBuffer(ctx sdk.Context, headerBlock hmTypes.Checkpoint) error { err := k.addCheckpoint(ctx, BufferCheckpointKey, headerBlock) if err != nil { return err @@ -101,7 +101,7 @@ func (k *Keeper) SetCheckpointBuffer(ctx sdk.Context, headerBlock hmTypes.Checkp } // addCheckpoint adds checkpoint to store -func (k *Keeper) addCheckpoint(ctx sdk.Context, key []byte, headerBlock hmTypes.CheckpointBlockHeader) error { +func (k *Keeper) addCheckpoint(ctx sdk.Context, key []byte, headerBlock hmTypes.Checkpoint) error { store := ctx.KVStore(k.storeKey) // create Checkpoint block and marshall @@ -118,10 +118,10 @@ func (k *Keeper) addCheckpoint(ctx sdk.Context, key []byte, headerBlock hmTypes. } // GetCheckpointByIndex to get checkpoint by header block index 10,000 ,20,000 and so on -func (k *Keeper) GetCheckpointByIndex(ctx sdk.Context, headerIndex uint64) (hmTypes.CheckpointBlockHeader, error) { +func (k *Keeper) GetCheckpointByIndex(ctx sdk.Context, headerIndex uint64) (hmTypes.Checkpoint, error) { store := ctx.KVStore(k.storeKey) headerKey := GetHeaderKey(headerIndex) - var _checkpoint hmTypes.CheckpointBlockHeader + var _checkpoint hmTypes.Checkpoint if store.Has(headerKey) { err := k.cdc.UnmarshalBinaryBare(store.Get(headerKey), &_checkpoint) @@ -136,11 +136,11 @@ func (k *Keeper) GetCheckpointByIndex(ctx sdk.Context, headerIndex uint64) (hmTy } // GetCheckpointList returns all checkpoints with params like page and limit -func (k *Keeper) GetCheckpointList(ctx sdk.Context, page uint64, limit uint64) ([]hmTypes.CheckpointBlockHeader, error) { +func (k *Keeper) GetCheckpointList(ctx sdk.Context, page uint64, limit uint64) ([]hmTypes.Checkpoint, error) { store := ctx.KVStore(k.storeKey) // create headers - var headers []hmTypes.CheckpointBlockHeader + var headers []hmTypes.Checkpoint // have max limit if limit > 20 { @@ -152,7 +152,7 @@ func (k *Keeper) GetCheckpointList(ctx sdk.Context, page uint64, limit uint64) ( // loop through validators to get valid validators for ; iterator.Valid(); iterator.Next() { - var checkpointHeader hmTypes.CheckpointBlockHeader + var checkpointHeader hmTypes.Checkpoint if err := k.cdc.UnmarshalBinaryBare(iterator.Value(), &checkpointHeader); err == nil { headers = append(headers, checkpointHeader) } @@ -162,7 +162,7 @@ func (k *Keeper) GetCheckpointList(ctx sdk.Context, page uint64, limit uint64) ( } // GetLastCheckpoint gets last checkpoint, headerIndex = TotalACKs * ChildBlockInterval -func (k *Keeper) GetLastCheckpoint(ctx sdk.Context) (hmTypes.CheckpointBlockHeader, error) { +func (k *Keeper) GetLastCheckpoint(ctx sdk.Context) (hmTypes.Checkpoint, error) { store := ctx.KVStore(k.storeKey) acksCount := k.GetACKCount(ctx) @@ -170,7 +170,7 @@ func (k *Keeper) GetLastCheckpoint(ctx sdk.Context) (hmTypes.CheckpointBlockHead lastCheckpointKey := helper.GetConfig().ChildBlockInterval * acksCount // fetch checkpoint and unmarshall - var _checkpoint hmTypes.CheckpointBlockHeader + var _checkpoint hmTypes.Checkpoint // no checkpoint received // header key @@ -206,11 +206,11 @@ func (k *Keeper) FlushCheckpointBuffer(ctx sdk.Context) { } // GetCheckpointFromBuffer gets checkpoint in buffer -func (k *Keeper) GetCheckpointFromBuffer(ctx sdk.Context) (*hmTypes.CheckpointBlockHeader, error) { +func (k *Keeper) GetCheckpointFromBuffer(ctx sdk.Context) (*hmTypes.Checkpoint, error) { store := ctx.KVStore(k.storeKey) // checkpoint block header - var checkpoint hmTypes.CheckpointBlockHeader + var checkpoint hmTypes.Checkpoint if store.Has(BufferCheckpointKey) { // Get checkpoint and unmarshall @@ -245,18 +245,18 @@ func (k *Keeper) GetLastNoAck(ctx sdk.Context) uint64 { } // GetCheckpointHeaders get checkpoint headers -func (k *Keeper) GetCheckpointHeaders(ctx sdk.Context) []hmTypes.CheckpointBlockHeader { +func (k *Keeper) GetCheckpointHeaders(ctx sdk.Context) []hmTypes.Checkpoint { store := ctx.KVStore(k.storeKey) // get checkpoint header iterator iterator := sdk.KVStorePrefixIterator(store, HeaderBlockKey) defer iterator.Close() // create headers - var headers []hmTypes.CheckpointBlockHeader + var headers []hmTypes.Checkpoint // loop through validators to get valid validators for ; iterator.Valid(); iterator.Next() { - var checkpointHeader hmTypes.CheckpointBlockHeader + var checkpointHeader hmTypes.Checkpoint if err := k.cdc.UnmarshalBinaryBare(iterator.Value(), &checkpointHeader); err == nil { headers = append(headers, checkpointHeader) } diff --git a/checkpoint/keeper_test.go b/checkpoint/keeper_test.go index ce7529b41..3076d1c2d 100644 --- a/checkpoint/keeper_test.go +++ b/checkpoint/keeper_test.go @@ -40,7 +40,7 @@ func (suite *KeeperTestSuite) TestAddCheckpoint() { timestamp := uint64(time.Now().Unix()) borChainId := "1234" - checkpointBlockHeader := hmTypes.CreateBlock( + Checkpoint := hmTypes.CreateBlock( startBlock, endBlock, rootHash, @@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) TestAddCheckpoint() { borChainId, timestamp, ) - err := keeper.AddCheckpoint(ctx, headerBlockNumber, checkpointBlockHeader) + err := keeper.AddCheckpoint(ctx, headerBlockNumber, Checkpoint) require.NoError(t, err) result, err := keeper.GetCheckpointByIndex(ctx, headerBlockNumber) @@ -81,7 +81,7 @@ func (suite *KeeperTestSuite) TestGetCheckpointList() { timestamp := uint64(time.Now().Unix()) + uint64(i) borChainId := "1234" - checkpointBlockHeader := hmTypes.CreateBlock( + Checkpoint := hmTypes.CreateBlock( startBlock, endBlock, rootHash, @@ -90,7 +90,7 @@ func (suite *KeeperTestSuite) TestGetCheckpointList() { timestamp, ) - keeper.AddCheckpoint(ctx, headerBlockNumber, checkpointBlockHeader) + keeper.AddCheckpoint(ctx, headerBlockNumber, Checkpoint) keeper.UpdateACKCount(ctx) } diff --git a/checkpoint/side_handler.go b/checkpoint/side_handler.go index 58d690a72..2978a98a1 100644 --- a/checkpoint/side_handler.go +++ b/checkpoint/side_handler.go @@ -152,7 +152,7 @@ func PostHandleMsgCheckpoint(ctx sdk.Context, k Keeper, msg types.MsgCheckpoint, timeStamp := uint64(ctx.BlockTime().Unix()) // Add checkpoint to buffer with root hash and account hash - k.SetCheckpointBuffer(ctx, hmTypes.CheckpointBlockHeader{ + k.SetCheckpointBuffer(ctx, hmTypes.Checkpoint{ StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, RootHash: msg.RootHash, diff --git a/checkpoint/simulation/genesis.go b/checkpoint/simulation/genesis.go index 15bb63afe..4f81ce611 100644 --- a/checkpoint/simulation/genesis.go +++ b/checkpoint/simulation/genesis.go @@ -29,10 +29,10 @@ func RandomizedGenState(simState *module.SimulationState) { timestamp, ) - checkpointBlockHeaders := make([]hmTypes.CheckpointBlockHeader, ackCount) + Checkpoints := make([]hmTypes.Checkpoint, ackCount) - for i := range checkpointBlockHeaders { - checkpointBlockHeaders[i] = bufferedCheckpoint + for i := range Checkpoints { + Checkpoints[i] = bufferedCheckpoint } params := types.DefaultParams() @@ -41,7 +41,7 @@ func RandomizedGenState(simState *module.SimulationState) { &bufferedCheckpoint, uint64(lastNoACK), uint64(ackCount), - checkpointBlockHeaders, + Checkpoints, ) simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(genesisState) diff --git a/checkpoint/types/genesis.go b/checkpoint/types/genesis.go index 5c27bd7eb..fb9392f1d 100644 --- a/checkpoint/types/genesis.go +++ b/checkpoint/types/genesis.go @@ -12,19 +12,19 @@ import ( type GenesisState struct { Params Params `json:"params" yaml:"params"` - BufferedCheckpoint *hmTypes.CheckpointBlockHeader `json:"buffered_checkpoint" yaml:"buffered_checkpoint"` - LastNoACK uint64 `json:"last_no_ack" yaml:"last_no_ack"` - AckCount uint64 `json:"ack_count" yaml:"ack_count"` - Headers []hmTypes.CheckpointBlockHeader `json:"headers" yaml:"headers"` + BufferedCheckpoint *hmTypes.Checkpoint `json:"buffered_checkpoint" yaml:"buffered_checkpoint"` + LastNoACK uint64 `json:"last_no_ack" yaml:"last_no_ack"` + AckCount uint64 `json:"ack_count" yaml:"ack_count"` + Headers []hmTypes.Checkpoint `json:"headers" yaml:"headers"` } // NewGenesisState creates a new genesis state. func NewGenesisState( params Params, - bufferedCheckpoint *hmTypes.CheckpointBlockHeader, + bufferedCheckpoint *hmTypes.Checkpoint, lastNoACK uint64, ackCount uint64, - headers []hmTypes.CheckpointBlockHeader, + headers []hmTypes.Checkpoint, ) GenesisState { return GenesisState{ Params: params, diff --git a/test/common.go b/test/common.go index cfce8f3f3..0afe06e83 100644 --- a/test/common.go +++ b/test/common.go @@ -63,7 +63,7 @@ func LoadValidatorSet(count int, t *testing.T, keeper staking.Keeper, ctx sdk.Co } // GenRandCheckpointHeader return headers -func GenRandCheckpointHeader(start uint64, headerSize uint64, maxCheckpointLenght uint64) (headerBlock types.CheckpointBlockHeader, err error) { +func GenRandCheckpointHeader(start uint64, headerSize uint64, maxCheckpointLenght uint64) (headerBlock types.Checkpoint, err error) { end := start + headerSize borChainID := "1234" rootHash := types.HexToHeimdallHash("123") diff --git a/types/header.go b/types/header.go index 27cdcb8fd..bbf2d8f6f 100644 --- a/types/header.go +++ b/types/header.go @@ -5,8 +5,8 @@ import ( "sort" ) -// CheckpointBlockHeader block header struct -type CheckpointBlockHeader struct { +// Checkpoint block header struct +type Checkpoint struct { Proposer HeimdallAddress `json:"proposer"` StartBlock uint64 `json:"start_block"` EndBlock uint64 `json:"end_block"` @@ -23,8 +23,8 @@ func CreateBlock( proposer HeimdallAddress, borChainID string, timestamp uint64, -) CheckpointBlockHeader { - return CheckpointBlockHeader{ +) Checkpoint { + return Checkpoint{ StartBlock: start, EndBlock: end, RootHash: rootHash, @@ -35,7 +35,7 @@ func CreateBlock( } // SortHeaders sorts array of headers on the basis for timestamps -func SortHeaders(headers []CheckpointBlockHeader) []CheckpointBlockHeader { +func SortHeaders(headers []Checkpoint) []Checkpoint { sort.Slice(headers, func(i, j int) bool { return headers[i].TimeStamp < headers[j].TimeStamp }) @@ -43,9 +43,9 @@ func SortHeaders(headers []CheckpointBlockHeader) []CheckpointBlockHeader { } // String returns human redable string -func (m CheckpointBlockHeader) String() string { +func (m Checkpoint) String() string { return fmt.Sprintf( - "CheckpointBlockHeader {%v (%d:%d) %v %v %v}", + "Checkpoint {%v (%d:%d) %v %v %v}", m.Proposer.String(), m.StartBlock, m.EndBlock,