From 20fe2384d8dec39e936af1a0f86e2d3a48822f07 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Thu, 16 Mar 2023 11:17:29 +0800 Subject: [PATCH] fix(): fix block hash_list bug --- blocks.go | 12 +++++++----- blocks_test.go | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/blocks.go b/blocks.go index eea8571..cec786b 100644 --- a/blocks.go +++ b/blocks.go @@ -23,6 +23,9 @@ func GetBlockIdxs(startHeight int64, arCli *goar.Client) (*BlockIdxs, error) { return nil, err } endHeight := info.Height + if endHeight-startHeight >= 10000 { + endHeight = startHeight + 9999 + } // get block hash_list from trust node spiltList, err := arCli.GetBlockHashList(int(startHeight), int(endHeight)) if err != nil { @@ -56,6 +59,10 @@ func (l *BlockIdxs) existBlock(b types.Block) bool { } func (l *BlockIdxs) VerifyBlock(b types.Block) error { + if !l.existBlock(b) { + log.Warn("block indepHash not exist blockIdxs", "blockHeight", b.Height, "blockIndepHash", b.IndepHash) + return errors.New("block indepHash not exist blockIdxs") + } /* 2.6 is out - https://github.com/ArweaveTeam/arweave/releases/tag/N.2.6.0. The fork activates at height 1132210, approximately 2023-03-06 14:00 UTC. @@ -66,12 +73,7 @@ func (l *BlockIdxs) VerifyBlock(b types.Block) error { return nil } - if !l.existBlock(b) { - log.Warn("block indepHash not exist blockIdxs", "blockHeight", b.Height, "blockIndepHash", b.IndepHash) - return errors.New("block indepHash not exist blockIdxs") - } indepHash := utils.GenerateIndepHash(b) - if indepHash != b.IndepHash { return fmt.Errorf("generateIndepHash not equal; b.IndepHash: %s", b.IndepHash) } diff --git a/blocks_test.go b/blocks_test.go index 636c658..4aebff1 100644 --- a/blocks_test.go +++ b/blocks_test.go @@ -7,7 +7,7 @@ import ( ) func TestGetBlockHashListByHeightRange(t *testing.T) { - start := int64(1095756) + start := int64(1000) arCli := goar.NewClient("https://arweave.net") // info, err := arCli.GetInfo() @@ -21,5 +21,6 @@ func TestGetBlockHashListByHeightRange(t *testing.T) { idx, err := GetBlockIdxs(start, arCli) assert.NoError(t, err) - t.Log(idx) + t.Log(idx.StartHeight) + t.Log(idx.EndHeight) }