Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(blockstate): if blocktree fails to search a hash in memory, load it from disk #3059

Merged
merged 35 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a86dcb3
Fixing descendant search
kishansagathiya Jan 23, 2023
b20a8e2
fix lint
kishansagathiya Jan 23, 2023
9e7be4d
parent -> hash
kishansagathiya Jan 23, 2023
d0aa5f8
different approach for getting descendants
kishansagathiya Jan 24, 2023
32db55a
different approach for getting descendants
kishansagathiya Jan 25, 2023
532db0e
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Jan 25, 2023
0f76155
fixed the use of bs.GetAllDescendants
kishansagathiya Jan 26, 2023
b7f0a8a
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Jan 26, 2023
d3cae2a
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Jan 26, 2023
d552579
Update dot/state/block.go
kishansagathiya Jan 30, 2023
0a9e2af
Update dot/state/block.go
kishansagathiya Jan 30, 2023
254951a
Update dot/state/block.go
kishansagathiya Jan 30, 2023
0ef5508
Update dot/state/block.go
kishansagathiya Jan 30, 2023
a2b1893
Update dot/state/block.go
kishansagathiya Jan 30, 2023
3103de3
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Jan 30, 2023
3529a36
temp
kishansagathiya Jan 30, 2023
57f5eb8
temo
kishansagathiya Jan 30, 2023
382592f
added a test for GetAllDescendants
kishansagathiya Feb 1, 2023
0385de1
Merge branch 'kishan/fix/syncing' of github.com:ChainSafe/gossamer in…
kishansagathiya Feb 1, 2023
15087ec
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Feb 1, 2023
8f0075f
fix lint
kishansagathiya Feb 1, 2023
166d7cf
addressed a review comment
kishansagathiya Feb 2, 2023
a50a5f6
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Feb 6, 2023
a8c026d
fix copyright
kishansagathiya Feb 6, 2023
5d681e8
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Feb 10, 2023
4bc59c1
tackle the scenario when multiple blocks have same block number
kishansagathiya Feb 10, 2023
47a507e
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Feb 13, 2023
73cb1b3
suppress deepsouce random warning
kishansagathiya Feb 14, 2023
c46b8fb
Merge branch 'development' into kishan/fix/syncing
kishansagathiya Feb 14, 2023
0f80ba4
try
kishansagathiya Feb 14, 2023
396f913
Update dot/state/block.go
kishansagathiya Feb 14, 2023
72a758a
Update dot/state/block.go
kishansagathiya Feb 14, 2023
2cf149b
Update lib/blocktree/test_helpers.go
kishansagathiya Feb 14, 2023
8e8756a
rename test_helpers to helpers_test
kishansagathiya Feb 14, 2023
89dce6d
Merge branch 'kishan/fix/syncing' of github.com:ChainSafe/gossamer in…
kishansagathiya Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,54 @@ func (bs *BlockState) GetHashByNumber(num uint) (common.Hash, error) {
return common.NewHash(bh), nil
}

// GetAllDescendants gets all the descendants even if hash is not stored in memory.
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
func (bs *BlockState) GetAllDescendants(hash common.Hash) ([]common.Hash, error) {
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
allDescendants, err := bs.bt.GetAllDescendants(hash)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
if err != nil && !errors.Is(err, blocktree.ErrNodeNotFound) {
return nil, err
}

if err == nil {
return allDescendants, nil
}

header, err := bs.GetHeader(hash)
if err != nil {
return nil, fmt.Errorf("getting header from hash %s: %w", hash, err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

// TODO: Use GetBlocksByNumber after https://github.com/ChainSafe/gossamer/issues/2748 is done
nextBlock, err := bs.GetBlockByNumber(header.Number + 1)
if err != nil {
return nil, fmt.Errorf("getting block by number %d: %w", header.Number+1, err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

// next block number is not descendant of hash
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
if nextBlock.Header.ParentHash != hash {
return nil, nil
}

allDescendants = append(allDescendants, nextBlock.Header.Hash())

nextDescendants, err := bs.bt.GetAllDescendants(nextBlock.Header.Hash())
if err != nil && !errors.Is(err, blocktree.ErrNodeNotFound) {
return nil, fmt.Errorf("failed to get descendants: %w", err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}
if err == nil {
allDescendants = append(allDescendants, nextDescendants...)
return allDescendants, nil
}

nextDescendants, err = bs.GetAllDescendants(nextBlock.Header.Hash())
if err != nil {
return nil, err
}

allDescendants = append(allDescendants, nextDescendants...)

return allDescendants, nil
}

// GetBlockHashesBySlot gets all block hashes that were produced in the given slot.
func (bs *BlockState) GetBlockHashesBySlot(slotNum uint64) ([]common.Hash, error) {
highestFinalisedHash, err := bs.GetHighestFinalisedHash()
Expand All @@ -258,7 +306,13 @@ func (bs *BlockState) GetBlockHashesBySlot(slotNum uint64) ([]common.Hash, error
}

descendants, err := bs.bt.GetAllDescendants(highestFinalisedHash)
if err != nil {
if errors.Is(err, blocktree.ErrNodeNotFound) {
var err2 error
descendants, err2 = bs.GetAllDescendants(highestFinalisedHash)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
if err2 != nil {
return nil, fmt.Errorf("failed to get descendants: %w", err2)
}
} else if err != nil {
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("failed to get descendants: %w", err)
}

Expand Down
1 change: 1 addition & 0 deletions lib/blocktree/blocktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/ChainSafe/gossamer/dot/types"

kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
"github.com/ChainSafe/gossamer/lib/common"
"github.com/disiqueira/gotree"
"github.com/prometheus/client_golang/prometheus"
Expand Down