Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

swarm/network: Keep span across roundtrip #1210

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c5eccae
core/vm: remove unused constants
matthalp Feb 15, 2019
26d3a8c
rpc: skip websocket origin check if there is no origin header
fjl Feb 19, 2019
d225624
rpc: fixup change to not verify websocket origin (#19128)
fjl Feb 19, 2019
f7f6a46
eth, node: use APPDATA env to support cygwin/msys correctly (#17786)
hackmod Feb 19, 2019
b5e5b35
crypto: fix build when CGO_ENABLED=0 (#19121)
jeremyschlatter Feb 19, 2019
bf42535
core: remove redundant parentheses (#19106)
Matthalp-zz Feb 19, 2019
f1537b7
p2p/discover: make maximum packet size a constant (#19061)
Matthalp-zz Feb 19, 2019
514a947
trie: prefer nil slices over zero-length slices (#19084)
Matthalp-zz Feb 19, 2019
8af6c9e
eth: extract check for tracing transaction in block file (#19107)
Matthalp-zz Feb 19, 2019
2e8a5e5
core/vm: remove unused constants (#19095)
karalabe Feb 19, 2019
d3ccedc
p2p/simulations: enforce camel case variable names (#19053)
Matthalp-zz Feb 19, 2019
b7d9719
swarm/newtork: WIP Span request span until delivery and put
nolash Feb 8, 2019
dc6b4f4
swarm/storage: Introduce new trace across single fetcher lifespan
nolash Feb 8, 2019
7ea02ce
swarm/network: Put span ids for sendpriority in context value
nolash Feb 9, 2019
d7ab444
swarm: Add global span store in tracing
nolash Feb 11, 2019
bfd3346
swarm/tracing: Add context key constants
nolash Feb 11, 2019
c9fbfac
swarm/tracing: Add comments
nolash Feb 15, 2019
c5e9c61
swarm/storage: Remove redundant fix for filestore
nolash Feb 15, 2019
9333e24
swarm/tracing: Elaborate constants comments
nolash Feb 19, 2019
f0a4c63
swarm/network, swarm/storage, swarm:tracing: Minor cleanup
nolash Feb 20, 2019
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
7 changes: 6 additions & 1 deletion cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,12 @@ func DefaultConfigDir() string {
if runtime.GOOS == "darwin" {
return filepath.Join(home, "Library", "Signer")
} else if runtime.GOOS == "windows" {
return filepath.Join(home, "AppData", "Roaming", "Signer")
appdata := os.Getenv("APPDATA")
if appdata != "" {
return filepath.Join(appdata, "Signer")
} else {
return filepath.Join(home, "AppData", "Roaming", "Signer")
}
} else {
return filepath.Join(home, ".clef")
}
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (bc *BlockChain) repair(head **types.Block) error {
if block == nil {
return fmt.Errorf("missing block %d [%x]", (*head).NumberU64()-1, (*head).ParentHash())
}
(*head) = block
*head = block
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
}
b.StopTimer()
if got := chain.CurrentBlock().Transactions().Len(); got != numTxs*numBlocks {
b.Fatalf("Transactions were not included, expected %d, got %d", (numTxs * numBlocks), got)
b.Fatalf("Transactions were not included, expected %d, got %d", numTxs*numBlocks, got)

}
}
Expand Down
4 changes: 0 additions & 4 deletions core/vm/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ const (
GasMidStep uint64 = 8
GasSlowStep uint64 = 10
GasExtStep uint64 = 20

GasReturn uint64 = 0
GasStop uint64 = 0
GasContractByte uint64 = 200
)

// calcGas returns the actual gas cost of the call.
Expand Down
2 changes: 1 addition & 1 deletion crypto/signature_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// +build !nacl,!js,!nocgo
// +build !nacl,!js,cgo

package crypto

Expand Down
2 changes: 1 addition & 1 deletion crypto/signature_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// +build nacl js nocgo
// +build nacl js !cgo

package crypto

Expand Down
19 changes: 12 additions & 7 deletions eth/api_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) {
// If we're tracing a single transaction, make sure it's present
if config != nil && config.TxHash != (common.Hash{}) {
var exists bool
for _, tx := range block.Transactions() {
if exists = (tx.Hash() == config.TxHash); exists {
break
}
}
if !exists {
if !containsTx(block, config.TxHash) {
return nil, fmt.Errorf("transaction %#x not found in block", config.TxHash)
}
}
Expand Down Expand Up @@ -625,6 +619,17 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
return dumps, nil
}

// containsTx reports whether the transaction with a certain hash
// is contained within the specified block.
func containsTx(block *types.Block, hash common.Hash) bool {
for _, tx := range block.Transactions() {
if tx.Hash() == hash {
return true
}
}
return false
}

// computeStateDB retrieves the state database associated with a certain block.
// If no state is locally available for the given block, a number of blocks are
// attempted to be reexecuted to generate the desired state.
Expand Down
11 changes: 9 additions & 2 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ func init() {
home = user.HomeDir
}
}
if runtime.GOOS == "windows" {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
if runtime.GOOS == "darwin" {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
} else if runtime.GOOS == "windows" {
localappdata := os.Getenv("LOCALAPPDATA")
if localappdata != "" {
DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
} else {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
}
} else {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
}
Expand Down
37 changes: 33 additions & 4 deletions node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,47 @@ func DefaultDataDir() string {
// Try to place the data folder in the user's home dir
home := homeDir()
if home != "" {
if runtime.GOOS == "darwin" {
switch runtime.GOOS {
case "darwin":
return filepath.Join(home, "Library", "Ethereum")
} else if runtime.GOOS == "windows" {
return filepath.Join(home, "AppData", "Roaming", "Ethereum")
} else {
case "windows":
// We used to put everything in %HOME%\AppData\Roaming, but this caused
// problems with non-typical setups. If this fallback location exists and
// is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
fallback := filepath.Join(home, "AppData", "Roaming", "Ethereum")
appdata := windowsAppData()
if appdata == "" || isNonEmptyDir(fallback) {
return fallback
}
return filepath.Join(appdata, "Ethereum")
default:
return filepath.Join(home, ".ethereum")
}
}
// As we cannot guess a stable location, return empty and handle later
return ""
}

func windowsAppData() string {
if v := os.Getenv("LOCALAPPDATA"); v != "" {
return v // Vista+
}
if v := os.Getenv("APPDATA"); v != "" {
return filepath.Join(v, "Local")
}
return ""
}

func isNonEmptyDir(dir string) bool {
f, err := os.Open(dir)
if err != nil {
return false
}
names, _ := f.Readdir(1)
f.Close()
return len(names) > 0
}

func homeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
Expand Down
16 changes: 9 additions & 7 deletions p2p/discover/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ const (
ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP
ntpWarningCooldown = 10 * time.Minute // Minimum amount of time to pass before repeating NTP warning
driftThreshold = 10 * time.Second // Allowed clock drift before warning user

// Discovery packets are defined to be no larger than 1280 bytes.
// Packets larger than this size will be cut at the end and treated
// as invalid because their hash won't match.
maxPacketSize = 1280
)

// RPC packet types
Expand Down Expand Up @@ -496,7 +501,7 @@ var (
headSpace = make([]byte, headSize)

// Neighbors replies are sent across multiple packets to
// stay below the 1280 byte limit. We compute the maximum number
// stay below the packet size limit. We compute the maximum number
// of entries by stuffing a packet until it grows too large.
maxNeighbors int
)
Expand All @@ -511,7 +516,7 @@ func init() {
// If this ever happens, it will be caught by the unit tests.
panic("cannot encode: " + err.Error())
}
if headSize+size+1 >= 1280 {
if headSize+size+1 >= maxPacketSize {
maxNeighbors = n
break
}
Expand Down Expand Up @@ -562,10 +567,7 @@ func (t *udp) readLoop(unhandled chan<- ReadPacket) {
defer close(unhandled)
}

// Discovery packets are defined to be no larger than 1280 bytes.
// Packets larger than this size will be cut at the end and treated
// as invalid because their hash won't match.
buf := make([]byte, 1280)
buf := make([]byte, maxPacketSize)
for {
nbytes, from, err := t.conn.ReadFromUDP(buf)
if netutil.IsTemporaryError(err) {
Expand Down Expand Up @@ -715,7 +717,7 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID enode.ID, mac []by
t.tab.mutex.Unlock()

// Send neighbors in chunks with at most maxNeighbors per packet
// to stay below the 1280 byte limit.
// to stay below the packet size limit.
p := neighbors{Expiration: uint64(time.Now().Add(expiration).Unix())}
var sent bool
for _, n := range closest {
Expand Down
4 changes: 2 additions & 2 deletions p2p/simulations/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ OUTER:

connEventCount = nodeCount

OUTER_TWO:
OuterTwo:
for {
select {
case <-ctx.Done():
Expand All @@ -211,7 +211,7 @@ OUTER_TWO:
connEventCount--
log.Debug("ev", "count", connEventCount)
if connEventCount == 0 {
break OUTER_TWO
break OuterTwo
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions rpc/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ func wsHandshakeValidator(allowedOrigins []string) func(*websocket.Config, *http
log.Debug(fmt.Sprintf("Allowed origin(s) for WS RPC interface %v", origins.ToSlice()))

f := func(cfg *websocket.Config, req *http.Request) error {
// Skip origin verification if no Origin header is present. The origin check
// is supposed to protect against browser based attacks. Browsers always set
// Origin. Non-browser software can put anything in origin and checking it doesn't
// provide additional security.
if _, ok := req.Header["Origin"]; !ok {
return nil
}
// Verify origin against whitelist.
origin := strings.ToLower(req.Header.Get("Origin"))
if allowAllOrigins || origins.Contains(origin) {
Expand Down
27 changes: 18 additions & 9 deletions swarm/network/stream/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/swarm/network"
"github.com/ethereum/go-ethereum/swarm/spancontext"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/swarm/tracing"
opentracing "github.com/opentracing/opentracing-go"
)

Expand Down Expand Up @@ -143,7 +144,7 @@ func (d *Delivery) handleRetrieveRequestMsg(ctx context.Context, sp *Peer, req *
var osp opentracing.Span
ctx, osp = spancontext.StartSpan(
ctx,
"retrieve.request")
"stream.handle.retrieve")

s, err := sp.getServer(NewStream(swarmChunkServerStreamName, "", true))
if err != nil {
Expand Down Expand Up @@ -207,17 +208,19 @@ type ChunkDeliveryMsgRetrieval ChunkDeliveryMsg
//defines a chunk delivery for syncing (without accounting)
type ChunkDeliveryMsgSyncing ChunkDeliveryMsg

// TODO: Fix context SNAFU
// chunk delivery msg is response to retrieverequest msg
func (d *Delivery) handleChunkDeliveryMsg(ctx context.Context, sp *Peer, req *ChunkDeliveryMsg) error {
var osp opentracing.Span
ctx, osp = spancontext.StartSpan(
ctx,
"chunk.delivery")

processReceivedChunksCount.Inc(1)

// retrieve the span for the originating retrieverequest
spanId := fmt.Sprintf("stream.send.request.%v.%v", sp.ID(), req.Addr)
span := tracing.ShiftSpanByKey(spanId)

go func() {
defer osp.Finish()
if span != nil {
defer span.(opentracing.Span).Finish()
}

req.peer = sp
err := d.chunkStore.Put(ctx, storage.NewChunk(req.Addr, req.SData))
Expand All @@ -233,7 +236,9 @@ func (d *Delivery) handleChunkDeliveryMsg(ctx context.Context, sp *Peer, req *Ch
return nil
}

// RequestFromPeers sends a chunk retrieve request to
// RequestFromPeers sends a chunk retrieve request to a peer
// The most eligible peer that hasn't already been sent to is chosen
// TODO: define "eligible"
func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (*enode.ID, chan struct{}, error) {
requestFromPeersCount.Inc(1)
var sp *Peer
Expand Down Expand Up @@ -268,11 +273,15 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (
}
}

// setting this value in the context creates a new span that can persist across the sendpriority queue and the network roundtrip
// this span will finish only when delivery is handled (or times out)
ctx = context.WithValue(ctx, tracing.StoreLabelId, "stream.send.request")
ctx = context.WithValue(ctx, tracing.StoreLabelMeta, fmt.Sprintf("%v.%v", sp.ID(), req.Addr))
err := sp.SendPriority(ctx, &RetrieveRequestMsg{
Addr: req.Addr,
SkipCheck: req.SkipCheck,
HopCount: req.HopCount,
}, Top, "request.from.peers")
}, Top)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion swarm/network/stream/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (p *Peer) handleOfferedHashesMsg(ctx context.Context, req *OfferedHashesMsg
return
}
log.Trace("sending want batch", "peer", p.ID(), "stream", msg.Stream, "from", msg.From, "to", msg.To)
err := p.SendPriority(ctx, msg, c.priority, "")
err := p.SendPriority(ctx, msg, c.priority)
if err != nil {
log.Warn("SendPriority error", "err", err)
}
Expand Down
Loading