github.com/palisadeinc/bor@v0.0.0-20230615125219-ab7196213d15/consensus/bor/heimdallapp/checkpoint.go (about)

     1  package heimdallapp
     2  
     3  import (
     4  	"context"
     5  	"math/big"
     6  
     7  	"github.com/cosmos/cosmos-sdk/types"
     8  
     9  	"github.com/ethereum/go-ethereum/consensus/bor/heimdall/checkpoint"
    10  	"github.com/ethereum/go-ethereum/log"
    11  
    12  	hmTypes "github.com/maticnetwork/heimdall/types"
    13  	abci "github.com/tendermint/tendermint/abci/types"
    14  )
    15  
    16  func (h *HeimdallAppClient) FetchCheckpointCount(_ context.Context) (int64, error) {
    17  	log.Info("Fetching checkpoint count")
    18  
    19  	res := h.hApp.CheckpointKeeper.GetACKCount(h.NewContext())
    20  
    21  	log.Info("Fetched checkpoint count")
    22  
    23  	return int64(res), nil
    24  }
    25  
    26  func (h *HeimdallAppClient) FetchCheckpoint(_ context.Context, number int64) (*checkpoint.Checkpoint, error) {
    27  	log.Info("Fetching checkpoint", "number", number)
    28  
    29  	res, err := h.hApp.CheckpointKeeper.GetCheckpointByNumber(h.NewContext(), uint64(number))
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	log.Info("Fetched checkpoint", "number", number)
    35  
    36  	return toBorCheckpoint(res), nil
    37  }
    38  
    39  func (h *HeimdallAppClient) NewContext() types.Context {
    40  	return h.hApp.NewContext(true, abci.Header{Height: h.hApp.LastBlockHeight()})
    41  }
    42  
    43  func toBorCheckpoint(hdCheckpoint hmTypes.Checkpoint) *checkpoint.Checkpoint {
    44  	return &checkpoint.Checkpoint{
    45  		Proposer:   hdCheckpoint.Proposer.EthAddress(),
    46  		StartBlock: big.NewInt(int64(hdCheckpoint.StartBlock)),
    47  		EndBlock:   big.NewInt(int64(hdCheckpoint.EndBlock)),
    48  		RootHash:   hdCheckpoint.RootHash.EthHash(),
    49  		BorChainID: hdCheckpoint.BorChainID,
    50  		Timestamp:  hdCheckpoint.TimeStamp,
    51  	}
    52  }