Skip to content

Commit

Permalink
Check execution already exist before submit
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Mar 12, 2024
1 parent e8557c7 commit af93289
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,6 @@ func (h *Header) SyncExecutionHeader(ctx context.Context, blockRoot common.Hash)
if err != nil {
return fmt.Errorf("get header update by slot with ancestry proof: %w", err)
}
err = h.writer.WriteToParachainAndWatch(ctx, "EthereumBeaconClient.submit_execution_header", headerUpdate)
if err != nil {
return fmt.Errorf("submit_execution_header: %w", err)
}
var blockHash types.H256
if headerUpdate.ExecutionHeader.Deneb != nil {
blockHash = headerUpdate.ExecutionHeader.Deneb.BlockHash
Expand All @@ -354,6 +350,18 @@ func (h *Header) SyncExecutionHeader(ctx context.Context, blockRoot common.Hash)
if err != nil {
return fmt.Errorf("get compactExecutionHeaderState by blockHash: %w", err)
}
if compactExecutionHeaderState.BlockNumber != 0 {
log.WithFields(log.Fields{"blockRoot": blockRoot.Hex(), "blockHash": blockHash.Hex(), "blockNumber": compactExecutionHeaderState.BlockNumber}).Info("ExecutionHeaderState already exist")
return nil
}
err = h.writer.WriteToParachainAndWatch(ctx, "EthereumBeaconClient.submit_execution_header", headerUpdate)
if err != nil {
return fmt.Errorf("submit_execution_header: %w", err)
}
compactExecutionHeaderState, err = h.writer.GetCompactExecutionHeaderStateByBlockHash(blockHash)
if err != nil {
return fmt.Errorf("get compactExecutionHeaderState by blockHash: %w", err)
}
if compactExecutionHeaderState.BlockNumber == 0 {
return fmt.Errorf("invalid compactExecutionHeaderState")
}
Expand Down

0 comments on commit af93289

Please sign in to comment.