Skip to content

Commit

Permalink
fix(): fix block hash_list bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zyjblockchain committed Mar 16, 2023
1 parent c16d85d commit 20fe238
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}

0 comments on commit 20fe238

Please sign in to comment.