Skip to content

Commit

Permalink
fix header exchange init error (cosmos#962)
Browse files Browse the repository at this point in the history
Fixes cosmos#846 

As per the discussion in cosmos#846, the aggregator node only need to
initialize the store with genesis header, after that it only needs to
broadcast the header without directly trying to append to store. The
append is take care by the broadcast api which along with broadcasting
also puts the header in the local append queue which then appends to the
local store.

Co-authored-by: Ganesha Upadhyaya <gupadhyaya@Ganeshas-MacBook-Pro-2.local>
  • Loading branch information
gupadhyaya and Ganesha Upadhyaya authored May 31, 2023
1 parent 6e7d3a6 commit 8b1f9b4
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions node/header_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ func NewHeaderExchangeService(ctx context.Context, store ds.TxnDatastore, conf c
}, nil
}

func (hExService *HeaderExchangeService) initOrAppendHeaderStore(ctx context.Context, header *types.SignedHeader) error {
var err error

// Init the header store if first block, else append to store
if header.Height() == hExService.genesis.InitialHeight {
err = hExService.headerStore.Init(ctx, header)
} else {
err = hExService.headerStore.Append(ctx, header)
}
return err
}

func (hExService *HeaderExchangeService) initHeaderStoreAndStartSyncer(ctx context.Context, initial *types.SignedHeader) error {
if err := hExService.headerStore.Init(ctx, initial); err != nil {
return err
Expand All @@ -93,14 +81,13 @@ func (hExService *HeaderExchangeService) tryInitHeaderStoreAndStartSyncer(ctx co
}

func (hExService *HeaderExchangeService) writeToHeaderStoreAndBroadcast(ctx context.Context, signedHeader *types.SignedHeader) {
// Init the header store if first block, else append to store
if err := hExService.initOrAppendHeaderStore(ctx, signedHeader); err != nil {
hExService.logger.Error("failed to write block header to header store", "error", err)
}

// For genesis header, start the syncer
// For genesis header initialize the store and start the syncer
if signedHeader.Height() == hExService.genesis.InitialHeight {
if err := hExService.headerStore.Init(ctx, signedHeader); err != nil {
hExService.logger.Error("failed to initialize header store", "error", err)
}

if err := hExService.syncer.Start(hExService.ctx); err != nil {
hExService.logger.Error("failed to start syncer after initializing header store", "error", err)
}
}
Expand Down

0 comments on commit 8b1f9b4

Please sign in to comment.