aboutsummaryrefslogtreecommitdiffstats
path: root/les/peer.go
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2019-04-10 16:44:19 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2019-04-10 19:12:42 +0800
commit0de9f32ae8346ece3bbd596291f132385962d0ca (patch)
tree76dbadb75d51a85c5512c5bb0c6ae77af343f95e /les/peer.go
parent14ae1246b789dd2a0a2bd22f0c7d3256daa26759 (diff)
downloadgo-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.tar
go-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.tar.gz
go-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.tar.bz2
go-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.tar.lz
go-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.tar.xz
go-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.tar.zst
go-tangerine-0de9f32ae8346ece3bbd596291f132385962d0ca.zip
les: backported new SendTx cost calculation
Diffstat (limited to 'les/peer.go')
-rw-r--r--les/peer.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/les/peer.go b/les/peer.go
index 678384f0e..bf097f666 100644
--- a/les/peer.go
+++ b/les/peer.go
@@ -42,6 +42,11 @@ var (
const maxResponseErrors = 50 // number of invalid responses tolerated (makes the protocol less brittle but still avoids spam)
+// if the total encoded size of a sent transaction batch is over txSizeCostLimit
+// per transaction then the request cost is calculated as proportional to the
+// encoded size instead of the transaction count
+const txSizeCostLimit = 0x4000
+
const (
announceTypeNone = iota
announceTypeSimple
@@ -170,6 +175,32 @@ func (p *peer) GetRequestCost(msgcode uint64, amount int) uint64 {
return cost
}
+func (p *peer) GetTxRelayCost(amount, size int) uint64 {
+ p.lock.RLock()
+ defer p.lock.RUnlock()
+
+ var msgcode uint64
+ switch p.version {
+ case lpv1:
+ msgcode = SendTxMsg
+ case lpv2:
+ msgcode = SendTxV2Msg
+ default:
+ panic(nil)
+ }
+
+ cost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(amount)
+ sizeCost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(size)/txSizeCostLimit
+ if sizeCost > cost {
+ cost = sizeCost
+ }
+
+ if cost > p.fcServerParams.BufLimit {
+ cost = p.fcServerParams.BufLimit
+ }
+ return cost
+}
+
// HasBlock checks if the peer has a given block
func (p *peer) HasBlock(hash common.Hash, number uint64, hasState bool) bool {
p.lock.RLock()
@@ -307,9 +338,9 @@ func (p *peer) RequestTxStatus(reqID, cost uint64, txHashes []common.Hash) error
return sendRequest(p.rw, GetTxStatusMsg, reqID, cost, txHashes)
}
-// SendTxStatus sends a batch of transactions to be added to the remote transaction pool.
-func (p *peer) SendTxs(reqID, cost uint64, txs types.Transactions) error {
- p.Log().Debug("Fetching batch of transactions", "count", len(txs))
+// SendTxs sends a batch of transactions to be added to the remote transaction pool.
+func (p *peer) SendTxs(reqID, cost uint64, txs rlp.RawValue) error {
+ p.Log().Debug("Fetching batch of transactions", "size", len(txs))
switch p.version {
case lpv1:
return p2p.Send(p.rw, SendTxMsg, txs) // old message format does not include reqID