Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vitsalis committed Jul 11, 2022
1 parent f764d2b commit ff8aaaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion proto/babylon/btclightclient/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import "babylon/btclightclient/btclightclient.proto";

option go_package = "github.com/babylonchain/babylon/x/btclightclient/types";

// EventBTCRollBack is emitted on Msg/InsertHeader
// The header included in the event is the block in the history
// of the current mainchain to which we are rolling back to.
// In other words, there is one rollback event emitted per re-org, to the
// greatest common ancestor of the old and the new fork.
message EventBTCRollBack {
BTCHeaderInfo header = 1;
}

// EventBTCRollForward is emitted on Msg/InsertHeader
// The header included in the event is the one the main chain is extended with.
// In the event of a reorg, each block on the new fork that comes after
// the greatest common ancestor will have a corresponding roll forward event.
message EventBTCRollForward {
BTCHeaderInfo header = 1;
}
8 changes: 4 additions & 4 deletions x/btclightclient/keeper/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,16 @@ func (s HeadersState) GetHighestCommonAncestor(header1 *wire.BlockHeader, header
}

// GetInOrderAncestorsUntil returns the list of nodes starting from the child and ending with the block *before* the `ancestor`.
func (s HeadersState) GetInOrderAncestorsUntil(child *wire.BlockHeader, parent *wire.BlockHeader) []*wire.BlockHeader {
func (s HeadersState) GetInOrderAncestorsUntil(child *wire.BlockHeader, ancestor *wire.BlockHeader) []*wire.BlockHeader {
currentHeader := child

var ancestors []*wire.BlockHeader
ancestors = append(ancestors, child)
if isParent(child, parent) {
if isParent(child, ancestor) {
return ancestors
}
s.iterateReverseHeaders(func(header *wire.BlockHeader) bool {
if header.BlockHash() == parent.BlockHash() {
if header.BlockHash() == ancestor.BlockHash() {
return true
}
if header.BlockHash().String() == currentHeader.PrevBlock.String() {
Expand Down Expand Up @@ -313,7 +313,7 @@ func (s HeadersState) TipExists() bool {

// updateLongestChain checks whether the tip should be updated and returns true if it does
func (s HeadersState) updateLongestChain(header *wire.BlockHeader, cumulativeWork *big.Int) {
// If there is no existing tip, then the header is set as the tiBTCp
// If there is no existing tip, then the header is set as the tip
if !s.TipExists() {
s.CreateTip(header)
return
Expand Down

0 comments on commit ff8aaaf

Please sign in to comment.