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

eth/protocols/snap: add peer id and req id to the timeout logs #22591

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Changes from all commits
Commits
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
40 changes: 25 additions & 15 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ func (s *Syncer) assignAccountTasks(cancel chan struct{}) {
if idle == "" {
return
}
peer := s.peers[idle]

// Matched a pending task to an idle peer, allocate a unique request id
var reqid uint64
for {
Expand All @@ -834,22 +836,22 @@ func (s *Syncer) assignAccountTasks(cancel chan struct{}) {
task: task,
}
req.timeout = time.AfterFunc(requestTimeout, func() {
log.Debug("Account range request timed out")
peer.Log().Debug("Account range request timed out", "reqid", reqid)
s.scheduleRevertAccountRequest(req)
})
s.accountReqs[reqid] = req
delete(s.accountIdlers, idle)

s.pend.Add(1)
go func(peer SyncPeer, root common.Hash) {
go func(root common.Hash) {
defer s.pend.Done()

// Attempt to send the remote request and revert if it fails
if err := peer.RequestAccountRange(reqid, root, req.origin, req.limit, maxRequestSize); err != nil {
peer.Log().Debug("Failed to request account range", "err", err)
s.scheduleRevertAccountRequest(req)
}
}(s.peers[idle], s.root) // We're in the lock, peers[id] surely exists
}(s.root)

// Inject the request into the task to block further assignments
task.req = req
Expand Down Expand Up @@ -891,6 +893,8 @@ func (s *Syncer) assignBytecodeTasks(cancel chan struct{}) {
if idle == "" {
return
}
peer := s.peers[idle]

// Matched a pending task to an idle peer, allocate a unique request id
var reqid uint64
for {
Expand Down Expand Up @@ -921,22 +925,22 @@ func (s *Syncer) assignBytecodeTasks(cancel chan struct{}) {
task: task,
}
req.timeout = time.AfterFunc(requestTimeout, func() {
log.Debug("Bytecode request timed out")
peer.Log().Debug("Bytecode request timed out", "reqid", reqid)
s.scheduleRevertBytecodeRequest(req)
})
s.bytecodeReqs[reqid] = req
delete(s.bytecodeIdlers, idle)

s.pend.Add(1)
go func(peer SyncPeer) {
go func() {
defer s.pend.Done()

// Attempt to send the remote request and revert if it fails
if err := peer.RequestByteCodes(reqid, hashes, maxRequestSize); err != nil {
log.Debug("Failed to request bytecodes", "err", err)
s.scheduleRevertBytecodeRequest(req)
}
}(s.peers[idle]) // We're in the lock, peers[id] surely exists
}()
}
}

Expand Down Expand Up @@ -976,6 +980,8 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
if idle == "" {
return
}
peer := s.peers[idle]

// Matched a pending task to an idle peer, allocate a unique request id
var reqid uint64
for {
Expand Down Expand Up @@ -1045,14 +1051,14 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
req.limit = subtask.Last
}
req.timeout = time.AfterFunc(requestTimeout, func() {
log.Debug("Storage request timed out")
peer.Log().Debug("Storage request timed out", "reqid", reqid)
s.scheduleRevertStorageRequest(req)
})
s.storageReqs[reqid] = req
delete(s.storageIdlers, idle)

s.pend.Add(1)
go func(peer SyncPeer, root common.Hash) {
go func(root common.Hash) {
defer s.pend.Done()

// Attempt to send the remote request and revert if it fails
Expand All @@ -1064,7 +1070,7 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
log.Debug("Failed to request storage", "err", err)
s.scheduleRevertStorageRequest(req)
}
}(s.peers[idle], s.root) // We're in the lock, peers[id] surely exists
}(s.root)

// Inject the request into the subtask to block further assignments
if subtask != nil {
Expand Down Expand Up @@ -1121,6 +1127,8 @@ func (s *Syncer) assignTrienodeHealTasks(cancel chan struct{}) {
if idle == "" {
return
}
peer := s.peers[idle]

// Matched a pending task to an idle peer, allocate a unique request id
var reqid uint64
for {
Expand Down Expand Up @@ -1160,22 +1168,22 @@ func (s *Syncer) assignTrienodeHealTasks(cancel chan struct{}) {
task: s.healer,
}
req.timeout = time.AfterFunc(requestTimeout, func() {
log.Debug("Trienode heal request timed out")
peer.Log().Debug("Trienode heal request timed out", "reqid", reqid)
s.scheduleRevertTrienodeHealRequest(req)
})
s.trienodeHealReqs[reqid] = req
delete(s.trienodeHealIdlers, idle)

s.pend.Add(1)
go func(peer SyncPeer, root common.Hash) {
go func(root common.Hash) {
defer s.pend.Done()

// Attempt to send the remote request and revert if it fails
if err := peer.RequestTrieNodes(reqid, root, pathsets, maxRequestSize); err != nil {
log.Debug("Failed to request trienode healers", "err", err)
s.scheduleRevertTrienodeHealRequest(req)
}
}(s.peers[idle], s.root) // We're in the lock, peers[id] surely exists
}(s.root)
}
}

Expand Down Expand Up @@ -1227,6 +1235,8 @@ func (s *Syncer) assignBytecodeHealTasks(cancel chan struct{}) {
if idle == "" {
return
}
peer := s.peers[idle]

// Matched a pending task to an idle peer, allocate a unique request id
var reqid uint64
for {
Expand Down Expand Up @@ -1258,22 +1268,22 @@ func (s *Syncer) assignBytecodeHealTasks(cancel chan struct{}) {
task: s.healer,
}
req.timeout = time.AfterFunc(requestTimeout, func() {
log.Debug("Bytecode heal request timed out")
peer.Log().Debug("Bytecode heal request timed out", "reqid", reqid)
s.scheduleRevertBytecodeHealRequest(req)
})
s.bytecodeHealReqs[reqid] = req
delete(s.bytecodeHealIdlers, idle)

s.pend.Add(1)
go func(peer SyncPeer) {
go func() {
defer s.pend.Done()

// Attempt to send the remote request and revert if it fails
if err := peer.RequestByteCodes(reqid, hashes, maxRequestSize); err != nil {
log.Debug("Failed to request bytecode healers", "err", err)
s.scheduleRevertBytecodeHealRequest(req)
}
}(s.peers[idle]) // We're in the lock, peers[id] surely exists
}()
}
}

Expand Down