Skip to content

Commit

Permalink
get rid of block hash check (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 authored May 6, 2024
1 parent 7719ccc commit ecefcd4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
2 changes: 1 addition & 1 deletion executor/bsc_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"math/big"
"sync"
"time"

"github.com/avast/retry-go/v4"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down
23 changes: 0 additions & 23 deletions listener/bsc_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ func (l *BSCListener) monitorCrossChainPkgAt(nextHeight uint64, latestPolledBloc
}
logging.Logger.Infof("retrieved BSC block header at height=%d", nextHeight)

if l.config.BSCConfig.IsOpCrossChain() {
// check if the latest polled block in DB is forked, if so, delete it.
isForked, err := l.isForkedBlockAndDelete(latestPolledBlock, nextHeight, nextHeightBlockHeader.ParentHash)
if err != nil {
return err
}
if isForked {
return fmt.Errorf("there is fork at block height=%d", latestPolledBlock.Height)
}
}

logs, err := l.queryCrossChainLogs(nextHeight)
if err != nil {
return fmt.Errorf("failed to get logs from block at height=%d, err=%s", nextHeight, err.Error())
Expand Down Expand Up @@ -168,18 +157,6 @@ func (l *BSCListener) queryCrossChainLogs(height uint64) ([]types.Log, error) {
return logs, nil
}

func (l *BSCListener) isForkedBlockAndDelete(latestPolledBlock *model.BscBlock, nextHeight uint64, parentHash ethcommon.Hash) (bool, error) {
if latestPolledBlock.Height != 0 && latestPolledBlock.Height+1 == nextHeight && parentHash.String() != latestPolledBlock.BlockHash {
// delete latestPolledBlock and its cross-chain packages and votes for these packages from DB.
if err := l.DaoManager.BSCDao.DeleteBlockAndPackagesAndVotesAtHeight(latestPolledBlock.Height); err != nil {
return true, err
}
logging.Logger.Infof("deleted block at height=%d from DB due to there is a fork", latestPolledBlock.Height)
return true, nil
}
return false, nil
}

func (l *BSCListener) getCrossChainPackageEventHash() ethcommon.Hash {
return ethcommon.HexToHash(CrossChainPackageEventHex)
}
Expand Down

0 comments on commit ecefcd4

Please sign in to comment.