Skip to content

Commit

Permalink
chg: CheckpointBlockHeader to Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsayli committed May 18, 2020
1 parent e9573fd commit b478266
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions bridge/setu/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions checkpoint/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions checkpoint/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -70,7 +70,7 @@ func (suite *GenesisTestSuite) TestInitExportGenesis() {
&bufferedCheckpoint,
uint64(lastNoACK),
uint64(ackCount),
checkpointBlockHeaders,
Checkpoints,
)

checkpoint.InitGenesis(ctx, app.CheckpointKeeper, genesisState)
Expand Down
2 changes: 1 addition & 1 deletion checkpoint/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions checkpoint/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 15 additions & 15 deletions checkpoint/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
}
Expand All @@ -162,15 +162,15 @@ 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)

// fetch last checkpoint key (NumberOfACKs * ChildBlockInterval)
lastCheckpointKey := helper.GetConfig().ChildBlockInterval * acksCount

// fetch checkpoint and unmarshall
var _checkpoint hmTypes.CheckpointBlockHeader
var _checkpoint hmTypes.Checkpoint

// no checkpoint received
// header key
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions checkpoint/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func (suite *KeeperTestSuite) TestAddCheckpoint() {
timestamp := uint64(time.Now().Unix())
borChainId := "1234"

checkpointBlockHeader := hmTypes.CreateBlock(
Checkpoint := hmTypes.CreateBlock(
startBlock,
endBlock,
rootHash,
proposerAddress,
borChainId,
timestamp,
)
err := keeper.AddCheckpoint(ctx, headerBlockNumber, checkpointBlockHeader)
err := keeper.AddCheckpoint(ctx, headerBlockNumber, Checkpoint)
require.NoError(t, err)

result, err := keeper.GetCheckpointByIndex(ctx, headerBlockNumber)
Expand Down Expand Up @@ -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,
Expand All @@ -90,7 +90,7 @@ func (suite *KeeperTestSuite) TestGetCheckpointList() {
timestamp,
)

keeper.AddCheckpoint(ctx, headerBlockNumber, checkpointBlockHeader)
keeper.AddCheckpoint(ctx, headerBlockNumber, Checkpoint)
keeper.UpdateACKCount(ctx)
}

Expand Down
2 changes: 1 addition & 1 deletion checkpoint/side_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions checkpoint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -41,7 +41,7 @@ func RandomizedGenState(simState *module.SimulationState) {
&bufferedCheckpoint,
uint64(lastNoACK),
uint64(ackCount),
checkpointBlockHeaders,
Checkpoints,
)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(genesisState)

Expand Down
12 changes: 6 additions & 6 deletions checkpoint/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions types/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -23,8 +23,8 @@ func CreateBlock(
proposer HeimdallAddress,
borChainID string,
timestamp uint64,
) CheckpointBlockHeader {
return CheckpointBlockHeader{
) Checkpoint {
return Checkpoint{
StartBlock: start,
EndBlock: end,
RootHash: rootHash,
Expand All @@ -35,17 +35,17 @@ 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
})
return headers
}

// 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,
Expand Down

0 comments on commit b478266

Please sign in to comment.