-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
p2p receipts #11010
Changes from 9 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
"golang.org/x/sync/semaphore" | ||
"math/rand" | ||
"sort" | ||
"sync" | ||
|
@@ -291,7 +292,8 @@ type MultiClient struct { | |
// decouple sentry multi client from header and body downloading logic is done | ||
disableBlockDownload bool | ||
|
||
logger log.Logger | ||
logger log.Logger | ||
onlyOneGoroutineController *semaphore.Weighted | ||
} | ||
|
||
func NewMultiClient( | ||
|
@@ -356,6 +358,7 @@ func NewMultiClient( | |
maxBlockBroadcastPeers: maxBlockBroadcastPeers, | ||
disableBlockDownload: disableBlockDownload, | ||
logger: logger, | ||
onlyOneGoroutineController: semaphore.NewWeighted(1), | ||
} | ||
|
||
return cs, nil | ||
|
@@ -697,44 +700,49 @@ func (cs *MultiClient) getBlockBodies66(ctx context.Context, inreq *proto_sentry | |
} | ||
|
||
func (cs *MultiClient) getReceipts66(ctx context.Context, inreq *proto_sentry.InboundMessage, sentry direct.SentryClient) error { | ||
return nil //TODO: https://github.com/ledgerwatch/erigon/issues/10320 | ||
//var query eth.GetReceiptsPacket66 | ||
//if err := rlp.DecodeBytes(inreq.Data, &query); err != nil { | ||
// return fmt.Errorf("decoding getReceipts66: %w, data: %x", err, inreq.Data) | ||
//} | ||
//tx, err := cs.db.BeginRo(ctx) | ||
//if err != nil { | ||
// return err | ||
//} | ||
//defer tx.Rollback() | ||
//receipts, err := eth.AnswerGetReceiptsQuery(cs.blockReader, tx, query.GetReceiptsPacket) | ||
//if err != nil { | ||
// return err | ||
//} | ||
//tx.Rollback() | ||
//b, err := rlp.EncodeToBytes(ð.ReceiptsRLPPacket66{ | ||
// RequestId: query.RequestId, | ||
// ReceiptsRLPPacket: receipts, | ||
//}) | ||
//if err != nil { | ||
// return fmt.Errorf("encode header response: %w", err) | ||
//} | ||
//outreq := proto_sentry.SendMessageByIdRequest{ | ||
// PeerId: inreq.PeerId, | ||
// Data: &proto_sentry.OutboundMessageData{ | ||
// Id: proto_sentry.MessageId_RECEIPTS_66, | ||
// Data: b, | ||
// }, | ||
//} | ||
//_, err = sentry.SendMessageById(ctx, &outreq, &grpc.EmptyCallOption{}) | ||
//if err != nil { | ||
// if isPeerNotFoundErr(err) { | ||
// return nil | ||
// } | ||
// return fmt.Errorf("send bodies response: %w", err) | ||
//} | ||
////cs.logger.Info(fmt.Sprintf("[%s] GetReceipts responseLen %d", ConvertH512ToPeerID(inreq.PeerId), len(b))) | ||
//return nil | ||
err := cs.onlyOneGoroutineController.Acquire(ctx, 1) | ||
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.
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 |
||
if err != nil { | ||
return err | ||
} | ||
defer cs.onlyOneGoroutineController.Release(1) | ||
var query eth.GetReceiptsPacket66 | ||
if err := rlp.DecodeBytes(inreq.Data, &query); err != nil { | ||
return fmt.Errorf("decoding getReceipts66: %w, data: %x", err, inreq.Data) | ||
} | ||
|
||
tx, err := cs.db.BeginRo(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer tx.Rollback() | ||
receipts, err := eth.AnswerGetReceiptsQuery(ctx, cs.blockReader, tx, query.GetReceiptsPacket, cs.ChainConfig, cs.Engine) | ||
if err != nil { | ||
return err | ||
} | ||
tx.Rollback() | ||
b, err := rlp.EncodeToBytes(ð.ReceiptsRLPPacket66{ | ||
RequestId: query.RequestId, | ||
ReceiptsRLPPacket: receipts, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("encode header response: %w", err) | ||
} | ||
outreq := proto_sentry.SendMessageByIdRequest{ | ||
PeerId: inreq.PeerId, | ||
Data: &proto_sentry.OutboundMessageData{ | ||
Id: proto_sentry.MessageId_RECEIPTS_66, | ||
Data: b, | ||
}, | ||
} | ||
_, err = sentry.SendMessageById(ctx, &outreq, &grpc.EmptyCallOption{}) | ||
if err != nil { | ||
if isPeerNotFoundErr(err) { | ||
return nil | ||
} | ||
return fmt.Errorf("send bodies response: %w", err) | ||
} | ||
//cs.logger.Info(fmt.Sprintf("[%s] GetReceipts responseLen %d", ConvertH512ToPeerID(inreq.PeerId), len(b))) | ||
return nil | ||
} | ||
|
||
func MakeInboundMessage() *proto_sentry.InboundMessage { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,14 @@ import ( | |
"encoding/binary" | ||
"errors" | ||
"fmt" | ||
proto_sentry "github.com/ledgerwatch/erigon-lib/gointerfaces/sentryproto" | ||
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. enable imports auto-sort in IDE pls |
||
"github.com/ledgerwatch/erigon/eth/protocols/eth" | ||
"github.com/ledgerwatch/erigon/rlp" | ||
"math" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ledgerwatch/erigon-lib/common/hexutil" | ||
"github.com/ledgerwatch/erigon-lib/config3" | ||
"github.com/ledgerwatch/erigon-lib/log/v3" | ||
|
||
"github.com/holiman/uint256" | ||
|
@@ -319,10 +321,6 @@ func testReorgShort(t *testing.T) { | |
} | ||
|
||
func testReorg(t *testing.T, first, second []int64, td int64) { | ||
if config3.EnableHistoryV4InTest { | ||
t.Skip("TODO: [e4] implement me") | ||
} | ||
|
||
require := require.New(t) | ||
// Create a pristine chain and database | ||
m := newCanonical(t, 0) | ||
|
@@ -359,7 +357,11 @@ func testReorg(t *testing.T, first, second []int64, td int64) { | |
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
hashPacket := make([]libcommon.Hash, 0) | ||
|
||
for block.NumberU64() != 0 { | ||
hashPacket = append(hashPacket, block.Hash()) | ||
if prev.ParentHash() != block.Hash() { | ||
t.Errorf("parent block hash mismatch: have %x, want %x", prev.ParentHash(), block.Hash()) | ||
} | ||
|
@@ -369,6 +371,24 @@ func testReorg(t *testing.T, first, second []int64, td int64) { | |
t.Fatal(err) | ||
} | ||
} | ||
|
||
b, err := rlp.EncodeToBytes(ð.GetReceiptsPacket66{ | ||
RequestId: 1, | ||
GetReceiptsPacket: hashPacket, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
m.ReceiveWg.Add(1) | ||
for _, err = range m.Send(&proto_sentry.InboundMessage{Id: proto_sentry.MessageId_GET_RECEIPTS_66, Data: b, PeerId: m.PeerId}) { | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
m.ReceiveWg.Wait() | ||
|
||
// Make sure the chain total difficulty is the correct one | ||
want := new(big.Int).Add(m.Genesis.Difficulty(), big.NewInt(td)) | ||
have, err := rawdb.ReadTdByHash(tx, rawdb.ReadCurrentHeader(tx).Hash()) | ||
|
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.
seems this optimization lost. maybe move it inside generator
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.
done but not in generator because it's query response optimization, not receipt