Skip to content

Commit

Permalink
chore: rollback modification to network pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Apr 26, 2023
1 parent 16e8ee6 commit 90b4e40
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 124 deletions.
61 changes: 2 additions & 59 deletions dot/network/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,8 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
)

var (
blockRequestTimeout = time.Second * 20
)

func (s *Service) RequestWarpProof(to peer.ID, request *WarpSyncProofRequestMessage) (warpSyncResponse interface{}, err error) {
legacyWarpSyncID := s.host.protocolID + warpSyncID

s.host.p2pHost.ConnManager().Protect(to, "")
defer s.host.p2pHost.ConnManager().Unprotect(to, "")

ctx, cancel := context.WithTimeout(s.ctx, blockRequestTimeout)
defer cancel()

stream, err := s.host.p2pHost.NewStream(ctx, to, legacyWarpSyncID)
if err != nil {
return nil, err
}

defer func() {
err := stream.Close()
if err != nil {
logger.Warnf("failed to close stream: %s", err)
}
}()

if err = s.host.writeToStream(stream, request); err != nil {
return nil, err
}

return s.handleWarpSyncProofResponse(stream)
}
var blockRequestTimeout = time.Second * 20
var ErrReceivedEmptyMessage = errors.New("received empty message")

// DoBlockRequest sends a request to the given peer.
// If a response is received within a certain time period, it is returned,
Expand Down Expand Up @@ -77,34 +48,6 @@ func (s *Service) DoBlockRequest(to peer.ID, req *BlockRequestMessage) (*BlockRe
return s.receiveBlockResponse(stream)
}

func (s *Service) handleWarpSyncProofResponse(stream libp2pnetwork.Stream) (interface{}, error) {
s.blockResponseBufMu.Lock()
defer s.blockResponseBufMu.Unlock()

// TODO: should we create another buffer pool for warp proof response buffers?
buf := s.blockResponseBuf

n, err := readStream(stream, &buf, warpSyncMaxResponseSize)
if err != nil {
return nil, fmt.Errorf("reading warp sync stream: %w", err)
}

if n == 0 {
return nil, fmt.Errorf("empty warp sync proof")
}

fmt.Printf("WARP PROOF BYTES ---> %v\n", buf[:n])
warpProof := new(WarpSyncProofResponse)
err = warpProof.Decode(buf[:n])
if err != nil {
panic(fmt.Sprintf("failed to decode warp proof: %s", err))
}
fmt.Printf("WARP PROOF ---> %v\n", warpProof)
return nil, nil
}

var ErrReceivedEmptyMessage = errors.New("received empty message")

func (s *Service) receiveBlockResponse(stream libp2pnetwork.Stream) (*BlockResponseMessage, error) {
// allocating a new (large) buffer every time slows down the syncing by a dramatic amount,
// as malloc is one of the most CPU intensive tasks.
Expand Down
65 changes: 0 additions & 65 deletions dot/network/warp_sync_message.go

This file was deleted.

0 comments on commit 90b4e40

Please sign in to comment.