From a67398ca44fb34b66db9fd3e90c1644c3e7b36dc Mon Sep 17 00:00:00 2001 From: Vitalis Salis Date: Mon, 11 Jul 2022 14:50:27 +0300 Subject: [PATCH] Minor fixes --- proto/babylon/btclightclient/event.proto | 8 +++++++- x/btclightclient/keeper/state.go | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/proto/babylon/btclightclient/event.proto b/proto/babylon/btclightclient/event.proto index 60d005996..4a4fb9e74 100644 --- a/proto/babylon/btclightclient/event.proto +++ b/proto/babylon/btclightclient/event.proto @@ -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; } diff --git a/x/btclightclient/keeper/state.go b/x/btclightclient/keeper/state.go index e42b37058..8910058f8 100644 --- a/x/btclightclient/keeper/state.go +++ b/x/btclightclient/keeper/state.go @@ -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() { @@ -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