Commit 2c8c0632 authored by Esad Akar's avatar Esad Akar Committed by GitHub

pusher: receipt can only be nil for ErrWantSelf cases (#1494)

parent a342f89c
...@@ -10,6 +10,7 @@ package pusher ...@@ -10,6 +10,7 @@ package pusher
import ( import (
"context" "context"
"crypto/ecdsa"
"errors" "errors"
"fmt" "fmt"
"sync" "sync"
...@@ -138,7 +139,7 @@ LOOP: ...@@ -138,7 +139,7 @@ LOOP:
err error err error
startTime = time.Now() startTime = time.Now()
t *tags.Tag t *tags.Tag
setSent bool wantSelf bool
storerPeer swarm.Address storerPeer swarm.Address
) )
defer func() { defer func() {
...@@ -156,6 +157,7 @@ LOOP: ...@@ -156,6 +157,7 @@ LOOP:
mtx.Unlock() mtx.Unlock()
<-sem <-sem
}() }()
// Later when we process receipt, get the receipt and process it // Later when we process receipt, get the receipt and process it
// for now ignoring the receipt and checking only for error // for now ignoring the receipt and checking only for error
receipt, err := s.pushSyncer.PushChunkToClosest(ctx, ch) receipt, err := s.pushSyncer.PushChunkToClosest(ctx, ch)
...@@ -165,13 +167,15 @@ LOOP: ...@@ -165,13 +167,15 @@ LOOP:
// this is to make sure that the sent number does not diverge from the synced counter // this is to make sure that the sent number does not diverge from the synced counter
// the edge case is on the uploader node, in the case where the uploader node is // the edge case is on the uploader node, in the case where the uploader node is
// connected to other nodes, but is the closest one to the chunk. // connected to other nodes, but is the closest one to the chunk.
setSent = true wantSelf = true
} else { } else {
return return
} }
} }
publicKey, err := crypto.Recover(receipt.Signature, receipt.Address.Bytes()) if receipt != nil {
var publicKey *ecdsa.PublicKey
publicKey, err = crypto.Recover(receipt.Signature, receipt.Address.Bytes())
if err != nil { if err != nil {
err = fmt.Errorf("pusher: receipt recover: %w", err) err = fmt.Errorf("pusher: receipt recover: %w", err)
return return
...@@ -182,6 +186,7 @@ LOOP: ...@@ -182,6 +186,7 @@ LOOP:
err = fmt.Errorf("pusher: receipt storer address: %w", err) err = fmt.Errorf("pusher: receipt storer address: %w", err)
return return
} }
}
if err = s.storer.Set(ctx, storage.ModeSetSync, ch.Address()); err != nil { if err = s.storer.Set(ctx, storage.ModeSetSync, ch.Address()); err != nil {
err = fmt.Errorf("pusher: set sync: %w", err) err = fmt.Errorf("pusher: set sync: %w", err)
...@@ -195,7 +200,7 @@ LOOP: ...@@ -195,7 +200,7 @@ LOOP:
err = fmt.Errorf("pusher: increment synced: %v", err) err = fmt.Errorf("pusher: increment synced: %v", err)
return return
} }
if setSent { if wantSelf {
err = t.Inc(tags.StateSent) err = t.Inc(tags.StateSent)
if err != nil { if err != nil {
err = fmt.Errorf("pusher: increment sent: %w", err) err = fmt.Errorf("pusher: increment sent: %w", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment