diff --git a/core/indexer/indexer.go b/core/indexer/indexer.go index 05dfff0..dd10dc3 100644 --- a/core/indexer/indexer.go +++ b/core/indexer/indexer.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/cockroachdb/errors" "github.com/gaze-network/indexer-network/common/errs" "github.com/gaze-network/indexer-network/core/datasources" @@ -142,7 +143,7 @@ func (i *Indexer[T]) process(ctx context.Context) (err error) { // validate reorg from first input { remoteBlockHeader := firstInputHeader - if !remoteBlockHeader.PrevBlock.IsEqual(&i.currentBlock.Hash) { + if i.currentBlock.Hash != (chainhash.Hash{}) && !remoteBlockHeader.PrevBlock.IsEqual(&i.currentBlock.Hash) { logger.WarnContext(ctx, "Detected chain reorganization. Searching for fork point...", slogx.String("event", "reorg_detected"), slogx.Stringer("current_hash", i.currentBlock.Hash), @@ -215,7 +216,7 @@ func (i *Indexer[T]) process(ctx context.Context) (err error) { return errors.Wrapf(errs.InternalError, "input is not continuous, input[%d] height: %d, input[%d] height: %d", i-1, prevHeader.Height, i, header.Height) } - if !header.PrevBlock.IsEqual(&prevHeader.Hash) { + if prevHeader.Hash != (chainhash.Hash{}) && !header.PrevBlock.IsEqual(&prevHeader.Hash) { logger.WarnContext(ctx, "Chain Reorganization occurred in the middle of batch fetching inputs, need to try to fetch again") // end current round diff --git a/modules/runes/constants/constants.go b/modules/runes/constants/constants.go index 90233f3..a17a43f 100644 --- a/modules/runes/constants/constants.go +++ b/modules/runes/constants/constants.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/Cleverse/go-utilities/utils" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/gaze-network/indexer-network/common" "github.com/gaze-network/indexer-network/core/types" @@ -20,22 +19,19 @@ const ( EventHashVersion = 1 ) +// starting block heights and hashes should be 1 block before activation block, as indexer will start from the block after this value var StartingBlockHeader = map[common.Network]types.BlockHeader{ common.NetworkMainnet: { Height: 839999, - Hash: *utils.Must(chainhash.NewHashFromStr("0000000000000000000172014ba58d66455762add0512355ad651207918494ab")), }, common.NetworkTestnet: { Height: 2519999, - Hash: *utils.Must(chainhash.NewHashFromStr("000000000006f45c16402f05d9075db49d3571cf5273cf4cbeaa2aa295f7c833")), }, common.NetworkFractalMainnet: { Height: 83999, - Hash: *utils.Must(chainhash.NewHashFromStr("0000000000000000000000000000000000000000000000000000000000000000")), // TODO: Update this to match real hash }, common.NetworkFractalTestnet: { Height: 83999, - Hash: *utils.Must(chainhash.NewHashFromStr("00000000000000613ddfbdd1778b17cea3818febcbbf82762eafaa9461038343")), }, } diff --git a/modules/runes/processor_process.go b/modules/runes/processor_process.go index f819510..165df69 100644 --- a/modules/runes/processor_process.go +++ b/modules/runes/processor_process.go @@ -691,7 +691,7 @@ func (p *Processor) flushBlock(ctx context.Context, blockHeader types.BlockHeade if err != nil && errors.Is(err, errs.NotFound) && blockHeader.Height-1 == constants.StartingBlockHeader[p.network].Height { prevIndexedBlock = &entity.IndexedBlock{ Height: constants.StartingBlockHeader[p.network].Height, - Hash: constants.StartingBlockHeader[p.network].Hash, + Hash: chainhash.Hash{}, EventHash: chainhash.Hash{}, CumulativeEventHash: chainhash.Hash{}, }