Skip to content

Commit

Permalink
fix: dot/network: improve syncing at head (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Mar 16, 2021
1 parent 99a50eb commit 7859393
Show file tree
Hide file tree
Showing 19 changed files with 477 additions and 256 deletions.
2 changes: 0 additions & 2 deletions dot/core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ type BlockState interface {
GetBlockByHash(common.Hash) (*types.Block, error)
GenesisHash() common.Hash
GetSlotForBlock(common.Hash) (uint64, error)
HighestBlockHash() common.Hash
HighestBlockNumber() *big.Int
GetFinalizedHeader(uint64, uint64) (*types.Header, error)
GetFinalizedHash(uint64, uint64) (common.Hash, error)
SetFinalizedHash(common.Hash, uint64, uint64) error
Expand Down
4 changes: 2 additions & 2 deletions dot/core/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ func (s *mockSyncer) HandleBlockAnnounce(msg *network.BlockAnnounceMessage) erro
return nil
}

func (s *mockSyncer) ProcessBlockData(_ []*types.BlockData) error {
return nil
func (s *mockSyncer) ProcessBlockData(_ []*types.BlockData) (int, error) {
return 0, nil
}

func (s *mockSyncer) IsSynced() bool {
Expand Down
3 changes: 3 additions & 0 deletions dot/network/connmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func TestMaxPeers(t *testing.T) {
}

err = n.host.connect(*ainfo)
if err != nil {
err = n.host.connect(*ainfo)
}
require.NoError(t, err, i)
}

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

// Syncer is implemented by the syncing service
Expand All @@ -37,7 +38,7 @@ type Syncer interface {
CreateBlockResponse(*BlockRequestMessage) (*BlockResponseMessage, error)

// ProcessBlockData is called to process BlockData received in a BlockResponseMessage
ProcessBlockData(data []*types.BlockData) error
ProcessBlockData(data []*types.BlockData) (int, error)

// HandleBlockAnnounce is called upon receipt of a BlockAnnounceMessage to process it.
// If a request needs to be sent to the peer to retrieve the full block, this function will return it.
Expand Down
4 changes: 4 additions & 0 deletions dot/network/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ func (mbs *MockBlockState) BestBlockNumber() (*big.Int, error) {
func (mbs *MockBlockState) HasBlockBody(common.Hash) (bool, error) {
return false, nil
}

func (mbs *MockBlockState) GetFinalizedHeader(_, _ uint64) (*types.Header, error) {
return mbs.BestBlockHeader()
}
Loading

0 comments on commit 7859393

Please sign in to comment.