Skip to content

Commit 47c3b9d

Browse files
AlexeyAkhunovAlexey Sharp
andauthored
Fix for RPC filters, remove mined transactions (#3142)
Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
1 parent 12b46c5 commit 47c3b9d

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

cmd/rpcdaemon/commands/eth_filters.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ func (api *APIImpl) NewPendingTransactions(ctx context.Context) (*rpc.Subscripti
9595
select {
9696
case txs := <-txsCh:
9797
for _, t := range txs {
98-
err := notifier.Notify(rpcSub.ID, t.Hash())
99-
if err != nil {
100-
log.Warn("error while notifying subscription", "err", err)
98+
if t != nil {
99+
err := notifier.Notify(rpcSub.ID, t.Hash())
100+
if err != nil {
101+
log.Warn("error while notifying subscription", "err", err)
102+
}
101103
}
102104
}
103105
case <-rpcSub.Err():

cmd/rpcdaemon/filters/filters.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,12 @@ func (ff *Filters) subscribeToPendingBlocks(ctx context.Context, mining txpool.M
222222
}
223223

224224
func (ff *Filters) HandlePendingBlock(reply *txpool.OnPendingBlockReply) {
225+
if len(reply.RplBlock) == 0 {
226+
return
227+
}
225228
b := &types.Block{}
226229
if err := rlp.Decode(bytes.NewReader(reply.RplBlock), b); err != nil {
227-
log.Warn("OnNewTx rpc filters, unprocessable payload", "err", err)
230+
log.Warn("HandlePendingBlock rpc filters, unprocessable payload", "err", err)
228231
}
229232

230233
ff.mu.Lock()
@@ -263,9 +266,12 @@ func (ff *Filters) subscribeToPendingLogs(ctx context.Context, mining txpool.Min
263266
}
264267

265268
func (ff *Filters) HandlePendingLogs(reply *txpool.OnPendingLogsReply) {
269+
if len(reply.RplLogs) == 0 {
270+
return
271+
}
266272
l := []*types.Log{}
267273
if err := rlp.Decode(bytes.NewReader(reply.RplLogs), &l); err != nil {
268-
log.Warn("OnNewTx rpc filters, unprocessable payload", "err", err)
274+
log.Warn("HandlePendingLogs rpc filters, unprocessable payload", "err", err)
269275
}
270276

271277
ff.mu.RLock()
@@ -338,6 +344,9 @@ func (ff *Filters) OnNewEvent(event *remote.SubscribeReply) {
338344
switch event.Type {
339345
case remote.Event_HEADER:
340346
payload := event.Data
347+
if len(payload) == 0 {
348+
return
349+
}
341350
var header types.Header
342351

343352
err := rlp.Decode(bytes.NewReader(payload), &header)
@@ -385,6 +394,9 @@ func (ff *Filters) OnNewTx(reply *txpool.OnAddReply) {
385394

386395
txs := make([]types.Transaction, len(reply.RplTxs))
387396
for i, rlpTx := range reply.RplTxs {
397+
if len(rlpTx) == 0 {
398+
continue
399+
}
388400
var decodeErr error
389401
s := rlp.NewStream(bytes.NewReader(rlpTx), uint64(len(rlpTx)))
390402
txs[i], decodeErr = types.DecodeTransaction(s)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/json-iterator/go v1.1.12
3737
github.com/julienschmidt/httprouter v1.3.0
3838
github.com/kevinburke/go-bindata v3.21.0+incompatible
39-
github.com/ledgerwatch/erigon-lib v0.0.0-20211216220419-44c18ee5f94a
39+
github.com/ledgerwatch/erigon-lib v0.0.0-20211217093552-7d82c6ac76e6
4040
github.com/ledgerwatch/log/v3 v3.4.0
4141
github.com/ledgerwatch/secp256k1 v1.0.0
4242
github.com/logrusorgru/aurora/v3 v3.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3P
500500
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
501501
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
502502
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
503-
github.com/ledgerwatch/erigon-lib v0.0.0-20211216220419-44c18ee5f94a h1:saAP2TrAu8ifG6CJ30GAs5ydlaUtuVSmp0xe7clejIE=
504-
github.com/ledgerwatch/erigon-lib v0.0.0-20211216220419-44c18ee5f94a/go.mod h1:lyGP3i0x4CeabdKZ4beycD5xZfHWZwJsAX+70OfGj4Y=
503+
github.com/ledgerwatch/erigon-lib v0.0.0-20211217093552-7d82c6ac76e6 h1:xXbeZ6gQLwPSNE8o6W99hZqjDGwN95fF7Q2p3zmRfAE=
504+
github.com/ledgerwatch/erigon-lib v0.0.0-20211217093552-7d82c6ac76e6/go.mod h1:lyGP3i0x4CeabdKZ4beycD5xZfHWZwJsAX+70OfGj4Y=
505505
github.com/ledgerwatch/log/v3 v3.4.0 h1:SEIOcv5a2zkG3PmoT5jeTU9m/0nEUv0BJS5bzsjwKCI=
506506
github.com/ledgerwatch/log/v3 v3.4.0/go.mod h1:VXcz6Ssn6XEeU92dCMc39/g1F0OYAjw1Mt+dGP5DjXY=
507507
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=

0 commit comments

Comments
 (0)