Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

txpool: batch IdHashKnown calls - to reduce amount of mutex lock/unlock. less string(byte) casts #1128

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gointerfaces/downloader/downloader.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/downloader/downloader_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/execution/execution.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/execution/execution_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/remote/ethbackend.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/remote/ethbackend_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/remote/kv.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/remote/kv_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions gointerfaces/remote/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/sentinel/sentinel.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/sentinel/sentinel_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/sentry/sentry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/sentry/sentry_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/txpool/mining.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/txpool/mining_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/txpool/txpool.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gointerfaces/txpool/txpool_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gointerfaces/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 14 additions & 22 deletions txpool/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,15 @@ func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMes
if err != nil {
return fmt.Errorf("parsing NewPooledTransactionHashes: %w", err)
}
var hashbuf [32]byte
var unknownHashes types2.Hashes
for i := 0; i < hashCount; i++ {
_, pos, err = types2.ParseHash(req.Data, pos, hashbuf[:0])
if err != nil {
return fmt.Errorf("parsing NewPooledTransactionHashes: %w", err)
}
known, err := f.pool.IdHashKnown(tx, hashbuf[:])
if err != nil {
hashes := make([]byte, 32*hashCount)
for i := 0; i < len(hashes); i += 32 {
if _, pos, err = types2.ParseHash(req.Data, pos, hashes[i:]); err != nil {
return err
}
if !known {
unknownHashes = append(unknownHashes, hashbuf[:]...)
}
}
unknownHashes, err := f.pool.FilterKnownIdHashes(tx, hashes)
if err != nil {
return err
}
if len(unknownHashes) > 0 {
var encodedRequest []byte
Expand All @@ -256,15 +251,9 @@ func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMes
if err != nil {
return fmt.Errorf("parsing NewPooledTransactionHashes88: %w", err)
}
var unknownHashes types2.Hashes
for i := 0; i < len(hashes); i += 32 {
known, err := f.pool.IdHashKnown(tx, hashes[i:i+32])
if err != nil {
return err
}
if !known {
unknownHashes = append(unknownHashes, hashes[i:i+32]...)
}
unknownHashes, err := f.pool.FilterKnownIdHashes(tx, hashes)
if err != nil {
return err
}

if len(unknownHashes) > 0 {
Expand Down Expand Up @@ -482,7 +471,10 @@ func (f *Fetch) handleStateChanges(ctx context.Context, client StateChangesClien
if err = f.threadSafeParseStateChangeTxn(func(parseContext *types2.TxParseContext) error {
_, err = parseContext.ParseTransaction(change.Txs[i], 0, unwindTxs.Txs[i], unwindTxs.Senders.At(i), false /* hasEnvelope */, false /* wrappedWithBlobs */, nil)
if unwindTxs.Txs[i].Type == types2.BlobTxType {
knownBlobTxn := f.pool.GetKnownBlobTxn(tx, unwindTxs.Txs[i].IDHash[:])
knownBlobTxn, err := f.pool.GetKnownBlobTxn(tx, unwindTxs.Txs[i].IDHash[:])
if err != nil {
return err
}
if knownBlobTxn != nil {
unwindTxs.Txs[i] = knownBlobTxn.Tx
}
Expand Down
Loading
Loading