Skip to content

Commit d8ec9e3

Browse files
committed
Merge main into minhd-vu/rpc-methods
fix: update p2p package for go-ethereum 1.17.0 RawList API changes go-ethereum 1.17.0 changed eth protocol types to use rlp.RawList for lazy decoding optimization: - BlockHeadersPacket.List replaces BlockHeadersRequest - BlockBodiesPacket.List replaces BlockBodiesResponse - PooledTransactionsPacket.List replaces PooledTransactionsResponse - BlockBody fields now use rlp.RawList instead of slices - TransactionsPacket embeds rlp.RawList Updated all p2p code to use .Len() instead of len(), .Items() for decoding, and rlp.EncodeToRawList() for encoding.
2 parents 57d72f5 + fe08091 commit d8ec9e3

File tree

9 files changed

+217
-105
lines changed

9 files changed

+217
-105
lines changed

cmd/p2p/sensor/rpc.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ethereum/go-ethereum/common/hexutil"
1414
"github.com/ethereum/go-ethereum/core/types"
1515
"github.com/ethereum/go-ethereum/eth/protocols/eth"
16+
"github.com/ethereum/go-ethereum/rlp"
1617
"github.com/prometheus/client_golang/prometheus"
1718
"github.com/prometheus/client_golang/prometheus/promauto"
1819
"github.com/rs/zerolog/log"
@@ -475,11 +476,13 @@ func getBlockByNumber(req rpcRequest, conns *p2p.Conns) (any, *rpcError) {
475476
cache, found = conns.Blocks().Get(hash)
476477
if !found {
477478
// Construct cache from head block
479+
txList, _ := rlp.EncodeToRawList([]*types.Transaction(head.Block.Transactions()))
480+
uncleList, _ := rlp.EncodeToRawList(head.Block.Uncles())
478481
cache = p2p.BlockCache{
479482
Header: head.Block.Header(),
480483
Body: &eth.BlockBody{
481-
Transactions: head.Block.Transactions(),
482-
Uncles: head.Block.Uncles(),
484+
Transactions: txList,
485+
Uncles: uncleList,
483486
},
484487
TD: head.TD,
485488
}
@@ -527,7 +530,11 @@ func getTransactionByHash(req rpcRequest, conns *p2p.Conns) (any, *rpcError) {
527530
if !ok || cache.Body == nil {
528531
continue
529532
}
530-
for i, tx := range cache.Body.Transactions {
533+
txs, err := cache.Body.Transactions.Items()
534+
if err != nil {
535+
continue
536+
}
537+
for i, tx := range txs {
531538
if tx.Hash() == hash {
532539
return formatTransactionResponse(tx, blockHash, cache.Header, uint64(i)), nil
533540
}
@@ -564,11 +571,12 @@ func getTransactionByBlockHashAndIndex(req rpcRequest, conns *p2p.Conns) (any, *
564571
return nil, nil
565572
}
566573

567-
if int(index) >= len(cache.Body.Transactions) {
574+
txs, err := cache.Body.Transactions.Items()
575+
if err != nil || int(index) >= len(txs) {
568576
return nil, nil
569577
}
570578

571-
tx := cache.Body.Transactions[index]
579+
tx := txs[index]
572580
return formatTransactionResponse(tx, blockHash, cache.Header, index), nil
573581
}
574582

@@ -600,7 +608,7 @@ func getBlockTransactionCountByHash(req rpcRequest, conns *p2p.Conns) (any, *rpc
600608
if err != nil || cache.Body == nil {
601609
return nil, err
602610
}
603-
return hexutil.EncodeUint64(uint64(len(cache.Body.Transactions))), nil
611+
return hexutil.EncodeUint64(uint64(cache.Body.Transactions.Len())), nil
604612
}
605613

606614
// getUncleCountByBlockHash returns the uncle count in a block.
@@ -609,7 +617,7 @@ func getUncleCountByBlockHash(req rpcRequest, conns *p2p.Conns) (any, *rpcError)
609617
if err != nil || cache.Body == nil {
610618
return nil, err
611619
}
612-
return hexutil.EncodeUint64(uint64(len(cache.Body.Uncles))), nil
620+
return hexutil.EncodeUint64(uint64(cache.Body.Uncles.Len())), nil
613621
}
614622

615623
// formatBlockResponse formats a block cache into the Ethereum JSON-RPC block format.
@@ -666,16 +674,17 @@ func formatBlockResponse(hash common.Hash, cache p2p.BlockCache, fullTx bool) ma
666674
}
667675

668676
// Add transactions
669-
if cache.Body != nil && cache.Body.Transactions != nil {
677+
if cache.Body != nil && cache.Body.Transactions.Len() > 0 {
678+
txs, _ := cache.Body.Transactions.Items()
670679
if fullTx {
671-
txs := make([]map[string]any, len(cache.Body.Transactions))
672-
for i, tx := range cache.Body.Transactions {
673-
txs[i] = formatTransactionResponse(tx, hash, header, uint64(i))
680+
txResults := make([]map[string]any, len(txs))
681+
for i, tx := range txs {
682+
txResults[i] = formatTransactionResponse(tx, hash, header, uint64(i))
674683
}
675-
result["transactions"] = txs
684+
result["transactions"] = txResults
676685
} else {
677-
txHashes := make([]string, len(cache.Body.Transactions))
678-
for i, tx := range cache.Body.Transactions {
686+
txHashes := make([]string, len(txs))
687+
for i, tx := range txs {
679688
txHashes[i] = tx.Hash().Hex()
680689
}
681690
result["transactions"] = txHashes
@@ -685,9 +694,10 @@ func formatBlockResponse(hash common.Hash, cache p2p.BlockCache, fullTx bool) ma
685694
}
686695

687696
// Add uncles
688-
if cache.Body != nil && cache.Body.Uncles != nil {
689-
uncleHashes := make([]string, len(cache.Body.Uncles))
690-
for i, uncle := range cache.Body.Uncles {
697+
if cache.Body != nil && cache.Body.Uncles.Len() > 0 {
698+
uncles, _ := cache.Body.Uncles.Items()
699+
uncleHashes := make([]string, len(uncles))
700+
for i, uncle := range uncles {
691701
uncleHashes[i] = uncle.Hash().Hex()
692702
}
693703
result["uncles"] = uncleHashes

go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/cenkalti/backoff/v4 v4.3.0
99
github.com/chzyer/readline v1.5.1 // indirect
1010
github.com/cockroachdb/pebble v1.1.5
11-
github.com/ethereum/go-ethereum v1.16.8
11+
github.com/ethereum/go-ethereum v1.17.0
1212
github.com/gizak/termui/v3 v3.1.1-0.20231111080052-b3569a6cd52d
1313
github.com/google/gofuzz v1.2.0
1414
github.com/hashicorp/golang-lru v1.0.2
@@ -77,7 +77,6 @@ require (
7777
github.com/spf13/cast v1.10.0 // indirect
7878
github.com/subosito/gotenv v1.6.0 // indirect
7979
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
80-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 // indirect
8180
go.yaml.in/yaml/v2 v2.4.3 // indirect
8281
go.yaml.in/yaml/v3 v3.0.4 // indirect
8382
gopkg.in/yaml.v2 v2.4.0 // indirect
@@ -140,7 +139,6 @@ require (
140139
github.com/multiformats/go-multihash v0.2.3 // indirect
141140
github.com/multiformats/go-varint v0.0.7 // indirect
142141
github.com/nsf/termbox-go v1.1.1 // indirect
143-
github.com/olekukonko/tablewriter v0.0.5 // indirect
144142
github.com/pkg/errors v0.9.1 // indirect
145143
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
146144
github.com/prometheus/client_golang v1.23.2
@@ -198,11 +196,9 @@ require (
198196
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
199197
github.com/cometbft/cometbft-db v0.14.1 // indirect
200198
github.com/cosmos/gogoproto v1.7.0 // indirect
201-
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
202199
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
203200
github.com/dgraph-io/ristretto v0.1.1 // indirect
204201
github.com/dustin/go-humanize v1.0.1 // indirect
205-
github.com/ethereum/go-verkle v0.2.2 // indirect
206202
github.com/felixge/httpsnoop v1.0.4 // indirect
207203
github.com/go-kit/log v0.2.1 // indirect
208204
github.com/go-logfmt/logfmt v0.6.0 // indirect

go.sum

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEe
6666
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
6767
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
6868
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
69-
github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8=
70-
github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
69+
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
70+
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
7171
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
7272
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
7373
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
@@ -129,8 +129,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo
129129
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
130130
github.com/crate-crypto/go-eth-kzg v1.4.0 h1:WzDGjHk4gFg6YzV0rJOAsTK4z3Qkz5jd4RE3DAvPFkg=
131131
github.com/crate-crypto/go-eth-kzg v1.4.0/go.mod h1:J9/u5sWfznSObptgfa92Jq8rTswn6ahQWEuiLHOjCUI=
132-
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
133-
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM=
134132
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
135133
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
136134
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -180,10 +178,8 @@ github.com/ethereum/c-kzg-4844/v2 v2.1.5 h1:aVtoLK5xwJ6c5RiqO8g8ptJ5KU+2Hdquf6G3
180178
github.com/ethereum/c-kzg-4844/v2 v2.1.5/go.mod h1:u59hRTTah4Co6i9fDWtiCjTrblJv0UwsqZKCc0GfgUs=
181179
github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab h1:rvv6MJhy07IMfEKuARQ9TKojGqLVNxQajaXEp/BoqSk=
182180
github.com/ethereum/go-bigmodexpfix v0.0.0-20250911101455-f9e208c548ab/go.mod h1:IuLm4IsPipXKF7CW5Lzf68PIbZ5yl7FFd74l/E0o9A8=
183-
github.com/ethereum/go-ethereum v1.16.8 h1:LLLfkZWijhR5m6yrAXbdlTeXoqontH+Ga2f9igY7law=
184-
github.com/ethereum/go-ethereum v1.16.8/go.mod h1:Fs6QebQbavneQTYcA39PEKv2+zIjX7rPUZ14DER46wk=
185-
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
186-
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
181+
github.com/ethereum/go-ethereum v1.17.0 h1:2D+1Fe23CwZ5tQoAS5DfwKFNI1HGcTwi65/kRlAVxes=
182+
github.com/ethereum/go-ethereum v1.17.0/go.mod h1:2W3msvdosS/MCWytpqTcqgFiRYbTH59FxDJzqah120o=
187183
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
188184
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
189185
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
@@ -299,10 +295,14 @@ github.com/googleapis/gax-go/v2 v2.19.0 h1:fYQaUOiGwll0cGj7jmHT/0nPlcrZDFPrZRhTs
299295
github.com/googleapis/gax-go/v2 v2.19.0/go.mod h1:w2ROXVdfGEVFXzmlciUU4EdjHgWvB5h2n6x/8XSTTJA=
300296
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
301297
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
298+
github.com/grafana/pyroscope-go v1.2.7 h1:VWBBlqxjyR0Cwk2W6UrE8CdcdD80GOFNutj0Kb1T8ac=
299+
github.com/grafana/pyroscope-go v1.2.7/go.mod h1:o/bpSLiJYYP6HQtvcoVKiE9s5RiNgjYTj1DhiddP2Pc=
300+
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 h1:c1Us8i6eSmkW+Ez05d3co8kasnuOY813tbMN8i/a3Og=
301+
github.com/grafana/pyroscope-go/godeltaprof v0.1.9/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
302302
github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0=
303303
github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
304-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 h1:X5VWvz21y3gzm9Nw/kaUeku/1+uBhcekkmy4IkffJww=
305-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1/go.mod h1:Zanoh4+gvIgluNqcfMVTJueD4wSS5hT7zTt4Mrutd90=
304+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
305+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
306306
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
307307
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
308308
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
@@ -420,8 +420,6 @@ github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
420420
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
421421
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q=
422422
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
423-
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
424-
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
425423
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
426424
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
427425
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
@@ -583,10 +581,10 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6h
583581
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
584582
go.opentelemetry.io/otel v1.42.0 h1:lSQGzTgVR3+sgJDAU/7/ZMjN9Z+vUip7leaqBKy4sho=
585583
go.opentelemetry.io/otel v1.42.0/go.mod h1:lJNsdRMxCUIWuMlVJWzecSMuNjE7dOYyWlqOXWkdqCc=
586-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0 h1:Ahq7pZmv87yiyn3jeFz/LekZmPLLdKejuO3NcK9MssM=
587-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0/go.mod h1:MJTqhM0im3mRLw1i8uGHnCvUEeS7VwRyxlLC78PA18M=
588-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 h1:bDMKF3RUSxshZ5OjOTi8rsHGaPKsAt76FaqgvIUySLc=
589-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0/go.mod h1:dDT67G/IkA46Mr2l9Uj7HsQVwsjASyV9SjGofsiUZDA=
584+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 h1:f0cb2XPmrqn4XMy9PNliTgRKJgS5WcL/u0/WRYGz4t0=
585+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0/go.mod h1:vnakAaFckOMiMtOIhFI2MNH4FYrZzXCYxmb1LlhoGz8=
586+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.39.0 h1:Ckwye2FpXkYgiHX7fyVrN1uA/UYd9ounqqTuSNAv0k4=
587+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.39.0/go.mod h1:teIFJh5pW2y+AN7riv6IBPX2DuesS3HgP39mwOspKwU=
590588
go.opentelemetry.io/otel/metric v1.42.0 h1:2jXG+3oZLNXEPfNmnpxKDeZsFI5o4J+nz6xUlaFdF/4=
591589
go.opentelemetry.io/otel/metric v1.42.0/go.mod h1:RlUN/7vTU7Ao/diDkEpQpnz3/92J9ko05BIwxYa2SSI=
592590
go.opentelemetry.io/otel/sdk v1.42.0 h1:LyC8+jqk6UJwdrI/8VydAq/hvkFKNHZVIWuslJXYsDo=
@@ -595,8 +593,8 @@ go.opentelemetry.io/otel/sdk/metric v1.42.0 h1:D/1QR46Clz6ajyZ3G8SgNlTJKBdGp84q9
595593
go.opentelemetry.io/otel/sdk/metric v1.42.0/go.mod h1:Ua6AAlDKdZ7tdvaQKfSmnFTdHx37+J4ba8MwVCYM5hc=
596594
go.opentelemetry.io/otel/trace v1.42.0 h1:OUCgIPt+mzOnaUTpOQcBiM/PLQ/Op7oq6g4LenLmOYY=
597595
go.opentelemetry.io/otel/trace v1.42.0/go.mod h1:f3K9S+IFqnumBkKhRJMeaZeNk9epyhnCmQh/EysQCdc=
598-
go.opentelemetry.io/proto/otlp v1.7.0 h1:jX1VolD6nHuFzOYso2E73H85i92Mv8JQYk0K9vz09os=
599-
go.opentelemetry.io/proto/otlp v1.7.0/go.mod h1:fSKjH6YJ7HDlwzltzyMj036AJ3ejJLCgCSHGj4efDDo=
596+
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
597+
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
600598
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
601599
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
602600
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=

p2p/conns.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ethereum/go-ethereum/eth/protocols/eth"
1212
ethp2p "github.com/ethereum/go-ethereum/p2p"
1313
"github.com/ethereum/go-ethereum/p2p/enode"
14+
"github.com/ethereum/go-ethereum/rlp"
1415
"github.com/rs/zerolog/log"
1516

1617
ds "github.com/0xPolygon/polygon-cli/p2p/datastructures"
@@ -177,7 +178,14 @@ func (c *Conns) BroadcastTxs(txs types.Transactions) int {
177178
}
178179

179180
// Send as TransactionsPacket
180-
packet := eth.TransactionsPacket(unknownTxs)
181+
rawList, err := rlp.EncodeToRawList([]*types.Transaction(unknownTxs))
182+
if err != nil {
183+
cn.logger.Debug().
184+
Err(err).
185+
Msg("Failed to encode transactions")
186+
return
187+
}
188+
packet := &eth.TransactionsPacket{RawList: rawList}
181189
cn.countMsgSent(packet.Name(), float64(len(unknownTxs)))
182190
if err := ethp2p.Send(cn.rw, eth.TransactionsMsg, packet); err != nil {
183191
cn.logger.Debug().
@@ -236,7 +244,14 @@ func (c *Conns) BroadcastTxsAlways(txs types.Transactions) int {
236244
defer wg.Done()
237245

238246
// Send as TransactionsPacket
239-
packet := eth.TransactionsPacket(txs)
247+
rawList, err := rlp.EncodeToRawList([]*types.Transaction(txs))
248+
if err != nil {
249+
cn.logger.Debug().
250+
Err(err).
251+
Msg("Failed to encode transactions")
252+
return
253+
}
254+
packet := &eth.TransactionsPacket{RawList: rawList}
240255
cn.countMsgSent(packet.Name(), float64(len(txs)))
241256
if err := ethp2p.Send(cn.rw, eth.TransactionsMsg, packet); err != nil {
242257
cn.logger.Debug().

p2p/database/datastore.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -596,24 +596,33 @@ func (d *Datastore) writeBlockBody(ctx context.Context, body *eth.BlockBody, has
596596

597597
modified := false
598598

599-
if block.Transactions == nil && len(body.Transactions) > 0 {
600-
modified = true
601-
if d.shouldWriteTransactions {
602-
d.writeTransactions(ctx, body.Transactions, tfs)
603-
}
604-
605-
block.Transactions = make([]*datastore.Key, 0, len(body.Transactions))
606-
for _, tx := range body.Transactions {
607-
block.Transactions = append(block.Transactions, datastore.NameKey(TransactionsKind, tx.Hash().Hex(), nil))
599+
if block.Transactions == nil && body.Transactions.Len() > 0 {
600+
txs, err := body.Transactions.Items()
601+
if err != nil {
602+
log.Error().Err(err).Str("hash", hash.Hex()).Msg("Failed to decode transactions from block body")
603+
} else {
604+
modified = true
605+
if d.shouldWriteTransactions {
606+
d.writeTransactions(ctx, txs, tfs)
607+
}
608+
block.Transactions = make([]*datastore.Key, 0, len(txs))
609+
for _, tx := range txs {
610+
block.Transactions = append(block.Transactions, datastore.NameKey(TransactionsKind, tx.Hash().Hex(), nil))
611+
}
608612
}
609613
}
610614

611-
if block.Uncles == nil && len(body.Uncles) > 0 {
612-
modified = true
613-
block.Uncles = make([]*datastore.Key, 0, len(body.Uncles))
614-
for _, uncle := range body.Uncles {
615-
d.writeBlockHeader(ctx, uncle, tfs, false)
616-
block.Uncles = append(block.Uncles, datastore.NameKey(BlocksKind, uncle.Hash().Hex(), nil))
615+
if block.Uncles == nil && body.Uncles.Len() > 0 {
616+
uncles, err := body.Uncles.Items()
617+
if err != nil {
618+
log.Error().Err(err).Str("hash", hash.Hex()).Msg("Failed to decode uncles from block body")
619+
} else {
620+
modified = true
621+
block.Uncles = make([]*datastore.Key, 0, len(uncles))
622+
for _, uncle := range uncles {
623+
d.writeBlockHeader(ctx, uncle, tfs, false)
624+
block.Uncles = append(block.Uncles, datastore.NameKey(BlocksKind, uncle.Hash().Hex(), nil))
625+
}
617626
}
618627
}
619628

p2p/database/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ func (j *JSONDatabase) WriteBlockBody(ctx context.Context, body *eth.BlockBody,
261261
"type": "block_body",
262262
"sensor_id": j.sensorID,
263263
"hash": hash.Hex(),
264-
"tx_count": len(body.Transactions),
265-
"uncle_count": len(body.Uncles),
264+
"tx_count": body.Transactions.Len(),
265+
"uncle_count": body.Uncles.Len(),
266266
"time_first_seen": tfs,
267267
}
268268

p2p/gasprice.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ func (o *GasPriceOracle) suggestLegacyGasPrice() *big.Int {
8585
continue
8686
}
8787

88-
for _, tx := range cache.Body.Transactions {
88+
txs, err := cache.Body.Transactions.Items()
89+
if err != nil {
90+
continue
91+
}
92+
for _, tx := range txs {
8993
if price := tx.GasPrice(); price != nil && price.Sign() > 0 {
9094
prices = append(prices, new(big.Int).Set(price))
9195
}
@@ -189,8 +193,12 @@ func (o *GasPriceOracle) getBlockTips(hash common.Hash, limit int, ignoreUnder *
189193
}
190194

191195
// Calculate tips for all transactions
196+
txs, err := cache.Body.Transactions.Items()
197+
if err != nil {
198+
return nil
199+
}
192200
var allTips []*big.Int
193-
for _, tx := range cache.Body.Transactions {
201+
for _, tx := range txs {
194202
tip := effectiveGasTip(tx, baseFee)
195203
if tip != nil && tip.Sign() > 0 {
196204
allTips = append(allTips, tip)

0 commit comments

Comments
 (0)