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(lib/grandpa): fix grandpa stall and various bugs #1708

Merged
merged 25 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion dot/core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type BlockState interface {
GetSlotForBlock(common.Hash) (uint64, error)
GetFinalisedHeader(uint64, uint64) (*types.Header, error)
GetFinalisedHash(uint64, uint64) (common.Hash, error)
SetFinalisedHash(common.Hash, uint64, uint64) error
RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
UnregisterImportedChannel(id byte)
RegisterFinalizedChannel(ch chan<- *types.FinalisationInfo) (byte, error)
Expand Down
48 changes: 24 additions & 24 deletions dot/network/mock_block_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (s *Service) sentBlockIntervalTelemetry() {
}
bestHash := best.Hash()

finalized, err := s.blockState.GetFinalisedHeader(0, 0) //nolint
finalized, err := s.blockState.GetHighestFinalisedHeader() //nolint
if err != nil {
continue
}
Expand Down Expand Up @@ -519,16 +519,21 @@ func (s *Service) GossipMessage(msg NotificationsMessage) {
func (s *Service) SendMessage(to peer.ID, msg NotificationsMessage) error {
s.notificationsMu.Lock()
defer s.notificationsMu.Unlock()

for msgID, prtl := range s.notificationsProtocols {
if msg.Type() != msgID || prtl == nil {
if msg.Type() != msgID {
continue
}

hs, err := prtl.getHandshake()
if err != nil {
return err
}

s.sendData(to, hs, prtl, msg)
return nil
}

return errors.New("message not supported by any notifications protocol")
}

Expand Down
2 changes: 1 addition & 1 deletion dot/network/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type BlockState interface {
BestBlockNumber() (*big.Int, error)
GenesisHash() common.Hash
HasBlockBody(common.Hash) (bool, error)
GetFinalisedHeader(round, setID uint64) (*types.Header, error)
GetHighestFinalisedHeader() (*types.Header, error)
GetHashByNumber(num *big.Int) (common.Hash, error)
}

Expand Down
6 changes: 3 additions & 3 deletions dot/network/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (q *syncQueue) benchmark() {
goal := atomic.LoadInt64(&q.goal)

if before.Number.Int64() >= goal {
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0) //nolint
finalised, err := q.s.blockState.GetHighestFinalisedHeader() //nolint
if err != nil {
continue
}
Expand Down Expand Up @@ -767,7 +767,7 @@ func (q *syncQueue) handleBlockJustification(data []*types.BlockData) {
}

func (q *syncQueue) handleBlockData(data []*types.BlockData) {
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0)
finalised, err := q.s.blockState.GetHighestFinalisedHeader()
if err != nil {
panic(err) // this should never happen
}
Expand Down Expand Up @@ -815,7 +815,7 @@ func (q *syncQueue) handleBlockDataFailure(idx int, err error, data []*types.Blo
logger.Warn("failed to handle block data", "failed on block", q.currStart+int64(idx), "error", err)

if errors.Is(err, chaindb.ErrKeyNotFound) || errors.Is(err, blocktree.ErrParentNotFound) {
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0)
finalised, err := q.s.blockState.GetHighestFinalisedHeader()
if err != nil {
panic(err)
}
Expand Down
7 changes: 3 additions & 4 deletions dot/network/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// NewMockBlockState create and return a network BlockState interface mock
func NewMockBlockState(n *big.Int) *MockBlockState {
func NewMockBlockState(n *big.Int) *mockBlockState {
parentHash, _ := common.HexToHash("0x4545454545454545454545454545454545454545454545454545454545454545")
stateRoot, _ := common.HexToHash("0xb3266de137d20a5d0ff3a6401eb57127525fd9b2693701f0bf5a8a853fa3ebe0")
extrinsicsRoot, _ := common.HexToHash("0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314")
Expand All @@ -31,13 +31,12 @@ func NewMockBlockState(n *big.Int) *MockBlockState {
Digest: types.Digest{},
}

m := new(MockBlockState)
m := new(mockBlockState)
m.On("BestBlockHeader").Return(header, nil)

m.On("GetHighestFinalisedHeader").Return(header, nil)
m.On("GenesisHash").Return(common.NewHash([]byte{}))
m.On("BestBlockNumber").Return(big.NewInt(1), nil)
m.On("HasBlockBody", mock.AnythingOfType("common.Hash")).Return(false, nil)
m.On("GetFinalisedHeader", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(header, nil)
m.On("GetHashByNumber", mock.AnythingOfType("*big.Int")).Return(common.Hash{}, nil)

return m
Expand Down
3 changes: 2 additions & 1 deletion dot/rpc/modules/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type BlockAPI interface {
GetHeader(hash common.Hash) (*types.Header, error)
BestBlockHash() common.Hash
GetBlockByHash(hash common.Hash) (*types.Block, error)
GetBlockHash(blockNumber *big.Int) (*common.Hash, error)
GetBlockHash(blockNumber *big.Int) (common.Hash, error)
GetFinalisedHash(uint64, uint64) (common.Hash, error)
GetHighestFinalisedHash() (common.Hash, error)
HasJustification(hash common.Hash) (bool, error)
GetJustification(hash common.Hash) ([]byte, error)
RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
Expand Down
5 changes: 3 additions & 2 deletions dot/rpc/modules/api_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ func NewMockStorageAPI() *modulesmocks.MockStorageAPI {
}

// NewMockBlockAPI creates and return an rpc BlockAPI interface mock
func NewMockBlockAPI() *modulesmocks.MockBlockAPI {
m := new(modulesmocks.MockBlockAPI)
func NewMockBlockAPI() *modulesmocks.BlockAPI {
m := new(modulesmocks.BlockAPI)
m.On("GetHeader", mock.AnythingOfType("common.Hash")).Return(nil, nil)
m.On("BestBlockHash").Return(common.Hash{})
m.On("GetBlockByHash", mock.AnythingOfType("common.Hash")).Return(nil, nil)
m.On("GetBlockHash", mock.AnythingOfType("*big.Int")).Return(nil, nil)
m.On("GetFinalisedHash", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(common.Hash{}, nil)
m.On("GetHighestFinalisedHash").Return(common.Hash{}, nil)
m.On("RegisterImportedChannel", mock.AnythingOfType("chan<- *types.Block")).Return(byte(0), nil)
m.On("UnregisterImportedChannel", mock.AnythingOfType("uint8"))
m.On("RegisterFinalizedChannel", mock.AnythingOfType("chan<- *types.FinalisationInfo")).Return(byte(0), nil)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (cm *ChainModule) GetHead(r *http.Request, req *ChainBlockNumberRequest, re

// GetFinalizedHead returns the most recently finalised block hash
func (cm *ChainModule) GetFinalizedHead(r *http.Request, req *EmptyRequest, res *ChainHashResponse) error {
h, err := cm.blockAPI.GetFinalisedHash(0, 0)
h, err := cm.blockAPI.GetHighestFinalisedHash()
if err != nil {
return err
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading