-
Notifications
You must be signed in to change notification settings - Fork 1.5k
p2p receipts #11010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p receipts #11010
Changes from 31 commits
eea467a
9ff21c9
35a3f1f
f05ba60
28274e1
c917eb0
cf7fc0b
132d101
ddc0aae
7cf43ac
61ea076
894855e
c965d3f
f5740fe
9f1bb35
e879bd8
6072d54
8604911
490c1a8
0d23573
625a62c
d7c5fff
e25c4ec
ba044f6
74ab518
2107f89
6d3b7da
b632521
68b09d5
b2c0f15
0620327
7bd5c20
7626b76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,6 @@ func (f *Fetch) receiveMessageLoop(sentryClient sentry.SentryClient) { | |
| f.logger.Warn("[txpool.recvMessage] sentry not ready yet", "err", err) | ||
| continue | ||
| } | ||
|
|
||
| if err := f.receiveMessage(f.ctx, sentryClient); err != nil { | ||
| if grpcutil.IsRetryLater(err) || grpcutil.IsEndOfStream(err) { | ||
| time.Sleep(3 * time.Second) | ||
|
|
@@ -175,10 +174,10 @@ func (f *Fetch) receiveMessage(ctx context.Context, sentryClient sentry.SentryCl | |
| } | ||
| return err | ||
| } | ||
|
|
||
| var req *sentry.InboundMessage | ||
| for req, err = stream.Recv(); ; req, err = stream.Recv() { | ||
| if err != nil { | ||
| f.logger.Debug("[txpool.receiveMessage]", "err", err) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also: I understand why need log error which we not return. But if we return - then it's job of caller to log it (otherwise we may log same thing multiple times).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return wrapped error instead of logging |
||
| select { | ||
| case <-f.ctx.Done(): | ||
| return ctx.Err() | ||
|
|
@@ -187,14 +186,15 @@ func (f *Fetch) receiveMessage(ctx context.Context, sentryClient sentry.SentryCl | |
| return err | ||
| } | ||
| if req == nil { | ||
| f.logger.Warn("[txpool.receiveMessage]", "req nil") | ||
| return nil | ||
| } | ||
| if err := f.handleInboundMessage(streamCtx, req, sentryClient); err != nil { | ||
| if grpcutil.IsRetryLater(err) || grpcutil.IsEndOfStream(err) { | ||
| time.Sleep(3 * time.Second) | ||
| continue | ||
| } | ||
| f.logger.Debug("[txpool.fetch] Handling incoming message", "msg", req.Id.String(), "err", err) | ||
| f.logger.Debug("[txpool.fetch] Handling incoming message", "msg", string(req.Data), "reqID", req.Id.String(), "err", err) | ||
| } | ||
| if f.wg != nil { | ||
| f.wg.Done() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,10 @@ package eth | |
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/ledgerwatch/erigon-lib/chain" | ||
| libcommon "github.com/ledgerwatch/erigon-lib/common" | ||
| "github.com/ledgerwatch/erigon-lib/kv" | ||
| "github.com/ledgerwatch/erigon-lib/log/v3" | ||
|
|
||
| "github.com/ledgerwatch/erigon/common" | ||
| "github.com/ledgerwatch/erigon/core/rawdb" | ||
| "github.com/ledgerwatch/erigon/core/types" | ||
|
|
@@ -160,12 +159,17 @@ func AnswerGetBlockBodiesQuery(db kv.Tx, query GetBlockBodiesPacket, blockReader | |
| return bodies | ||
| } | ||
|
|
||
| func AnswerGetReceiptsQuery(br services.FullBlockReader, db kv.Tx, query GetReceiptsPacket) ([]rlp.RawValue, error) { //nolint:unparam | ||
| type ReceiptsGetter interface { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in an another file |
||
| GetReceipts(ctx context.Context, cfg *chain.Config, tx kv.Tx, block *types.Block, senders []libcommon.Address) (types.Receipts, error) | ||
| } | ||
|
|
||
| func AnswerGetReceiptsQuery(ctx context.Context, cfg *chain.Config, receiptsGetter ReceiptsGetter, br services.FullBlockReader, db kv.Tx, query GetReceiptsPacket) ([]rlp.RawValue, error) { //nolint:unparam | ||
| // Gather state data until the fetch or network limits is reached | ||
| var ( | ||
| bytes int | ||
| receipts []rlp.RawValue | ||
| ) | ||
|
|
||
| for lookups, hash := range query { | ||
| if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe || | ||
| lookups >= 2*maxReceiptsServe { | ||
|
|
@@ -183,7 +187,12 @@ func AnswerGetReceiptsQuery(br services.FullBlockReader, db kv.Tx, query GetRece | |
| if b == nil { | ||
| return nil, nil | ||
| } | ||
| results := rawdb.ReadReceipts(db, b, s) | ||
|
|
||
| results, err := receiptsGetter.GetReceipts(ctx, cfg, db, b, s) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if results == nil { | ||
| header, err := rawdb.ReadHeaderByHash(db, hash) | ||
| if err != nil { | ||
|
|
@@ -193,6 +202,12 @@ func AnswerGetReceiptsQuery(br services.FullBlockReader, db kv.Tx, query GetRece | |
| continue | ||
| } | ||
| } | ||
| // For debug | ||
| //println("receipts:") | ||
| //for _, result := range results { | ||
| // println(result.String()) | ||
| //} | ||
|
|
||
| // If known, encode and queue for response packet | ||
| if encoded, err := rlp.EncodeToBytes(results); err != nil { | ||
| return nil, fmt.Errorf("failed to encode receipt: %w", err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason to log ctx cancelation.
for example if node shutting-down by Ctrl+C - it's not an error, but expected behavior.
let's move under
selector let's useerrors.Is(context.Canceled)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return wrapped error instead of logging