aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/types/transaction_test.go29
-rw-r--r--p2p/discv5/metrics.go8
-rw-r--r--p2p/discv5/udp.go5
3 files changed, 19 insertions, 23 deletions
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go
index d1861b14c..b390f45c6 100644
--- a/core/types/transaction_test.go
+++ b/core/types/transaction_test.go
@@ -165,28 +165,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
t.Errorf("invalid nonce ordering: tx #%d (A=%x N=%v) < tx #%d (A=%x N=%v)", i, fromi[:4], txi.Nonce(), i+j, fromj[:4], txj.Nonce())
}
}
- // Find the previous and next nonce of this account
- prev, next := i-1, i+1
- for j := i - 1; j >= 0; j-- {
- if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
- prev = j
- break
- }
- }
- for j := i + 1; j < len(txs); j++ {
- if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
- next = j
- break
- }
- }
- // Make sure that in between the neighbor nonces, the transaction is correctly positioned price wise
- for j := prev + 1; j < next; j++ {
- fromj, _ := Sender(signer, txs[j])
- if j < i && txs[j].GasPrice().Cmp(txi.GasPrice()) < 0 {
- t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", j, fromj[:4], txs[j].GasPrice(), i, fromi[:4], txi.GasPrice())
- }
- if j > i && txs[j].GasPrice().Cmp(txi.GasPrice()) > 0 {
- t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) > tx #%d (A=%x P=%v)", j, fromj[:4], txs[j].GasPrice(), i, fromi[:4], txi.GasPrice())
+
+ // If the next tx has different from account, the price must be lower than the current one
+ if i+1 < len(txs) {
+ next := txs[i+1]
+ fromNext, _ := Sender(signer, next)
+ if fromi != fromNext && txi.GasPrice().Cmp(next.GasPrice()) < 0 {
+ t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", i, fromi[:4], txi.GasPrice(), i+1, fromNext[:4], next.GasPrice())
}
}
}
diff --git a/p2p/discv5/metrics.go b/p2p/discv5/metrics.go
new file mode 100644
index 000000000..cb11d7eac
--- /dev/null
+++ b/p2p/discv5/metrics.go
@@ -0,0 +1,8 @@
+package discv5
+
+import "github.com/ethereum/go-ethereum/metrics"
+
+var (
+ ingressTrafficMeter = metrics.NewRegisteredMeter("discv5/InboundTraffic", nil)
+ egressTrafficMeter = metrics.NewRegisteredMeter("discv5/OutboundTraffic", nil)
+)
diff --git a/p2p/discv5/udp.go b/p2p/discv5/udp.go
index 09e5f8b37..49e1cb811 100644
--- a/p2p/discv5/udp.go
+++ b/p2p/discv5/udp.go
@@ -334,8 +334,10 @@ func (t *udp) sendPacket(toid NodeID, toaddr *net.UDPAddr, ptype byte, req inter
return hash, err
}
log.Trace(fmt.Sprintf(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr))
- if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil {
+ if nbytes, err := t.conn.WriteToUDP(packet, toaddr); err != nil {
log.Trace(fmt.Sprint("UDP send failed:", err))
+ } else {
+ egressTrafficMeter.Mark(int64(nbytes))
}
//fmt.Println(err)
return hash, err
@@ -374,6 +376,7 @@ func (t *udp) readLoop() {
buf := make([]byte, 1280)
for {
nbytes, from, err := t.conn.ReadFromUDP(buf)
+ ingressTrafficMeter.Mark(int64(nbytes))
if netutil.IsTemporaryError(err) {
// Ignore temporary read errors.
log.Debug(fmt.Sprintf("Temporary read error: %v", err))